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
artInstrumentationMethodEntryFromCode(ArtMethod * method,mirror::Object * this_object,Thread * self,uintptr_t lr)27 extern "C" const void* artInstrumentationMethodEntryFromCode(ArtMethod* method,
28 mirror::Object* this_object,
29 Thread* self,
30 uintptr_t lr)
31 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
32 ScopedQuickEntrypointChecks sqec(self);
33 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
34 const void* result;
35 if (instrumentation->IsDeoptimized(method)) {
36 result = GetQuickToInterpreterBridge();
37 } else {
38 result = instrumentation->GetQuickCodeFor(method, sizeof(void*));
39 DCHECK(!Runtime::Current()->GetClassLinker()->IsQuickToInterpreterBridge(result));
40 }
41 bool interpreter_entry = (result == GetQuickToInterpreterBridge());
42 instrumentation->PushInstrumentationStackFrame(self, method->IsStatic() ? nullptr : this_object,
43 method, lr, interpreter_entry);
44 CHECK(result != nullptr) << PrettyMethod(method);
45 return result;
46 }
47
artInstrumentationMethodExitFromCode(Thread * self,ArtMethod ** sp,uint64_t gpr_result,uint64_t fpr_result)48 extern "C" TwoWordReturn artInstrumentationMethodExitFromCode(Thread* self, ArtMethod** sp,
49 uint64_t gpr_result,
50 uint64_t fpr_result)
51 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
52 // Compute address of return PC and sanity check that it currently holds 0.
53 size_t return_pc_offset = GetCalleeSaveReturnPcOffset(kRuntimeISA, Runtime::kRefsOnly);
54 uintptr_t* return_pc = reinterpret_cast<uintptr_t*>(reinterpret_cast<uint8_t*>(sp) +
55 return_pc_offset);
56 CHECK_EQ(*return_pc, 0U);
57
58 // Pop the frame filling in the return pc. The low half of the return value is 0 when
59 // deoptimization shouldn't be performed with the high-half having the return address. When
60 // deoptimization should be performed the low half is zero and the high-half the address of the
61 // deoptimization entry point.
62 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
63 TwoWordReturn return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame(
64 self, return_pc, gpr_result, fpr_result);
65 return return_or_deoptimize_pc;
66 }
67
68 } // namespace art
69