jdk/src/java.base/share/native/libjava/Version.c
author amurillo
Fri, 19 Jun 2015 10:58:00 -0700
changeset 33986 5cbe9cd17789
parent 33984 2333676816eb
permissions -rw-r--r--
8087202: Add support for PATCH field and remove unused fields of new version string Reviewed-by: dholmes, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33984
2333676816eb 8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents: 25859
diff changeset
     2
 * Copyright (c) 2005, 2015, 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 "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "jdk_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "sun_misc_Version.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
static void setStaticIntField(JNIEnv* env, jclass cls, const char* name, jint value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    jfieldID fid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    fid = (*env)->GetStaticFieldID(env, cls, name, "I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    if (fid != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
        (*env)->SetStaticIntField(env, cls, fid, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
typedef void (JNICALL *GetJvmVersionInfo_fp)(JNIEnv*, jvm_version_info*, size_t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
Java_sun_misc_Version_getJvmVersionInfo(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    jvm_version_info info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    GetJvmVersionInfo_fp func_p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    if (!JDK_InitJvmHandle()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup");
22266
d70900404b67 8029007: Check src/share/native/sun/misc code for JNI pending exceptions
dxu
parents: 5506
diff changeset
    52
        return JNI_FALSE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    func_p = (GetJvmVersionInfo_fp) JDK_FindJvmEntry("JVM_GetVersionInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    if (func_p == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    (*func_p)(env, &info, sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    setStaticIntField(env, cls, "jvm_major_version", JVM_VERSION_MAJOR(info.jvm_version));
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    61
    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    setStaticIntField(env, cls, "jvm_minor_version", JVM_VERSION_MINOR(info.jvm_version));
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    63
    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
33984
2333676816eb 8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents: 25859
diff changeset
    64
    setStaticIntField(env, cls, "jvm_security_version", JVM_VERSION_SECURITY(info.jvm_version));
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    65
    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version));
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    67
    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
33986
5cbe9cd17789 8087202: Add support for PATCH field and remove unused fields of new version string
amurillo
parents: 33984
diff changeset
    68
    setStaticIntField(env, cls, "jvm_patch_version", info.patch_version);
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    69
    JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
Java_sun_misc_Version_getJdkVersionInfo(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    jdk_version_info info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    JDK_GetVersionInfo0(&info, sizeof(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    setStaticIntField(env, cls, "jdk_major_version", JDK_VERSION_MAJOR(info.jdk_version));
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    81
    JNU_CHECK_EXCEPTION(env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    setStaticIntField(env, cls, "jdk_minor_version", JDK_VERSION_MINOR(info.jdk_version));
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    83
    JNU_CHECK_EXCEPTION(env);
33984
2333676816eb 8085822: JEP 223: New Version-String Scheme (initial integration)
ihse
parents: 25859
diff changeset
    84
    setStaticIntField(env, cls, "jdk_security_version", JDK_VERSION_SECURITY(info.jdk_version));
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    85
    JNU_CHECK_EXCEPTION(env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version));
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    87
    JNU_CHECK_EXCEPTION(env);
33986
5cbe9cd17789 8087202: Add support for PATCH field and remove unused fields of new version string
amurillo
parents: 33984
diff changeset
    88
    setStaticIntField(env, cls, "jdk_patch_version", info.patch_version);
22637
d4b45e70a981 8031737: CHECK_NULL and CHECK_EXCEPTION macros cleanup
rriggs
parents: 22266
diff changeset
    89
    JNU_CHECK_EXCEPTION(env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
}