blob: a361af05423b1f3e757da5a03e51671bbcf10ad4 [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
27class Thread;
28class ShadowFrame;
29
30namespace mirror {
31
32class ArtMethod;
33class Object;
34
35} // 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
Andreas Gampe799681b2015-05-15 19:24:12 -070052 static void Invoke(Thread* self,
53 const DexFile::CodeItem* code_item,
54 ShadowFrame* shadow_frame,
55 JValue* result,
56 size_t arg_offset)
57 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
58
59 static void Jni(Thread* self,
60 mirror::ArtMethod* method,
61 mirror::Object* receiver,
62 uint32_t* args,
63 JValue* result)
64 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
65
66 private:
67 // Methods that intercept available libcore implementations.
68#define UNSTARTED_DIRECT(ShortName, SigIgnored) \
69 static void Unstarted ## ShortName(Thread* self, \
70 ShadowFrame* shadow_frame, \
71 JValue* result, \
72 size_t arg_offset) \
73 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
74#include "unstarted_runtime_list.h"
75 UNSTARTED_RUNTIME_DIRECT_LIST(UNSTARTED_DIRECT)
76#undef UNSTARTED_RUNTIME_DIRECT_LIST
77#undef UNSTARTED_RUNTIME_JNI_LIST
78#undef UNSTARTED_DIRECT
79
80 // Methods that are native.
81#define UNSTARTED_JNI(ShortName, SigIgnored) \
82 static void UnstartedJNI ## ShortName(Thread* self, \
83 mirror::ArtMethod* method, \
84 mirror::Object* receiver, \
85 uint32_t* args, \
86 JValue* result) \
87 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
88#include "unstarted_runtime_list.h"
89 UNSTARTED_RUNTIME_JNI_LIST(UNSTARTED_JNI)
90#undef UNSTARTED_RUNTIME_DIRECT_LIST
91#undef UNSTARTED_RUNTIME_JNI_LIST
92#undef UNSTARTED_JNI
93
94 static void InitializeInvokeHandlers();
95 static void InitializeJNIHandlers();
96
97 friend class UnstartedRuntimeTest;
98
99 DISALLOW_ALLOCATION();
100 DISALLOW_COPY_AND_ASSIGN(UnstartedRuntime);
101};
Andreas Gampe2969bcd2015-03-09 12:57:41 -0700102
103} // namespace interpreter
104} // namespace art
105
106#endif // ART_RUNTIME_INTERPRETER_UNSTARTED_RUNTIME_H_