blob: 6e5ef712a7d2e0711ed63ac895fc5e530b6406b7 [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"
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070022#include "obj_ptr.h"
Brian Carlstrom6b4ef022011-10-23 14:59:04 -070023#include "primitive.h"
Elliott Hughes418d20f2011-09-22 14:00:39 -070024
25namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080026namespace mirror {
Brian Carlstromea46f952013-07-30 01:26:50 -070027 class Class;
28 class Object;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080029} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070030class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070031class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032union JValue;
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070033class ScopedObjectAccessAlreadyRunnable;
Ian Rogers53b8b092014-03-13 23:45:53 -070034class ShadowFrame;
Elliott Hughes418d20f2011-09-22 14:00:39 -070035
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070036ObjPtr<mirror::Object> BoxPrimitive(Primitive::Type src_class, const JValue& value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070037 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070038
39bool UnboxPrimitiveForField(ObjPtr<mirror::Object> o,
40 ObjPtr<mirror::Class> dst_class,
41 ArtField* f,
Ian Rogers84956ff2014-03-26 23:52:41 -070042 JValue* unboxed_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070043 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070044
45bool UnboxPrimitiveForResult(ObjPtr<mirror::Object> o,
46 ObjPtr<mirror::Class> dst_class,
47 JValue* unboxed_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070048 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes418d20f2011-09-22 14:00:39 -070049
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000050ALWAYS_INLINE bool ConvertPrimitiveValue(bool unbox_for_result,
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070051 Primitive::Type src_class,
52 Primitive::Type dst_class,
53 const JValue& src,
54 JValue* dst)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070055 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes418d20f2011-09-22 14:00:39 -070056
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070057JValue InvokeWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa,
58 jobject obj,
59 jmethodID mid,
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070060 va_list args)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070061 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -070062
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070063JValue InvokeWithJValues(const ScopedObjectAccessAlreadyRunnable& soa,
64 jobject obj,
65 jmethodID mid,
Jeff Hao39b6c242015-05-19 20:30:23 -070066 jvalue* args)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070067 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers53b8b092014-03-13 23:45:53 -070068
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070069JValue InvokeVirtualOrInterfaceWithJValues(const ScopedObjectAccessAlreadyRunnable& soa,
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070070 jobject obj,
71 jmethodID mid,
72 jvalue* args)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070073 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers53b8b092014-03-13 23:45:53 -070074
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -070075JValue InvokeVirtualOrInterfaceWithVarArgs(const ScopedObjectAccessAlreadyRunnable& soa,
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070076 jobject obj,
77 jmethodID mid,
78 va_list args)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070079 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers53b8b092014-03-13 23:45:53 -070080
Mathieu Chartierfc58af42015-04-16 18:00:39 -070081// num_frames is number of frames we look up for access check.
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070082jobject InvokeMethod(const ScopedObjectAccessAlreadyRunnable& soa,
83 jobject method,
84 jobject receiver,
85 jobject args,
86 size_t num_frames = 1)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070087 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers53b8b092014-03-13 23:45:53 -070088
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070089ALWAYS_INLINE bool VerifyObjectIsClass(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070090 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes418d20f2011-09-22 14:00:39 -070091
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070092bool VerifyAccess(Thread* self,
93 ObjPtr<mirror::Object> obj,
94 ObjPtr<mirror::Class> declaring_class,
95 uint32_t access_flags,
96 ObjPtr<mirror::Class>* calling_class,
97 size_t num_frames)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070098 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao11d5d8f2014-03-26 15:08:20 -070099
Mathieu Chartierf36cb5f2015-04-24 16:55:16 -0700100// This version takes a known calling class.
Mathieu Chartiera59d9b22016-09-26 18:13:17 -0700101bool VerifyAccess(ObjPtr<mirror::Object> obj,
102 ObjPtr<mirror::Class> declaring_class,
Mathieu Chartier268764d2016-09-13 12:09:38 -0700103 uint32_t access_flags,
Mathieu Chartiera59d9b22016-09-26 18:13:17 -0700104 ObjPtr<mirror::Class> calling_class)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700105 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierf36cb5f2015-04-24 16:55:16 -0700106
107// Get the calling class by using a stack visitor, may return null for unattached native threads.
Mathieu Chartiera59d9b22016-09-26 18:13:17 -0700108ObjPtr<mirror::Class> GetCallingClass(Thread* self, size_t num_frames)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700109 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierf36cb5f2015-04-24 16:55:16 -0700110
Mathieu Chartiera59d9b22016-09-26 18:13:17 -0700111void InvalidReceiverError(ObjPtr<mirror::Object> o, ObjPtr<mirror::Class> c)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700112 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartierdaaf3262015-03-24 13:30:28 -0700113
Mathieu Chartiera59d9b22016-09-26 18:13:17 -0700114void UpdateReference(Thread* self, jobject obj, ObjPtr<mirror::Object> result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700115 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao83c81952015-05-27 19:29:29 -0700116
Elliott Hughes418d20f2011-09-22 14:00:39 -0700117} // namespace art
118
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700119#endif // ART_RUNTIME_REFLECTION_H_