blob: 03d7026ef748a694494001255a86b0e346a9f731 [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
22#include "dex_file.h"
23#include "jvalue.h"
24
25namespace art {
26
Mathieu Chartiere401d142015-04-22 13:56:20 -070027class ArtMethod;
Andreas Gampe2969bcd2015-03-09 12:57:41 -070028class Thread;
29class ShadowFrame;
30
31namespace mirror {
Andreas Gampe2969bcd2015-03-09 12:57:41 -070032class Object;
Andreas Gampe2969bcd2015-03-09 12:57:41 -070033} // namespace mirror
34
35namespace interpreter {
36
Andreas Gampe799681b2015-05-15 19:24:12 -070037// 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 Gampe2969bcd2015-03-09 12:57:41 -070045
Andreas Gampe799681b2015-05-15 19:24:12 -070046class UnstartedRuntime {
47 public:
48 static void Initialize();
Andreas Gampe2969bcd2015-03-09 12:57:41 -070049
Andreas Gampe799681b2015-05-15 19:24:12 -070050 static void Invoke(Thread* self,
51 const DexFile::CodeItem* code_item,
52 ShadowFrame* shadow_frame,
53 JValue* result,
54 size_t arg_offset)
Mathieu Chartier90443472015-07-16 20:32:27 -070055 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070056
57 static void Jni(Thread* self,
Mathieu Chartiere401d142015-04-22 13:56:20 -070058 ArtMethod* method,
Andreas Gampe799681b2015-05-15 19:24:12 -070059 mirror::Object* receiver,
60 uint32_t* args,
61 JValue* result)
Mathieu Chartier90443472015-07-16 20:32:27 -070062 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070063
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 Chartier90443472015-07-16 20:32:27 -070071 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070072#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 Chartiere401d142015-04-22 13:56:20 -070081 ArtMethod* method, \
Andreas Gampe799681b2015-05-15 19:24:12 -070082 mirror::Object* receiver, \
83 uint32_t* args, \
84 JValue* result) \
Mathieu Chartier90443472015-07-16 20:32:27 -070085 SHARED_REQUIRES(Locks::mutator_lock_);
Andreas Gampe799681b2015-05-15 19:24:12 -070086#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 Gampe2969bcd2015-03-09 12:57:41 -0700100
101} // namespace interpreter
102} // namespace art
103
104#endif // ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_