1 /* 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include "jni.h" 27 #include "jni_util.h" 28 #include "jvm.h" 29 #include "jdk_util.h" 30 31 #include "sun_misc_Version.h" 32 33 char jvm_special_version = '\0'; 34 char jdk_special_version = '\0'; 35 static void setStaticIntField(JNIEnv* env, jclass cls, const char* name, jint value) 36 { 37 char errmsg[100]; 38 jfieldID fid; 39 fid = (*env)->GetStaticFieldID(env, cls, name, "I"); 40 if (fid != 0) { 41 (*env)->SetStaticIntField(env, cls, fid, value); 42 } else { 43 sprintf(errmsg, "Static int field %s not found", name); 44 JNU_ThrowInternalError(env, errmsg); 45 } 46 } 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 75 typedef void (JNICALL *GetJvmVersionInfo_fp)(JNIEnv*, jvm_version_info*, size_t); 76 77 JNIEXPORT jboolean JNICALL 78 Java_sun_misc_Version_getJvmVersionInfo(JNIEnv *env, jclass cls) 79 { 80 jvm_version_info info; 81 GetJvmVersionInfo_fp func_p; 82 83 if (!JDK_InitJvmHandle()) { 84 JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup"); 85 } 86 func_p = (GetJvmVersionInfo_fp) JDK_FindJvmEntry("JVM_GetVersionInfo"); 87 if (func_p == NULL) { 88 return JNI_FALSE; 89 } 90 91 (*func_p)(env, &info, sizeof(info)); 92 setStaticIntField(env, cls, "jvm_major_version", JVM_VERSION_MAJOR(info.jvm_version)); 93 setStaticIntField(env, cls, "jvm_minor_version", JVM_VERSION_MINOR(info.jvm_version)); 94 setStaticIntField(env, cls, "jvm_micro_version", JVM_VERSION_MICRO(info.jvm_version)); 95 setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version)); 96 setStaticIntField(env, cls, "jvm_update_version", info.update_version); 97 jvm_special_version = info.special_update_version; 98 99 return JNI_TRUE; 100 } 101 102 JNIEXPORT jstring JNICALL 103 Java_sun_misc_Version_getJvmSpecialVersion(JNIEnv *env, jclass cls) { 104 char s[2]; 105 jstring special; 106 s[0] = jvm_special_version; 107 s[1] = '\0'; 108 special = (*env)->NewStringUTF(env, s); 109 return special; 110 } 111 112 JNIEXPORT void JNICALL 113 Java_sun_misc_Version_getJdkVersionInfo(JNIEnv *env, jclass cls) 114 { 115 jdk_version_info info; 116 117 JDK_GetVersionInfo0(&info, sizeof(info)); 118 setStaticIntField(env, cls, "jdk_major_version", JDK_VERSION_MAJOR(info.jdk_version)); 119 setStaticIntField(env, cls, "jdk_minor_version", JDK_VERSION_MINOR(info.jdk_version)); 120 setStaticIntField(env, cls, "jdk_micro_version", JDK_VERSION_MICRO(info.jdk_version)); 121 setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version)); 122 setStaticIntField(env, cls, "jdk_update_version", info.update_version); 123 jdk_special_version = info.special_update_version; 124 } 125 126 JNIEXPORT jstring JNICALL 127 Java_sun_misc_Version_getJdkSpecialVersion(JNIEnv *env, jclass cls) { 128 char s[2]; 129 jstring special; 130 s[0] = jdk_special_version; 131 s[1] = '\0'; 132 special = (*env)->NewStringUTF(env, s); 133 return special; 134 } | 1 /* 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. 4 * 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #include "jni.h" 27 #include "jni_util.h" 28 #include "jvm.h" 29 #include "jdk_util.h" 30 31 #include "sun_misc_Version.h" 32 33 char jvm_special_version = '\0'; 34 char jdk_special_version = '\0'; 35 static void setStaticIntField(JNIEnv* env, jclass cls, const char* name, jint value) 36 { 37 jfieldID fid; 38 fid = (*env)->GetStaticFieldID(env, cls, name, "I"); 39 if (fid != 0) { 40 (*env)->SetStaticIntField(env, cls, fid, value); 41 } 42 } 43 44 typedef void (JNICALL *GetJvmVersionInfo_fp)(JNIEnv*, jvm_version_info*, size_t); 45 46 JNIEXPORT jboolean JNICALL 47 Java_sun_misc_Version_getJvmVersionInfo(JNIEnv *env, jclass cls) 48 { 49 jvm_version_info info; 50 GetJvmVersionInfo_fp func_p; 51 52 if (!JDK_InitJvmHandle()) { 53 JNU_ThrowInternalError(env, "Handle for JVM not found for symbol lookup"); 54 return JNI_FALSE; 55 } 56 func_p = (GetJvmVersionInfo_fp) JDK_FindJvmEntry("JVM_GetVersionInfo"); 57 if (func_p == NULL) { 58 return JNI_FALSE; 59 } 60 61 (*func_p)(env, &info, sizeof(info)); 62 setStaticIntField(env, cls, "jvm_major_version", JVM_VERSION_MAJOR(info.jvm_version)); 63 CHECK_EXCEPTION_RETURN(env, JNI_FALSE); 64 setStaticIntField(env, cls, "jvm_minor_version", JVM_VERSION_MINOR(info.jvm_version)); 65 CHECK_EXCEPTION_RETURN(env, JNI_FALSE); 66 setStaticIntField(env, cls, "jvm_micro_version", JVM_VERSION_MICRO(info.jvm_version)); 67 CHECK_EXCEPTION_RETURN(env, JNI_FALSE); 68 setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version)); 69 CHECK_EXCEPTION_RETURN(env, JNI_FALSE); 70 setStaticIntField(env, cls, "jvm_update_version", info.update_version); 71 CHECK_EXCEPTION_RETURN(env, JNI_FALSE); 72 jvm_special_version = info.special_update_version; 73 74 return JNI_TRUE; 75 } 76 77 JNIEXPORT jstring JNICALL 78 Java_sun_misc_Version_getJvmSpecialVersion(JNIEnv *env, jclass cls) { 79 char s[2]; 80 jstring special; 81 s[0] = jvm_special_version; 82 s[1] = '\0'; 83 special = (*env)->NewStringUTF(env, s); 84 return special; 85 } 86 87 JNIEXPORT void JNICALL 88 Java_sun_misc_Version_getJdkVersionInfo(JNIEnv *env, jclass cls) 89 { 90 jdk_version_info info; 91 92 JDK_GetVersionInfo0(&info, sizeof(info)); 93 setStaticIntField(env, cls, "jdk_major_version", JDK_VERSION_MAJOR(info.jdk_version)); 94 CHECK_EXCEPTION(env); 95 setStaticIntField(env, cls, "jdk_minor_version", JDK_VERSION_MINOR(info.jdk_version)); 96 CHECK_EXCEPTION(env); 97 setStaticIntField(env, cls, "jdk_micro_version", JDK_VERSION_MICRO(info.jdk_version)); 98 CHECK_EXCEPTION(env); 99 setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version)); 100 CHECK_EXCEPTION(env); 101 setStaticIntField(env, cls, "jdk_update_version", info.update_version); 102 CHECK_EXCEPTION(env); 103 jdk_special_version = info.special_update_version; 104 } 105 106 JNIEXPORT jstring JNICALL 107 Java_sun_misc_Version_getJdkSpecialVersion(JNIEnv *env, jclass cls) { 108 char s[2]; 109 jstring special; 110 s[0] = jdk_special_version; 111 s[1] = '\0'; 112 special = (*env)->NewStringUTF(env, s); 113 return special; 114 } |