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
20 #include "base/locks.h"
21 #include "base/macros.h"
22 #include "dex/dex_file.h"
23 #include "dex/code_item_accessors.h"
24 #include "jvalue.h"
25 #include "obj_ptr.h"
26
27 namespace art HIDDEN {
28
29 class ShadowFrame;
30 class Thread;
31
32 namespace interpreter {
33
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 JValue result;
44 };
45
46 // The actual internal implementation of the switch interpreter.
47 template<bool transaction_active>
48 void ExecuteSwitchImplCpp(SwitchImplContext* ctx)
49 REQUIRES_SHARED(Locks::mutator_lock_);
50
51 // Hand-written assembly method which wraps the C++ implementation,
52 // while defining the DEX PC in the CFI so that libunwind can resolve it.
53 extern "C" void ExecuteSwitchImplAsm(
54 SwitchImplContext* ctx, const 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.
ExecuteSwitchImpl(Thread * self,const CodeItemDataAccessor & accessor,ShadowFrame & shadow_frame,JValue result_register,const void * switch_impl_cpp)58 ALWAYS_INLINE inline JValue ExecuteSwitchImpl(Thread* self,
59 const CodeItemDataAccessor& accessor,
60 ShadowFrame& shadow_frame,
61 JValue result_register,
62 const void* switch_impl_cpp)
63 REQUIRES_SHARED(Locks::mutator_lock_) {
64 SwitchImplContext ctx {
65 .self = self,
66 .accessor = accessor,
67 .shadow_frame = shadow_frame,
68 .result_register = result_register,
69 .result = JValue(),
70 };
71 const uint16_t* dex_pc = ctx.accessor.Insns();
72 ExecuteSwitchImplAsm(&ctx, switch_impl_cpp, dex_pc);
73 return ctx.result;
74 }
75
76 } // namespace interpreter
77 } // namespace art
78
79 #endif // ART_RUNTIME_INTERPRETER_INTERPRETER_SWITCH_IMPL_H_
80