1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18#define LOG_TAG "ObjectStreamClass" 19 20#include "JNIHelp.h" 21#include "JniConstants.h" 22 23static jobject getSignature(JNIEnv* env, jclass c, jobject object) { 24 jmethodID mid = env->GetMethodID(c, "getSignature", "()Ljava/lang/String;"); 25 if (!mid) { 26 return NULL; 27 } 28 jclass objectClass = env->GetObjectClass(object); 29 return env->CallNonvirtualObjectMethod(object, objectClass, mid); 30} 31 32static jobject ObjectStreamClass_getFieldSignature(JNIEnv* env, jclass, jobject field) { 33 return getSignature(env, JniConstants::fieldClass, field); 34} 35 36static jobject ObjectStreamClass_getMethodSignature(JNIEnv* env, jclass, jobject method) { 37 return getSignature(env, JniConstants::methodClass, method); 38} 39 40static jobject ObjectStreamClass_getConstructorSignature(JNIEnv* env, jclass, jobject constructor) { 41 return getSignature(env, JniConstants::constructorClass, constructor); 42} 43 44static jboolean ObjectStreamClass_hasClinit(JNIEnv * env, jclass, jclass targetClass) { 45 jmethodID mid = env->GetStaticMethodID(targetClass, "<clinit>", "()V"); 46 env->ExceptionClear(); 47 return (mid != 0); 48} 49 50static jlong ObjectStreamClass_getConstructorId(JNIEnv* env, jclass, jclass constructorClass) { 51 return reinterpret_cast<jlong>(env->GetMethodID(constructorClass, "<init>", "()V")); 52} 53 54static jobject ObjectStreamClass_newInstance(JNIEnv* env, jclass, jclass instantiationClass, jlong methodId) { 55 return env->NewObject(instantiationClass, reinterpret_cast<jmethodID>(methodId)); 56} 57 58static JNINativeMethod gMethods[] = { 59 NATIVE_METHOD(ObjectStreamClass, getConstructorId, "(Ljava/lang/Class;)J"), 60 NATIVE_METHOD(ObjectStreamClass, getConstructorSignature, "(Ljava/lang/reflect/Constructor;)Ljava/lang/String;"), 61 NATIVE_METHOD(ObjectStreamClass, getFieldSignature, "(Ljava/lang/reflect/Field;)Ljava/lang/String;"), 62 NATIVE_METHOD(ObjectStreamClass, getMethodSignature, "(Ljava/lang/reflect/Method;)Ljava/lang/String;"), 63 NATIVE_METHOD(ObjectStreamClass, hasClinit, "(Ljava/lang/Class;)Z"), 64 NATIVE_METHOD(ObjectStreamClass, newInstance, "(Ljava/lang/Class;J)Ljava/lang/Object;"), 65}; 66void register_java_io_ObjectStreamClass(JNIEnv* env) { 67 jniRegisterNativeMethods(env, "java/io/ObjectStreamClass", gMethods, NELEM(gMethods)); 68} 69