blob: 3ab234fecf6c7a4f1f7d90d5df674657dd826c71 [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"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070019#include "dex_file-inl.h"
Ian Rogers7db619b2013-01-16 18:35:48 -080020#include "interpreter/interpreter.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "mirror/abstract_method-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070022#include "mirror/class-inl.h"
Ian Rogers4f6ad8a2013-03-18 15:27:28 -070023#include "mirror/object-inl.h"
Ian Rogersf3e98552013-03-20 15:49:49 -070024#include "mirror/object_array-inl.h"
Ian Rogers7db619b2013-01-16 18:35:48 -080025#include "object_utils.h"
26
27namespace art {
28
29// Visits arguments on the stack placing them into the shadow frame.
Jeff Hao5fa60c32013-04-04 17:57:01 -070030class BuildShadowFrameVisitor : public QuickArgumentVisitor {
Ian Rogers7db619b2013-01-16 18:35:48 -080031 public:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032 BuildShadowFrameVisitor(MethodHelper& caller_mh, mirror::AbstractMethod** sp,
Ian Rogers7db619b2013-01-16 18:35:48 -080033 ShadowFrame& sf, size_t first_arg_reg) :
Jeff Hao5fa60c32013-04-04 17:57:01 -070034 QuickArgumentVisitor(caller_mh, sp), sf_(sf), cur_reg_(first_arg_reg) {}
Ian Rogers7db619b2013-01-16 18:35:48 -080035
36 virtual void Visit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
37 Primitive::Type type = GetParamPrimitiveType();
38 switch (type) {
39 case Primitive::kPrimLong: // Fall-through.
40 case Primitive::kPrimDouble:
41 if (IsSplitLongOrDouble()) {
42 sf_.SetVRegLong(cur_reg_, ReadSplitLongParam());
43 } else {
44 sf_.SetVRegLong(cur_reg_, *reinterpret_cast<jlong*>(GetParamAddress()));
45 }
Ian Rogersf3e98552013-03-20 15:49:49 -070046 ++cur_reg_;
Ian Rogers7db619b2013-01-16 18:35:48 -080047 break;
48 case Primitive::kPrimNot:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049 sf_.SetVRegReference(cur_reg_, *reinterpret_cast<mirror::Object**>(GetParamAddress()));
Ian Rogers7db619b2013-01-16 18:35:48 -080050 break;
51 case Primitive::kPrimBoolean: // Fall-through.
52 case Primitive::kPrimByte: // Fall-through.
53 case Primitive::kPrimChar: // Fall-through.
54 case Primitive::kPrimShort: // Fall-through.
55 case Primitive::kPrimInt: // Fall-through.
56 case Primitive::kPrimFloat:
57 sf_.SetVReg(cur_reg_, *reinterpret_cast<jint*>(GetParamAddress()));
58 break;
59 case Primitive::kPrimVoid:
60 LOG(FATAL) << "UNREACHABLE";
61 break;
62 }
63 ++cur_reg_;
64 }
65
66 private:
67 ShadowFrame& sf_;
68 size_t cur_reg_;
69
70 DISALLOW_COPY_AND_ASSIGN(BuildShadowFrameVisitor);
71};
72
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073extern "C" uint64_t artInterpreterEntry(mirror::AbstractMethod* method, Thread* self,
74 mirror::AbstractMethod** sp)
Ian Rogers7db619b2013-01-16 18:35:48 -080075 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
76 // Ensure we don't get thread suspension until the object arguments are safely in the shadow
77 // frame.
78 const char* old_cause = self->StartAssertNoThreadSuspension("Building interpreter shadow frame");
79 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
80
81 MethodHelper mh(method);
82 const DexFile::CodeItem* code_item = mh.GetCodeItem();
83 UniquePtr<ShadowFrame> shadow_frame(ShadowFrame::Create(code_item->registers_size_,
84 NULL, // No last shadow coming from quick.
85 method, 0));
86 size_t first_arg_reg = code_item->registers_size_ - code_item->ins_size_;
87 BuildShadowFrameVisitor shadow_frame_builder(mh, sp, *shadow_frame.get(), first_arg_reg);
88 shadow_frame_builder.VisitArguments();
89 // Push a transition back into managed code onto the linked list in thread.
90 ManagedStack fragment;
91 self->PushManagedStackFragment(&fragment);
92 self->PushShadowFrame(shadow_frame.get());
93 self->EndAssertNoThreadSuspension(old_cause);
Ian Rogersf3e98552013-03-20 15:49:49 -070094
95 if (method->IsStatic() && !method->GetDeclaringClass()->IsInitializing()) {
96 // Ensure static method's class is initialized.
97 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(method->GetDeclaringClass(),
98 true, true)) {
99 DCHECK(Thread::Current()->IsExceptionPending());
Sebastien Hertza7b0c422013-04-05 16:19:39 +0200100 self->PopManagedStackFragment(fragment);
Ian Rogersf3e98552013-03-20 15:49:49 -0700101 return 0;
102 }
103 }
104
Ian Rogers7db619b2013-01-16 18:35:48 -0800105 JValue result = interpreter::EnterInterpreterFromStub(self, mh, code_item, *shadow_frame.get());
106 // Pop transition.
107 self->PopManagedStackFragment(fragment);
108 return result.GetJ();
109}
110
111} // namespace art