src/java.base/share/native/libjava/ObjectStreamClass.c
author rriggs
Fri, 09 Nov 2018 13:28:16 -0500
changeset 52478 b915bd68d907
parent 47216 71c04702a3d5
permissions -rw-r--r--
8185496: Improve performance of system properties initialization in initPhase1 8213424: VersionProps duplicate and skipped initialization Reviewed-by: mchung, redestad, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2001, 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "java_io_ObjectStreamClass.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
static jclass noSuchMethodErrCl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Class:     java_io_ObjectStreamClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Method:    initNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Native code initialization hook.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
Java_java_io_ObjectStreamClass_initNative(JNIEnv *env, jclass this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    jclass cl = (*env)->FindClass(env, "java/lang/NoSuchMethodError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    if (cl == NULL) {           /* exception thrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    noSuchMethodErrCl = (*env)->NewGlobalRef(env, cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Class:     java_io_ObjectStreamClass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Method:    hasStaticInitializer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Signature: (Ljava/lang/Class;)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Returns true if the given class defines a <clinit>()V method; returns false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
Java_java_io_ObjectStreamClass_hasStaticInitializer(JNIEnv *env, jclass this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                                    jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    jclass superCl = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    jmethodID superClinitId = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    jmethodID clinitId =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        (*env)->GetStaticMethodID(env, clazz, "<clinit>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    if (clinitId == NULL) {     /* error thrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        jthrowable th = (*env)->ExceptionOccurred(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        (*env)->ExceptionClear(env);    /* normal return */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        if (!(*env)->IsInstanceOf(env, th, noSuchMethodErrCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            (*env)->Throw(env, th);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Check superclass for static initializer as well--if the same method ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * is returned, then the static initializer is from a superclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Empirically, this step appears to be unnecessary in 1.4; however, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * JNI spec makes no guarantee that GetStaticMethodID will not return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * ID for a superclass initializer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    if ((superCl = (*env)->GetSuperclass(env, clazz)) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    superClinitId =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        (*env)->GetStaticMethodID(env, superCl, "<clinit>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    if (superClinitId == NULL) {        /* error thrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        jthrowable th = (*env)->ExceptionOccurred(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        (*env)->ExceptionClear(env);    /* normal return */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (!(*env)->IsInstanceOf(env, th, noSuchMethodErrCl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            (*env)->Throw(env, th);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    return (clinitId != superClinitId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}