Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 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 | |
Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 17 | #include "base/logging.h" // For VLOG_IS_ON. |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 18 | #include "base/mutex.h" |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 19 | #include "callee_save_frame.h" |
| 20 | #include "interpreter/interpreter.h" |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 21 | #include "obj_ptr-inl.h" // TODO: Find the other include that isn't complete, and clean this up. |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 22 | #include "quick_exception_handler.h" |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 23 | #include "runtime.h" |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 24 | #include "thread.h" |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 28 | NO_RETURN static void artDeoptimizeImpl(Thread* self, DeoptimizationKind kind, bool single_frame) |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 29 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 30 | Runtime::Current()->IncrementDeoptimizationCount(kind); |
Andreas Gampe | f3d1f94 | 2015-05-18 21:41:13 -0700 | [diff] [blame] | 31 | if (VLOG_IS_ON(deopt)) { |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 32 | 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 Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 37 | self->Dump(LOG_STREAM(INFO)); |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 38 | } |
Andreas Gampe | f3d1f94 | 2015-05-18 21:41:13 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Sebastien Hertz | 0747466 | 2015-08-25 15:12:33 +0000 | [diff] [blame] | 41 | self->AssertHasDeoptimizationContext(); |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 42 | QuickExceptionHandler exception_handler(self, true); |
Nicolas Geoffray | 62e7c09 | 2019-01-08 09:43:01 +0000 | [diff] [blame^] | 43 | if (single_frame) { |
| 44 | exception_handler.DeoptimizeSingleFrame(kind); |
| 45 | } else { |
| 46 | exception_handler.DeoptimizeStack(); |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 47 | } |
| 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 Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 60 | extern "C" NO_RETURN void artDeoptimize(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 61 | ScopedQuickEntrypointChecks sqec(self); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 62 | artDeoptimizeImpl(self, DeoptimizationKind::kFullFrame, false); |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 65 | // This is called directly from compiled code by an HDeoptimize. |
| 66 | extern "C" NO_RETURN void artDeoptimizeFromCompiledCode(DeoptimizationKind kind, Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 67 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0747466 | 2015-08-25 15:12:33 +0000 | [diff] [blame] | 68 | 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 Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 72 | self->PushDeoptimizationContext(return_value, |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 73 | /* is_reference= */ false, |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 74 | self->GetException(), |
Andreas Gampe | 98ea9d9 | 2018-10-19 14:06:15 -0700 | [diff] [blame] | 75 | /* from_code= */ true, |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 76 | DeoptimizationMethodType::kDefault); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 77 | artDeoptimizeImpl(self, kind, true); |
Sebastien Hertz | 0747466 | 2015-08-25 15:12:33 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 80 | } // namespace art |