blob: 98751cc7c5ec887510252bbcc4c8f89ecee9abe8 [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"
20#include "object.h"
21#include "object_utils.h"
22
23namespace art {
24
25// Visits arguments on the stack placing them into the shadow frame.
26class BuildShadowFrameVisitor : public ArgumentVisitor {
27 public:
28 BuildShadowFrameVisitor(MethodHelper& caller_mh, AbstractMethod** sp,
29 ShadowFrame& sf, size_t first_arg_reg) :
30 ArgumentVisitor(caller_mh, sp), sf_(sf), cur_reg_(first_arg_reg) {}
31
32 virtual void Visit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
33 Primitive::Type type = GetParamPrimitiveType();
34 switch (type) {
35 case Primitive::kPrimLong: // Fall-through.
36 case Primitive::kPrimDouble:
37 if (IsSplitLongOrDouble()) {
38 sf_.SetVRegLong(cur_reg_, ReadSplitLongParam());
39 } else {
40 sf_.SetVRegLong(cur_reg_, *reinterpret_cast<jlong*>(GetParamAddress()));
41 }
42 break;
43 case Primitive::kPrimNot:
44 sf_.SetVRegReference(cur_reg_, *reinterpret_cast<Object**>(GetParamAddress()));
45 break;
46 case Primitive::kPrimBoolean: // Fall-through.
47 case Primitive::kPrimByte: // Fall-through.
48 case Primitive::kPrimChar: // Fall-through.
49 case Primitive::kPrimShort: // Fall-through.
50 case Primitive::kPrimInt: // Fall-through.
51 case Primitive::kPrimFloat:
52 sf_.SetVReg(cur_reg_, *reinterpret_cast<jint*>(GetParamAddress()));
53 break;
54 case Primitive::kPrimVoid:
55 LOG(FATAL) << "UNREACHABLE";
56 break;
57 }
58 ++cur_reg_;
59 }
60
61 private:
62 ShadowFrame& sf_;
63 size_t cur_reg_;
64
65 DISALLOW_COPY_AND_ASSIGN(BuildShadowFrameVisitor);
66};
67
68extern "C" uint64_t artInterpreterEntry(AbstractMethod* method, Thread* self, AbstractMethod** sp)
69 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
70 // Ensure we don't get thread suspension until the object arguments are safely in the shadow
71 // frame.
72 const char* old_cause = self->StartAssertNoThreadSuspension("Building interpreter shadow frame");
73 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
74
75 MethodHelper mh(method);
76 const DexFile::CodeItem* code_item = mh.GetCodeItem();
77 UniquePtr<ShadowFrame> shadow_frame(ShadowFrame::Create(code_item->registers_size_,
78 NULL, // No last shadow coming from quick.
79 method, 0));
80 size_t first_arg_reg = code_item->registers_size_ - code_item->ins_size_;
81 BuildShadowFrameVisitor shadow_frame_builder(mh, sp, *shadow_frame.get(), first_arg_reg);
82 shadow_frame_builder.VisitArguments();
83 // Push a transition back into managed code onto the linked list in thread.
84 ManagedStack fragment;
85 self->PushManagedStackFragment(&fragment);
86 self->PushShadowFrame(shadow_frame.get());
87 self->EndAssertNoThreadSuspension(old_cause);
88 JValue result = interpreter::EnterInterpreterFromStub(self, mh, code_item, *shadow_frame.get());
89 // Pop transition.
90 self->PopManagedStackFragment(fragment);
91 return result.GetJ();
92}
93
94} // namespace art