blob: 11a67ac5dd89d60b85ef61a1e9f701e18c2b4cfd [file] [log] [blame]
Elliott Hughes0f3c5532012-03-30 14:51:51 -07001/*
2 * Copyright (C) 2012 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 */
buzbee54330722011-08-23 16:46:55 -070016
Ian Rogers7655f292013-07-29 11:07:13 -070017#ifndef ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_
18#define ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_
Ian Rogers450dcb52013-09-20 17:36:02 -070019
Mingyao Yang98d1cc82014-05-15 17:02:16 -070020#include <jni.h>
21#include <stdint.h>
22
Ian Rogers450dcb52013-09-20 17:36:02 -070023#include "base/macros.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070024#include "base/mutex.h"
25#include "gc/allocator_type.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070026#include "invoke_type.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070027#include "jvalue.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070028
Shih-wei Liao2d831012011-09-28 22:06:53 -070029namespace art {
Ian Rogers848871b2013-08-05 10:56:33 -070030
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031namespace mirror {
Ian Rogers848871b2013-08-05 10:56:33 -070032 class Class;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070033 class Array;
Brian Carlstromea46f952013-07-30 01:26:50 -070034 class ArtField;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070035 class ArtMethod;
Ian Rogers848871b2013-08-05 10:56:33 -070036 class Object;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070037 class String;
Ian Rogers848871b2013-08-05 10:56:33 -070038} // namespace mirror
Ian Rogers57b86d42012-03-27 16:05:41 -070039
Mingyao Yang98d1cc82014-05-15 17:02:16 -070040class ScopedObjectAccessAlreadyRunnable;
41class Thread;
42
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080043// TODO: Fix no thread safety analysis when GCC can handle template specialization.
44template <const bool kAccessCheck>
45ALWAYS_INLINE static inline mirror::Class* CheckObjectAlloc(uint32_t type_idx,
46 mirror::ArtMethod* method,
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080047 Thread* self, bool* slow_path)
Mingyao Yang98d1cc82014-05-15 17:02:16 -070048 NO_THREAD_SAFETY_ANALYSIS;
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070049
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080050// TODO: Fix no thread safety analysis when annotalysis is smarter.
51ALWAYS_INLINE static inline mirror::Class* CheckClassInitializedForObjectAlloc(mirror::Class* klass,
52 Thread* self, bool* slow_path)
Mingyao Yang98d1cc82014-05-15 17:02:16 -070053 NO_THREAD_SAFETY_ANALYSIS;
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080054
Ian Rogers57b86d42012-03-27 16:05:41 -070055// Given the context of a calling Method, use its DexCache to resolve a type to a Class. If it
56// cannot be resolved, throw an error. If it can, use it to create an instance.
57// When verification/compiler hasn't been able to verify access, optionally perform an access
58// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080059// TODO: Fix NO_THREAD_SAFETY_ANALYSIS when GCC is smarter.
60template <bool kAccessCheck, bool kInstrumented>
61ALWAYS_INLINE static inline mirror::Object* AllocObjectFromCode(uint32_t type_idx,
62 mirror::ArtMethod* method,
63 Thread* self,
Mingyao Yang98d1cc82014-05-15 17:02:16 -070064 gc::AllocatorType allocator_type);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070065
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080066// Given the context of a calling Method and a resolved class, create an instance.
67// TODO: Fix NO_THREAD_SAFETY_ANALYSIS when GCC is smarter.
68template <bool kInstrumented>
69ALWAYS_INLINE static inline mirror::Object* AllocObjectFromCodeResolved(mirror::Class* klass,
70 mirror::ArtMethod* method,
71 Thread* self,
72 gc::AllocatorType allocator_type)
Mingyao Yang98d1cc82014-05-15 17:02:16 -070073 NO_THREAD_SAFETY_ANALYSIS;
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080074
75// Given the context of a calling Method and an initialized class, create an instance.
76// TODO: Fix NO_THREAD_SAFETY_ANALYSIS when GCC is smarter.
77template <bool kInstrumented>
78ALWAYS_INLINE static inline mirror::Object* AllocObjectFromCodeInitialized(mirror::Class* klass,
79 mirror::ArtMethod* method,
80 Thread* self,
Mingyao Yang98d1cc82014-05-15 17:02:16 -070081 gc::AllocatorType allocator_type);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080082
83
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080084// TODO: Fix no thread safety analysis when GCC can handle template specialization.
85template <bool kAccessCheck>
86ALWAYS_INLINE static inline mirror::Class* CheckArrayAlloc(uint32_t type_idx,
87 mirror::ArtMethod* method,
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080088 int32_t component_count,
89 bool* slow_path)
Mingyao Yang98d1cc82014-05-15 17:02:16 -070090 NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers57b86d42012-03-27 16:05:41 -070091
92// Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
93// it cannot be resolved, throw an error. If it can, use it to create an array.
94// When verification/compiler hasn't been able to verify access, optionally perform an access
95// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080096// TODO: Fix no thread safety analysis when GCC can handle template specialization.
97template <bool kAccessCheck, bool kInstrumented>
98ALWAYS_INLINE static inline mirror::Array* AllocArrayFromCode(uint32_t type_idx,
99 mirror::ArtMethod* method,
100 int32_t component_count,
101 Thread* self,
102 gc::AllocatorType allocator_type)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700103 NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers57b86d42012-03-27 16:05:41 -0700104
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800105template <bool kAccessCheck, bool kInstrumented>
106ALWAYS_INLINE static inline mirror::Array* AllocArrayFromCodeResolved(mirror::Class* klass,
107 mirror::ArtMethod* method,
108 int32_t component_count,
109 Thread* self,
110 gc::AllocatorType allocator_type)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700111 NO_THREAD_SAFETY_ANALYSIS;
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800112
Brian Carlstromea46f952013-07-30 01:26:50 -0700113extern mirror::Array* CheckAndAllocArrayFromCode(uint32_t type_idx, mirror::ArtMethod* method,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800114 int32_t component_count, Thread* self,
115 bool access_check,
116 gc::AllocatorType allocator_type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700117 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700118
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800119extern mirror::Array* CheckAndAllocArrayFromCodeInstrumented(uint32_t type_idx,
120 mirror::ArtMethod* method,
121 int32_t component_count, Thread* self,
122 bool access_check,
123 gc::AllocatorType allocator_type)
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700124 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
125
Ian Rogers08f753d2012-08-24 14:35:25 -0700126// Type of find field operation for fast and slow case.
127enum FindFieldType {
128 InstanceObjectRead,
129 InstanceObjectWrite,
130 InstancePrimitiveRead,
131 InstancePrimitiveWrite,
132 StaticObjectRead,
133 StaticObjectWrite,
134 StaticPrimitiveRead,
135 StaticPrimitiveWrite,
136};
137
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200138template<FindFieldType type, bool access_check>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800139static inline mirror::ArtField* FindFieldFromCode(uint32_t field_idx, mirror::ArtMethod* referrer,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700140 Thread* self, size_t expected_size)
141 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200142
143template<InvokeType type, bool access_check>
Mathieu Chartierd565caf2014-02-16 15:59:00 -0800144static inline mirror::ArtMethod* FindMethodFromCode(uint32_t method_idx,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700145 mirror::Object** this_object,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700146 mirror::ArtMethod** referrer, Thread* self)
147 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700148
Ian Rogers08f753d2012-08-24 14:35:25 -0700149// Fast path field resolution that can't initialize classes or throw exceptions.
Brian Carlstromea46f952013-07-30 01:26:50 -0700150static inline mirror::ArtField* FindFieldFast(uint32_t field_idx,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800151 mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700152 FindFieldType type, size_t expected_size)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700153 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700154
Ian Rogers08f753d2012-08-24 14:35:25 -0700155// Fast path method resolution that can't throw exceptions.
Brian Carlstromea46f952013-07-30 01:26:50 -0700156static inline mirror::ArtMethod* FindMethodFast(uint32_t method_idx,
157 mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800158 mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700159 bool access_check, InvokeType type)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700160 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700161
Ian Rogersfa46d3e2013-05-15 00:16:04 -0700162static inline mirror::Class* ResolveVerifyAndClinit(uint32_t type_idx,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800163 mirror::ArtMethod* referrer,
Ian Rogersfa46d3e2013-05-15 00:16:04 -0700164 Thread* self, bool can_run_clinit,
165 bool verify_access)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700166 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700167
jeffhaod7521322012-11-21 15:38:24 -0800168extern void ThrowStackOverflowError(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
169
Ian Rogersef7d42f2014-01-06 12:55:46 -0800170static inline mirror::String* ResolveStringFromCode(mirror::ArtMethod* referrer,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800171 uint32_t string_idx)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700172 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao2d831012011-09-28 22:06:53 -0700173
TDYa1273d71d802012-08-15 03:47:03 -0700174static inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700175 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa1273d71d802012-08-15 03:47:03 -0700176
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800177static inline void CheckReferenceResult(mirror::Object* o, Thread* self)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700178 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa1273d71d802012-08-15 03:47:03 -0700179
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700180static inline void CheckSuspend(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao373c52f2012-11-20 16:11:52 -0800181
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700182JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
Brian Carlstromea46f952013-07-30 01:26:50 -0700183 jobject rcvr_jobj, jobject interface_art_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800184 std::vector<jvalue>& args)
Brian Carlstrom02c8cc62013-07-18 15:54:44 -0700185 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800186
Jeff Hao58df3272013-04-22 15:28:53 -0700187// Entry point for deoptimization.
Ian Rogers848871b2013-08-05 10:56:33 -0700188extern "C" void art_quick_deoptimize();
189static inline uintptr_t GetQuickDeoptimizationEntryPoint() {
Jeff Hao58df3272013-04-22 15:28:53 -0700190 return reinterpret_cast<uintptr_t>(art_quick_deoptimize);
191}
192
193// Return address of instrumentation stub.
Ian Rogers848871b2013-08-05 10:56:33 -0700194extern "C" void art_quick_instrumentation_entry(void*);
195static inline void* GetQuickInstrumentationEntryPoint() {
196 return reinterpret_cast<void*>(art_quick_instrumentation_entry);
Jeff Hao58df3272013-04-22 15:28:53 -0700197}
198
199// The return_pc of instrumentation exit stub.
Ian Rogers848871b2013-08-05 10:56:33 -0700200extern "C" void art_quick_instrumentation_exit();
201static inline uintptr_t GetQuickInstrumentationExitPc() {
202 return reinterpret_cast<uintptr_t>(art_quick_instrumentation_exit);
203}
204
Brian Carlstromea46f952013-07-30 01:26:50 -0700205extern "C" void art_portable_to_interpreter_bridge(mirror::ArtMethod*);
Ian Rogers848871b2013-08-05 10:56:33 -0700206static inline const void* GetPortableToInterpreterBridge() {
207 return reinterpret_cast<void*>(art_portable_to_interpreter_bridge);
208}
209
Ian Rogersef7d42f2014-01-06 12:55:46 -0800210static inline const void* GetPortableToQuickBridge() {
211 // TODO: portable to quick bridge. Bug: 8196384
212 return GetPortableToInterpreterBridge();
213}
214
Brian Carlstromea46f952013-07-30 01:26:50 -0700215extern "C" void art_quick_to_interpreter_bridge(mirror::ArtMethod*);
Ian Rogers848871b2013-08-05 10:56:33 -0700216static inline const void* GetQuickToInterpreterBridge() {
217 return reinterpret_cast<void*>(art_quick_to_interpreter_bridge);
Jeff Hao58df3272013-04-22 15:28:53 -0700218}
219
Ian Rogersef7d42f2014-01-06 12:55:46 -0800220static inline const void* GetQuickToPortableBridge() {
221 // TODO: quick to portable bridge. Bug: 8196384
Ian Rogers848871b2013-08-05 10:56:33 -0700222 return GetQuickToInterpreterBridge();
Jeff Hao58df3272013-04-22 15:28:53 -0700223}
224
Ian Rogers848871b2013-08-05 10:56:33 -0700225extern "C" void art_portable_proxy_invoke_handler();
226static inline const void* GetPortableProxyInvokeHandler() {
227 return reinterpret_cast<void*>(art_portable_proxy_invoke_handler);
Jeff Hao79fe5392013-04-24 18:41:58 -0700228}
229
Ian Rogers848871b2013-08-05 10:56:33 -0700230extern "C" void art_quick_proxy_invoke_handler();
231static inline const void* GetQuickProxyInvokeHandler() {
232 return reinterpret_cast<void*>(art_quick_proxy_invoke_handler);
Jeff Hao79fe5392013-04-24 18:41:58 -0700233}
234
Ian Rogers848871b2013-08-05 10:56:33 -0700235extern "C" void* art_jni_dlsym_lookup_stub(JNIEnv*, jobject);
Jeff Hao79fe5392013-04-24 18:41:58 -0700236static inline void* GetJniDlsymLookupStub() {
237 return reinterpret_cast<void*>(art_jni_dlsym_lookup_stub);
238}
Jeff Hao58df3272013-04-22 15:28:53 -0700239
Ian Rogers450dcb52013-09-20 17:36:02 -0700240template <typename INT_TYPE, typename FLOAT_TYPE>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700241static inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
Ian Rogers450dcb52013-09-20 17:36:02 -0700242
Shih-wei Liao2d831012011-09-28 22:06:53 -0700243} // namespace art
Ian Rogersad42e132011-09-17 20:23:33 -0700244
Ian Rogers7655f292013-07-29 11:07:13 -0700245#endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_