Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tstuefe committed Jul 6, 2023
1 parent edb2be1 commit c7093a5
Show file tree
Hide file tree
Showing 20 changed files with 641 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/hotspot/share/classfile/stringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "gc/shared/oopStorage.inline.hpp"
#include "gc/shared/oopStorageSet.hpp"
#include "gc/shared/stringdedup/stringDedup.hpp"
#include "runtime/trimNative.hpp"
#include "logging/log.hpp"
#include "logging/logStream.hpp"
#include "memory/allocation.inline.hpp"
Expand Down Expand Up @@ -456,6 +457,7 @@ void StringTable::clean_dead_entries(JavaThread* jt) {

StringTableDeleteCheck stdc;
StringTableDoDelete stdd;
TrimNative::PauseMark trim_native_pause("stringtable");
{
TraceTime timer("Clean", TRACETIME_LOG(Debug, stringtable, perf));
while(bdt.do_task(jt, stdc, stdd)) {
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/classfile/symbolTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "classfile/compactHashtable.hpp"
#include "classfile/javaClasses.hpp"
#include "classfile/symbolTable.hpp"
#include "runtime/trimNative.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/metaspaceClosure.hpp"
#include "memory/resourceArea.hpp"
Expand Down Expand Up @@ -737,6 +738,7 @@ void SymbolTable::clean_dead_entries(JavaThread* jt) {

SymbolTableDeleteCheck stdc;
SymbolTableDoDelete stdd;
TrimNative::PauseMark trim_native_pause("symboltable");
{
TraceTime timer("Clean", TRACETIME_LOG(Debug, symboltable, perf));
while (bdt.do_task(jt, stdc, stdd)) {
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#include "gc/shared/taskqueue.inline.hpp"
#include "gc/shared/taskTerminator.hpp"
#include "gc/shared/tlab_globals.hpp"
#include "runtime/trimNative.hpp"
#include "gc/shared/workerPolicy.hpp"
#include "gc/shared/weakProcessor.inline.hpp"
#include "logging/log.hpp"
Expand Down Expand Up @@ -914,6 +915,8 @@ bool G1CollectedHeap::do_full_collection(bool clear_all_soft_refs,
return false;
}

TrimNative::PauseMark trim_native_pause("gc");

const bool do_clear_all_soft_refs = clear_all_soft_refs ||
soft_ref_policy()->should_clear_all_soft_refs();

Expand Down Expand Up @@ -2549,6 +2552,7 @@ void G1CollectedHeap::retire_tlabs() {

void G1CollectedHeap::do_collection_pause_at_safepoint_helper() {
ResourceMark rm;
TrimNative::PauseMark trim_native_pause("gc");

IsGCActiveMark active_gc_mark;
GCIdMark gc_id_mark;
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "gc/shared/suspendibleThreadSet.hpp"
#include "gc/shared/taskTerminator.hpp"
#include "gc/shared/taskqueue.inline.hpp"
#include "runtime/trimNative.hpp"
#include "gc/shared/weakProcessor.inline.hpp"
#include "gc/shared/workerPolicy.hpp"
#include "jvm.h"
Expand Down Expand Up @@ -1234,6 +1235,8 @@ void G1ConcurrentMark::remark() {
return;
}

TrimNative::PauseMark trim_native_pause("gc");

G1Policy* policy = _g1h->policy();
policy->record_concurrent_mark_remark_start();

Expand Down Expand Up @@ -1448,6 +1451,8 @@ void G1ConcurrentMark::cleanup() {
return;
}

TrimNative::PauseMark trim_native_pause("gc");

G1Policy* policy = _g1h->policy();
policy->record_concurrent_mark_cleanup_start();

Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/gc/parallel/psParallelCompact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "gc/shared/gcTimer.hpp"
#include "gc/shared/gcTrace.hpp"
#include "gc/shared/gcTraceTime.inline.hpp"
#include "runtime/trimNative.hpp"
#include "gc/shared/isGCActiveMark.hpp"
#include "gc/shared/oopStorage.inline.hpp"
#include "gc/shared/oopStorageSet.inline.hpp"
Expand Down Expand Up @@ -1709,6 +1710,9 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
return false;
}

// Pause native trimming for the duration of the GC
TrimNative::PauseMark trim_native_pause("gc");

ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();

GCIdMark gc_id_mark;
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/gc/shared/genCollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "gc/shared/scavengableNMethods.hpp"
#include "gc/shared/space.hpp"
#include "gc/shared/strongRootsScope.hpp"
#include "runtime/trimNative.hpp"
#include "gc/shared/weakProcessor.hpp"
#include "gc/shared/workerThread.hpp"
#include "memory/iterator.hpp"
Expand Down Expand Up @@ -442,6 +443,8 @@ void GenCollectedHeap::do_collection(bool full,
"the requesting thread should have the Heap_lock");
guarantee(!is_gc_active(), "collection is not reentrant");

TrimNative::PauseMark trim_native_pause("gc");

if (GCLocker::check_active_before_gc()) {
return; // GC is disabled (e.g. JNI GetXXXCritical operation)
}
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "gc/shenandoah/shenandoahVMOperations.hpp"
#include "gc/shenandoah/shenandoahWorkerPolicy.hpp"
#include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
#include "runtime/trimNative.hpp"
#include "memory/iterator.hpp"
#include "memory/metaspaceUtils.hpp"
#include "memory/metaspaceStats.hpp"
Expand Down Expand Up @@ -422,6 +423,7 @@ void ShenandoahControlThread::stop_service() {
}

void ShenandoahControlThread::service_stw_full_cycle(GCCause::Cause cause) {
TrimNative::PauseMark trim_native_pause("gc");
GCIdMark gc_id_mark;
ShenandoahGCSession session(cause);

Expand All @@ -436,6 +438,7 @@ void ShenandoahControlThread::service_stw_full_cycle(GCCause::Cause cause) {
void ShenandoahControlThread::service_stw_degenerated_cycle(GCCause::Cause cause, ShenandoahGC::ShenandoahDegenPoint point) {
assert (point != ShenandoahGC::_degenerated_unset, "Degenerated point should be set");

TrimNative::PauseMark trim_native_pause("gc");
GCIdMark gc_id_mark;
ShenandoahGCSession session(cause);

Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahPhaseTimings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class outputStream;
f(full_gc_heapdump_post, " Post Heap Dump") \
\
f(conc_uncommit, "Concurrent Uncommit") \
f(conc_trim, "Concurrent Trim") \
f(pacing, "Pacing") \
\
f(heap_iteration_roots, "Heap Iteration") \
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/gc/x/xDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "gc/shared/gcLocker.hpp"
#include "gc/shared/gcVMOperations.hpp"
#include "gc/shared/isGCActiveMark.hpp"
#include "runtime/trimNative.hpp"
#include "gc/x/xAbort.inline.hpp"
#include "gc/x/xBreakpoint.hpp"
#include "gc/x/xCollectedHeap.hpp"
Expand Down Expand Up @@ -114,6 +115,8 @@ class VM_XOperation : public VM_Operation {
return;
}

TrimNative::PauseMark trim_native_pause("gc");

// Setup GC id and active marker
GCIdMark gc_id_mark(_gc_id);
IsGCActiveMark gc_active_mark;
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/gc/z/zGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "gc/shared/gcVMOperations.hpp"
#include "gc/shared/isGCActiveMark.hpp"
#include "gc/shared/suspendibleThreadSet.hpp"
#include "runtime/trimNative.hpp"
#include "gc/z/zAllocator.inline.hpp"
#include "gc/z/zBarrierSet.hpp"
#include "gc/z/zBarrierSetAssembler.hpp"
Expand Down Expand Up @@ -431,6 +432,8 @@ class VM_ZOperation : public VM_Operation {
}

virtual void doit() {
TrimNative::PauseMark trim_native_pause("gc");

// Setup GC id and active marker
GCIdMark gc_id_mark(_gc_id);
IsGCActiveMark gc_active_mark;
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/logging/logTag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ class outputStream;
LOG_TAG(timer) \
LOG_TAG(tlab) \
LOG_TAG(tracking) \
LOG_TAG(trim) \
LOG_TAG(unload) /* Trace unloading of classes */ \
LOG_TAG(unmap) \
LOG_TAG(unshareable) \
Expand Down
25 changes: 21 additions & 4 deletions src/hotspot/share/memory/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

#include "precompiled.hpp"
#include "runtime/trimNative.hpp"
#include "memory/allocation.hpp"
#include "memory/allocation.inline.hpp"
#include "memory/resourceArea.hpp"
Expand Down Expand Up @@ -52,7 +53,7 @@ class ChunkPool {
const size_t _size; // (inner payload) size of the chunks this pool serves

// Our four static pools
static const int _num_pools = 4;
static constexpr int _num_pools = 4;
static ChunkPool _pools[_num_pools];

public:
Expand Down Expand Up @@ -80,7 +81,6 @@ class ChunkPool {
void prune() {
// Free all chunks while in ThreadCritical lock
// so NMT adjustment is stable.
ThreadCritical tc;
Chunk* cur = _first;
Chunk* next = nullptr;
while (cur != nullptr) {
Expand All @@ -91,9 +91,26 @@ class ChunkPool {
_first = nullptr;
}

static void clean() {
bool empty() const {
return _first == nullptr;
}

static bool needs_cleaning() {
for (int i = 0; i < _num_pools; i++) {
_pools[i].prune();
if (!_pools[i].empty()) {
return false;
}
}
return true;
}

static void clean() {
ThreadCritical tc;
if (needs_cleaning()) {
TrimNative::PauseMark trim_native_pause("chunk pool cleaner");
for (int i = 0; i < _num_pools; i++) {
_pools[i].prune();
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/memory/universe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "gc/shared/plab.hpp"
#include "gc/shared/stringdedup/stringDedup.hpp"
#include "gc/shared/tlab_globals.hpp"
#include "runtime/trimNative.hpp"
#include "logging/log.hpp"
#include "logging/logStream.hpp"
#include "memory/metadataFactory.hpp"
Expand Down Expand Up @@ -1055,6 +1056,11 @@ bool universe_post_init() {
#if INCLUDE_CDS
MetaspaceShared::post_initialize(CHECK_false);
#endif

if (TrimNativeHeap) {
TrimNative::initialize();
}

return true;
}

Expand Down
10 changes: 10 additions & 0 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,16 @@ const int ObjectAlignmentInBytes = 8;
"1: monitors & legacy stack-locking (LM_LEGACY, default), " \
"2: monitors & new lightweight locking (LM_LIGHTWEIGHT)") \
range(0, 2) \
\
product(bool, TrimNativeHeap, false, EXPERIMENTAL, \
"GC will attempt to trim the native heap periodically. By " \
"default, the interval time is 60 seconds, but can be " \
"changed using TrimNativeHeapInterval.") \
\
product(uint, TrimNativeHeapInterval, 60, EXPERIMENTAL, \
"If TrimNativeHeap is enabled: interval, in seconds, in which " \
"the GC will attempt to trim the native heap.") \
range(1, UINT_MAX) \

// end of RUNTIME_FLAGS

Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/runtime/java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "compiler/compileBroker.hpp"
#include "compiler/compilerOracle.hpp"
#include "gc/shared/collectedHeap.hpp"
#include "runtime/trimNative.hpp"
#include "gc/shared/stringdedup/stringDedup.hpp"
#include "interpreter/bytecodeHistogram.hpp"
#include "jfr/jfrEvents.hpp"
Expand Down Expand Up @@ -479,6 +480,8 @@ void before_exit(JavaThread* thread, bool halt) {
StatSampler::disengage();
StatSampler::destroy();

TrimNative::cleanup();

// Stop concurrent GC threads
Universe::heap()->stop();

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/runtime/synchronizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "precompiled.hpp"
#include "classfile/vmSymbols.hpp"
#include "gc/shared/suspendibleThreadSet.hpp"
#include "runtime/trimNative.hpp"
#include "jfr/jfrEvents.hpp"
#include "logging/log.hpp"
#include "logging/logStream.hpp"
Expand Down Expand Up @@ -1646,6 +1647,7 @@ class VM_RendezvousGCThreads : public VM_Operation {
};

static size_t delete_monitors(GrowableArray<ObjectMonitor*>* delete_list) {
TrimNative::PauseMark trim_native_pause("monitor deletion");
size_t count = 0;
for (ObjectMonitor* monitor: *delete_list) {
delete monitor;
Expand Down
Loading

0 comments on commit c7093a5

Please sign in to comment.