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 "arch/context.h"
18 #include "callee_save_frame.h"
19 #include "jit/jit.h"
20 #include "runtime.h"
21 #include "thread-inl.h"
22
23 namespace art HIDDEN {
24
artDeoptimizeIfNeeded(Thread * self,uintptr_t result,bool is_ref)25 extern "C" Context* artDeoptimizeIfNeeded(Thread* self, uintptr_t result, bool is_ref)
26 REQUIRES_SHARED(Locks::mutator_lock_) {
27 ScopedQuickEntrypointChecks sqec(self);
28 instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation();
29 DCHECK(!self->IsExceptionPending());
30
31 ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrame();
32 DCHECK(sp != nullptr && (*sp)->IsRuntimeMethod());
33
34 DeoptimizationMethodType type = instr->GetDeoptimizationMethodType(*sp);
35 JValue jvalue;
36 jvalue.SetJ(result);
37 std::unique_ptr<Context> context = instr->DeoptimizeIfNeeded(self, sp, type, jvalue, is_ref);
38 return context.release();
39 }
40
artTestSuspendFromCode(Thread * self)41 extern "C" Context* artTestSuspendFromCode(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) {
42 // Called when there is a pending checkpoint or suspend request.
43 ScopedQuickEntrypointChecks sqec(self);
44 self->CheckSuspend();
45
46 // We could have other dex instructions at the same dex pc as suspend and we need to execute
47 // those instructions. So we should start executing from the current dex pc.
48 ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrame();
49 JValue result;
50 result.SetJ(0);
51 std::unique_ptr<Context> context = Runtime::Current()->GetInstrumentation()->DeoptimizeIfNeeded(
52 self, sp, DeoptimizationMethodType::kKeepDexPc, result, /* is_ref= */ false);
53 return context.release();
54 }
55
artImplicitSuspendFromCode(Thread * self)56 extern "C" Context* artImplicitSuspendFromCode(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) {
57 // Called when there is a pending checkpoint or suspend request.
58 ScopedQuickEntrypointChecks sqec(self);
59 self->CheckSuspend(/*implicit=*/ true);
60
61 // We could have other dex instructions at the same dex pc as suspend and we need to execute
62 // those instructions. So we should start executing from the current dex pc.
63 ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrame();
64 JValue result;
65 result.SetJ(0);
66 std::unique_ptr<Context> context = Runtime::Current()->GetInstrumentation()->DeoptimizeIfNeeded(
67 self, sp, DeoptimizationMethodType::kKeepDexPc, result, /* is_ref= */ false);
68 return context.release();
69 }
70
artCompileOptimized(ArtMethod * method,Thread * self)71 extern "C" void artCompileOptimized(ArtMethod* method, Thread* self)
72 REQUIRES_SHARED(Locks::mutator_lock_) {
73 ScopedQuickEntrypointChecks sqec(self);
74 // It is important this method is not suspended due to:
75 // * It is called on entry, and object parameters are in locations that are
76 // not marked in the stack map.
77 // * Async deoptimization does not expect runtime methods other than the
78 // suspend entrypoint before executing the first instruction of a Java
79 // method.
80 ScopedAssertNoThreadSuspension sants("Enqueuing optimized compilation");
81 Runtime::Current()->GetJit()->EnqueueOptimizedCompilation(method, self);
82 }
83
84 } // namespace art
85