1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2012 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker *
4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker *
8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker *
10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker */
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker #include "arch/context.h"
18*795d594fSAndroid Build Coastguard Worker #include "callee_save_frame.h"
19*795d594fSAndroid Build Coastguard Worker #include "jit/jit.h"
20*795d594fSAndroid Build Coastguard Worker #include "runtime.h"
21*795d594fSAndroid Build Coastguard Worker #include "thread-inl.h"
22*795d594fSAndroid Build Coastguard Worker
23*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
24*795d594fSAndroid Build Coastguard Worker
artDeoptimizeIfNeeded(Thread * self,uintptr_t result,bool is_ref)25*795d594fSAndroid Build Coastguard Worker extern "C" Context* artDeoptimizeIfNeeded(Thread* self, uintptr_t result, bool is_ref)
26*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_) {
27*795d594fSAndroid Build Coastguard Worker ScopedQuickEntrypointChecks sqec(self);
28*795d594fSAndroid Build Coastguard Worker instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation();
29*795d594fSAndroid Build Coastguard Worker DCHECK(!self->IsExceptionPending());
30*795d594fSAndroid Build Coastguard Worker
31*795d594fSAndroid Build Coastguard Worker ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrame();
32*795d594fSAndroid Build Coastguard Worker DCHECK(sp != nullptr && (*sp)->IsRuntimeMethod());
33*795d594fSAndroid Build Coastguard Worker
34*795d594fSAndroid Build Coastguard Worker DeoptimizationMethodType type = instr->GetDeoptimizationMethodType(*sp);
35*795d594fSAndroid Build Coastguard Worker JValue jvalue;
36*795d594fSAndroid Build Coastguard Worker jvalue.SetJ(result);
37*795d594fSAndroid Build Coastguard Worker std::unique_ptr<Context> context = instr->DeoptimizeIfNeeded(self, sp, type, jvalue, is_ref);
38*795d594fSAndroid Build Coastguard Worker return context.release();
39*795d594fSAndroid Build Coastguard Worker }
40*795d594fSAndroid Build Coastguard Worker
artTestSuspendFromCode(Thread * self)41*795d594fSAndroid Build Coastguard Worker extern "C" Context* artTestSuspendFromCode(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) {
42*795d594fSAndroid Build Coastguard Worker // Called when there is a pending checkpoint or suspend request.
43*795d594fSAndroid Build Coastguard Worker ScopedQuickEntrypointChecks sqec(self);
44*795d594fSAndroid Build Coastguard Worker self->CheckSuspend();
45*795d594fSAndroid Build Coastguard Worker
46*795d594fSAndroid Build Coastguard Worker // We could have other dex instructions at the same dex pc as suspend and we need to execute
47*795d594fSAndroid Build Coastguard Worker // those instructions. So we should start executing from the current dex pc.
48*795d594fSAndroid Build Coastguard Worker ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrame();
49*795d594fSAndroid Build Coastguard Worker JValue result;
50*795d594fSAndroid Build Coastguard Worker result.SetJ(0);
51*795d594fSAndroid Build Coastguard Worker std::unique_ptr<Context> context = Runtime::Current()->GetInstrumentation()->DeoptimizeIfNeeded(
52*795d594fSAndroid Build Coastguard Worker self, sp, DeoptimizationMethodType::kKeepDexPc, result, /* is_ref= */ false);
53*795d594fSAndroid Build Coastguard Worker return context.release();
54*795d594fSAndroid Build Coastguard Worker }
55*795d594fSAndroid Build Coastguard Worker
artImplicitSuspendFromCode(Thread * self)56*795d594fSAndroid Build Coastguard Worker extern "C" Context* artImplicitSuspendFromCode(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) {
57*795d594fSAndroid Build Coastguard Worker // Called when there is a pending checkpoint or suspend request.
58*795d594fSAndroid Build Coastguard Worker ScopedQuickEntrypointChecks sqec(self);
59*795d594fSAndroid Build Coastguard Worker self->CheckSuspend(/*implicit=*/ true);
60*795d594fSAndroid Build Coastguard Worker
61*795d594fSAndroid Build Coastguard Worker // We could have other dex instructions at the same dex pc as suspend and we need to execute
62*795d594fSAndroid Build Coastguard Worker // those instructions. So we should start executing from the current dex pc.
63*795d594fSAndroid Build Coastguard Worker ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrame();
64*795d594fSAndroid Build Coastguard Worker JValue result;
65*795d594fSAndroid Build Coastguard Worker result.SetJ(0);
66*795d594fSAndroid Build Coastguard Worker std::unique_ptr<Context> context = Runtime::Current()->GetInstrumentation()->DeoptimizeIfNeeded(
67*795d594fSAndroid Build Coastguard Worker self, sp, DeoptimizationMethodType::kKeepDexPc, result, /* is_ref= */ false);
68*795d594fSAndroid Build Coastguard Worker return context.release();
69*795d594fSAndroid Build Coastguard Worker }
70*795d594fSAndroid Build Coastguard Worker
artCompileOptimized(ArtMethod * method,Thread * self)71*795d594fSAndroid Build Coastguard Worker extern "C" void artCompileOptimized(ArtMethod* method, Thread* self)
72*795d594fSAndroid Build Coastguard Worker REQUIRES_SHARED(Locks::mutator_lock_) {
73*795d594fSAndroid Build Coastguard Worker ScopedQuickEntrypointChecks sqec(self);
74*795d594fSAndroid Build Coastguard Worker // It is important this method is not suspended due to:
75*795d594fSAndroid Build Coastguard Worker // * It is called on entry, and object parameters are in locations that are
76*795d594fSAndroid Build Coastguard Worker // not marked in the stack map.
77*795d594fSAndroid Build Coastguard Worker // * Async deoptimization does not expect runtime methods other than the
78*795d594fSAndroid Build Coastguard Worker // suspend entrypoint before executing the first instruction of a Java
79*795d594fSAndroid Build Coastguard Worker // method.
80*795d594fSAndroid Build Coastguard Worker ScopedAssertNoThreadSuspension sants("Enqueuing optimized compilation");
81*795d594fSAndroid Build Coastguard Worker Runtime::Current()->GetJit()->EnqueueOptimizedCompilation(method, self);
82*795d594fSAndroid Build Coastguard Worker }
83*795d594fSAndroid Build Coastguard Worker
84*795d594fSAndroid Build Coastguard Worker } // namespace art
85