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 "callee_save_frame.h"
18 #include "instrumentation.h"
19 #include "mirror/art_method-inl.h"
20 #include "mirror/object-inl.h"
21 #include "runtime.h"
22 #include "thread-inl.h"
23
24 namespace art {
25
artInstrumentationMethodEntryFromCode(mirror::ArtMethod * method,mirror::Object * this_object,Thread * self,mirror::ArtMethod ** sp,uintptr_t lr)26 extern "C" const void* artInstrumentationMethodEntryFromCode(mirror::ArtMethod* method,
27 mirror::Object* this_object,
28 Thread* self,
29 mirror::ArtMethod** sp,
30 uintptr_t lr)
31 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
32 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsAndArgs);
33 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
34 const void* result = instrumentation->GetQuickCodeFor(method);
35 bool interpreter_entry = (result == GetQuickToInterpreterBridge());
36 instrumentation->PushInstrumentationStackFrame(self, method->IsStatic() ? NULL : this_object,
37 method, lr, interpreter_entry);
38 CHECK(result != NULL) << PrettyMethod(method);
39 return result;
40 }
41
artInstrumentationMethodExitFromCode(Thread * self,mirror::ArtMethod ** sp,uint64_t gpr_result,uint64_t fpr_result)42 extern "C" uint64_t artInstrumentationMethodExitFromCode(Thread* self, mirror::ArtMethod** sp,
43 uint64_t gpr_result, uint64_t fpr_result)
44 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
45 // TODO: use FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly) not the hand inlined below.
46 // We use the hand inline version to ensure the return_pc is assigned before verifying the
47 // stack.
48 // Be aware the store below may well stomp on an incoming argument.
49 Locks::mutator_lock_->AssertSharedHeld(self);
50 mirror::ArtMethod* callee_save = Runtime::Current()->GetCalleeSaveMethod(Runtime::kRefsOnly);
51 *sp = callee_save;
52 uintptr_t* return_pc = reinterpret_cast<uintptr_t*>(reinterpret_cast<byte*>(sp) +
53 callee_save->GetReturnPcOffsetInBytes());
54 CHECK_EQ(*return_pc, 0U);
55 self->SetTopOfStack(sp, 0);
56 self->VerifyStack();
57 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
58 uint64_t return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame(self, return_pc,
59 gpr_result,
60 fpr_result);
61 self->VerifyStack();
62 return return_or_deoptimize_pc;
63 }
64
65 } // namespace art
66