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