jdk/src/share/native/sun/misc/Version.c
changeset 22266 d70900404b67
parent 5506 202f599c92aa
child 22637 d4b45e70a981
equal deleted inserted replaced
22265:1f8702989948 22266:d70900404b67
     1 /*
     1 /*
     2  * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    32 
    32 
    33 char jvm_special_version = '\0';
    33 char jvm_special_version = '\0';
    34 char jdk_special_version = '\0';
    34 char jdk_special_version = '\0';
    35 static void setStaticIntField(JNIEnv* env, jclass cls, const char* name, jint value)
    35 static void setStaticIntField(JNIEnv* env, jclass cls, const char* name, jint value)
    36 {
    36 {
    37     char errmsg[100];
       
    38     jfieldID fid;
    37     jfieldID fid;
    39     fid = (*env)->GetStaticFieldID(env, cls, name, "I");
    38     fid = (*env)->GetStaticFieldID(env, cls, name, "I");
    40     if (fid != 0) {
    39     if (fid != 0) {
    41         (*env)->SetStaticIntField(env, cls, fid, value);
    40         (*env)->SetStaticIntField(env, cls, fid, value);
    42     } else {
       
    43         sprintf(errmsg, "Static int field %s not found", name);
       
    44         JNU_ThrowInternalError(env, errmsg);
       
    45     }
    41     }
    46 }
    42 }
    47 
       
    48 static void setStaticBooleanField(JNIEnv* env, jclass cls, const char* name, jboolean value)
       
    49 {
       
    50     char errmsg[100];
       
    51     jfieldID fid;
       
    52     fid = (*env)->GetStaticFieldID(env, cls, name, "Z");
       
    53     if (fid != 0) {
       
    54         (*env)->SetStaticBooleanField(env, cls, fid, value);
       
    55     } else {
       
    56         sprintf(errmsg, "Static boolean field %s not found", name);
       
    57         JNU_ThrowInternalError(env, errmsg);
       
    58     }
       
    59 }
       
    60 
       
    61 static void setStaticStringField(JNIEnv* env, jclass cls, const char* name, jstring value)
       
    62 {
       
    63     char errmsg[100];
       
    64     jfieldID fid;
       
    65     fid = (*env)->GetStaticFieldID(env, cls, name, "Ljava/lang/String");
       
    66     if (fid != 0) {
       
    67         (*env)->SetStaticObjectField(env, cls, fid, value);
       
    68     } else {
       
    69         sprintf(errmsg, "Static String field %s not found", name);
       
    70         JNU_ThrowInternalError(env, errmsg);
       
    71     }
       
    72 }
       
    73 
       
    74 
    43 
    75 typedef void (JNICALL *GetJvmVersionInfo_fp)(JNIEnv*, jvm_version_info*, size_t);
    44 typedef void (JNICALL *GetJvmVersionInfo_fp)(JNIEnv*, jvm_version_info*, size_t);
    76 
    45 
    77 JNIEXPORT jboolean JNICALL
    46 JNIEXPORT jboolean JNICALL
    78 Java_sun_misc_Version_getJvmVersionInfo(JNIEnv *env, jclass cls)
    47 Java_sun_misc_Version_getJvmVersionInfo(JNIEnv *env, jclass cls)
    80     jvm_version_info info;
    49     jvm_version_info info;
    81     GetJvmVersionInfo_fp func_p;
    50     GetJvmVersionInfo_fp func_p;
    82 
    51 
    83     if (!JDK_InitJvmHandle()) {
    52     if (!JDK_InitJvmHandle()) {
    84         JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup");
    53         JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup");
       
    54         return JNI_FALSE;
    85     }
    55     }
    86     func_p = (GetJvmVersionInfo_fp) JDK_FindJvmEntry("JVM_GetVersionInfo");
    56     func_p = (GetJvmVersionInfo_fp) JDK_FindJvmEntry("JVM_GetVersionInfo");
    87     if (func_p == NULL) {
    57     if (func_p == NULL) {
    88         return JNI_FALSE;
    58         return JNI_FALSE;
    89     }
    59     }
    90 
    60 
    91     (*func_p)(env, &info, sizeof(info));
    61     (*func_p)(env, &info, sizeof(info));
    92     setStaticIntField(env, cls, "jvm_major_version", JVM_VERSION_MAJOR(info.jvm_version));
    62     setStaticIntField(env, cls, "jvm_major_version", JVM_VERSION_MAJOR(info.jvm_version));
       
    63     CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
    93     setStaticIntField(env, cls, "jvm_minor_version", JVM_VERSION_MINOR(info.jvm_version));
    64     setStaticIntField(env, cls, "jvm_minor_version", JVM_VERSION_MINOR(info.jvm_version));
       
    65     CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
    94     setStaticIntField(env, cls, "jvm_micro_version", JVM_VERSION_MICRO(info.jvm_version));
    66     setStaticIntField(env, cls, "jvm_micro_version", JVM_VERSION_MICRO(info.jvm_version));
       
    67     CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
    95     setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version));
    68     setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version));
       
    69     CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
    96     setStaticIntField(env, cls, "jvm_update_version", info.update_version);
    70     setStaticIntField(env, cls, "jvm_update_version", info.update_version);
       
    71     CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
    97     jvm_special_version = info.special_update_version;
    72     jvm_special_version = info.special_update_version;
    98 
    73 
    99     return JNI_TRUE;
    74     return JNI_TRUE;
   100 }
    75 }
   101 
    76 
   114 {
    89 {
   115     jdk_version_info info;
    90     jdk_version_info info;
   116 
    91 
   117     JDK_GetVersionInfo0(&info, sizeof(info));
    92     JDK_GetVersionInfo0(&info, sizeof(info));
   118     setStaticIntField(env, cls, "jdk_major_version", JDK_VERSION_MAJOR(info.jdk_version));
    93     setStaticIntField(env, cls, "jdk_major_version", JDK_VERSION_MAJOR(info.jdk_version));
       
    94     CHECK_EXCEPTION(env);
   119     setStaticIntField(env, cls, "jdk_minor_version", JDK_VERSION_MINOR(info.jdk_version));
    95     setStaticIntField(env, cls, "jdk_minor_version", JDK_VERSION_MINOR(info.jdk_version));
       
    96     CHECK_EXCEPTION(env);
   120     setStaticIntField(env, cls, "jdk_micro_version", JDK_VERSION_MICRO(info.jdk_version));
    97     setStaticIntField(env, cls, "jdk_micro_version", JDK_VERSION_MICRO(info.jdk_version));
       
    98     CHECK_EXCEPTION(env);
   121     setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version));
    99     setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version));
       
   100     CHECK_EXCEPTION(env);
   122     setStaticIntField(env, cls, "jdk_update_version", info.update_version);
   101     setStaticIntField(env, cls, "jdk_update_version", info.update_version);
       
   102     CHECK_EXCEPTION(env);
   123     jdk_special_version = info.special_update_version;
   103     jdk_special_version = info.special_update_version;
   124 }
   104 }
   125 
   105 
   126 JNIEXPORT jstring JNICALL
   106 JNIEXPORT jstring JNICALL
   127 Java_sun_misc_Version_getJdkSpecialVersion(JNIEnv *env, jclass cls) {
   107 Java_sun_misc_Version_getJdkSpecialVersion(JNIEnv *env, jclass cls) {