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 "art_method-inl.h" 18 #include "callee_save_frame.h" 19 #include "entrypoints/runtime_asm_entrypoints.h" 20 #include "instrumentation.h" 21 #include "mirror/object-inl.h" 22 #include "runtime.h" 23 #include "thread-inl.h" 24 25 namespace art { 26 27 extern "C" const void* artInstrumentationMethodEntryFromCode(ArtMethod* method, 28 mirror::Object* this_object, 29 Thread* self, 30 uintptr_t lr) 31 SHARED_REQUIRES(Locks::mutator_lock_) { 32 // Instrumentation changes the stack. Thus, when exiting, the stack cannot be verified, so skip 33 // that part. 34 ScopedQuickEntrypointChecks sqec(self, kIsDebugBuild, false); 35 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); 36 const void* result; 37 if (instrumentation->IsDeoptimized(method)) { 38 result = GetQuickToInterpreterBridge(); 39 } else { 40 result = instrumentation->GetQuickCodeFor(method, sizeof(void*)); 41 DCHECK(!Runtime::Current()->GetClassLinker()->IsQuickToInterpreterBridge(result)); 42 } 43 bool interpreter_entry = (result == GetQuickToInterpreterBridge()); 44 instrumentation->PushInstrumentationStackFrame(self, method->IsStatic() ? nullptr : this_object, 45 method, lr, interpreter_entry); 46 CHECK(result != nullptr) << PrettyMethod(method); 47 return result; 48 } 49 50 extern "C" TwoWordReturn artInstrumentationMethodExitFromCode(Thread* self, ArtMethod** sp, 51 uint64_t gpr_result, 52 uint64_t fpr_result) 53 SHARED_REQUIRES(Locks::mutator_lock_) { 54 // Instrumentation exit stub must not be entered with a pending exception. 55 CHECK(!self->IsExceptionPending()) << "Enter instrumentation exit stub with pending exception " 56 << self->GetException()->Dump(); 57 // Compute address of return PC and sanity check that it currently holds 0. 58 size_t return_pc_offset = GetCalleeSaveReturnPcOffset(kRuntimeISA, Runtime::kRefsOnly); 59 uintptr_t* return_pc = reinterpret_cast<uintptr_t*>(reinterpret_cast<uint8_t*>(sp) + 60 return_pc_offset); 61 CHECK_EQ(*return_pc, 0U); 62 63 // Pop the frame filling in the return pc. The low half of the return value is 0 when 64 // deoptimization shouldn't be performed with the high-half having the return address. When 65 // deoptimization should be performed the low half is zero and the high-half the address of the 66 // deoptimization entry point. 67 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); 68 TwoWordReturn return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame( 69 self, return_pc, gpr_result, fpr_result); 70 return return_or_deoptimize_pc; 71 } 72 73 } // namespace art 74