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