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