blob: d06dbcb12a3bc8045572bb58a41dedd1856d16a5 [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 Gampe57943812017-12-06 21:39:13 -080017#include "base/logging.h" // For VLOG_IS_ON.
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"
Andreas Gampe8228cdf2017-05-30 15:03:54 -070023#include "runtime.h"
Ian Rogers306057f2012-11-26 12:45:53 -080024#include "thread.h"
Ian Rogers306057f2012-11-26 12:45:53 -080025
26namespace art {
27
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010028NO_RETURN static void artDeoptimizeImpl(Thread* self, DeoptimizationKind kind, bool single_frame)
Andreas Gampec6ea7d02017-02-01 16:46:28 -080029 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010030 Runtime::Current()->IncrementDeoptimizationCount(kind);
Andreas Gampef3d1f942015-05-18 21:41:13 -070031 if (VLOG_IS_ON(deopt)) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -070032 if (single_frame) {
33 // Deopt logging will be in DeoptimizeSingleFrame. It is there to take advantage of the
34 // specialized visitor that will show whether a method is Quick or Shadow.
35 } else {
36 LOG(INFO) << "Deopting:";
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070037 self->Dump(LOG_STREAM(INFO));
Mingyao Yangf711f2c2016-05-23 12:29:39 -070038 }
Andreas Gampef3d1f942015-05-18 21:41:13 -070039 }
40
Sebastien Hertz07474662015-08-25 15:12:33 +000041 self->AssertHasDeoptimizationContext();
Mingyao Yangf711f2c2016-05-23 12:29:39 -070042 QuickExceptionHandler exception_handler(self, true);
Nicolas Geoffray62e7c092019-01-08 09:43:01 +000043 if (single_frame) {
44 exception_handler.DeoptimizeSingleFrame(kind);
45 } else {
46 exception_handler.DeoptimizeStack();
Mingyao Yangf711f2c2016-05-23 12:29:39 -070047 }
48 uintptr_t return_pc = exception_handler.UpdateInstrumentationStack();
49 if (exception_handler.IsFullFragmentDone()) {
50 exception_handler.DoLongJump(true);
51 } else {
52 exception_handler.DeoptimizePartialFragmentFixup(return_pc);
53 // We cannot smash the caller-saves, as we need the ArtMethod in a parameter register that would
54 // be caller-saved. This has the downside that we cannot track incorrect register usage down the
55 // line.
56 exception_handler.DoLongJump(false);
57 }
Ian Rogers306057f2012-11-26 12:45:53 -080058}
59
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070060extern "C" NO_RETURN void artDeoptimize(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -070061 ScopedQuickEntrypointChecks sqec(self);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010062 artDeoptimizeImpl(self, DeoptimizationKind::kFullFrame, false);
Mingyao Yangf711f2c2016-05-23 12:29:39 -070063}
64
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010065// This is called directly from compiled code by an HDeoptimize.
66extern "C" NO_RETURN void artDeoptimizeFromCompiledCode(DeoptimizationKind kind, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070067 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz07474662015-08-25 15:12:33 +000068 ScopedQuickEntrypointChecks sqec(self);
69 // Before deoptimizing to interpreter, we must push the deoptimization context.
70 JValue return_value;
71 return_value.SetJ(0); // we never deoptimize from compiled code with an invoke result.
Mingyao Yang2ee17902017-08-30 11:37:08 -070072 self->PushDeoptimizationContext(return_value,
Andreas Gampe98ea9d92018-10-19 14:06:15 -070073 /* is_reference= */ false,
Mingyao Yang2ee17902017-08-30 11:37:08 -070074 self->GetException(),
Andreas Gampe98ea9d92018-10-19 14:06:15 -070075 /* from_code= */ true,
Mingyao Yang2ee17902017-08-30 11:37:08 -070076 DeoptimizationMethodType::kDefault);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010077 artDeoptimizeImpl(self, kind, true);
Sebastien Hertz07474662015-08-25 15:12:33 +000078}
79
Ian Rogers306057f2012-11-26 12:45:53 -080080} // namespace art