blob: c782c9c9492182a7430681400e4d3700b3de2201 [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"
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010019#include "base/systrace.h"
Ian Rogers306057f2012-11-26 12:45:53 -080020#include "callee_save_frame.h"
21#include "interpreter/interpreter.h"
Andreas Gampec6ea7d02017-02-01 16:46:28 -080022#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 -070023#include "quick_exception_handler.h"
Andreas Gampe8228cdf2017-05-30 15:03:54 -070024#include "runtime.h"
Ian Rogers306057f2012-11-26 12:45:53 -080025#include "thread.h"
Ian Rogers306057f2012-11-26 12:45:53 -080026
27namespace art {
28
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010029NO_RETURN static void artDeoptimizeImpl(Thread* self, DeoptimizationKind kind, bool single_frame)
Andreas Gampec6ea7d02017-02-01 16:46:28 -080030 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010031 Runtime::Current()->IncrementDeoptimizationCount(kind);
Andreas Gampef3d1f942015-05-18 21:41:13 -070032 if (VLOG_IS_ON(deopt)) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -070033 if (single_frame) {
34 // Deopt logging will be in DeoptimizeSingleFrame. It is there to take advantage of the
35 // specialized visitor that will show whether a method is Quick or Shadow.
36 } else {
37 LOG(INFO) << "Deopting:";
Andreas Gampe3fec9ac2016-09-13 10:47:28 -070038 self->Dump(LOG_STREAM(INFO));
Mingyao Yangf711f2c2016-05-23 12:29:39 -070039 }
Andreas Gampef3d1f942015-05-18 21:41:13 -070040 }
41
Sebastien Hertz07474662015-08-25 15:12:33 +000042 self->AssertHasDeoptimizationContext();
Mingyao Yangf711f2c2016-05-23 12:29:39 -070043 QuickExceptionHandler exception_handler(self, true);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010044 {
45 ScopedTrace trace(std::string("Deoptimization ") + GetDeoptimizationKindName(kind));
46 if (single_frame) {
47 exception_handler.DeoptimizeSingleFrame(kind);
48 } else {
49 exception_handler.DeoptimizeStack();
50 }
Mingyao Yangf711f2c2016-05-23 12:29:39 -070051 }
52 uintptr_t return_pc = exception_handler.UpdateInstrumentationStack();
53 if (exception_handler.IsFullFragmentDone()) {
54 exception_handler.DoLongJump(true);
55 } else {
56 exception_handler.DeoptimizePartialFragmentFixup(return_pc);
57 // We cannot smash the caller-saves, as we need the ArtMethod in a parameter register that would
58 // be caller-saved. This has the downside that we cannot track incorrect register usage down the
59 // line.
60 exception_handler.DoLongJump(false);
61 }
Ian Rogers306057f2012-11-26 12:45:53 -080062}
63
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070064extern "C" NO_RETURN void artDeoptimize(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yangf711f2c2016-05-23 12:29:39 -070065 ScopedQuickEntrypointChecks sqec(self);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010066 artDeoptimizeImpl(self, DeoptimizationKind::kFullFrame, false);
Mingyao Yangf711f2c2016-05-23 12:29:39 -070067}
68
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010069// This is called directly from compiled code by an HDeoptimize.
70extern "C" NO_RETURN void artDeoptimizeFromCompiledCode(DeoptimizationKind kind, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070071 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz07474662015-08-25 15:12:33 +000072 ScopedQuickEntrypointChecks sqec(self);
73 // Before deoptimizing to interpreter, we must push the deoptimization context.
74 JValue return_value;
75 return_value.SetJ(0); // we never deoptimize from compiled code with an invoke result.
Mingyao Yang2ee17902017-08-30 11:37:08 -070076 self->PushDeoptimizationContext(return_value,
77 false /* is_reference */,
78 self->GetException(),
79 true /* from_code */,
80 DeoptimizationMethodType::kDefault);
Nicolas Geoffray4e92c3c2017-05-08 09:34:26 +010081 artDeoptimizeImpl(self, kind, true);
Sebastien Hertz07474662015-08-25 15:12:33 +000082}
83
Ian Rogers306057f2012-11-26 12:45:53 -080084} // namespace art