1 /* 2 * Copyright (C) 2015 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_UNSTARTED_RUNTIME_H_ 18 #define ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_ 19 20 #include "interpreter.h" 21 22 #include "dex/dex_file.h" 23 #include "jvalue.h" 24 #include "unstarted_runtime_list.h" 25 26 namespace art { 27 28 class ArtMethod; 29 class CodeItemDataAccessor; 30 class Thread; 31 class ShadowFrame; 32 33 namespace mirror { 34 class Object; 35 } // namespace mirror 36 37 namespace interpreter { 38 39 // Support for an unstarted runtime. These are special handwritten implementations for select 40 // libcore native and non-native methods so we can compile-time initialize classes in the boot 41 // image. 42 // 43 // While it would technically be OK to only expose the public functions, a class was chosen to 44 // wrap this so the actual implementations are exposed for testing. This is also why the private 45 // methods are not documented here - they are not intended to be used directly except in 46 // testing. 47 48 class UnstartedRuntime { 49 public: 50 static void Initialize(); 51 52 // For testing. When we destroy the Runtime and create a new one, 53 // we need to reinitialize maps with new `ArtMethod*` keys. 54 static void Reinitialize(); 55 56 static void Invoke(Thread* self, 57 const CodeItemDataAccessor& accessor, 58 ShadowFrame* shadow_frame, 59 JValue* result, 60 size_t arg_offset) 61 REQUIRES_SHARED(Locks::mutator_lock_); 62 63 static void Jni(Thread* self, 64 ArtMethod* method, 65 mirror::Object* receiver, 66 uint32_t* args, 67 JValue* result) 68 REQUIRES_SHARED(Locks::mutator_lock_); 69 70 private: 71 // Methods that intercept available libcore implementations. 72 #define UNSTARTED_DIRECT(ShortName, DescriptorIgnored, NameIgnored, SignatureIgnored) \ 73 static void Unstarted ## ShortName(Thread* self, \ 74 ShadowFrame* shadow_frame, \ 75 JValue* result, \ 76 size_t arg_offset) \ 77 REQUIRES_SHARED(Locks::mutator_lock_); 78 UNSTARTED_RUNTIME_DIRECT_LIST(UNSTARTED_DIRECT) 79 #undef UNSTARTED_DIRECT 80 81 // Methods that are native. 82 #define UNSTARTED_JNI(ShortName, DescriptorIgnored, NameIgnored, SignatureIgnored) \ 83 static void UnstartedJNI ## ShortName(Thread* self, \ 84 ArtMethod* method, \ 85 mirror::Object* receiver, \ 86 uint32_t* args, \ 87 JValue* result) \ 88 REQUIRES_SHARED(Locks::mutator_lock_); 89 UNSTARTED_RUNTIME_JNI_LIST(UNSTARTED_JNI) 90 #undef UNSTARTED_JNI 91 92 static void UnstartedClassForNameCommon(Thread* self, 93 ShadowFrame* shadow_frame, 94 JValue* result, 95 size_t arg_offset, 96 bool long_form) REQUIRES_SHARED(Locks::mutator_lock_); 97 98 static void InitializeInvokeHandlers(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); 99 static void InitializeJNIHandlers(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); 100 101 friend class UnstartedRuntimeTest; 102 103 DISALLOW_ALLOCATION(); 104 DISALLOW_COPY_AND_ASSIGN(UnstartedRuntime); 105 }; 106 107 } // namespace interpreter 108 } // namespace art 109 110 #endif // ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_ 111