< prev index next >

jdk/src/java.base/share/classes/sun/misc/Version.java.template

Print this page




  38     private static final String java_runtime_name =
  39         "@@RUNTIME_NAME@@";
  40 
  41     private static final String java_runtime_version =
  42         "@@VERSION_STRING@@";
  43 
  44     static {
  45         init();
  46     }
  47 
  48     public static void init() {
  49         System.setProperty("java.version", java_version);
  50         System.setProperty("java.runtime.version", java_runtime_version);
  51         System.setProperty("java.runtime.name", java_runtime_name);
  52     }
  53 
  54     private static boolean versionsInitialized = false;
  55     private static int jvm_major_version = 0;
  56     private static int jvm_minor_version = 0;
  57     private static int jvm_security_version = 0;
  58     private static int jvm_update_version = 0;
  59     private static int jvm_build_number = 0;
  60     private static String jvm_special_version = null;
  61     private static int jdk_major_version = 0;
  62     private static int jdk_minor_version = 0;
  63     private static int jdk_security_version = 0;
  64     private static int jdk_update_version = 0;
  65     private static int jdk_build_number = 0;
  66     private static String jdk_special_version = null;
  67 
  68     /**
  69      * In case you were wondering this method is called by java -version.
  70      * Sad that it prints to stderr; would be nicer if default printed on
  71      * stdout.
  72      */
  73     public static void print() {
  74         print(System.err);
  75     }
  76 
  77     /**
  78      * This is the same as print except that it adds an extra line-feed
  79      * at the end, typically used by the -showversion in the launcher
  80      */
  81     public static void println() {
  82         print(System.err);
  83         System.err.println();
  84     }
  85 
  86     /**


 129             initVersions();
 130         }
 131         return jvm_major_version;
 132     }
 133 
 134     /**
 135      * Returns the minor version of the running JVM if it's 1.6 or newer
 136      * or any RE VM build. It will return 0 if it's an internal 1.5 or
 137      * 1.4.x build.
 138      * @since 1.6
 139      */
 140     public static synchronized int jvmMinorVersion() {
 141         if (!versionsInitialized) {
 142             initVersions();
 143         }
 144         return jvm_minor_version;
 145     }
 146 
 147 
 148     /**
 149      * Returns the security version of the running JVM if it's 1.6 or newer
 150      * or any RE VM build. It will return 0 if it's an internal 1.5 or
 151      * 1.4.x build.
 152      * @since 1.6
 153      */
 154     public static synchronized int jvmSecurityVersion() {
 155         if (!versionsInitialized) {
 156             initVersions();
 157         }
 158         return jvm_security_version;
 159     }
 160 
 161     /**
 162      * Returns the update release version of the running JVM if it's
 163      * a RE build. It will return 0 if it's an internal build.
 164      * @since 1.6
 165      */
 166     public static synchronized int jvmUpdateVersion() {
 167         if (!versionsInitialized) {
 168             initVersions();
 169         }
 170         return jvm_update_version;
 171     }
 172 
 173     public static synchronized String jvmSpecialVersion() {
 174         if (!versionsInitialized) {
 175             initVersions();
 176         }
 177         if (jvm_special_version == null) {
 178             jvm_special_version = getJvmSpecialVersion();
 179         }
 180         return jvm_special_version;
 181     }
 182     public static native String getJvmSpecialVersion();
 183 
 184     /**
 185      * Returns the build number of the running JVM if it's a RE build
 186      * It will return 0 if it's an internal build.
 187      * @since 1.6
 188      */
 189     public static synchronized int jvmBuildNumber() {
 190         if (!versionsInitialized) {
 191             initVersions();
 192         }
 193         return jvm_build_number;
 194     }
 195 
 196     /**
 197      * Returns the major version of the running JDK.
 198      *
 199      * @since 1.6
 200      */
 201     public static synchronized int jdkMajorVersion() {
 202         if (!versionsInitialized) {
 203             initVersions();
 204         }
 205         return jdk_major_version;
 206     }


 211      */
 212     public static synchronized int jdkMinorVersion() {
 213         if (!versionsInitialized) {
 214             initVersions();
 215         }
 216         return jdk_minor_version;
 217     }
 218 
 219     /**
 220      * Returns the security version of the running JDK.
 221      * @since 1.6
 222      */
 223     public static synchronized int jdkSecurityVersion() {
 224         if (!versionsInitialized) {
 225             initVersions();
 226         }
 227         return jdk_security_version;
 228     }
 229 
 230     /**
 231      * Returns the update release version of the running JDK if it's
 232      * a RE build. It will return 0 if it's an internal build.
 233      * @since 1.6
 234      */
 235     public static synchronized int jdkUpdateVersion() {
 236         if (!versionsInitialized) {
 237             initVersions();
 238         }
 239         return jdk_update_version;
 240     }
 241 
 242     public static synchronized String jdkSpecialVersion() {
 243         if (!versionsInitialized) {
 244             initVersions();
 245         }
 246         if (jdk_special_version == null) {
 247             jdk_special_version = getJdkSpecialVersion();
 248         }
 249         return jdk_special_version;
 250     }
 251     public static native String getJdkSpecialVersion();
 252 
 253     /**
 254      * Returns the build number of the running JDK if it's a RE build
 255      * It will return 0 if it's an internal build.
 256      * @since 1.6
 257      */
 258     public static synchronized int jdkBuildNumber() {
 259         if (!versionsInitialized) {
 260             initVersions();
 261         }
 262         return jdk_build_number;
 263     }
 264 
 265     // true if JVM exports the version info including the capabilities
 266     private static boolean jvmVersionInfoAvailable;
 267     private static synchronized void initVersions() {
 268         if (versionsInitialized) {
 269             return;
 270         }
 271         jvmVersionInfoAvailable = getJvmVersionInfo();
 272         if (!jvmVersionInfoAvailable) {
 273             // parse java.vm.version for older JVM before the
 274             // new JVM_GetVersionInfo is added.
 275             // valid format of the version string is:
 276             // n.n.n[_uu[c]][-<identifer>]-bxx
 277             CharSequence cs = System.getProperty("java.vm.version");
 278             if (cs.length() >= 5 &&
 279                 Character.isDigit(cs.charAt(0)) && cs.charAt(1) == '.' &&
 280                 Character.isDigit(cs.charAt(2)) && cs.charAt(3) == '.' &&
 281                 Character.isDigit(cs.charAt(4))) {
 282                 jvm_major_version = Character.digit(cs.charAt(0), 10);
 283                 jvm_minor_version = Character.digit(cs.charAt(2), 10);
 284                 jvm_security_version = Character.digit(cs.charAt(4), 10);
 285                 cs = cs.subSequence(5, cs.length());
 286                 if (cs.charAt(0) == '_' && cs.length() >= 3 &&
 287                     Character.isDigit(cs.charAt(1)) &&
 288                     Character.isDigit(cs.charAt(2))) {
 289                     int nextChar = 3;
 290                     try {
 291                         String uu = cs.subSequence(1, 3).toString();
 292                         jvm_update_version = Integer.valueOf(uu).intValue();
 293                         if (cs.length() >= 4) {
 294                             char c = cs.charAt(3);
 295                             if (c >= 'a' && c <= 'z') {
 296                                 jvm_special_version = Character.toString(c);
 297                                 nextChar++;
 298                             }
 299                         }
 300                     } catch (NumberFormatException e) {
 301                         // not conforming to the naming convention
 302                         return;
 303                     }
 304                     cs = cs.subSequence(nextChar, cs.length());
 305                 }
 306                 if (cs.charAt(0) == '-') {
 307                     // skip the first character
 308                     // valid format: <identifier>-bxx or bxx
 309                     // non-product VM will have -debug|-release appended
 310                     cs = cs.subSequence(1, cs.length());
 311                     String[] res = cs.toString().split("-");
 312                     for (String s : res) {
 313                         if (s.charAt(0) == 'b' && s.length() == 3 &&
 314                             Character.isDigit(s.charAt(1)) &&
 315                             Character.isDigit(s.charAt(2))) {
 316                             jvm_build_number =
 317                                 Integer.valueOf(s.substring(1, 3)).intValue();
 318                             break;
 319                         }
 320                     }
 321                 }
 322             }
 323         }
 324         getJdkVersionInfo();
 325         versionsInitialized = true;
 326     }
 327 
 328     // Gets the JVM version info if available and sets the jvm_*_version fields
 329     // and its capabilities.
 330     //
 331     // Return false if not available which implies an old VM (Tiger or before).
 332     private static native boolean getJvmVersionInfo();
 333     private static native void getJdkVersionInfo();
 334 }
 335 
 336 // Help Emacs a little because this file doesn't end in .java.
 337 //
 338 // Local Variables: ***
 339 // mode: java ***
 340 // End: ***


  38     private static final String java_runtime_name =
  39         "@@RUNTIME_NAME@@";
  40 
  41     private static final String java_runtime_version =
  42         "@@VERSION_STRING@@";
  43 
  44     static {
  45         init();
  46     }
  47 
  48     public static void init() {
  49         System.setProperty("java.version", java_version);
  50         System.setProperty("java.runtime.version", java_runtime_version);
  51         System.setProperty("java.runtime.name", java_runtime_name);
  52     }
  53 
  54     private static boolean versionsInitialized = false;
  55     private static int jvm_major_version = 0;
  56     private static int jvm_minor_version = 0;
  57     private static int jvm_security_version = 0;
  58     private static int jvm_patch_version = 0;
  59     private static int jvm_build_number = 0;

  60     private static int jdk_major_version = 0;
  61     private static int jdk_minor_version = 0;
  62     private static int jdk_security_version = 0;
  63     private static int jdk_patch_version = 0;
  64     private static int jdk_build_number = 0;

  65 
  66     /**
  67      * In case you were wondering this method is called by java -version.
  68      * Sad that it prints to stderr; would be nicer if default printed on
  69      * stdout.
  70      */
  71     public static void print() {
  72         print(System.err);
  73     }
  74 
  75     /**
  76      * This is the same as print except that it adds an extra line-feed
  77      * at the end, typically used by the -showversion in the launcher
  78      */
  79     public static void println() {
  80         print(System.err);
  81         System.err.println();
  82     }
  83 
  84     /**


 127             initVersions();
 128         }
 129         return jvm_major_version;
 130     }
 131 
 132     /**
 133      * Returns the minor version of the running JVM if it's 1.6 or newer
 134      * or any RE VM build. It will return 0 if it's an internal 1.5 or
 135      * 1.4.x build.
 136      * @since 1.6
 137      */
 138     public static synchronized int jvmMinorVersion() {
 139         if (!versionsInitialized) {
 140             initVersions();
 141         }
 142         return jvm_minor_version;
 143     }
 144 
 145 
 146     /**
 147      * Returns the security version of the running JVM 


 148      * @since 1.6
 149      */
 150     public static synchronized int jvmSecurityVersion() {
 151         if (!versionsInitialized) {
 152             initVersions();
 153         }
 154         return jvm_security_version;
 155     }
 156 
 157     /**
 158      * Returns the patch release version of the running JVM
 159      * @since JDK9

 160      */
 161     public static synchronized int jvmPatchVersion() {
 162         if (!versionsInitialized) {
 163             initVersions();
 164         }
 165         return jvm_patch_version;
 166     }
 167 











 168     /**
 169      * Returns the build number of the running JVM

 170      * @since 1.6
 171      */
 172     public static synchronized int jvmBuildNumber() {
 173         if (!versionsInitialized) {
 174             initVersions();
 175         }
 176         return jvm_build_number;
 177     }
 178 
 179     /**
 180      * Returns the major version of the running JDK.
 181      *
 182      * @since 1.6
 183      */
 184     public static synchronized int jdkMajorVersion() {
 185         if (!versionsInitialized) {
 186             initVersions();
 187         }
 188         return jdk_major_version;
 189     }


 194      */
 195     public static synchronized int jdkMinorVersion() {
 196         if (!versionsInitialized) {
 197             initVersions();
 198         }
 199         return jdk_minor_version;
 200     }
 201 
 202     /**
 203      * Returns the security version of the running JDK.
 204      * @since 1.6
 205      */
 206     public static synchronized int jdkSecurityVersion() {
 207         if (!versionsInitialized) {
 208             initVersions();
 209         }
 210         return jdk_security_version;
 211     }
 212 
 213     /**
 214      * Returns the patch release version of the running JDK
 215      * @since JDK9

 216      */
 217     public static synchronized int jdkPatchVersion() {
 218         if (!versionsInitialized) {
 219             initVersions();
 220         }
 221         return jdk_patch_version;
 222     }
 223 











 224     /**
 225      * Returns the build number of the running JDK

 226      * @since 1.6
 227      */
 228     public static synchronized int jdkBuildNumber() {
 229         if (!versionsInitialized) {
 230             initVersions();
 231         }
 232         return jdk_build_number;
 233     }
 234 


 235     private static synchronized void initVersions() {
 236         if (versionsInitialized) {
 237             return;
 238         }
 239         if (!getJvmVersionInfo()) {
 240             throw new RuntimeException("Unable to obtain JVM version info");


















































 241         }
 242         getJdkVersionInfo();
 243         versionsInitialized = true;
 244     }
 245 
 246     // Gets the JVM version info if available and sets the jvm_*_version fields
 247     // and its capabilities.


 248     private static native boolean getJvmVersionInfo();
 249     private static native void getJdkVersionInfo();
 250 }
 251 
 252 // Help Emacs a little because this file doesn't end in .java.
 253 //
 254 // Local Variables: ***
 255 // mode: java ***
 256 // End: ***
< prev index next >