Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8293114: JVM should trim the native heap #14781

Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c7093a5
Initial implementation
tstuefe Jul 6, 2023
9ba4448
Fix test for non-glibc platforms
tstuefe Jul 6, 2023
459eddf
fix ChunkPool::needs_cleaning
tstuefe Jul 6, 2023
fa98c06
rename pause, unpause -> suspend, resume
tstuefe Jul 6, 2023
dd4cb47
seconds->ms
tstuefe Jul 6, 2023
cd8c0f1
restructuring
tstuefe Jul 6, 2023
9b47c64
last cleanups and shade feedback
tstuefe Jul 6, 2023
bc5fe46
Merge branch 'master' into JDK-8293114-JVM-should-trim-the-native-heap
tstuefe Jul 7, 2023
6f70f28
Leo: fix copyrights
tstuefe Jul 7, 2023
2dba123
Purge all mentionings of GC from patch
tstuefe Jul 7, 2023
47ad3c5
Add missing gtest
tstuefe Jul 7, 2023
7a43a3f
change to os::elapsedTime
tstuefe Jul 7, 2023
41828b0
Aleksey: cosmetic changes 1
tstuefe Jul 7, 2023
7456784
Aleksey: cosmetic changes 2
tstuefe Jul 7, 2023
06b8f40
Aleksey: changes 3
tstuefe Jul 7, 2023
d141b51
Fix include guard name
tstuefe Jul 7, 2023
eddfca6
Renamings
tstuefe Jul 7, 2023
285c4b1
Test Unsafe->WB
tstuefe Jul 7, 2023
c919203
rework test
tstuefe Jul 7, 2023
3423306
fix 32-bit
tstuefe Jul 8, 2023
367ae22
No need for atomics
tstuefe Jul 8, 2023
aa4dbc0
Add test with 1ms trim interval
tstuefe Jul 8, 2023
2de57c3
Merge branch 'master' into JDK-8293114-JVM-should-trim-the-native-heap
tstuefe Jul 10, 2023
5f54191
Fix linker errors
tstuefe Jul 10, 2023
66c17aa
suspend count return 16 bits
tstuefe Jul 10, 2023
ddd5421
Aleksey cosmetics
tstuefe Jul 10, 2023
d64a960
Improve comments for non-supportive platforms
tstuefe Jul 10, 2023
682e25f
Remove TrimNativeHeap and expand TrimNativeHeapInterval
tstuefe Jul 10, 2023
130fe0d
When probing for safepoint end, use the smaller of (interval, 250ms)
tstuefe Jul 10, 2023
df10572
rename logtag again
tstuefe Jul 10, 2023
1b25704
Dont query procfs if logging is off
tstuefe Jul 10, 2023
1556676
Make test spikes more pronounced
tstuefe Jul 10, 2023
2017e58
Alekseys patch
tstuefe Jul 13, 2023
fa19197
Merge branch 'master' into JDK-8293114-JVM-should-trim-the-native-heap
tstuefe Jul 13, 2023
e821d51
Fix windows build
tstuefe Jul 13, 2023
c8d4643
Bikeshed Trim log lines
tstuefe Jul 13, 2023
9196908
David simple cosmetics
tstuefe Jul 14, 2023
34037c8
Aleksey trim stats; state printerich; David better gtest; misc stuff
tstuefe Jul 14, 2023
af75c0c
Last Aleksey Feedback
tstuefe Jul 14, 2023
d22248f
Display unsupported text with UL warning level, + test
tstuefe Jul 14, 2023
74b1aac
Merge branch 'master' into JDK-8293114-JVM-should-trim-the-native-heap
tstuefe Jul 20, 2023
9c5f6df
Merge branch 'master' into JDK-8293114-JVM-should-trim-the-native-heap
tstuefe Jul 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hotspot/os/aix/os_aix.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inline bool os::must_commit_stack_guard_pages() {
inline void os::map_stack_shadow_pages(address sp) {
}

// stubbed-out trim-native support
// Trim-native support, stubbed out for now, may be enabled later
inline bool os::can_trim_native_heap() { return false; }
inline bool os::trim_native_heap(os::size_change_t* rss_change) { return false; }

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os/bsd/os_bsd.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ inline bool os::must_commit_stack_guard_pages() {
inline void os::map_stack_shadow_pages(address sp) {
}

// stubbed-out trim-native support
// Trim-native support, stubbed out for now, may be enabled later
inline bool os::can_trim_native_heap() { return false; }
inline bool os::trim_native_heap(os::size_change_t* rss_change) { return false; }

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os/windows/os_windows.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ inline void PlatformMonitor::notify_all() {
WakeAllConditionVariable(&_cond);
}

// stubbed-out trim-native support
// Trim-native support, stubbed out for now, may be enabled later
inline bool os::can_trim_native_heap() { return false; }
inline bool os::trim_native_heap(os::size_change_t* rss_change) { return false; }

Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/classfile/stringTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "runtime/mutexLocker.hpp"
#include "runtime/safepointVerifiers.hpp"
#include "runtime/timerTrace.hpp"
#include "runtime/trimNativeHeap.hpp"
#include "services/diagnosticCommand.hpp"
#include "utilities/concurrentHashTable.inline.hpp"
#include "utilities/concurrentHashTableTasks.inline.hpp"
Expand Down Expand Up @@ -456,6 +457,7 @@ void StringTable::clean_dead_entries(JavaThread* jt) {

StringTableDeleteCheck stdc;
StringTableDoDelete stdd;
NativeHeapTrimmer::SuspendMark sm("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 @@ -37,6 +37,7 @@
#include "runtime/atomic.hpp"
#include "runtime/interfaceSupport.inline.hpp"
#include "runtime/timerTrace.hpp"
#include "runtime/trimNativeHeap.hpp"
#include "services/diagnosticCommand.hpp"
#include "utilities/concurrentHashTable.inline.hpp"
#include "utilities/concurrentHashTableTasks.inline.hpp"
Expand Down Expand Up @@ -737,6 +738,7 @@ void SymbolTable::clean_dead_entries(JavaThread* jt) {

SymbolTableDeleteCheck stdc;
SymbolTableDoDelete stdd;
NativeHeapTrimmer::SuspendMark sm("symboltable");
{
TraceTime timer("Clean", TRACETIME_LOG(Debug, symboltable, perf));
while (bdt.do_task(jt, stdc, stdd)) {
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 @@ -198,6 +198,7 @@ class outputStream;
LOG_TAG(timer) \
LOG_TAG(tlab) \
LOG_TAG(tracking) \
LOG_TAG(trimnative) /* trim native heap */ \
LOG_TAG(unload) /* Trace unloading of classes */ \
LOG_TAG(unmap) \
LOG_TAG(unshareable) \
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/memory/arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "runtime/os.hpp"
#include "runtime/task.hpp"
#include "runtime/threadCritical.hpp"
#include "runtime/trimNativeHeap.hpp"
#include "services/memTracker.inline.hpp"
#include "utilities/align.hpp"
#include "utilities/debug.hpp"
Expand Down Expand Up @@ -92,6 +93,7 @@ class ChunkPool {
}

static void clean() {
NativeHeapTrimmer::SuspendMark sm("chunk pool cleaner");
for (int i = 0; i < _num_pools; i++) {
_pools[i].prune();
}
Expand Down
9 changes: 9 additions & 0 deletions src/hotspot/share/prims/whitebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2580,6 +2580,14 @@ WB_ENTRY(jboolean, WB_SetVirtualThreadsNotifyJvmtiMode(JNIEnv* env, jobject wb,
return result;
WB_END

WB_ENTRY(void, WB_PreTouchMemory(JNIEnv* env, jobject wb, jlong addr, jlong size))
void* const from = (void*)addr;
void* const to = (void*)(addr + size);
if (from > to) {
os::pretouch_memory(from, to, os::vm_page_size());
}
WB_END

#define CC (char*)

static JNINativeMethod methods[] = {
Expand Down Expand Up @@ -2861,6 +2869,7 @@ static JNINativeMethod methods[] = {
{CC"lockCritical", CC"()V", (void*)&WB_LockCritical},
{CC"unlockCritical", CC"()V", (void*)&WB_UnlockCritical},
{CC"setVirtualThreadsNotifyJvmtiMode", CC"(Z)Z", (void*)&WB_SetVirtualThreadsNotifyJvmtiMode},
{CC"preTouchMemory", CC"(JJ)V", (void*)&WB_PreTouchMemory},
};


Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,13 @@ const int ObjectAlignmentInBytes = 8;
"1: monitors & legacy stack-locking (LM_LEGACY, default), " \
"2: monitors & new lightweight locking (LM_LIGHTWEIGHT)") \
range(0, 2) \
\
product(uint, TrimNativeHeapInterval, 0, EXPERIMENTAL, \
"Interval, in ms, at which the JVM will trim the native heap if " \
"the platform supports that. Lower values will reclaim memory " \
"more eagerly at the cost of higher overhead. A value of 0 " \
"(default) disables the native heap trimming.") \
tstuefe marked this conversation as resolved.
Show resolved Hide resolved
range(0, 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 @@ -70,6 +70,7 @@
#include "runtime/task.hpp"
#include "runtime/threads.hpp"
#include "runtime/timer.hpp"
#include "runtime/trimNativeHeap.hpp"
#include "runtime/vmOperations.hpp"
#include "runtime/vmThread.hpp"
#include "runtime/vm_version.hpp"
Expand Down Expand Up @@ -479,6 +480,8 @@ void before_exit(JavaThread* thread, bool halt) {
StatSampler::disengage();
StatSampler::destroy();

NativeHeapTrimmer::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 @@ -54,6 +54,7 @@
#include "runtime/synchronizer.hpp"
#include "runtime/threads.hpp"
#include "runtime/timer.hpp"
#include "runtime/trimNativeHeap.hpp"
#include "runtime/vframe.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/align.hpp"
Expand Down Expand Up @@ -1646,6 +1647,7 @@ class VM_RendezvousGCThreads : public VM_Operation {
};

static size_t delete_monitors(GrowableArray<ObjectMonitor*>* delete_list) {
NativeHeapTrimmer::SuspendMark trim_native_pause("monitor deletion");
tstuefe marked this conversation as resolved.
Show resolved Hide resolved
size_t count = 0;
for (ObjectMonitor* monitor: *delete_list) {
delete monitor;
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/runtime/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include "runtime/threadSMR.inline.hpp"
#include "runtime/timer.hpp"
#include "runtime/timerTrace.hpp"
#include "runtime/trimNativeHeap.hpp"
#include "runtime/vmOperations.hpp"
#include "runtime/vm_version.hpp"
#include "services/attachListener.hpp"
Expand Down Expand Up @@ -755,6 +756,10 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
}
#endif

if (NativeHeapTrimmer::enabled()) {
NativeHeapTrimmer::initialize();
}

// Always call even when there are not JVMTI environments yet, since environments
// may be attached late and JVMTI must track phases of VM execution
JvmtiExport::enter_live_phase();
Expand Down
Loading