Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 1 | /* |
| 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 Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 19 | #include "dex_file-inl.h" |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 20 | #include "interpreter/interpreter.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | #include "mirror/abstract_method-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 22 | #include "mirror/class-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 23 | #include "mirror/object-inl.h" |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 24 | #include "mirror/object_array-inl.h" |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 25 | #include "object_utils.h" |
| 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | // Visits arguments on the stack placing them into the shadow frame. |
Jeff Hao | 5fa60c3 | 2013-04-04 17:57:01 -0700 | [diff] [blame] | 30 | class BuildShadowFrameVisitor : public QuickArgumentVisitor { |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 31 | public: |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 32 | BuildShadowFrameVisitor(MethodHelper& caller_mh, mirror::AbstractMethod** sp, |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 33 | ShadowFrame& sf, size_t first_arg_reg) : |
Jeff Hao | 5fa60c3 | 2013-04-04 17:57:01 -0700 | [diff] [blame] | 34 | QuickArgumentVisitor(caller_mh, sp), sf_(sf), cur_reg_(first_arg_reg) {} |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 35 | |
| 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 Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 46 | ++cur_reg_; |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 47 | break; |
| 48 | case Primitive::kPrimNot: |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 49 | sf_.SetVRegReference(cur_reg_, *reinterpret_cast<mirror::Object**>(GetParamAddress())); |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 50 | 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 Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 73 | extern "C" uint64_t artInterpreterEntry(mirror::AbstractMethod* method, Thread* self, |
| 74 | mirror::AbstractMethod** sp) |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 75 | 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 Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 94 | |
| 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 Hertz | a7b0c42 | 2013-04-05 16:19:39 +0200 | [diff] [blame] | 100 | self->PopManagedStackFragment(fragment); |
Ian Rogers | f3e9855 | 2013-03-20 15:49:49 -0700 | [diff] [blame] | 101 | return 0; |
| 102 | } |
| 103 | } |
| 104 | |
Ian Rogers | 7db619b | 2013-01-16 18:35:48 -0800 | [diff] [blame] | 105 | 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 |