从一个例子看JVM启动过程(1)
开题从一个例子说起:
public class NativeMemoryGC{ @SuppressWarnings("restriction") public static void main(String[] args) throws SecurityException, NoSuchFieldException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException, InterruptedException { System.out.println("maxMemoryValue:"+sun.misc.VM.maxDirectMemory()); Class c = Class.forName("java.nio.Bits"); Field maxMemory = c.getDeclaredField("maxMemory"); maxMemory.setAccessible(true); synchronized (c) { Long maxMemoryValue = (Long)maxMemory.get(null); System.out.println("maxMemoryValue:"+maxMemoryValue); } }}
private static volatile long maxMemory = VM.maxDirectMemory();