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