blob: 3dce55994fa0000ea8519665204723a080775129 [file] [log] [blame]
Elliott Hughesd369bb72011-09-12 14:41:14 -07001/*
2 * Copyright (C) 2008 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#include "jni_internal.h"
18#include "class_linker.h"
Brian Carlstromf91c8c32011-09-21 17:30:34 -070019#include "class_loader.h"
Elliott Hughesd369bb72011-09-12 14:41:14 -070020#include "object.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080021#include "object_utils.h"
Elliott Hughes80609252011-09-23 17:24:51 -070022#include "ScopedLocalRef.h"
Brian Carlstromf91c8c32011-09-21 17:30:34 -070023#include "ScopedUtfChars.h"
Elliott Hughesd369bb72011-09-12 14:41:14 -070024
25#include "JniConstants.h" // Last to avoid problems with LOG redefinition.
26
27namespace art {
28
Brian Carlstromf91c8c32011-09-21 17:30:34 -070029// "name" is in "binary name" format, e.g. "dalvik.system.Debug$1".
Elliott Hughes0512f022012-03-15 22:10:52 -070030static jclass Class_classForName(JNIEnv* env, jclass, jstring javaName, jboolean initialize, jobject javaLoader) {
Brian Carlstromb82b6872011-10-26 17:18:07 -070031 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable);
Brian Carlstromf91c8c32011-09-21 17:30:34 -070032 ScopedUtfChars name(env, javaName);
33 if (name.c_str() == NULL) {
34 return NULL;
35 }
36
37 // We need to validate and convert the name (from x.y.z to x/y/z). This
38 // is especially handy for array types, since we want to avoid
39 // auto-generating bogus array classes.
Elliott Hughes906e6852011-10-28 14:52:10 -070040 if (!IsValidBinaryClassName(name.c_str())) {
Elliott Hughes5cb5ad22011-10-02 12:13:39 -070041 Thread::Current()->ThrowNewExceptionF("Ljava/lang/ClassNotFoundException;",
Brian Carlstromf91c8c32011-09-21 17:30:34 -070042 "Invalid name: %s", name.c_str());
43 return NULL;
44 }
45
46 std::string descriptor(DotToDescriptor(name.c_str()));
47 Object* loader = Decode<Object*>(env, javaLoader);
48 ClassLoader* class_loader = down_cast<ClassLoader*>(loader);
49 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
50 Class* c = class_linker->FindClass(descriptor.c_str(), class_loader);
Brian Carlstrom395520e2011-09-25 19:35:00 -070051 if (c == NULL) {
Elliott Hughes844f9a02012-01-24 20:19:58 -080052 ScopedLocalRef<jthrowable> cause(env, env->ExceptionOccurred());
Brian Carlstrom395520e2011-09-25 19:35:00 -070053 env->ExceptionClear();
Elliott Hughes844f9a02012-01-24 20:19:58 -080054 static jclass ClassNotFoundException_class = CacheClass(env, "java/lang/ClassNotFoundException");
55 static jmethodID ctor = env->GetMethodID(ClassNotFoundException_class, "<init>", "(Ljava/lang/String;Ljava/lang/Throwable;)V");
56 jthrowable cnfe = reinterpret_cast<jthrowable>(env->NewObject(ClassNotFoundException_class, ctor, javaName, cause.get()));
57 env->Throw(cnfe);
Brian Carlstrom395520e2011-09-25 19:35:00 -070058 return NULL;
59 }
Brian Carlstromf91c8c32011-09-21 17:30:34 -070060 if (initialize) {
61 class_linker->EnsureInitialized(c, true);
62 }
63 return AddLocalReference<jclass>(env, c);
64}
65
Elliott Hughes0512f022012-03-15 22:10:52 -070066static jint Class_getAnnotationDirectoryOffset(JNIEnv* env, jclass javaClass) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080067 Class* c = Decode<Class*>(env, javaClass);
68 if (c->IsPrimitive() || c->IsArrayClass() || c->IsProxyClass()) {
69 return 0; // primitive, array and proxy classes don't have class definitions
70 }
71 const DexFile::ClassDef* class_def = ClassHelper(c).GetClassDef();
72 if (class_def == NULL) {
73 return 0; // not found
74 } else {
75 return class_def->annotations_off_;
76 }
77}
78
Elliott Hughes80609252011-09-23 17:24:51 -070079template<typename T>
Elliott Hughes0512f022012-03-15 22:10:52 -070080static jobjectArray ToArray(JNIEnv* env, const char* array_class_name, const std::vector<T*>& objects) {
Elliott Hughes80609252011-09-23 17:24:51 -070081 jclass array_class = env->FindClass(array_class_name);
82 jobjectArray result = env->NewObjectArray(objects.size(), array_class, NULL);
83 for (size_t i = 0; i < objects.size(); ++i) {
84 ScopedLocalRef<jobject> object(env, AddLocalReference<jobject>(env, objects[i]));
85 env->SetObjectArrayElement(result, i, object.get());
86 }
87 return result;
88}
89
Ian Rogersd418eda2012-01-30 12:14:28 -080090static bool IsVisibleConstructor(Method* m, bool public_only) {
Elliott Hughes80609252011-09-23 17:24:51 -070091 if (public_only && !m->IsPublic()) {
92 return false;
93 }
Ian Rogers9074b992011-10-26 17:41:55 -070094 if (m->IsStatic()) {
Elliott Hughes80609252011-09-23 17:24:51 -070095 return false;
96 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080097 return m->IsConstructor();
Elliott Hughes80609252011-09-23 17:24:51 -070098}
99
Elliott Hughes0512f022012-03-15 22:10:52 -0700100static jobjectArray Class_getDeclaredConstructors(JNIEnv* env, jclass javaClass, jboolean publicOnly) {
Elliott Hughes80609252011-09-23 17:24:51 -0700101 Class* c = Decode<Class*>(env, javaClass);
102
103 std::vector<Method*> constructors;
104 for (size_t i = 0; i < c->NumDirectMethods(); ++i) {
105 Method* m = c->GetDirectMethod(i);
106 if (IsVisibleConstructor(m, publicOnly)) {
107 constructors.push_back(m);
108 }
109 }
110
111 return ToArray(env, "java/lang/reflect/Constructor", constructors);
112}
113
Ian Rogersd418eda2012-01-30 12:14:28 -0800114static bool IsVisibleField(Field* f, bool public_only) {
Elliott Hughesc0dd3122011-09-26 10:15:43 -0700115 if (public_only && !f->IsPublic()) {
Elliott Hughes80609252011-09-23 17:24:51 -0700116 return false;
117 }
Elliott Hughes80609252011-09-23 17:24:51 -0700118 return true;
119}
120
Elliott Hughes0512f022012-03-15 22:10:52 -0700121static jobjectArray Class_getDeclaredFields(JNIEnv* env, jclass javaClass, jboolean publicOnly) {
Elliott Hughes80609252011-09-23 17:24:51 -0700122 Class* c = Decode<Class*>(env, javaClass);
123
124 std::vector<Field*> fields;
125 for (size_t i = 0; i < c->NumInstanceFields(); ++i) {
126 Field* f = c->GetInstanceField(i);
127 if (IsVisibleField(f, publicOnly)) {
128 fields.push_back(f);
129 }
Jesse Wilson53494312011-11-29 16:43:09 -0500130 if (env->ExceptionOccurred()) {
131 return NULL;
132 }
Elliott Hughes80609252011-09-23 17:24:51 -0700133 }
134 for (size_t i = 0; i < c->NumStaticFields(); ++i) {
135 Field* f = c->GetStaticField(i);
136 if (IsVisibleField(f, publicOnly)) {
137 fields.push_back(f);
138 }
Jesse Wilson53494312011-11-29 16:43:09 -0500139 if (env->ExceptionOccurred()) {
140 return NULL;
141 }
Elliott Hughes80609252011-09-23 17:24:51 -0700142 }
143
144 return ToArray(env, "java/lang/reflect/Field", fields);
145}
146
Ian Rogersd418eda2012-01-30 12:14:28 -0800147static bool IsVisibleMethod(Method* m, bool public_only) {
Elliott Hughes80609252011-09-23 17:24:51 -0700148 if (public_only && !m->IsPublic()) {
149 return false;
150 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800151 if (m->IsConstructor()) {
Elliott Hughes80609252011-09-23 17:24:51 -0700152 return false;
153 }
Ian Rogers56437422012-02-06 21:46:00 -0800154 if (m->IsMiranda()) {
155 return false;
156 }
Elliott Hughes80609252011-09-23 17:24:51 -0700157 return true;
158}
159
Elliott Hughes0512f022012-03-15 22:10:52 -0700160static jobjectArray Class_getDeclaredMethods(JNIEnv* env, jclass javaClass, jboolean publicOnly) {
Elliott Hughes80609252011-09-23 17:24:51 -0700161 Class* c = Decode<Class*>(env, javaClass);
Elliott Hughes80609252011-09-23 17:24:51 -0700162 std::vector<Method*> methods;
163 for (size_t i = 0; i < c->NumVirtualMethods(); ++i) {
164 Method* m = c->GetVirtualMethod(i);
165 if (IsVisibleMethod(m, publicOnly)) {
166 methods.push_back(m);
167 }
Jesse Wilson53494312011-11-29 16:43:09 -0500168 if (env->ExceptionOccurred()) {
169 return NULL;
170 }
Elliott Hughes80609252011-09-23 17:24:51 -0700171 }
172 for (size_t i = 0; i < c->NumDirectMethods(); ++i) {
173 Method* m = c->GetDirectMethod(i);
174 if (IsVisibleMethod(m, publicOnly)) {
175 methods.push_back(m);
176 }
Jesse Wilson53494312011-11-29 16:43:09 -0500177 if (env->ExceptionOccurred()) {
178 return NULL;
179 }
Elliott Hughes80609252011-09-23 17:24:51 -0700180 }
181
182 return ToArray(env, "java/lang/reflect/Method", methods);
183}
184
Elliott Hughes0512f022012-03-15 22:10:52 -0700185static jobject Class_getDex(JNIEnv* env, jobject javaClass) {
Jesse Wilson6bf19152011-09-29 13:12:33 -0400186 Class* c = Decode<Class*>(env, javaClass);
187
188 DexCache* dex_cache = c->GetDexCache();
189 if (dex_cache == NULL) {
190 return NULL;
191 }
192
193 return Runtime::Current()->GetClassLinker()->FindDexFile(dex_cache).GetDexObject(env);
194}
195
Ian Rogersd418eda2012-01-30 12:14:28 -0800196static bool MethodMatches(MethodHelper* mh, const std::string& name, ObjectArray<Class>* arg_array) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800197 if (name != mh->GetName()) {
Elliott Hughes418d20f2011-09-22 14:00:39 -0700198 return false;
199 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800200 const DexFile::TypeList* m_type_list = mh->GetParameterTypeList();
201 uint32_t m_type_list_size = m_type_list == NULL ? 0 : m_type_list->Size();
202 uint32_t sig_length = arg_array->GetLength();
203
204 if (m_type_list_size != sig_length) {
Elliott Hughes418d20f2011-09-22 14:00:39 -0700205 return false;
206 }
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800207
208 for (uint32_t i = 0; i < sig_length; i++) {
209 if (mh->GetClassFromTypeIdx(m_type_list->GetTypeItem(i).type_idx_) != arg_array->Get(i)) {
210 return false;
211 }
Jesse Wilson8ea36f82011-11-21 10:35:06 -0500212 }
Elliott Hughes418d20f2011-09-22 14:00:39 -0700213 return true;
214}
215
Ian Rogersd418eda2012-01-30 12:14:28 -0800216static Method* FindConstructorOrMethodInArray(ObjectArray<Method>* methods, const std::string& name,
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800217 ObjectArray<Class>* arg_array) {
Jesse Wilson8ea36f82011-11-21 10:35:06 -0500218 if (methods == NULL) {
219 return NULL;
220 }
221 Method* result = NULL;
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800222 MethodHelper mh;
Jesse Wilson8ea36f82011-11-21 10:35:06 -0500223 for (int32_t i = 0; i < methods->GetLength(); ++i) {
224 Method* method = methods->Get(i);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800225 mh.ChangeMethod(method);
226 if (method->IsMiranda() || !MethodMatches(&mh, name, arg_array)) {
Jesse Wilson8ea36f82011-11-21 10:35:06 -0500227 continue;
228 }
229
230 result = method;
231
232 // Covariant return types permit the class to define multiple
233 // methods with the same name and parameter types. Prefer to return
234 // a non-synthetic method in such situations. We may still return
235 // a synthetic method to handle situations like escalated visibility.
236 if (!method->IsSynthetic()) {
237 break;
238 }
239 }
240 return result;
241}
242
Elliott Hughes0512f022012-03-15 22:10:52 -0700243static jobject Class_getDeclaredConstructorOrMethod(JNIEnv* env, jclass javaClass, jstring javaName,
244 jobjectArray javaArgs) {
Elliott Hughes418d20f2011-09-22 14:00:39 -0700245 Class* c = Decode<Class*>(env, javaClass);
Elliott Hughes95572412011-12-13 18:14:20 -0800246 std::string name(Decode<String*>(env, javaName)->ToModifiedUtf8());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800247 ObjectArray<Class>* arg_array = Decode<ObjectArray<Class>*>(env, javaArgs);
Brian Carlstrom3a7b4f22011-09-17 15:01:57 -0700248
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800249 Method* m = FindConstructorOrMethodInArray(c->GetDirectMethods(), name, arg_array);
Jesse Wilson8ea36f82011-11-21 10:35:06 -0500250 if (m == NULL) {
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800251 m = FindConstructorOrMethodInArray(c->GetVirtualMethods(), name, arg_array);
Brian Carlstrom3a7b4f22011-09-17 15:01:57 -0700252 }
253
Jesse Wilson8ea36f82011-11-21 10:35:06 -0500254 if (m != NULL) {
Jesse Wilson8ea36f82011-11-21 10:35:06 -0500255 return AddLocalReference<jobject>(env, m);
256 } else {
257 return NULL;
Brian Carlstrom3a7b4f22011-09-17 15:01:57 -0700258 }
Brian Carlstrom3a7b4f22011-09-17 15:01:57 -0700259}
260
Elliott Hughes0512f022012-03-15 22:10:52 -0700261static jobject Class_getDeclaredFieldNative(JNIEnv* env, jclass jklass, jobject jname) {
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700262 Class* klass = Decode<Class*>(env, jklass);
263 DCHECK(klass->IsClass());
264 String* name = Decode<String*>(env, jname);
Elliott Hughesdbb40792011-11-18 17:05:22 -0800265 DCHECK(name->GetClass()->IsStringClass());
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700266
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800267 FieldHelper fh;
Elliott Hughes80609252011-09-23 17:24:51 -0700268 for (size_t i = 0; i < klass->NumInstanceFields(); ++i) {
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700269 Field* f = klass->GetInstanceField(i);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800270 fh.ChangeField(f);
271 if (name->Equals(fh.GetName())) {
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700272 return AddLocalReference<jclass>(env, f);
273 }
274 }
275 for (size_t i = 0; i < klass->NumStaticFields(); ++i) {
276 Field* f = klass->GetStaticField(i);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800277 fh.ChangeField(f);
278 if (name->Equals(fh.GetName())) {
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700279 return AddLocalReference<jclass>(env, f);
280 }
281 }
282 return NULL;
283}
284
Elliott Hughes0512f022012-03-15 22:10:52 -0700285static jstring Class_getNameNative(JNIEnv* env, jobject javaThis) {
Ian Rogersf45b1542012-02-03 18:03:48 -0800286 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable);
Elliott Hughes6bdc3b22011-09-16 19:24:10 -0700287 Class* c = Decode<Class*>(env, javaThis);
Ian Rogersd418eda2012-01-30 12:14:28 -0800288 return AddLocalReference<jstring>(env, c->ComputeName());
Elliott Hughes6bdc3b22011-09-16 19:24:10 -0700289}
290
Elliott Hughes0512f022012-03-15 22:10:52 -0700291static jboolean Class_isAssignableFrom(JNIEnv* env, jobject javaLhs, jclass javaRhs) {
Brian Carlstromb82b6872011-10-26 17:18:07 -0700292 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable);
Elliott Hughesdd8df692011-09-23 14:42:41 -0700293 Class* lhs = Decode<Class*>(env, javaLhs);
294 Class* rhs = Decode<Class*>(env, javaRhs);
295 if (rhs == NULL) {
296 Thread::Current()->ThrowNewException("Ljava/lang/NullPointerException;", "class == null");
297 return JNI_FALSE;
298 }
299 return lhs->IsAssignableFrom(rhs) ? JNI_TRUE : JNI_FALSE;
300}
301
Elliott Hughes0512f022012-03-15 22:10:52 -0700302static jboolean Class_isInstance(JNIEnv* env, jobject javaClass, jobject javaObject) {
Elliott Hughesdd8df692011-09-23 14:42:41 -0700303 Class* c = Decode<Class*>(env, javaClass);
304 Object* o = Decode<Object*>(env, javaObject);
305 if (o == NULL) {
306 return JNI_FALSE;
307 }
Brian Carlstrom5d40f182011-09-26 22:29:18 -0700308 return o->InstanceOf(c) ? JNI_TRUE : JNI_FALSE;
Elliott Hughesdd8df692011-09-23 14:42:41 -0700309}
310
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700311// Validate method/field access.
Ian Rogersd418eda2012-01-30 12:14:28 -0800312static bool CheckMemberAccess(const Class* access_from, Class* access_to, uint32_t member_flags) {
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700313 // quick accept for public access */
314 if (member_flags & kAccPublic) {
315 return true;
316 }
317
318 // quick accept for access from same class
319 if (access_from == access_to) {
320 return true;
321 }
322
323 // quick reject for private access from another class
324 if (member_flags & kAccPrivate) {
325 return false;
326 }
327
328 // Semi-quick test for protected access from a sub-class, which may or
329 // may not be in the same package.
330 if (member_flags & kAccProtected) {
331 if (access_from->IsSubClass(access_to)) {
332 return true;
333 }
334 }
335
336 // Allow protected and private access from other classes in the same
337 return access_from->IsInSamePackage(access_to);
338}
339
Elliott Hughes0512f022012-03-15 22:10:52 -0700340static jobject Class_newInstanceImpl(JNIEnv* env, jobject javaThis) {
Brian Carlstromb82b6872011-10-26 17:18:07 -0700341 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable);
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700342 Class* c = Decode<Class*>(env, javaThis);
343 if (c->IsPrimitive() || c->IsInterface() || c->IsArrayClass() || c->IsAbstract()) {
Elliott Hughes5cb5ad22011-10-02 12:13:39 -0700344 Thread::Current()->ThrowNewExceptionF("Ljava/lang/InstantiationException;",
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800345 "Class %s can not be instantiated", PrettyDescriptor(ClassHelper(c).GetDescriptor()).c_str());
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700346 return NULL;
347 }
348
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700349 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(c, true)) {
350 return NULL;
351 }
352
Brian Carlstrom01a96582012-03-12 15:17:29 -0700353 Method* init = c->FindDeclaredDirectMethod("<init>", "()V");
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700354 if (init == NULL) {
Elliott Hughes5cb5ad22011-10-02 12:13:39 -0700355 Thread::Current()->ThrowNewExceptionF("Ljava/lang/InstantiationException;",
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800356 "Class %s has no default <init>()V constructor", PrettyDescriptor(ClassHelper(c).GetDescriptor()).c_str());
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700357 return NULL;
358 }
359
360 // Verify access from the call site.
361 //
362 // First, make sure the method invoking Class.newInstance() has permission
363 // to access the class.
364 //
365 // Second, make sure it has permission to invoke the constructor. The
366 // constructor must be public or, if the caller is in the same package,
367 // have package scope.
368 // TODO: need SmartFrame (Thread::WalkStack-like iterator).
369 Frame frame = Thread::Current()->GetTopOfStack();
370 frame.Next();
371 frame.Next();
372 Method* caller_caller = frame.GetMethod();
373 Class* caller_class = caller_caller->GetDeclaringClass();
374
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800375 ClassHelper caller_ch(caller_class);
Brian Carlstrombc2f3e32011-09-22 17:16:54 -0700376 if (!caller_class->CanAccess(c)) {
Elliott Hughes5cb5ad22011-10-02 12:13:39 -0700377 Thread::Current()->ThrowNewExceptionF("Ljava/lang/IllegalAccessException;",
378 "Class %s is not accessible from class %s",
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800379 PrettyDescriptor(ClassHelper(c).GetDescriptor()).c_str(),
380 PrettyDescriptor(caller_ch.GetDescriptor()).c_str());
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700381 return NULL;
382 }
383 if (!CheckMemberAccess(caller_class, init->GetDeclaringClass(), init->GetAccessFlags())) {
Elliott Hughes5cb5ad22011-10-02 12:13:39 -0700384 Thread::Current()->ThrowNewExceptionF("Ljava/lang/IllegalAccessException;",
385 "%s is not accessible from class %s",
386 PrettyMethod(init).c_str(),
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800387 PrettyDescriptor(caller_ch.GetDescriptor()).c_str());
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700388 return NULL;
389 }
390
391 Object* new_obj = c->AllocObject();
392 if (new_obj == NULL) {
393 DCHECK(Thread::Current()->IsExceptionPending());
394 return NULL;
395 }
396
397 // invoke constructor; unlike reflection calls, we don't wrap exceptions
398 jclass jklass = AddLocalReference<jclass>(env, c);
399 jmethodID mid = EncodeMethod(init);
400 return env->NewObject(jklass, mid);
401}
402
Elliott Hughesd369bb72011-09-12 14:41:14 -0700403static JNINativeMethod gMethods[] = {
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700404 NATIVE_METHOD(Class, classForName, "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;"),
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800405 NATIVE_METHOD(Class, getAnnotationDirectoryOffset, "()I"),
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800406 NATIVE_METHOD(Class, getDeclaredConstructorOrMethod, "(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Member;"),
407 NATIVE_METHOD(Class, getDeclaredConstructors, "(Z)[Ljava/lang/reflect/Constructor;"),
408 NATIVE_METHOD(Class, getDeclaredFieldNative, "(Ljava/lang/String;)Ljava/lang/reflect/Field;"),
409 NATIVE_METHOD(Class, getDeclaredFields, "(Z)[Ljava/lang/reflect/Field;"),
410 NATIVE_METHOD(Class, getDeclaredMethods, "(Z)[Ljava/lang/reflect/Method;"),
Jesse Wilson6bf19152011-09-29 13:12:33 -0400411 NATIVE_METHOD(Class, getDex, "()Lcom/android/dex/Dex;"),
Elliott Hughes6bdc3b22011-09-16 19:24:10 -0700412 NATIVE_METHOD(Class, getNameNative, "()Ljava/lang/String;"),
Elliott Hughesdd8df692011-09-23 14:42:41 -0700413 NATIVE_METHOD(Class, isAssignableFrom, "(Ljava/lang/Class;)Z"),
414 NATIVE_METHOD(Class, isInstance, "(Ljava/lang/Object;)Z"),
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700415 NATIVE_METHOD(Class, newInstanceImpl, "()Ljava/lang/Object;"),
Elliott Hughesd369bb72011-09-12 14:41:14 -0700416};
417
Elliott Hughesd369bb72011-09-12 14:41:14 -0700418void register_java_lang_Class(JNIEnv* env) {
419 jniRegisterNativeMethods(env, "java/lang/Class", gMethods, NELEM(gMethods));
420}
421
422} // namespace art