Skip to content

Commit f667b35

Browse files
committed
8293114: JVM should trim the native heap
Reviewed-by: stuefe Backport-of: 9e4fc568a6f1a93c84a84d6cc5220c6eb4e546a5
1 parent 1421540 commit f667b35

File tree

20 files changed

+847
-7
lines changed

20 files changed

+847
-7
lines changed

src/hotspot/os/aix/os_aix.inline.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ inline bool os::must_commit_stack_guard_pages() {
4747
inline void os::map_stack_shadow_pages(address sp) {
4848
}
4949

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

src/hotspot/os/bsd/os_bsd.inline.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ inline bool os::must_commit_stack_guard_pages() {
5151
inline void os::map_stack_shadow_pages(address sp) {
5252
}
5353

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

src/hotspot/os/windows/os_windows.inline.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ inline void os::PlatformMonitor::notify_all() {
9393
WakeAllConditionVariable(&_cond);
9494
}
9595

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

src/hotspot/share/classfile/stringTable.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "runtime/safepointVerifiers.hpp"
5050
#include "runtime/timerTrace.hpp"
5151
#include "runtime/interfaceSupport.inline.hpp"
52+
#include "runtime/trimNativeHeap.hpp"
5253
#include "services/diagnosticCommand.hpp"
5354
#include "utilities/concurrentHashTable.inline.hpp"
5455
#include "utilities/concurrentHashTableTasks.inline.hpp"
@@ -431,6 +432,7 @@ void StringTable::clean_dead_entries(JavaThread* jt) {
431432

432433
StringTableDeleteCheck stdc;
433434
StringTableDoDelete stdd;
435+
NativeHeapTrimmer::SuspendMark sm("stringtable");
434436
{
435437
TraceTime timer("Clean", TRACETIME_LOG(Debug, stringtable, perf));
436438
while(bdt.do_task(jt, stdc, stdd)) {

src/hotspot/share/classfile/symbolTable.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "runtime/atomic.hpp"
3838
#include "runtime/interfaceSupport.inline.hpp"
3939
#include "runtime/timerTrace.hpp"
40+
#include "runtime/trimNativeHeap.hpp"
4041
#include "services/diagnosticCommand.hpp"
4142
#include "utilities/concurrentHashTable.inline.hpp"
4243
#include "utilities/concurrentHashTableTasks.inline.hpp"
@@ -697,6 +698,7 @@ void SymbolTable::clean_dead_entries(JavaThread* jt) {
697698

698699
SymbolTableDeleteCheck stdc;
699700
SymbolTableDoDelete stdd;
701+
NativeHeapTrimmer::SuspendMark sm("symboltable");
700702
{
701703
TraceTime timer("Clean", TRACETIME_LOG(Debug, symboltable, perf));
702704
while (bdt.do_task(jt, stdc, stdd)) {

src/hotspot/share/logging/logTag.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
LOG_TAG(timer) \
188188
LOG_TAG(tlab) \
189189
LOG_TAG(tracking) \
190+
LOG_TAG(trimnative) /* trim native heap */ \
190191
LOG_TAG(unload) /* Trace unloading of classes */ \
191192
LOG_TAG(unshareable) \
192193
LOG_TAG(update) \

src/hotspot/share/memory/arena.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "runtime/task.hpp"
3131
#include "runtime/threadCritical.hpp"
3232
#include "services/memTracker.hpp"
33+
#include "runtime/trimNativeHeap.hpp"
3334
#include "utilities/ostream.hpp"
3435

3536
//--------------------------------------------------------------------------------------
@@ -136,6 +137,7 @@ class ChunkPool: public CHeapObj<mtInternal> {
136137
}
137138

138139
static void clean() {
140+
NativeHeapTrimmer::SuspendMark sm("chunk pool cleaner");
139141
enum { BlocksToKeep = 5 };
140142
_tiny_pool->free_all_but(BlocksToKeep);
141143
_small_pool->free_all_but(BlocksToKeep);

src/hotspot/share/prims/whitebox.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,14 @@ WB_ENTRY(void, WB_UnlockCritical(JNIEnv* env, jobject wb))
23642364
GCLocker::unlock_critical(thread);
23652365
WB_END
23662366

2367+
WB_ENTRY(void, WB_PreTouchMemory(JNIEnv* env, jobject wb, jlong addr, jlong size))
2368+
void* const from = (void*)addr;
2369+
void* const to = (void*)(addr + size);
2370+
if (from > to) {
2371+
os::pretouch_memory(from, to, os::vm_page_size());
2372+
}
2373+
WB_END
2374+
23672375
#define CC (char*)
23682376

23692377
static JNINativeMethod methods[] = {
@@ -2631,6 +2639,7 @@ static JNINativeMethod methods[] = {
26312639

26322640
{CC"lockCritical", CC"()V", (void*)&WB_LockCritical},
26332641
{CC"unlockCritical", CC"()V", (void*)&WB_UnlockCritical},
2642+
{CC"preTouchMemory", CC"(JJ)V", (void*)&WB_PreTouchMemory},
26342643
};
26352644

26362645

src/hotspot/share/runtime/globals.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -2093,6 +2093,13 @@ const intx ObjectAlignmentInBytes = 8;
20932093
\
20942094
develop(bool, TraceOptimizedUpcallStubs, false, \
20952095
"Trace optimized upcall stub generation") \
2096+
\
2097+
product(uint, TrimNativeHeapInterval, 0, EXPERIMENTAL, \
2098+
"Interval, in ms, at which the JVM will trim the native heap if " \
2099+
"the platform supports that. Lower values will reclaim memory " \
2100+
"more eagerly at the cost of higher overhead. A value of 0 " \
2101+
"(default) disables native heap trimming.") \
2102+
range(0, UINT_MAX) \
20962103

20972104
// end of RUNTIME_FLAGS
20982105

src/hotspot/share/runtime/java.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include "runtime/task.hpp"
7272
#include "runtime/thread.inline.hpp"
7373
#include "runtime/timer.hpp"
74+
#include "runtime/trimNativeHeap.hpp"
7475
#include "runtime/vmOperations.hpp"
7576
#include "runtime/vmThread.hpp"
7677
#include "runtime/vm_version.hpp"
@@ -467,6 +468,8 @@ void before_exit(JavaThread* thread, bool halt) {
467468
StringDedup::stop();
468469
}
469470

471+
NativeHeapTrimmer::cleanup();
472+
470473
// Stop concurrent GC threads
471474
Universe::heap()->stop();
472475

src/hotspot/share/runtime/synchronizer.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "runtime/synchronizer.hpp"
5252
#include "runtime/thread.inline.hpp"
5353
#include "runtime/timer.hpp"
54+
#include "runtime/trimNativeHeap.hpp"
5455
#include "runtime/vframe.hpp"
5556
#include "runtime/vmThread.hpp"
5657
#include "utilities/align.hpp"
@@ -1544,6 +1545,8 @@ size_t ObjectSynchronizer::deflate_idle_monitors() {
15441545
}
15451546
}
15461547

1548+
NativeHeapTrimmer::SuspendMark sm("monitor deletion");
1549+
15471550
// After the handshake, safely free the ObjectMonitors that were
15481551
// deflated in this cycle.
15491552
size_t deleted_count = 0;

src/hotspot/share/runtime/thread.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
#include "runtime/threadWXSetters.inline.hpp"
113113
#include "runtime/timer.hpp"
114114
#include "runtime/timerTrace.hpp"
115+
#include "runtime/trimNativeHeap.hpp"
115116
#include "runtime/vframe.inline.hpp"
116117
#include "runtime/vframeArray.hpp"
117118
#include "runtime/vframe_hp.hpp"
@@ -3082,6 +3083,10 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) {
30823083
}
30833084
#endif
30843085

3086+
if (NativeHeapTrimmer::enabled()) {
3087+
NativeHeapTrimmer::initialize();
3088+
}
3089+
30853090
// Always call even when there are not JVMTI environments yet, since environments
30863091
// may be attached late and JVMTI must track phases of VM execution
30873092
JvmtiExport::enter_live_phase();

0 commit comments

Comments
 (0)