Profile Image
vishnupriya

What is JVM startup parameter: -XX:+TraceClassUnloading?

What is JVM startup parameter: -XX:+TraceClassUnloading? Have you used this JVM arguement before? What are the pros & cons of using this Java argument? Can you share your perspective/experience in using this JVM argument?

  • jvmargument

  • xx-traceclassunloading

  • x-traceclassunloading

  • JVM startup parameter

Please Sign In or to post your comment or answer

Profile Image

Pavel Khodakovsky

Usage:


 This flag traces and track all unloaded classes.

 

Since:

 

Starting from JDK 6.

 

Since:

 

Obsoleted in JDK 16.

 

Expired in JDK 17.

 

Examples:

 

To trace all unloaded classes when running your application:

 

java -XX:+TraceClassUnloading MainClass

 

Description:

 

Garbage Collector is a way of the JVM to clean the memory and makes the java memory more efficient. It tracks (Mark step) and removes (sweep step) every unused object available in the JVM heap space. An object is considered unused when it’s referenced by null, assigned to another reference or by anonymous object …. There are 5 type of GC implementations:

  • Serial Garbage Collector
  • Parallel Garbage Collector
  • CMS Garbage Collector
  • G1 Garbage Collector
  • Z Garbage Collector

 

-XX:+TraceClassUnloading The parameter is to track the unloading of the class. Since the classes loaded by the system class loader will not be unloaded and loaded only once, it is difficult for ordinary projects to obtain the log of class unloading.

 

When running your application with this flag, you won’t see any log printed which means no unloading classes has occurred that’s because classes loaded by the system class loader cannot be unloaded. So, to see logs that track class unloading, we need to use a custom class loader. A class loaded by a custom class loader will be garbage collected and unloaded when the class is unreachable.

 

In general, custom class loaders are rarely implemented in the development process, unless there are special requirements scenarios that require class loading through a custom class loader.

 

Default Value:

 

By default, this flag is disabled.

 

Note:

 

If you encounter frequent Full GC, but the old generation space is not used much, the situation after the young generation GC is also normal, and there is no sudden large object, but the meta space keeps increasing, then you can consider the following Is the use of reflection and other means to cause too many classes to be loaded in the metaspace, causing the metaspace to be full and triggering Full GC

 

Arguments related:

 

TraceClassLoadingPreorder, TraceClassResolution, TraceClassLoading and TraceLoaderConstraints.

 

Related Posts:

 

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • jvmargument

  • xx-traceclassunloading

  • x-traceclassunloading

  • JVM startup parameter