001: /**
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */package com.tc.util.runtime;
005:
006: /**
007: * Utility class for understanding the current JVM version. Access the VM version information by looking at
008: * {@link #VERSION} directly or calling the static helper methods.
009: */
010: public class Vm {
011:
012: /**
013: * Version info is parsed from system properties and stored here.
014: */
015: public static final VmVersion VERSION;
016: static {
017: try {
018: VERSION = new VmVersion(System.getProperties());
019: } catch (UnknownJvmVersionException mve) {
020: throw new RuntimeException(mve);
021: } catch (UnknownRuntimeVersionException mve) {
022: throw new RuntimeException(mve);
023: }
024: }
025:
026: private Vm() {
027: // utility class
028: }
029:
030: /**
031: * Get mega version (ie 1 in 1.2.3)
032: *
033: * @return Mega version
034: */
035: public static int getMegaVersion() {
036: return VERSION.getMegaVersion();
037: }
038:
039: /**
040: * Get major version (ie 2 in 1.2.3)
041: *
042: * @return Major version
043: */
044: public static int getMajorVersion() {
045: return VERSION.getMajorVersion();
046: }
047:
048: /**
049: * Get minor version (ie 3 in 1.2.3)
050: *
051: * @return Minor version
052: */
053: public static int getMinorVersion() {
054: return VERSION.getMinorVersion();
055: }
056:
057: /**
058: * Get patch level (ie 12 in 1.4.2_12)
059: *
060: * @return Patch level
061: */
062: public static String getPatchLevel() {
063: return VERSION.getPatchLevel();
064: }
065:
066: /**
067: * True if mega/major is 1.4
068: *
069: * @return True if 1.4
070: */
071: public static boolean isJDK14() {
072: return VERSION.isJDK14();
073: }
074:
075: /**
076: * True if mega/major is 1.5
077: *
078: * @return True if 1.5
079: */
080: public static boolean isJDK15() {
081: return VERSION.isJDK15();
082: }
083:
084: /**
085: * True if mega/major is 1.6
086: *
087: * @return True if 1.6
088: */
089: public static boolean isJDK16() {
090: return VERSION.isJDK16();
091: }
092:
093: /**
094: * True if mega/major is 1.7
095: *
096: * @return True if 1.7
097: */
098: public static boolean isJDK17() {
099: return VERSION.isJDK17();
100: }
101:
102: /**
103: * True if JDK is 1.5+
104: *
105: * @return True if JDK 1.5/1.6/1.7
106: */
107: public static boolean isJDK15Compliant() {
108: return VERSION.getMajorVersion() >= 5;
109: }
110:
111: /**
112: * True if JDK is 1.6+
113: *
114: * @return True if JDK 1.6/1.7
115: */
116: public static boolean isJDK16Compliant() {
117: return VERSION.getMajorVersion() >= 6;
118: }
119:
120: /**
121: * True if IBM JDK
122: *
123: * @return True if IBM JDK
124: */
125: public static boolean isIBM() {
126: if (VERSION == null) {
127: // Our instrumentation for java.lang.reflect.Field can end up calling here while in <clinit> for
128: // this class -- this avoids the NPE
129: return VmVersion.this VMisIBM();
130: }
131: return VERSION.isIBM();
132: }
133:
134: /**
135: * True if JRockit
136: *
137: * @return True if BEA Jrockit VM
138: */
139: public static boolean isJRockit() {
140: return VERSION.isJRockit();
141: }
142:
143: }
|