1 /* 2 * Copyright (c) 2005, 2015, 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 JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE); 64 setStaticIntField(env, cls, "jvm_minor_version", JVM_VERSION_MINOR(info.jvm_version)); 65 JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE); 66 setStaticIntField(env, cls, "jvm_security_version", JVM_VERSION_SECURITY(info.jvm_version)); 67 JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE); 68 setStaticIntField(env, cls, "jvm_build_number", JVM_VERSION_BUILD(info.jvm_version)); 69 JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE); 70 setStaticIntField(env, cls, "jvm_update_version", info.update_version); 71 JNU_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 JNU_CHECK_EXCEPTION(env); 95 setStaticIntField(env, cls, "jdk_minor_version", JDK_VERSION_MINOR(info.jdk_version)); 96 JNU_CHECK_EXCEPTION(env); 97 setStaticIntField(env, cls, "jdk_security_version", JDK_VERSION_SECURITY(info.jdk_version)); 98 JNU_CHECK_EXCEPTION(env); 99 setStaticIntField(env, cls, "jdk_build_number", JDK_VERSION_BUILD(info.jdk_version)); 100 JNU_CHECK_EXCEPTION(env); 101 setStaticIntField(env, cls, "jdk_update_version", info.update_version); 102 JNU_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 }