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 <stdlib.h> 27 #include <string.h> 28 #include <ctype.h> 29 #include <assert.h> 30 31 #include "jvm.h" 32 #include "jdk_util.h" 33 34 #ifndef JDK_UPDATE_VERSION 35 /* if not defined set to 00 */ 36 #define JDK_UPDATE_VERSION "00" 37 #endif 38 39 JNIEXPORT void 40 JDK_GetVersionInfo0(jdk_version_info* info, size_t info_size) { 41 /* These JDK_* macros are set at Makefile or the command line */ 42 const unsigned int jdk_major_version = 43 (unsigned int) atoi(JDK_MAJOR_VERSION); 44 const unsigned int jdk_minor_version = 45 (unsigned int) atoi(JDK_MINOR_VERSION); 46 const unsigned int jdk_micro_version = 47 (unsigned int) atoi(JDK_MICRO_VERSION); 48 49 const char* jdk_build_string = JDK_BUILD_NUMBER; 50 char build_number[4]; 51 unsigned int jdk_build_number = 0; 52 53 const char* jdk_update_string = JDK_UPDATE_VERSION; 54 unsigned int jdk_update_version = 0; 55 char update_ver[3]; 56 char jdk_special_version = '\0'; 57 58 /* If the JDK_BUILD_NUMBER is of format bXX and XX is an integer 59 * XX is the jdk_build_number. 60 */ 61 size_t len = strlen(jdk_build_string); 62 if (jdk_build_string[0] == 'b' && len >= 2) { 63 size_t i = 0; 64 for (i = 1; i < len; i++) { 65 if (isdigit(jdk_build_string[i])) { 66 build_number[i-1] = jdk_build_string[i]; 67 } else { 68 // invalid build number 69 i = -1; 70 break; 71 } 72 } 73 if (i == len) { 74 build_number[len-1] = '\0'; 75 jdk_build_number = (unsigned int) atoi(build_number) ; 76 } 77 } 78 79 assert(jdk_build_number <= 255); 80 81 if (strlen(jdk_update_string) == 2 || strlen(jdk_update_string) == 3) { 82 if (isdigit(jdk_update_string[0]) && isdigit(jdk_update_string[1])) { 83 update_ver[0] = jdk_update_string[0]; 84 update_ver[1] = jdk_update_string[1]; 85 update_ver[2] = '\0'; 86 jdk_update_version = (unsigned int) atoi(update_ver); 87 if (strlen(jdk_update_string) == 3) { 88 jdk_special_version = jdk_update_string[2]; 89 } 90 } 91 } 92 93 memset(info, 0, info_size); 94 info->jdk_version = ((jdk_major_version & 0xFF) << 24) | 95 ((jdk_minor_version & 0xFF) << 16) | 96 ((jdk_micro_version & 0xFF) << 8) | 97 (jdk_build_number & 0xFF); 98 info->update_version = jdk_update_version; 99 info->special_update_version = (unsigned int) jdk_special_version; 100 info->thread_park_blocker = 1; 101 // Advertise presence of sun.misc.PostVMInitHook: 102 // future optimization: detect if this is enabled. 103 info->post_vm_init_hook_enabled = 1; 104 info->pending_list_uses_discovered_field = 1; 105 }