1 /* 2 * Copyright (C) 2011 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_REFLECTION_H_ 18 #define ART_RUNTIME_REFLECTION_H_ 19 20 #include "base/locks.h" 21 #include "dex/primitive.h" 22 #include "jni.h" 23 #include "obj_ptr.h" 24 25 namespace art { 26 namespace mirror { 27 class Class; 28 class Object; 29 } // namespace mirror 30 class ArtField; 31 class ArtMethod; 32 union JValue; 33 class ScopedObjectAccessAlreadyRunnable; 34 class ShadowFrame; 35 36 ObjPtr<mirror::Object> BoxPrimitive(Primitive::Type src_class, const JValue& value) 37 REQUIRES_SHARED(Locks::mutator_lock_); 38 39 bool UnboxPrimitiveForField(ObjPtr<mirror::Object> o, 40 ObjPtr<mirror::Class> dst_class, 41 ArtField* f, 42 JValue* unboxed_value) 43 REQUIRES_SHARED(Locks::mutator_lock_); 44 45 bool UnboxPrimitiveForResult(ObjPtr<mirror::Object> o, 46 ObjPtr<mirror::Class> dst_class, 47 JValue* unboxed_value) 48 REQUIRES_SHARED(Locks::mutator_lock_); 49 50 ALWAYS_INLINE bool ConvertPrimitiveValueNoThrow(Primitive::Type src_class, 51 Primitive::Type dst_class, 52 const JValue& src, 53 JValue* dst) 54 REQUIRES_SHARED(Locks::mutator_lock_); 55 56 ALWAYS_INLINE bool ConvertPrimitiveValue(bool unbox_for_result, 57 Primitive::Type src_class, 58 Primitive::Type dst_class, 59 const JValue& src, 60 JValue* dst) 61 REQUIRES_SHARED(Locks::mutator_lock_); 62 63 JValue InvokeWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, 64 jobject obj, 65 jmethodID mid, 66 va_list args) 67 REQUIRES_SHARED(Locks::mutator_lock_); 68 69 JValue InvokeWithJValues(const ScopedObjectAccessAlreadyRunnable& soa, 70 jobject obj, 71 jmethodID mid, 72 const jvalue* args) 73 REQUIRES_SHARED(Locks::mutator_lock_); 74 75 JValue InvokeVirtualOrInterfaceWithJValues(const ScopedObjectAccessAlreadyRunnable& soa, 76 jobject obj, 77 jmethodID mid, 78 const jvalue* args) 79 REQUIRES_SHARED(Locks::mutator_lock_); 80 81 JValue InvokeVirtualOrInterfaceWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, 82 jobject obj, 83 jmethodID mid, 84 va_list args) 85 REQUIRES_SHARED(Locks::mutator_lock_); 86 87 // num_frames is number of frames we look up for access check. 88 jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, 89 jobject method, 90 jobject receiver, 91 jobject args, 92 size_t num_frames = 1) 93 REQUIRES_SHARED(Locks::mutator_lock_); 94 95 // Special-casing of the above. Assumes that the method is the correct constructor, the class is 96 // initialized, and that the receiver is an instance of the class. 97 void InvokeConstructor(const ScopedObjectAccessAlreadyRunnable& soa, 98 ArtMethod* constructor, 99 ObjPtr<mirror::Object> receiver, 100 jobject args) 101 REQUIRES_SHARED(Locks::mutator_lock_); 102 103 ALWAYS_INLINE bool VerifyObjectIsClass(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c) 104 REQUIRES_SHARED(Locks::mutator_lock_); 105 106 bool VerifyAccess(Thread* self, 107 ObjPtr<mirror::Object> obj, 108 ObjPtr<mirror::Class> declaring_class, 109 uint32_t access_flags, 110 ObjPtr<mirror::Class>* calling_class, 111 size_t num_frames) 112 REQUIRES_SHARED(Locks::mutator_lock_); 113 114 // This version takes a known calling class. 115 bool VerifyAccess(ObjPtr<mirror::Object> obj, 116 ObjPtr<mirror::Class> declaring_class, 117 uint32_t access_flags, 118 ObjPtr<mirror::Class> calling_class) 119 REQUIRES_SHARED(Locks::mutator_lock_); 120 121 // Get the calling class by using a stack visitor, may return null for unattached native threads. 122 ObjPtr<mirror::Class> GetCallingClass(Thread* self, size_t num_frames) 123 REQUIRES_SHARED(Locks::mutator_lock_); 124 125 void InvalidReceiverError(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c) 126 REQUIRES_SHARED(Locks::mutator_lock_); 127 128 void UpdateReference(Thread* self, jobject obj, ObjPtr<mirror::Object> result) 129 REQUIRES_SHARED(Locks::mutator_lock_); 130 131 } // namespace art 132 133 #endif // ART_RUNTIME_REFLECTION_H_ 134