blob: c5d67aa1dfdafcbaf948ad89f30cf8cc3c57ea77 [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)
Ian Rogerse5877a12014-07-16 12:06:35 -070048 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
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)
Ian Rogerse5877a12014-07-16 12:06:35 -070053 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
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,
Ian Rogerse5877a12014-07-16 12:06:35 -070064 gc::AllocatorType allocator_type)
65 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070066
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080067// Given the context of a calling Method and a resolved class, create an instance.
68// TODO: Fix NO_THREAD_SAFETY_ANALYSIS when GCC is smarter.
69template <bool kInstrumented>
70ALWAYS_INLINE static inline mirror::Object* AllocObjectFromCodeResolved(mirror::Class* klass,
71 mirror::ArtMethod* method,
72 Thread* self,
73 gc::AllocatorType allocator_type)
Ian Rogerse5877a12014-07-16 12:06:35 -070074 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080075
76// Given the context of a calling Method and an initialized class, create an instance.
77// TODO: Fix NO_THREAD_SAFETY_ANALYSIS when GCC is smarter.
78template <bool kInstrumented>
79ALWAYS_INLINE static inline mirror::Object* AllocObjectFromCodeInitialized(mirror::Class* klass,
80 mirror::ArtMethod* method,
81 Thread* self,
Ian Rogerse5877a12014-07-16 12:06:35 -070082 gc::AllocatorType allocator_type)
83 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080084
85
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080086// TODO: Fix no thread safety analysis when GCC can handle template specialization.
87template <bool kAccessCheck>
88ALWAYS_INLINE static inline mirror::Class* CheckArrayAlloc(uint32_t type_idx,
89 mirror::ArtMethod* method,
Mathieu Chartiere6da9af2013-12-16 11:54:42 -080090 int32_t component_count,
91 bool* slow_path)
Ian Rogerse5877a12014-07-16 12:06:35 -070092 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -070093
94// Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
95// it cannot be resolved, throw an error. If it can, use it to create an array.
96// When verification/compiler hasn't been able to verify access, optionally perform an access
97// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080098// TODO: Fix no thread safety analysis when GCC can handle template specialization.
99template <bool kAccessCheck, bool kInstrumented>
100ALWAYS_INLINE static inline mirror::Array* AllocArrayFromCode(uint32_t type_idx,
101 mirror::ArtMethod* method,
102 int32_t component_count,
103 Thread* self,
104 gc::AllocatorType allocator_type)
Ian Rogerse5877a12014-07-16 12:06:35 -0700105 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700106
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800107template <bool kAccessCheck, bool kInstrumented>
108ALWAYS_INLINE static inline mirror::Array* AllocArrayFromCodeResolved(mirror::Class* klass,
109 mirror::ArtMethod* method,
110 int32_t component_count,
111 Thread* self,
112 gc::AllocatorType allocator_type)
Ian Rogerse5877a12014-07-16 12:06:35 -0700113 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800114
Brian Carlstromea46f952013-07-30 01:26:50 -0700115extern mirror::Array* CheckAndAllocArrayFromCode(uint32_t type_idx, mirror::ArtMethod* method,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800116 int32_t component_count, Thread* self,
117 bool access_check,
118 gc::AllocatorType allocator_type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700119 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700120
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800121extern mirror::Array* CheckAndAllocArrayFromCodeInstrumented(uint32_t type_idx,
122 mirror::ArtMethod* method,
123 int32_t component_count, Thread* self,
124 bool access_check,
125 gc::AllocatorType allocator_type)
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700126 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
127
Ian Rogers08f753d2012-08-24 14:35:25 -0700128// Type of find field operation for fast and slow case.
129enum FindFieldType {
130 InstanceObjectRead,
131 InstanceObjectWrite,
132 InstancePrimitiveRead,
133 InstancePrimitiveWrite,
134 StaticObjectRead,
135 StaticObjectWrite,
136 StaticPrimitiveRead,
137 StaticPrimitiveWrite,
138};
139
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200140template<FindFieldType type, bool access_check>
Ian Rogersef7d42f2014-01-06 12:55:46 -0800141static inline mirror::ArtField* FindFieldFromCode(uint32_t field_idx, mirror::ArtMethod* referrer,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700142 Thread* self, size_t expected_size)
143 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200144
145template<InvokeType type, bool access_check>
Mathieu Chartierd565caf2014-02-16 15:59:00 -0800146static inline mirror::ArtMethod* FindMethodFromCode(uint32_t method_idx,
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700147 mirror::Object** this_object,
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700148 mirror::ArtMethod** referrer, Thread* self)
149 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700150
Ian Rogers08f753d2012-08-24 14:35:25 -0700151// Fast path field resolution that can't initialize classes or throw exceptions.
Brian Carlstromea46f952013-07-30 01:26:50 -0700152static inline mirror::ArtField* FindFieldFast(uint32_t field_idx,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800153 mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700154 FindFieldType type, size_t expected_size)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700155 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700156
Ian Rogers08f753d2012-08-24 14:35:25 -0700157// Fast path method resolution that can't throw exceptions.
Brian Carlstromea46f952013-07-30 01:26:50 -0700158static inline mirror::ArtMethod* FindMethodFast(uint32_t method_idx,
159 mirror::Object* this_object,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800160 mirror::ArtMethod* referrer,
Brian Carlstromea46f952013-07-30 01:26:50 -0700161 bool access_check, InvokeType type)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700162 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700163
Ian Rogersfa46d3e2013-05-15 00:16:04 -0700164static inline mirror::Class* ResolveVerifyAndClinit(uint32_t type_idx,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800165 mirror::ArtMethod* referrer,
Ian Rogersfa46d3e2013-05-15 00:16:04 -0700166 Thread* self, bool can_run_clinit,
167 bool verify_access)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700168 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700169
jeffhaod7521322012-11-21 15:38:24 -0800170extern void ThrowStackOverflowError(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
171
Ian Rogersef7d42f2014-01-06 12:55:46 -0800172static inline mirror::String* ResolveStringFromCode(mirror::ArtMethod* referrer,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800173 uint32_t string_idx)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700174 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Shih-wei Liao2d831012011-09-28 22:06:53 -0700175
Ian Rogerse5877a12014-07-16 12:06:35 -0700176// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
TDYa1273d71d802012-08-15 03:47:03 -0700177static inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
Ian Rogerse5877a12014-07-16 12:06:35 -0700178 NO_THREAD_SAFETY_ANALYSIS;
TDYa1273d71d802012-08-15 03:47:03 -0700179
Ian Rogerse5877a12014-07-16 12:06:35 -0700180void CheckReferenceResult(mirror::Object* o, Thread* self)
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700181 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
TDYa1273d71d802012-08-15 03:47:03 -0700182
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700183static inline void CheckSuspend(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
jeffhao373c52f2012-11-20 16:11:52 -0800184
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700185JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
Brian Carlstromea46f952013-07-30 01:26:50 -0700186 jobject rcvr_jobj, jobject interface_art_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800187 std::vector<jvalue>& args)
Brian Carlstrom02c8cc62013-07-18 15:54:44 -0700188 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800189
Jeff Hao58df3272013-04-22 15:28:53 -0700190// Entry point for deoptimization.
Ian Rogers848871b2013-08-05 10:56:33 -0700191extern "C" void art_quick_deoptimize();
192static inline uintptr_t GetQuickDeoptimizationEntryPoint() {
Jeff Hao58df3272013-04-22 15:28:53 -0700193 return reinterpret_cast<uintptr_t>(art_quick_deoptimize);
194}
195
196// Return address of instrumentation stub.
Ian Rogers848871b2013-08-05 10:56:33 -0700197extern "C" void art_quick_instrumentation_entry(void*);
198static inline void* GetQuickInstrumentationEntryPoint() {
199 return reinterpret_cast<void*>(art_quick_instrumentation_entry);
Jeff Hao58df3272013-04-22 15:28:53 -0700200}
201
202// The return_pc of instrumentation exit stub.
Ian Rogers848871b2013-08-05 10:56:33 -0700203extern "C" void art_quick_instrumentation_exit();
204static inline uintptr_t GetQuickInstrumentationExitPc() {
205 return reinterpret_cast<uintptr_t>(art_quick_instrumentation_exit);
206}
207
Brian Carlstromea46f952013-07-30 01:26:50 -0700208extern "C" void art_portable_to_interpreter_bridge(mirror::ArtMethod*);
Ian Rogers848871b2013-08-05 10:56:33 -0700209static inline const void* GetPortableToInterpreterBridge() {
210 return reinterpret_cast<void*>(art_portable_to_interpreter_bridge);
211}
212
Ian Rogersef7d42f2014-01-06 12:55:46 -0800213static inline const void* GetPortableToQuickBridge() {
214 // TODO: portable to quick bridge. Bug: 8196384
215 return GetPortableToInterpreterBridge();
216}
217
Brian Carlstromea46f952013-07-30 01:26:50 -0700218extern "C" void art_quick_to_interpreter_bridge(mirror::ArtMethod*);
Ian Rogers848871b2013-08-05 10:56:33 -0700219static inline const void* GetQuickToInterpreterBridge() {
220 return reinterpret_cast<void*>(art_quick_to_interpreter_bridge);
Jeff Hao58df3272013-04-22 15:28:53 -0700221}
222
Ian Rogersef7d42f2014-01-06 12:55:46 -0800223static inline const void* GetQuickToPortableBridge() {
224 // TODO: quick to portable bridge. Bug: 8196384
Ian Rogers848871b2013-08-05 10:56:33 -0700225 return GetQuickToInterpreterBridge();
Jeff Hao58df3272013-04-22 15:28:53 -0700226}
227
Ian Rogers848871b2013-08-05 10:56:33 -0700228extern "C" void art_portable_proxy_invoke_handler();
229static inline const void* GetPortableProxyInvokeHandler() {
230 return reinterpret_cast<void*>(art_portable_proxy_invoke_handler);
Jeff Hao79fe5392013-04-24 18:41:58 -0700231}
232
Ian Rogers848871b2013-08-05 10:56:33 -0700233extern "C" void art_quick_proxy_invoke_handler();
234static inline const void* GetQuickProxyInvokeHandler() {
235 return reinterpret_cast<void*>(art_quick_proxy_invoke_handler);
Jeff Hao79fe5392013-04-24 18:41:58 -0700236}
237
Ian Rogers848871b2013-08-05 10:56:33 -0700238extern "C" void* art_jni_dlsym_lookup_stub(JNIEnv*, jobject);
Jeff Hao79fe5392013-04-24 18:41:58 -0700239static inline void* GetJniDlsymLookupStub() {
240 return reinterpret_cast<void*>(art_jni_dlsym_lookup_stub);
241}
Jeff Hao58df3272013-04-22 15:28:53 -0700242
Ian Rogers450dcb52013-09-20 17:36:02 -0700243template <typename INT_TYPE, typename FLOAT_TYPE>
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700244static inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
Ian Rogers450dcb52013-09-20 17:36:02 -0700245
Shih-wei Liao2d831012011-09-28 22:06:53 -0700246} // namespace art
Ian Rogersad42e132011-09-17 20:23:33 -0700247
Ian Rogers7655f292013-07-29 11:07:13 -0700248#endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_