blob: 8b31f8f441a511e83b17ebdab3cd4c3eb9f5f9eb [file] [log] [blame]
Andreas Gampe2969bcd2015-03-09 12:57:41 -07001/*
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 Sehr9e734c72018-01-04 17:56:19 -080022#include "dex/dex_file.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070023#include "jvalue.h"
Vladimir Marko83881482021-01-07 10:59:54 +000024#include "unstarted_runtime_list.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070025
26namespace art {
27
Mathieu Chartiere401d142015-04-22 13:56:20 -070028class ArtMethod;
Mathieu Chartier808c7a52017-12-15 11:19:33 -080029class CodeItemDataAccessor;
Andreas Gampe2969bcd2015-03-09 12:57:41 -070030class Thread;
31class ShadowFrame;
32
33namespace mirror {
Andreas Gampe2969bcd2015-03-09 12:57:41 -070034class Object;
Andreas Gampe2969bcd2015-03-09 12:57:41 -070035} // namespace mirror
36
37namespace interpreter {
38
Andreas Gampe799681b2015-05-15 19:24:12 -070039// 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 Gampe2969bcd2015-03-09 12:57:41 -070047
Andreas Gampe799681b2015-05-15 19:24:12 -070048class UnstartedRuntime {
49 public:
50 static void Initialize();
Andreas Gampe2969bcd2015-03-09 12:57:41 -070051
Vladimir Marko83881482021-01-07 10:59:54 +000052 // 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 Gampe799681b2015-05-15 19:24:12 -070056 static void Invoke(Thread* self,
Mathieu Chartier808c7a52017-12-15 11:19:33 -080057 const CodeItemDataAccessor& accessor,
Andreas Gampe799681b2015-05-15 19:24:12 -070058 ShadowFrame* shadow_frame,
59 JValue* result,
60 size_t arg_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070061 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070062
63 static void Jni(Thread* self,
Mathieu Chartiere401d142015-04-22 13:56:20 -070064 ArtMethod* method,
Andreas Gampe799681b2015-05-15 19:24:12 -070065 mirror::Object* receiver,
66 uint32_t* args,
67 JValue* result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070068 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070069
70 private:
71 // Methods that intercept available libcore implementations.
Vladimir Marko83881482021-01-07 10:59:54 +000072#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 Gampebdf7f1c2016-08-30 16:38:47 -070077 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070078 UNSTARTED_RUNTIME_DIRECT_LIST(UNSTARTED_DIRECT)
Andreas Gampe799681b2015-05-15 19:24:12 -070079#undef UNSTARTED_DIRECT
80
81 // Methods that are native.
Vladimir Marko83881482021-01-07 10:59:54 +000082#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 Gampebdf7f1c2016-08-30 16:38:47 -070088 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070089 UNSTARTED_RUNTIME_JNI_LIST(UNSTARTED_JNI)
Andreas Gampe799681b2015-05-15 19:24:12 -070090#undef UNSTARTED_JNI
91
Andreas Gampe47de0fa2017-02-15 19:29:36 -080092 static void UnstartedClassForNameCommon(Thread* self,
93 ShadowFrame* shadow_frame,
94 JValue* result,
95 size_t arg_offset,
Vladimir Marko0685b982021-03-25 11:59:22 +000096 bool long_form) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe47de0fa2017-02-15 19:29:36 -080097
Vladimir Marko83881482021-01-07 10:59:54 +000098 static void InitializeInvokeHandlers(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
99 static void InitializeJNIHandlers(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -0700100
101 friend class UnstartedRuntimeTest;
102
103 DISALLOW_ALLOCATION();
104 DISALLOW_COPY_AND_ASSIGN(UnstartedRuntime);
105};
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700106
107} // namespace interpreter
108} // namespace art
109
110#endif // ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_