blob: b38c685d9bfbaa7c12ccc7460ddc57151d381954 [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"
24
25namespace art {
26
Mathieu Chartiere401d142015-04-22 13:56:20 -070027class ArtMethod;
Mathieu Chartier808c7a52017-12-15 11:19:33 -080028class CodeItemDataAccessor;
Andreas Gampe2969bcd2015-03-09 12:57:41 -070029class Thread;
30class ShadowFrame;
31
32namespace mirror {
Andreas Gampe2969bcd2015-03-09 12:57:41 -070033class Object;
Andreas Gampe2969bcd2015-03-09 12:57:41 -070034} // namespace mirror
35
36namespace interpreter {
37
Andreas Gampe799681b2015-05-15 19:24:12 -070038// 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 Gampe2969bcd2015-03-09 12:57:41 -070046
Andreas Gampe799681b2015-05-15 19:24:12 -070047class UnstartedRuntime {
48 public:
49 static void Initialize();
Andreas Gampe2969bcd2015-03-09 12:57:41 -070050
Andreas Gampe799681b2015-05-15 19:24:12 -070051 static void Invoke(Thread* self,
Mathieu Chartier808c7a52017-12-15 11:19:33 -080052 const CodeItemDataAccessor& accessor,
Andreas Gampe799681b2015-05-15 19:24:12 -070053 ShadowFrame* shadow_frame,
54 JValue* result,
55 size_t arg_offset)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070056 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070057
58 static void Jni(Thread* self,
Mathieu Chartiere401d142015-04-22 13:56:20 -070059 ArtMethod* method,
Andreas Gampe799681b2015-05-15 19:24:12 -070060 mirror::Object* receiver,
61 uint32_t* args,
62 JValue* result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070063 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070064
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 Gampebdf7f1c2016-08-30 16:38:47 -070072 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070073#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 Chartiere401d142015-04-22 13:56:20 -070082 ArtMethod* method, \
Andreas Gampe799681b2015-05-15 19:24:12 -070083 mirror::Object* receiver, \
84 uint32_t* args, \
85 JValue* result) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070086 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070087#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 Gampe47de0fa2017-02-15 19:29:36 -080093 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 Gampe799681b2015-05-15 19:24:12 -0700100 static void InitializeInvokeHandlers();
101 static void InitializeJNIHandlers();
102
103 friend class UnstartedRuntimeTest;
104
105 DISALLOW_ALLOCATION();
106 DISALLOW_COPY_AND_ASSIGN(UnstartedRuntime);
107};
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700108
109} // namespace interpreter
110} // namespace art
111
112#endif // ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_