blob: a02ef2719aa9977fd3abdc934728a853197ffa31 [file] [log] [blame]
Ian Rogers7db619b2013-01-16 18:35:48 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "argument_visitor.h"
18#include "callee_save_frame.h"
19#include "interpreter/interpreter.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080020#include "mirror/abstract_method-inl.h"
21#include "mirror/object.h"
22#include "mirror/object_array-inl.h"
Ian Rogers7db619b2013-01-16 18:35:48 -080023#include "object_utils.h"
24
25namespace art {
26
27// Visits arguments on the stack placing them into the shadow frame.
28class BuildShadowFrameVisitor : public ArgumentVisitor {
29 public:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030 BuildShadowFrameVisitor(MethodHelper& caller_mh, mirror::AbstractMethod** sp,
Ian Rogers7db619b2013-01-16 18:35:48 -080031 ShadowFrame& sf, size_t first_arg_reg) :
32 ArgumentVisitor(caller_mh, sp), sf_(sf), cur_reg_(first_arg_reg) {}
33
34 virtual void Visit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
35 Primitive::Type type = GetParamPrimitiveType();
36 switch (type) {
37 case Primitive::kPrimLong: // Fall-through.
38 case Primitive::kPrimDouble:
39 if (IsSplitLongOrDouble()) {
40 sf_.SetVRegLong(cur_reg_, ReadSplitLongParam());
41 } else {
42 sf_.SetVRegLong(cur_reg_, *reinterpret_cast<jlong*>(GetParamAddress()));
43 }
44 break;
45 case Primitive::kPrimNot:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080046 sf_.SetVRegReference(cur_reg_, *reinterpret_cast<mirror::Object**>(GetParamAddress()));
Ian Rogers7db619b2013-01-16 18:35:48 -080047 break;
48 case Primitive::kPrimBoolean: // Fall-through.
49 case Primitive::kPrimByte: // Fall-through.
50 case Primitive::kPrimChar: // Fall-through.
51 case Primitive::kPrimShort: // Fall-through.
52 case Primitive::kPrimInt: // Fall-through.
53 case Primitive::kPrimFloat:
54 sf_.SetVReg(cur_reg_, *reinterpret_cast<jint*>(GetParamAddress()));
55 break;
56 case Primitive::kPrimVoid:
57 LOG(FATAL) << "UNREACHABLE";
58 break;
59 }
60 ++cur_reg_;
61 }
62
63 private:
64 ShadowFrame& sf_;
65 size_t cur_reg_;
66
67 DISALLOW_COPY_AND_ASSIGN(BuildShadowFrameVisitor);
68};
69
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080070extern "C" uint64_t artInterpreterEntry(mirror::AbstractMethod* method, Thread* self,
71 mirror::AbstractMethod** sp)
Ian Rogers7db619b2013-01-16 18:35:48 -080072 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
73 // Ensure we don't get thread suspension until the object arguments are safely in the shadow
74 // frame.
75 const char* old_cause = self->StartAssertNoThreadSuspension("Building interpreter shadow frame");
76 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
77
78 MethodHelper mh(method);
79 const DexFile::CodeItem* code_item = mh.GetCodeItem();
80 UniquePtr<ShadowFrame> shadow_frame(ShadowFrame::Create(code_item->registers_size_,
81 NULL, // No last shadow coming from quick.
82 method, 0));
83 size_t first_arg_reg = code_item->registers_size_ - code_item->ins_size_;
84 BuildShadowFrameVisitor shadow_frame_builder(mh, sp, *shadow_frame.get(), first_arg_reg);
85 shadow_frame_builder.VisitArguments();
86 // Push a transition back into managed code onto the linked list in thread.
87 ManagedStack fragment;
88 self->PushManagedStackFragment(&fragment);
89 self->PushShadowFrame(shadow_frame.get());
90 self->EndAssertNoThreadSuspension(old_cause);
91 JValue result = interpreter::EnterInterpreterFromStub(self, mh, code_item, *shadow_frame.get());
92 // Pop transition.
93 self->PopManagedStackFragment(fragment);
94 return result.GetJ();
95}
96
97} // namespace art