GC notifications are sent to the ServiceThread, as shown in the Groovy shell example in this gist. The ServiceThread is a JavaThread, so it can execute Java code.
To see GC notification in action, refer to a conversation in hotspot-gc-dev. Another thread of interest is the discussions on 7110173: GCNotifier::pushNotification publishes stale data.
In the HotSpot VM, GC notifications are pushed with GCNotifier::pushNotification()
, in GCMemoryManager::gc_end()
, which is in turn called by MemoryService::gc_end()
.
hotspot/src/share/vm/runtime/serviceThread.cpp