xref: /aosp_15_r20/art/runtime/entrypoints/quick/quick_deoptimization_entrypoints.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
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 "base/logging.h"  // For VLOG_IS_ON.
19 #include "base/mutex.h"
20 #include "callee_save_frame.h"
21 #include "interpreter/interpreter.h"
22 #include "obj_ptr-inl.h"  // TODO: Find the other include that isn't complete, and clean this up.
23 #include "quick_exception_handler.h"
24 #include "runtime.h"
25 #include "thread.h"
26 
27 namespace art HIDDEN {
28 
artDeoptimize(Thread * self,bool skip_method_exit_callbacks)29 extern "C" Context* artDeoptimize(Thread* self, bool skip_method_exit_callbacks)
30     REQUIRES_SHARED(Locks::mutator_lock_) {
31   ScopedQuickEntrypointChecks sqec(self);
32   std::unique_ptr<Context> context = self->Deoptimize(DeoptimizationKind::kFullFrame,
33                                                       /*single_frame=*/ false,
34                                                       skip_method_exit_callbacks);
35   DCHECK(context != nullptr);
36   return context.release();
37 }
38 
39 // This is called directly from compiled code by an HDeoptimize.
artDeoptimizeFromCompiledCode(DeoptimizationKind kind,Thread * self)40 extern "C" Context* artDeoptimizeFromCompiledCode(DeoptimizationKind kind, Thread* self)
41     REQUIRES_SHARED(Locks::mutator_lock_) {
42   ScopedQuickEntrypointChecks sqec(self);
43   // Before deoptimizing to interpreter, we must push the deoptimization context.
44   JValue return_value;
45   return_value.SetJ(0);  // we never deoptimize from compiled code with an invoke result.
46   self->PushDeoptimizationContext(return_value,
47                                   /* is_reference= */ false,
48                                   self->GetException(),
49                                   /* from_code= */ true,
50                                   DeoptimizationMethodType::kDefault);
51   // Deopting from compiled code, so method exit haven't run yet. Don't skip method exit callbacks
52   // if required.
53   std::unique_ptr<Context> context = self->Deoptimize(kind,
54                                                       /*single_frame=*/ true,
55                                                       /* skip_method_exit_callbacks= */ false);
56   DCHECK(context != nullptr);
57   return context.release();
58 }
59 
60 }  // namespace art
61