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" |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 19 | #include "base/systrace.h" |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 20 | #include "callee_save_frame.h" |
| 21 | #include "interpreter/interpreter.h" |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 22 | #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] | 23 | #include "quick_exception_handler.h" |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 24 | #include "runtime.h" |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 25 | #include "thread.h" |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 29 | NO_RETURN static void artDeoptimizeImpl(Thread* self, DeoptimizationKind kind, bool single_frame) |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 30 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 31 | Runtime::Current()->IncrementDeoptimizationCount(kind); |
Andreas Gampe | f3d1f94 | 2015-05-18 21:41:13 -0700 | [diff] [blame] | 32 | if (VLOG_IS_ON(deopt)) { |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 33 | 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 Gampe | 3fec9ac | 2016-09-13 10:47:28 -0700 | [diff] [blame] | 38 | self->Dump(LOG_STREAM(INFO)); |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 39 | } |
Andreas Gampe | f3d1f94 | 2015-05-18 21:41:13 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Sebastien Hertz | 0747466 | 2015-08-25 15:12:33 +0000 | [diff] [blame] | 42 | self->AssertHasDeoptimizationContext(); |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 43 | QuickExceptionHandler exception_handler(self, true); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 44 | { |
| 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 Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 51 | } |
| 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 Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 64 | 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] | 65 | ScopedQuickEntrypointChecks sqec(self); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 66 | artDeoptimizeImpl(self, DeoptimizationKind::kFullFrame, false); |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 69 | // This is called directly from compiled code by an HDeoptimize. |
| 70 | extern "C" NO_RETURN void artDeoptimizeFromCompiledCode(DeoptimizationKind kind, Thread* self) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 71 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Sebastien Hertz | 0747466 | 2015-08-25 15:12:33 +0000 | [diff] [blame] | 72 | 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 Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 76 | self->PushDeoptimizationContext(return_value, |
| 77 | false /* is_reference */, |
| 78 | self->GetException(), |
| 79 | true /* from_code */, |
| 80 | DeoptimizationMethodType::kDefault); |
Nicolas Geoffray | 4e92c3c | 2017-05-08 09:34:26 +0100 | [diff] [blame] | 81 | artDeoptimizeImpl(self, kind, true); |
Sebastien Hertz | 0747466 | 2015-08-25 15:12:33 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Ian Rogers | 306057f | 2012-11-26 12:45:53 -0800 | [diff] [blame] | 84 | } // namespace art |