blob: 3820d854f9cecdcee860a21767b31492fd54295e [file] [log] [blame]
Ian Rogers306057f2012-11-26 12:45:53 -08001/*
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
Andreas Gampef3d1f942015-05-18 21:41:13 -070017#include "base/logging.h"
Andreas Gampec6ea7d02017-02-01 16:46:28 -080018#include "base/mutex.h"
Ian Rogers306057f2012-11-26 12:45:53 -080019#include "callee_save_frame.h"
20#include "interpreter/interpreter.h"
Andreas Gampec6ea7d02017-02-01 16:46:28 -080021#include "obj_ptr-inl.h" // TODO: Find the other include that isn't complete, and clean this up.
Andreas Gampe639bdd12015-06-03 11:22:45 -070022#include "quick_exception_handler.h"
Ian Rogers306057f2012-11-26 12:45:53 -080023#include "thread.h"
Ian Rogers306057f2012-11-26 12:45:53 -080024
25namespace art {
26
Mingyao Yangf711f2c2016-05-23 12:29:39 -070027NO_RETURN static void artDeoptimizeImpl(Thread* self, bool single_frame)
Andreas Gampec6ea7d02017-02-01 16:46:28 -080028 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampef3d1f942015-05-18 21:41:13 -070029 if (VLOG_IS_ON(deopt)) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -070030 if (single_frame) {
31 // Deopt logging will be in DeoptimizeSingleFrame. It is there to take advantage of the
32 // specialized visitor that will show whether a method is Quick or Shadow.
33 } else {
34 LOG(INFO) << "Deopting:";
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070035 self->Dump(LOG_STREAM(INFO));
Mingyao Yangf711f2c2016-05-23 12:29:39 -070036 }
Andreas Gampef3d1f942015-05-18 21:41:13 -070037 }
38
Sebastien Hertz07474662015-08-25 15:12:33 +000039 self->AssertHasDeoptimizationContext();
Mingyao Yangf711f2c2016-05-23 12:29:39 -070040 QuickExceptionHandler exception_handler(self, true);
41 if (single_frame) {
42 exception_handler.DeoptimizeSingleFrame();
43 } else {
44 exception_handler.DeoptimizeStack();
45 }
46 uintptr_t return_pc = exception_handler.UpdateInstrumentationStack();
47 if (exception_handler.IsFullFragmentDone()) {
48 exception_handler.DoLongJump(true);
49 } else {
50 exception_handler.DeoptimizePartialFragmentFixup(return_pc);
51 // We cannot smash the caller-saves, as we need the ArtMethod in a parameter register that would
52 // be caller-saved. This has the downside that we cannot track incorrect register usage down the
53 // line.
54 exception_handler.DoLongJump(false);
55 }
Ian Rogers306057f2012-11-26 12:45:53 -080056}
57
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070058extern "C" NO_RETURN void artDeoptimize(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -070059 ScopedQuickEntrypointChecks sqec(self);
60 artDeoptimizeImpl(self, false);
61}
62
63// This is called directly from compiled code by an HDepptimize.
Sebastien Hertz07474662015-08-25 15:12:33 +000064extern "C" NO_RETURN void artDeoptimizeFromCompiledCode(Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070065 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz07474662015-08-25 15:12:33 +000066 ScopedQuickEntrypointChecks sqec(self);
67 // Before deoptimizing to interpreter, we must push the deoptimization context.
68 JValue return_value;
69 return_value.SetJ(0); // we never deoptimize from compiled code with an invoke result.
Nicolas Geoffray73be1e82015-09-17 15:22:56 +010070 self->PushDeoptimizationContext(return_value, false, /* from_code */ true, self->GetException());
Mingyao Yangf711f2c2016-05-23 12:29:39 -070071 artDeoptimizeImpl(self, true);
Sebastien Hertz07474662015-08-25 15:12:33 +000072}
73
Ian Rogers306057f2012-11-26 12:45:53 -080074} // namespace art