从一个例子看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);
        } 
    }
}


Bits.java
   
private static volatile long maxMemory = VM.maxDirectMemory();

执行结果:
maxMemoryValue:259522560
maxMemoryValue:67108864

从源代码来看2者皆是调用的VM类的静态方法maxDirectMemory(),为什么2者会有不一样的结果呢??
------内网字数限制,需要分篇解析-----

你可能感兴趣的:(jvm)