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 | |
| 22 | #include "dex_file.h" |
| 23 | #include "jvalue.h" |
| 24 | |
| 25 | namespace art { |
| 26 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 27 | class ArtMethod; |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 28 | class Thread; |
| 29 | class ShadowFrame; |
| 30 | |
| 31 | namespace mirror { |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 32 | class Object; |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 33 | } // namespace mirror |
| 34 | |
| 35 | namespace interpreter { |
| 36 | |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 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. |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 45 | |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 46 | class UnstartedRuntime { |
| 47 | public: |
| 48 | static void Initialize(); |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 49 | |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 50 | static void Invoke(Thread* self, |
| 51 | const DexFile::CodeItem* code_item, |
| 52 | ShadowFrame* shadow_frame, |
| 53 | JValue* result, |
| 54 | size_t arg_offset) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 55 | SHARED_REQUIRES(Locks::mutator_lock_); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 56 | |
| 57 | static void Jni(Thread* self, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 58 | ArtMethod* method, |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 59 | mirror::Object* receiver, |
| 60 | uint32_t* args, |
| 61 | JValue* result) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 62 | SHARED_REQUIRES(Locks::mutator_lock_); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 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) \ |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 71 | SHARED_REQUIRES(Locks::mutator_lock_); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 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, \ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 81 | ArtMethod* method, \ |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 82 | mirror::Object* receiver, \ |
| 83 | uint32_t* args, \ |
| 84 | JValue* result) \ |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 85 | SHARED_REQUIRES(Locks::mutator_lock_); |
Andreas Gampe | 799681b | 2015-05-15 19:24:12 -0700 | [diff] [blame] | 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 | }; |
Andreas Gampe | 2969bcd | 2015-03-09 12:57:41 -0700 | [diff] [blame] | 100 | |
| 101 | } // namespace interpreter |
| 102 | } // namespace art |
| 103 | |
| 104 | #endif // ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_ |