| 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" |
| Vladimir Marko | 8388148 | 2021-01-07 10:59:54 +0000 | [diff] [blame] | 24 | #include "unstarted_runtime_list.h" |
| Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 25 | |
| 26 | namespace art { |
| 27 | |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 28 | class ArtMethod; |
| Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 29 | class CodeItemDataAccessor; |
| Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 30 | class Thread; |
| 31 | class ShadowFrame; |
| 32 | |
| 33 | namespace mirror { |
| Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 34 | class Object; |
| Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 35 | } // namespace mirror |
| 36 | |
| 37 | namespace interpreter { |
| 38 | |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 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. |
| Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 47 | |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 48 | class UnstartedRuntime { |
| 49 | public: |
| 50 | static void Initialize(); |
| Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 51 | |
| Vladimir Marko | 8388148 | 2021-01-07 10:59:54 +0000 | [diff] [blame] | 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 | |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 56 | static void Invoke(Thread* self, |
| Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 57 | const CodeItemDataAccessor& accessor, |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 58 | ShadowFrame* shadow_frame, |
| 59 | JValue* result, |
| 60 | size_t arg_offset) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 61 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 62 | |
| 63 | static void Jni(Thread* self, |
| Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 64 | ArtMethod* method, |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 65 | mirror::Object* receiver, |
| 66 | uint32_t* args, |
| 67 | JValue* result) |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 68 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 69 | |
| 70 | private: |
| 71 | // Methods that intercept available libcore implementations. |
| Vladimir Marko | 8388148 | 2021-01-07 10:59:54 +0000 | [diff] [blame] | 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) \ |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 77 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 78 | UNSTARTED_RUNTIME_DIRECT_LIST(UNSTARTED_DIRECT) |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 79 | #undef UNSTARTED_DIRECT |
| 80 | |
| 81 | // Methods that are native. |
| Vladimir Marko | 8388148 | 2021-01-07 10:59:54 +0000 | [diff] [blame] | 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) \ |
| Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 88 | REQUIRES_SHARED(Locks::mutator_lock_); |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 89 | UNSTARTED_RUNTIME_JNI_LIST(UNSTARTED_JNI) |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 90 | #undef UNSTARTED_JNI |
| 91 | |
| Andreas Gampe | 47de0fa | 2017-02-15 19:29:36 -0800 | [diff] [blame] | 92 | static void UnstartedClassForNameCommon(Thread* self, |
| 93 | ShadowFrame* shadow_frame, |
| 94 | JValue* result, |
| 95 | size_t arg_offset, |
| Vladimir Marko | 0685b98 | 2021-03-25 11:59:22 +0000 | [diff] [blame] | 96 | bool long_form) REQUIRES_SHARED(Locks::mutator_lock_); |
| Andreas Gampe | 47de0fa | 2017-02-15 19:29:36 -0800 | [diff] [blame] | 97 | |
| Vladimir Marko | 8388148 | 2021-01-07 10:59:54 +0000 | [diff] [blame] | 98 | static void InitializeInvokeHandlers(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); |
| 99 | static void InitializeJNIHandlers(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); |
| Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 100 | |
| 101 | friend class UnstartedRuntimeTest; |
| 102 | |
| 103 | DISALLOW_ALLOCATION(); |
| 104 | DISALLOW_COPY_AND_ASSIGN(UnstartedRuntime); |
| 105 | }; |
| Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 106 | |
| 107 | } // namespace interpreter |
| 108 | } // namespace art |
| 109 | |
| 110 | #endif // ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_ |