Java-8 – the java8 metaspacesize flag does not work

I have a simple test code that sets - XX: metaspacesize and - XX: maxmetaspacesize to the same value I don't think Metaspace should be dynamically resized But from my test (checking the Metaspace diagram of visualvm GC and printing the log through jstat), I saw that the Metaspace increased from the low value to the maximum value I set So - XX: does metaspacesize not work properly?

My test code:

try {

    while(true){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(A.class);
        enhancer.setUseCache(false);
        enhancer.setCallback((MethodInterceptor) (obj,method,args1,methodProxy) -> methodProxy.invokeSuper(obj,args1));
        enhancer.create();

        Thread.sleep(50);
    }
} catch (Throwable throwable) {
    throwable.printStackTrace();
}

VM args:

-XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m

Java version:

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02,mixed mode)

Jstat result: (MC value continues to increase to about 10m)

C:\Users\dyu>jstat -gc 12336 1000 20
S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT
8192.0 8192.0  0.0   2207.8 49152.0  43399.2   131072.0     16.0    7168.0 6777.9 768.0  677.7       1    0.015   0      0.000    0.015
8192.0 8192.0  0.0   2207.8 49152.0  48166.1   131072.0     16.0    7168.0 6777.9 768.0  677.7       1    0.015   0      0.000    0.015
8192.0 8192.0 2592.0  0.0   49152.0   3691.9   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0   7537.9   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0  11378.9   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0  16180.3   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0  20021.3   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0  24822.5   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0  28663.5   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0  33466.8   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0  37312.8   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0  42114.1   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0 2592.0  0.0   49152.0  45955.1   131072.0     24.0    8832.0 8403.6 896.0  795.9       2    0.020   0      0.000    0.020
8192.0 8192.0  0.0   3488.0 49152.0   1925.1   131072.0     32.0    10752.0 10225.1 1024.0 934.2       3    0.026   0      0.000    0.026
8192.0 8192.0  0.0   3488.0 49152.0   6737.6   131072.0     32.0    10752.0 10225.1 1024.0 934.2       3    0.026   0      0.000    0.026
8192.0 8192.0  0.0   3488.0 49152.0  11758.5   131072.0     32.0    10752.0 10225.1 1024.0 934.2       3    0.026   0      0.000    0.026
8192.0 8192.0  0.0   3488.0 49152.0  15608.7   131072.0     32.0    10752.0 10225.1 1024.0 934.2       3    0.026   0      0.000    0.026
8192.0 8192.0  0.0   3488.0 49152.0  29056.4   131072.0     32.0    10752.0 10225.1 1024.0 934.2       3    0.026   0      0.000    0.026
8192.0 8192.0  0.0   3488.0 49152.0  34196.6   131072.0     32.0    10752.0 10225.1 1024.0 934.2       3    0.026   0      0.000    0.026
8192.0 8192.0  0.0   3488.0 49152.0  39339.7   131072.0     32.0    10752.0 10225.1 1024.0 934.2       3    0.026   0      0.000    0.026

Solution

You misunderstood the function of - XX: metaspacesize:

The name of this option can be considered misleading unless you interpret it as "expected size", so obviously it should trigger garbage collection when exceeded (while the maximum size defines a hard limit)

There is an open bug report. Jdk-8067205 requires setting the option of initial meta space size

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>