Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 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 | |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 22 | #include "dex/dex_file.h" |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 23 | #include "jvalue.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | class ArtMethod; |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 28 | class CodeItemDataAccessor; |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 29 | class Thread; |
| 30 | class ShadowFrame; |
| 31 | |
| 32 | namespace mirror { |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 33 | class Object; |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 34 | } // namespace mirror |
| 35 | |
| 36 | namespace interpreter { |
| 37 | |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 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. |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 46 | |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 47 | class UnstartedRuntime { |
| 48 | public: |
| 49 | static void Initialize(); |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 50 | |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 51 | static void Invoke(Thread* self, |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 52 | const CodeItemDataAccessor& accessor, |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 53 | ShadowFrame* shadow_frame, |
| 54 | JValue* result, |
| 55 | size_t arg_offset) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 56 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 57 | |
| 58 | static void Jni(Thread* self, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 59 | ArtMethod* method, |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 60 | mirror::Object* receiver, |
| 61 | uint32_t* args, |
| 62 | JValue* result) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 63 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 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) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 72 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 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, \ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 82 | ArtMethod* method, \ |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 83 | mirror::Object* receiver, \ |
| 84 | uint32_t* args, \ |
| 85 | JValue* result) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 86 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 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 | |
Andreas Gampe | 47de0fa | 2017-02-15 19:29:36 -0800 | [diff] [blame] | 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 | |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 100 | static void InitializeInvokeHandlers(); |
| 101 | static void InitializeJNIHandlers(); |
| 102 | |
| 103 | friend class UnstartedRuntimeTest; |
| 104 | |
| 105 | DISALLOW_ALLOCATION(); |
| 106 | DISALLOW_COPY_AND_ASSIGN(UnstartedRuntime); |
| 107 | }; |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 108 | |
| 109 | } // namespace interpreter |
| 110 | } // namespace art |
| 111 | |
| 112 | #endif // ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_ |