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