!7 static String OS_ARCH = System.getProperty("os.arch"); static boolean JRE_IS_64BIT_HOTSPOT; static boolean COMPRESSED_REFS_ENABLED; static String MANAGEMENT_FACTORY_CLASS = "java.lang.management.ManagementFactory"; static String HOTSPOT_BEAN_CLASS = "com.sun.management.HotSpotDiagnosticMXBean"; p { boolean is64Bit = false; final String x = System.getProperty("sun.arch.data.model"); if (x != null) { is64Bit = x.contains("64"); } else { if (OS_ARCH != null && OS_ARCH.contains("64")) { is64Bit = true; } else { is64Bit = false; } } boolean compressedOops = false; boolean is64BitHotspot = false; if (is64Bit) { try { final Class beanClazz = Class.forName(HOTSPOT_BEAN_CLASS); // we use reflection for this, because the management factory is // not part // of Java 8's compact profile: final Object hotSpotBean = Class.forName(MANAGEMENT_FACTORY_CLASS).getMethod("getPlatformMXBean", Class.class) .invoke(null, beanClazz); if (hotSpotBean != null) { is64BitHotspot = true; final Method getVMOptionMethod = beanClazz.getMethod("getVMOption", String.class); try { final Object vmOption = getVMOptionMethod.invoke(hotSpotBean, "UseCompressedOops"); compressedOops = Boolean.parseBoolean(vmOption.getClass().getMethod("getValue").invoke(vmOption).toString()); } catch (ReflectiveOperationException | RuntimeException e) { is64BitHotspot = false; } } } catch (ReflectiveOperationException | RuntimeException e) { is64BitHotspot = false; } } JRE_IS_64BIT_HOTSPOT = is64BitHotspot; COMPRESSED_REFS_ENABLED = compressedOops; print("Is 64bit Hotspot JVM: " + JRE_IS_64BIT_HOTSPOT); print("Compressed Oops enabled: " + COMPRESSED_REFS_ENABLED); print("isCompressedOopsOffOn64Bit: " + isCompressedOopsOffOn64Bit()); } static bool isCompressedOopsOffOn64Bit() { ret JRE_IS_64BIT_HOTSPOT && !COMPRESSED_REFS_ENABLED; }