Some sun.misc internal APIs are deprectaed in JDK 9 and will be encapsulated or removed in a future release.
@SuppressWarnings("restriction") @Override public double get() { return sun.misc.VM.maxDirectMemory(); } }).register(CollectorRegistry.defaultRegistry);
int h = 127; String integerCacheHighPropValue = sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high"); if (integerCacheHighPropValue != null) { try { int i = parseInt(integerCacheHighPropValue); i = Math.max(i, 127); // Maximum array size is Integer.MAX_VALUE h = Math.min(i, Integer.MAX_VALUE - (-low) -1); } catch( NumberFormatException nfe) { // If the property cannot be parsed into an int, ignore it. } } high = h;
sun.misc.VM.initializeOSEnvironment(); sun.misc.VM.maxDirectMemory(); sun.misc.VM.allowArraySyntax(); sun.misc.VM.booted();
/** * @deprecated No replacement. This method will be removed in a future * release. */ @Deprecated @CallerSensitive public static Class getCallerClass(int depth) { if (sun.misc.VM.allowGetCallerClass()) { return getCallerClass0(depth+1); } throw new UnsupportedOperationException("This method has been disabled by a " + "system property"); }
public static long getMaxDirectMemory() { long result = sun.misc.VM.maxDirectMemory(); return result; }
static { // high value may be configured by property int h = 127; String integerCacheHighPropValue = sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high"); if (integerCacheHighPropValue != null) { int i = parseInt(integerCacheHighPropValue); i = Math.max(i, 127); // Maximum array size is Integer.MAX_VALUE h = Math.min(i, Integer.MAX_VALUE - (-low) -1); } high = h; cache = new Integer[(high - low) + 1]; int j = low; for(int k = 0; k < cache.length; k++) cache[k] = new Integer(j++); }
public static SystemResourceUsage getSystemResourceUsage(final BrokerHostUsage brokerHostUsage) throws IOException { SystemResourceUsage systemResourceUsage = brokerHostUsage.getBrokerHostUsage(); // Override System memory usage and limit with JVM heap usage and limit long maxHeapMemoryInBytes = Runtime.getRuntime().maxMemory(); long memoryUsageInBytes = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); systemResourceUsage.memory.usage = (double) memoryUsageInBytes / MIBI; systemResourceUsage.memory.limit = (double) maxHeapMemoryInBytes / MIBI; // Collect JVM direct memory systemResourceUsage.directMemory.usage = (double) (JvmMetrics.getJvmDirectMemoryUsed() / MIBI); systemResourceUsage.directMemory.limit = (double) (sun.misc.VM.maxDirectMemory() / MIBI); return systemResourceUsage; }
sun.misc.VM.getSavedProperty("java.lang.Integer.IntegerCache.high"); if (integerCacheHighPropValue != null) { int i = parseInt(integerCacheHighPropValue);
public static void main(String[] args) { List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class); for (BufferPoolMXBean pool:pools) { System.out.println(String.format( "%s %d/%d", pool.getName(), pool.getMemoryUsed(), pool.getTotalCapacity())); } RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean(); for (String arg:RuntimemxBean.getInputArguments()) { System.out.println(arg); } HotSpotDiagnosticMXBean hsdiag = ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class); for (VMOption i:hsdiag.getDiagnosticOptions()) { System.out.println(i.getName() + ":" + i.getValue()); } System.out.println(hsdiag.getVMOption("MaxDirectMemorySize")); System.out.println(sun.misc.VM.maxDirectMemory()); System.out.println(getDirectMemoryUsed()); } }
/** * return maxDirectMemory * if Sun, returns 66650112 if not set via jvmarg * if JRockit, returns Long.MAX_VALUE if not set via jvmarg * * @return */ @SuppressWarnings("restriction") public static long maxDirectMemory() { if (isJRockit()) { return extractMaxDirectMemoryJrockit(); } if (isHotSpot() || isOpenJdk() || isIBM()) { return sun.misc.VM.maxDirectMemory(); } throw new RuntimeException("Don't know how to find maxDirectMemory for this VM"); }
/** * return maxDirectMemory * if Sun, returns 66650112 if not set via jvmarg * if JRockit, returns Long.MAX_VALUE if not set via jvmarg * * @return */ @SuppressWarnings("restriction") public static long maxDirectMemory() { if (isJRockit()) { return extractMaxDirectMemoryJrockit(); } if (isHotSpot() || isOpenJdk() || isIBM()) { return sun.misc.VM.maxDirectMemory(); } throw new RuntimeException("Don't know how to find maxDirectMemory for this VM"); }
/** * return maxDirectMemory * if Sun, returns 66650112 if not set via jvmarg * if JRockit, returns Long.MAX_VALUE if not set via jvmarg * * @return */ @SuppressWarnings("restriction") public static long maxDirectMemory() { if (isJRockit()) { return extractMaxDirectMemoryJrockit(); } if (isHotSpot() || isOpenJdk() || isIBM()) { return sun.misc.VM.maxDirectMemory(); } throw new RuntimeException("Don't know how to find maxDirectMemory for this VM"); }
m.put("jvm_max_direct_memory", sun.misc.VM.maxDirectMemory()); m.put("jvm_thread_cnt", getThreadCount());
@SuppressWarnings("restriction") public List<Metrics> generate() { Metrics m = createMetrics(); Runtime r = Runtime.getRuntime(); m.put("jvm_heap_used", r.totalMemory() - r.freeMemory()); m.put("jvm_max_memory", r.maxMemory()); m.put("jvm_total_memory", r.totalMemory()); m.put("jvm_direct_memory_used", getJvmDirectMemoryUsed()); m.put("jvm_max_direct_memory", sun.misc.VM.maxDirectMemory()); m.put("jvm_thread_cnt", getThreadCount()); m.put("jvm_gc_young_pause", currentYoungGcTime); m.put("jvm_gc_young_count", currentYoungGcCount); m.put("jvm_gc_old_pause", currentOldGcTime); m.put("jvm_gc_old_count", currentOldGcCount); long totalAllocated = 0; long totalUsed = 0; for (PoolArenaMetric arena : PooledByteBufAllocator.DEFAULT.directArenas()) { for (PoolChunkListMetric list : arena.chunkLists()) { for (PoolChunkMetric chunk : list) { int size = chunk.chunkSize(); int used = size - chunk.freeBytes(); totalAllocated += size; totalUsed += used; } } } m.put(this.componentName + "_default_pool_allocated", totalAllocated); m.put(this.componentName + "_default_pool_used", totalUsed); return Lists.newArrayList(m); }