blob: 8e660a246d1a356e60b40dec764c6632c603cd6e [file] [log] [blame]
jeffhao725a9572012-11-13 18:20:12 -08001/*
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
Mathieu Chartiere401d142015-04-22 13:56:20 -070017#include "art_method-inl.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080018#include "callee_save_frame.h"
Ian Rogers6f3dbba2014-10-14 17:41:57 -070019#include "entrypoints/runtime_asm_entrypoints.h"
jeffhao725a9572012-11-13 18:20:12 -080020#include "instrumentation.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080021#include "mirror/object-inl.h"
jeffhao725a9572012-11-13 18:20:12 -080022#include "runtime.h"
Ian Rogers04d7aa92013-03-16 14:29:17 -070023#include "thread-inl.h"
jeffhao725a9572012-11-13 18:20:12 -080024
25namespace art {
26
Mathieu Chartiere401d142015-04-22 13:56:20 -070027extern "C" const void* artInstrumentationMethodEntryFromCode(ArtMethod* method,
Ian Rogers62d6c772013-02-27 08:32:07 -080028 mirror::Object* this_object,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029 Thread* self,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080030 uintptr_t lr)
Mathieu Chartier90443472015-07-16 20:32:27 -070031 SHARED_REQUIRES(Locks::mutator_lock_) {
Andreas Gampe3b45ef22015-05-26 21:34:09 -070032 // Instrumentation changes the stack. Thus, when exiting, the stack cannot be verified, so skip
33 // that part.
34 ScopedQuickEntrypointChecks sqec(self, kIsDebugBuild, false);
Ian Rogers62d6c772013-02-27 08:32:07 -080035 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Sebastien Hertz320deb22014-06-11 19:45:05 +020036 const void* result;
37 if (instrumentation->IsDeoptimized(method)) {
38 result = GetQuickToInterpreterBridge();
39 } else {
Mathieu Chartiera7dd0382014-11-20 17:08:58 -080040 result = instrumentation->GetQuickCodeFor(method, sizeof(void*));
Sebastien Hertz8315ee02014-11-17 16:10:44 +010041 DCHECK(!Runtime::Current()->GetClassLinker()->IsQuickToInterpreterBridge(result));
Sebastien Hertz320deb22014-06-11 19:45:05 +020042 }
Ian Rogers848871b2013-08-05 10:56:33 -070043 bool interpreter_entry = (result == GetQuickToInterpreterBridge());
Sebastien Hertz320deb22014-06-11 19:45:05 +020044 instrumentation->PushInstrumentationStackFrame(self, method->IsStatic() ? nullptr : this_object,
Jeff Hao9a916d32013-06-27 18:45:37 -070045 method, lr, interpreter_entry);
Mathieu Chartier2cebb242015-04-21 16:50:40 -070046 CHECK(result != nullptr) << PrettyMethod(method);
Ian Rogers62d6c772013-02-27 08:32:07 -080047 return result;
jeffhao725a9572012-11-13 18:20:12 -080048}
49
Mathieu Chartiere401d142015-04-22 13:56:20 -070050extern "C" TwoWordReturn artInstrumentationMethodExitFromCode(Thread* self, ArtMethod** sp,
Andreas Gamped58342c2014-06-05 14:18:08 -070051 uint64_t gpr_result,
52 uint64_t fpr_result)
Mathieu Chartier90443472015-07-16 20:32:27 -070053 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz07474662015-08-25 15:12:33 +000054 // 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();
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070057 // Compute address of return PC and sanity check that it currently holds 0.
Ian Rogersc7dd2952014-10-21 23:31:19 -070058 size_t return_pc_offset = GetCalleeSaveReturnPcOffset(kRuntimeISA, Runtime::kRefsOnly);
Ian Rogers13735952014-10-08 12:43:28 -070059 uintptr_t* return_pc = reinterpret_cast<uintptr_t*>(reinterpret_cast<uint8_t*>(sp) +
Vladimir Marko4c1c5102014-05-14 16:51:16 +010060 return_pc_offset);
Brian Carlstrom42748892013-07-18 18:04:08 -070061 CHECK_EQ(*return_pc, 0U);
Ian Rogers1d8cdbc2014-09-22 22:51:09 -070062
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.
Ian Rogers62d6c772013-02-27 08:32:07 -080067 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Andreas Gamped58342c2014-06-05 14:18:08 -070068 TwoWordReturn return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame(
69 self, return_pc, gpr_result, fpr_result);
Ian Rogers62d6c772013-02-27 08:32:07 -080070 return return_or_deoptimize_pc;
jeffhao725a9572012-11-13 18:20:12 -080071}
72
73} // namespace art