blob: d9c38c1064cd8b22e0cbf0371da76096865e6c6d [file] [log] [blame]
Elliott Hughes418d20f2011-09-22 14:00:39 -07001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_REFLECTION_H_
18#define ART_RUNTIME_REFLECTION_H_
Elliott Hughes418d20f2011-09-22 14:00:39 -070019
Ian Rogers68d8b422014-07-17 11:09:10 -070020#include "base/mutex.h"
Elliott Hughes418d20f2011-09-22 14:00:39 -070021#include "jni.h"
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070022#include "primitive.h"
Elliott Hughes418d20f2011-09-22 14:00:39 -070023
24namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080025namespace mirror {
Brian Carlstromea46f952013-07-30 01:26:50 -070026 class Class;
27 class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070029class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070030class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031union JValue;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070032class ScopedObjectAccessAlreadyRunnable;
Ian Rogers53b8b092014-03-13 23:45:53 -070033class ShadowFrame;
Elliott Hughes418d20f2011-09-22 14:00:39 -070034
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035mirror::Object* BoxPrimitive(Primitive::Type src_class, const JValue& value)
Mathieu Chartier90443472015-07-16 20:32:27 -070036 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierc7853442015-03-27 14:35:38 -070037bool UnboxPrimitiveForField(mirror::Object* o, mirror::Class* dst_class, ArtField* f,
Ian Rogers84956ff2014-03-26 23:52:41 -070038 JValue* unboxed_value)
Mathieu Chartier90443472015-07-16 20:32:27 -070039 SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000040bool UnboxPrimitiveForResult(mirror::Object* o, mirror::Class* dst_class, JValue* unboxed_value)
Mathieu Chartier90443472015-07-16 20:32:27 -070041 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes418d20f2011-09-22 14:00:39 -070042
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000043ALWAYS_INLINE bool ConvertPrimitiveValue(bool unbox_for_result,
Mathieu Chartier76433272014-09-26 14:32:37 -070044 Primitive::Type src_class, Primitive::Type dst_class,
45 const JValue& src, JValue* dst)
Mathieu Chartier90443472015-07-16 20:32:27 -070046 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes418d20f2011-09-22 14:00:39 -070047
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070048JValue InvokeWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa, jobject obj, jmethodID mid,
49 va_list args)
Mathieu Chartier90443472015-07-16 20:32:27 -070050 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -070051
Jeff Hao39b6c242015-05-19 20:30:23 -070052JValue InvokeWithJValues(const ScopedObjectAccessAlreadyRunnable& soa, jobject obj, jmethodID mid,
53 jvalue* args)
Mathieu Chartier90443472015-07-16 20:32:27 -070054 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers53b8b092014-03-13 23:45:53 -070055
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070056JValue InvokeVirtualOrInterfaceWithJValues(const ScopedObjectAccessAlreadyRunnable& soa,
Jeff Hao39b6c242015-05-19 20:30:23 -070057 jobject obj, jmethodID mid, jvalue* args)
Mathieu Chartier90443472015-07-16 20:32:27 -070058 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers53b8b092014-03-13 23:45:53 -070059
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070060JValue InvokeVirtualOrInterfaceWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa,
Ian Rogers53b8b092014-03-13 23:45:53 -070061 jobject obj, jmethodID mid, va_list args)
Mathieu Chartier90443472015-07-16 20:32:27 -070062 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers53b8b092014-03-13 23:45:53 -070063
Mathieu Chartierfc58af42015-04-16 18:00:39 -070064// num_frames is number of frames we look up for access check.
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070065jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa, jobject method, jobject receiver,
Mathieu Chartierfc58af42015-04-16 18:00:39 -070066 jobject args, size_t num_frames = 1)
Mathieu Chartier90443472015-07-16 20:32:27 -070067 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers53b8b092014-03-13 23:45:53 -070068
Mathieu Chartierdaaf3262015-03-24 13:30:28 -070069ALWAYS_INLINE bool VerifyObjectIsClass(mirror::Object* o, mirror::Class* c)
Mathieu Chartier90443472015-07-16 20:32:27 -070070 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes418d20f2011-09-22 14:00:39 -070071
Mathieu Chartier76433272014-09-26 14:32:37 -070072bool VerifyAccess(Thread* self, mirror::Object* obj, mirror::Class* declaring_class,
Mathieu Chartierca239af2015-03-29 18:27:50 -070073 uint32_t access_flags, mirror::Class** calling_class, size_t num_frames)
Mathieu Chartier90443472015-07-16 20:32:27 -070074 SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao11d5d8f2014-03-26 15:08:20 -070075
Mathieu Chartierf36cb5f2015-04-24 16:55:16 -070076// 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)
Mathieu Chartier90443472015-07-16 20:32:27 -070079 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierf36cb5f2015-04-24 16:55:16 -070080
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)
Mathieu Chartier90443472015-07-16 20:32:27 -070083 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierf36cb5f2015-04-24 16:55:16 -070084
Mathieu Chartierdaaf3262015-03-24 13:30:28 -070085void InvalidReceiverError(mirror::Object* o, mirror::Class* c)
Mathieu Chartier90443472015-07-16 20:32:27 -070086 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierdaaf3262015-03-24 13:30:28 -070087
Jeff Hao83c81952015-05-27 19:29:29 -070088void UpdateReference(Thread* self, jobject obj, mirror::Object* result)
Mathieu Chartier90443472015-07-16 20:32:27 -070089 SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao83c81952015-05-27 19:29:29 -070090
Elliott Hughes418d20f2011-09-22 14:00:39 -070091} // namespace art
92
Brian Carlstromfc0e3212013-07-17 14:40:12 -070093#endif // ART_RUNTIME_REFLECTION_H_