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