entrypoint_utils.h revision 9f612ffab2b188d80027d961d7118eb2c461b5ad
1/*
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 */
16
17#ifndef ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_
18#define ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_
19
20#include <jni.h>
21#include <stdint.h>
22
23#include "base/macros.h"
24#include "base/mutex.h"
25#include "dex_instruction.h"
26#include "gc/allocator_type.h"
27#include "invoke_type.h"
28#include "jvalue.h"
29
30namespace art {
31
32namespace mirror {
33  class Class;
34  class Array;
35  class ArtField;
36  class ArtMethod;
37  class Object;
38  class String;
39}  // namespace mirror
40
41class ScopedObjectAccessAlreadyRunnable;
42class Thread;
43
44template <const bool kAccessCheck>
45ALWAYS_INLINE inline mirror::Class* CheckObjectAlloc(uint32_t type_idx,
46                                                     mirror::ArtMethod* method,
47                                                     Thread* self, bool* slow_path)
48    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
49
50ALWAYS_INLINE inline mirror::Class* CheckClassInitializedForObjectAlloc(mirror::Class* klass,
51                                                                        Thread* self,
52                                                                        bool* slow_path)
53    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
54
55// 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.
59template <bool kAccessCheck, bool kInstrumented>
60ALWAYS_INLINE inline mirror::Object* AllocObjectFromCode(uint32_t type_idx,
61                                                         mirror::ArtMethod* method,
62                                                         Thread* self,
63                                                         gc::AllocatorType allocator_type)
64    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
65
66// Given the context of a calling Method and a resolved class, create an instance.
67template <bool kInstrumented>
68ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeResolved(mirror::Class* klass,
69                                                                 Thread* self,
70                                                                 gc::AllocatorType allocator_type)
71    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
72
73// Given the context of a calling Method and an initialized class, create an instance.
74template <bool kInstrumented>
75ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeInitialized(mirror::Class* klass,
76                                                                    Thread* self,
77                                                                    gc::AllocatorType allocator_type)
78    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
79
80
81template <bool kAccessCheck>
82ALWAYS_INLINE inline mirror::Class* CheckArrayAlloc(uint32_t type_idx,
83                                                    mirror::ArtMethod* method,
84                                                    int32_t component_count,
85                                                    bool* slow_path)
86    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
87
88// Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
89// it cannot be resolved, throw an error. If it can, use it to create an array.
90// When verification/compiler hasn't been able to verify access, optionally perform an access
91// check.
92template <bool kAccessCheck, bool kInstrumented>
93ALWAYS_INLINE inline mirror::Array* AllocArrayFromCode(uint32_t type_idx,
94                                                       mirror::ArtMethod* method,
95                                                       int32_t component_count,
96                                                       Thread* self,
97                                                       gc::AllocatorType allocator_type)
98    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
99
100template <bool kAccessCheck, bool kInstrumented>
101ALWAYS_INLINE inline mirror::Array* AllocArrayFromCodeResolved(mirror::Class* klass,
102                                                               mirror::ArtMethod* method,
103                                                               int32_t component_count,
104                                                               Thread* self,
105                                                               gc::AllocatorType allocator_type)
106    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
107
108extern mirror::Array* CheckAndAllocArrayFromCode(uint32_t type_idx, mirror::ArtMethod* method,
109                                                 int32_t component_count, Thread* self,
110                                                 bool access_check,
111                                                 gc::AllocatorType allocator_type)
112    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
113
114extern mirror::Array* CheckAndAllocArrayFromCodeInstrumented(uint32_t type_idx,
115                                                             mirror::ArtMethod* method,
116                                                             int32_t component_count, Thread* self,
117                                                             bool access_check,
118                                                             gc::AllocatorType allocator_type)
119    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
120
121// Type of find field operation for fast and slow case.
122enum FindFieldType {
123  InstanceObjectRead,
124  InstanceObjectWrite,
125  InstancePrimitiveRead,
126  InstancePrimitiveWrite,
127  StaticObjectRead,
128  StaticObjectWrite,
129  StaticPrimitiveRead,
130  StaticPrimitiveWrite,
131};
132
133template<FindFieldType type, bool access_check>
134inline mirror::ArtField* FindFieldFromCode(uint32_t field_idx, mirror::ArtMethod* referrer,
135                                           Thread* self, size_t expected_size)
136    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
137
138template<InvokeType type, bool access_check>
139inline mirror::ArtMethod* FindMethodFromCode(uint32_t method_idx,
140                                             mirror::Object** this_object,
141                                             mirror::ArtMethod** referrer, Thread* self)
142    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
143
144// Fast path field resolution that can't initialize classes or throw exceptions.
145inline mirror::ArtField* FindFieldFast(uint32_t field_idx,
146                                       mirror::ArtMethod* referrer,
147                                       FindFieldType type, size_t expected_size)
148    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
149
150// Fast path method resolution that can't throw exceptions.
151inline mirror::ArtMethod* FindMethodFast(uint32_t method_idx,
152                                         mirror::Object* this_object,
153                                         mirror::ArtMethod* referrer,
154                                         bool access_check, InvokeType type)
155    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
156
157inline mirror::Class* ResolveVerifyAndClinit(uint32_t type_idx,
158                                             mirror::ArtMethod* referrer,
159                                             Thread* self, bool can_run_clinit,
160                                             bool verify_access)
161    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
162
163extern void ThrowStackOverflowError(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
164
165inline mirror::String* ResolveStringFromCode(mirror::ArtMethod* referrer, uint32_t string_idx)
166    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
167
168// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
169inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
170    NO_THREAD_SAFETY_ANALYSIS;
171
172void CheckReferenceResult(mirror::Object* o, Thread* self)
173    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
174
175JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
176                                    jobject rcvr_jobj, jobject interface_art_method_jobj,
177                                    std::vector<jvalue>& args)
178    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
179
180bool FillArrayData(mirror::Object* obj, const Instruction::ArrayDataPayload* payload)
181    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
182
183template <typename INT_TYPE, typename FLOAT_TYPE>
184inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
185
186}  // namespace art
187
188#endif  // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_
189