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/mutex.h" 21#include "jni.h" 22#include "primitive.h" 23 24namespace art { 25namespace mirror { 26 class Class; 27 class Object; 28} // namespace mirror 29class ArtField; 30class ArtMethod; 31union JValue; 32class ScopedObjectAccessAlreadyRunnable; 33class ShadowFrame; 34 35mirror::Object* BoxPrimitive(Primitive::Type src_class, const JValue& value) 36 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 37bool UnboxPrimitiveForField(mirror::Object* o, mirror::Class* dst_class, ArtField* f, 38 JValue* unboxed_value) 39 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 40bool UnboxPrimitiveForResult(mirror::Object* o, mirror::Class* dst_class, JValue* unboxed_value) 41 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 42 43ALWAYS_INLINE bool ConvertPrimitiveValue(bool unbox_for_result, 44 Primitive::Type src_class, Primitive::Type dst_class, 45 const JValue& src, JValue* dst) 46 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 47 48JValue InvokeWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, jobject obj, jmethodID mid, 49 va_list args) 50 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 51 52JValue InvokeWithJValues(const ScopedObjectAccessAlreadyRunnable& soa, jobject obj, jmethodID mid, 53 jvalue* args) 54 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 55 56JValue InvokeVirtualOrInterfaceWithJValues(const ScopedObjectAccessAlreadyRunnable& soa, 57 jobject obj, jmethodID mid, jvalue* args) 58 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 59 60JValue InvokeVirtualOrInterfaceWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, 61 jobject obj, jmethodID mid, va_list args) 62 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 63 64// num_frames is number of frames we look up for access check. 65jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject method, jobject receiver, 66 jobject args, size_t num_frames = 1) 67 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 68 69ALWAYS_INLINE bool VerifyObjectIsClass(mirror::Object* o, mirror::Class* c) 70 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 71 72bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class, 73 uint32_t access_flags, mirror::Class** calling_class, size_t num_frames) 74 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 75 76// This version takes a known calling class. 77bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class, 78 uint32_t access_flags, mirror::Class* calling_class) 79 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 80 81// Get the calling class by using a stack visitor, may return null for unattached native threads. 82mirror::Class* GetCallingClass(Thread* self, size_t num_frames) 83 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 84 85void InvalidReceiverError(mirror::Object* o, mirror::Class* c) 86 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 87 88void UpdateReference(Thread* self, jobject obj, mirror::Object* result) 89 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 90 91} // namespace art 92 93#endif // ART_RUNTIME_REFLECTION_H_ 94