Andreas Gampe | 5e26eb1 | 2016-08-22 17:54:17 -0700 | [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 | |
| 17 | #ifndef ART_RUNTIME_INTERPRETER_INTERPRETER_SWITCH_IMPL_H_ |
| 18 | #define ART_RUNTIME_INTERPRETER_INTERPRETER_SWITCH_IMPL_H_ |
| 19 | |
Andreas Gampe | 7fbc4a5 | 2018-11-28 08:26:47 -0800 | [diff] [blame] | 20 | #include "base/locks.h" |
Andreas Gampe | 5e26eb1 | 2016-08-22 17:54:17 -0700 | [diff] [blame] | 21 | #include "base/macros.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 22 | #include "dex/dex_file.h" |
David Srbecky | 946bb09 | 2018-03-09 17:23:01 +0000 | [diff] [blame] | 23 | #include "dex/code_item_accessors.h" |
Andreas Gampe | 5e26eb1 | 2016-08-22 17:54:17 -0700 | [diff] [blame] | 24 | #include "jvalue.h" |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 25 | #include "obj_ptr.h" |
Andreas Gampe | 5e26eb1 | 2016-08-22 17:54:17 -0700 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
| 29 | class ShadowFrame; |
| 30 | class Thread; |
| 31 | |
| 32 | namespace interpreter { |
| 33 | |
David Srbecky | 946bb09 | 2018-03-09 17:23:01 +0000 | [diff] [blame] | 34 | // Group all the data that is needed in the switch interpreter. |
| 35 | // We need to pass it to the hand-written assembly and back, |
| 36 | // so it is easier to pass it through a single pointer. |
| 37 | // Similarly, returning the JValue type would be non-trivial. |
| 38 | struct SwitchImplContext { |
| 39 | Thread* self; |
| 40 | const CodeItemDataAccessor& accessor; |
| 41 | ShadowFrame& shadow_frame; |
| 42 | JValue& result_register; |
| 43 | bool interpret_one_instruction; |
| 44 | JValue result; |
| 45 | }; |
| 46 | |
| 47 | // The actual internal implementation of the switch interpreter. |
Andreas Gampe | 5e26eb1 | 2016-08-22 17:54:17 -0700 | [diff] [blame] | 48 | template<bool do_access_check, bool transaction_active> |
David Srbecky | 946bb09 | 2018-03-09 17:23:01 +0000 | [diff] [blame] | 49 | void ExecuteSwitchImplCpp(SwitchImplContext* ctx) |
| 50 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 51 | |
| 52 | // Hand-written assembly method which wraps the C++ implementation, |
| 53 | // while defining the DEX PC in the CFI so that libunwind can resolve it. |
| 54 | extern "C" void ExecuteSwitchImplAsm(SwitchImplContext* ctx, void* impl, const uint16_t* dexpc) |
| 55 | REQUIRES_SHARED(Locks::mutator_lock_); |
| 56 | |
| 57 | // Wrapper around the switch interpreter which ensures we can unwind through it. |
| 58 | template<bool do_access_check, bool transaction_active> |
| 59 | ALWAYS_INLINE JValue ExecuteSwitchImpl(Thread* self, const CodeItemDataAccessor& accessor, |
| 60 | ShadowFrame& shadow_frame, JValue result_register, |
| 61 | bool interpret_one_instruction) |
| 62 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 63 | SwitchImplContext ctx { |
| 64 | .self = self, |
| 65 | .accessor = accessor, |
| 66 | .shadow_frame = shadow_frame, |
| 67 | .result_register = result_register, |
| 68 | .interpret_one_instruction = interpret_one_instruction, |
| 69 | .result = JValue(), |
| 70 | }; |
| 71 | void* impl = reinterpret_cast<void*>(&ExecuteSwitchImplCpp<do_access_check, transaction_active>); |
| 72 | const uint16_t* dex_pc = ctx.accessor.Insns(); |
| 73 | ExecuteSwitchImplAsm(&ctx, impl, dex_pc); |
| 74 | return ctx.result; |
| 75 | } |
Andreas Gampe | 5e26eb1 | 2016-08-22 17:54:17 -0700 | [diff] [blame] | 76 | |
| 77 | } // namespace interpreter |
| 78 | } // namespace art |
| 79 | |
| 80 | #endif // ART_RUNTIME_INTERPRETER_INTERPRETER_SWITCH_IMPL_H_ |