Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java8 MetaspaceSize flag not working

I have a simple test code that setup both -XX:MetaspaceSize and -XX:MaxMetaspaceSize to a same value. I think the metaspace then should not dynamically resizing. But from my testing (check Metaspace diagram from VisualVM GC and print out log by jstat), i saw metaspace keep growing from a low value to the max value i set. So doesn't the -XX:MetaspaceSize not working?

My testing 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 keep growing to around 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
like image 251
dereck Avatar asked Dec 23 '22 12:12

dereck


1 Answers

You have misunderstood what -XX:MetaspaceSize does:

-XX:MetaspaceSize=size

Sets the size of the allocated class metadata space that will trigger a garbage collection the first time it is exceeded. This threshold for a garbage collection is increased or decreased depending on the amount of metadata used.

The name of that option might be considered misleading, unless you interpret it as “intended size”, so obviously it should trigger garbage collection when exceeded (while max size defines the hard limit).

There is an open bug report, JDK-8067205 calling for an option to set the initial metaspace size.

like image 113
Holger Avatar answered Jan 29 '23 03:01

Holger