Neil
Neil

Reputation: 1948

Can the G1 garbage collector be used when System.gc() is called

In Hotspot, when System.gc() is invoked, I can have this use the Concurrent-Mark-Sweep collector by adding the -XX:+ExplicitGCInvokesConcurrent option to the command line.

Is there anything equivalent to make the JVM use the G1 collector when System.gc() is invoked? By default, the standard parallel collector appears to be used.

I'm guessing not, but I just wondered if anyone could confirm.

Don't worry! I'm not planning to invoke System.gc() myself, but there are parts of the JVM (direct buffers, RMI) that rely on it being called.

Upvotes: 4

Views: 1517

Answers (2)

Kirk
Kirk

Reputation: 749

bool G1CollectedHeap::should_do_concurrent_full_gc(GCCause::Cause cause) {
  switch (cause) {
    case GCCause::_gc_locker:               return GCLockerInvokesConcurrent;
    case GCCause::_java_lang_system_gc:     return ExplicitGCInvokesConcurrent;
    case GCCause::_g1_humongous_allocation: return true;
    default:                                return false;

} }

And

bool ExplicitGCInvokesConcurrent = false {product}

Upvotes: 0

alain.janinm
alain.janinm

Reputation: 20065

From this bug post :

G1 now observes ExplicitGCInvokesConcurrent

there is also this link that confirm it.

AFAIK there is no special command, neither the list of Oracle JVM options nor this longer list refer such command option.

Upvotes: 4

Related Questions