Path: blob/master/src/java.base/share/native/libjava/ObjectStreamClass.c
41149 views
/*1* Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "jni.h"26#include "jvm.h"2728#include "java_io_ObjectStreamClass.h"2930static jclass noSuchMethodErrCl;3132/*33* Class: java_io_ObjectStreamClass34* Method: initNative35* Signature: ()V36*37* Native code initialization hook.38*/39JNIEXPORT void JNICALL40Java_java_io_ObjectStreamClass_initNative(JNIEnv *env, jclass this)41{42jclass cl = (*env)->FindClass(env, "java/lang/NoSuchMethodError");43if (cl == NULL) { /* exception thrown */44return;45}46noSuchMethodErrCl = (*env)->NewGlobalRef(env, cl);47}4849/*50* Class: java_io_ObjectStreamClass51* Method: hasStaticInitializer52* Signature: (Ljava/lang/Class;)Z53*54* Returns true if the given class defines a <clinit>()V method; returns false55* otherwise.56*/57JNIEXPORT jboolean JNICALL58Java_java_io_ObjectStreamClass_hasStaticInitializer(JNIEnv *env, jclass this,59jclass clazz)60{61jclass superCl = NULL;62jmethodID superClinitId = NULL;63jmethodID clinitId =64(*env)->GetStaticMethodID(env, clazz, "<clinit>", "()V");65if (clinitId == NULL) { /* error thrown */66jthrowable th = (*env)->ExceptionOccurred(env);67(*env)->ExceptionClear(env); /* normal return */68if (!(*env)->IsInstanceOf(env, th, noSuchMethodErrCl)) {69(*env)->Throw(env, th);70}71return JNI_FALSE;72}7374/*75* Check superclass for static initializer as well--if the same method ID76* is returned, then the static initializer is from a superclass.77* Empirically, this step appears to be unnecessary in 1.4; however, the78* JNI spec makes no guarantee that GetStaticMethodID will not return the79* ID for a superclass initializer.80*/8182if ((superCl = (*env)->GetSuperclass(env, clazz)) == NULL) {83return JNI_TRUE;84}85superClinitId =86(*env)->GetStaticMethodID(env, superCl, "<clinit>", "()V");87if (superClinitId == NULL) { /* error thrown */88jthrowable th = (*env)->ExceptionOccurred(env);89(*env)->ExceptionClear(env); /* normal return */90if (!(*env)->IsInstanceOf(env, th, noSuchMethodErrCl)) {91(*env)->Throw(env, th);92}93return JNI_TRUE;94}9596return (clinitId != superClinitId);97}9899100