Skip to content

Commit 8bc2fbe

Browse files
Sonia Zaldana Calleststuefe
authored andcommitted
8333769: Pretouching tests dont test pretouching
Reviewed-by: stuefe, asmehra
1 parent 91bd85d commit 8bc2fbe

File tree

9 files changed

+178
-79
lines changed

9 files changed

+178
-79
lines changed

src/hotspot/os/aix/os_aix.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ julong os::physical_memory() {
287287
return Aix::physical_memory();
288288
}
289289

290+
size_t os::rss() { return (size_t)0; }
291+
290292
// Cpu architecture string
291293
#if defined(PPC32)
292294
static char cpu_arch[] = "ppc";

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,22 @@ julong os::physical_memory() {
210210
return Bsd::physical_memory();
211211
}
212212

213+
size_t os::rss() {
214+
size_t rss = 0;
215+
#ifdef __APPLE__
216+
mach_task_basic_info info;
217+
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
218+
219+
kern_return_t ret = task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
220+
(task_info_t)&info, &count);
221+
if (ret == KERN_SUCCESS) {
222+
rss = info.resident_size;
223+
}
224+
#endif // __APPLE__
225+
226+
return rss;
227+
}
228+
213229
// Cpu architecture string
214230
#if defined(ZERO)
215231
static char cpu_arch[] = ZERO_LIBARCH;

src/hotspot/os/linux/os_linux.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,15 @@ julong os::physical_memory() {
359359
return phys_mem;
360360
}
361361

362+
size_t os::rss() {
363+
size_t size = 0;
364+
os::Linux::meminfo_t info;
365+
if (os::Linux::query_process_memory_info(&info)) {
366+
size = info.vmrss * K;
367+
}
368+
return size;
369+
}
370+
362371
static uint64_t initial_total_ticks = 0;
363372
static uint64_t initial_steal_ticks = 0;
364373
static bool has_initial_tick_info = false;

src/hotspot/os/windows/os_windows.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,19 @@ julong os::physical_memory() {
858858
return win32::physical_memory();
859859
}
860860

861+
size_t os::rss() {
862+
size_t rss = 0;
863+
PROCESS_MEMORY_COUNTERS_EX pmex;
864+
ZeroMemory(&pmex, sizeof(PROCESS_MEMORY_COUNTERS_EX));
865+
pmex.cb = sizeof(pmex);
866+
BOOL ret = GetProcessMemoryInfo(
867+
GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS *)&pmex, sizeof(pmex));
868+
if (ret) {
869+
rss = pmex.WorkingSetSize;
870+
}
871+
return rss;
872+
}
873+
861874
bool os::has_allocatable_memory_limit(size_t* limit) {
862875
MEMORYSTATUSEX ms;
863876
ms.dwLength = sizeof(ms);

src/hotspot/share/prims/whitebox.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,6 +2657,11 @@ WB_ENTRY(void, WB_CleanMetaspaces(JNIEnv* env, jobject target))
26572657
ClassLoaderDataGraph::safepoint_and_clean_metaspaces();
26582658
WB_END
26592659

2660+
// Reports resident set size (RSS) in bytes
2661+
WB_ENTRY(jlong, WB_Rss(JNIEnv* env, jobject o))
2662+
return os::rss();
2663+
WB_END
2664+
26602665
#define CC (char*)
26612666

26622667
static JNINativeMethod methods[] = {
@@ -2944,6 +2949,7 @@ static JNINativeMethod methods[] = {
29442949
{CC"setVirtualThreadsNotifyJvmtiMode", CC"(Z)Z", (void*)&WB_SetVirtualThreadsNotifyJvmtiMode},
29452950
{CC"preTouchMemory", CC"(JJ)V", (void*)&WB_PreTouchMemory},
29462951
{CC"cleanMetaspaces", CC"()V", (void*)&WB_CleanMetaspaces},
2952+
{CC"rss", CC"()J", (void*)&WB_Rss},
29472953
};
29482954

29492955

src/hotspot/share/runtime/os.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ class os: AllStatic {
344344
static julong physical_memory();
345345
static bool has_allocatable_memory_limit(size_t* limit);
346346
static bool is_server_class_machine();
347+
static size_t rss();
347348

348349
// Returns the id of the processor on which the calling thread is currently executing.
349350
// The returned value is guaranteed to be between 0 and (os::processor_count() - 1).
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright (c) 2014, 2024, Alibaba Group Holding Limited. All rights reserved.
3+
* Copyright (c) 2024, Red Hat Inc.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
package gc;
26+
27+
/**
28+
* @test id=ParallelCollector
29+
* @summary tests AlwaysPreTouch
30+
* @requires vm.gc.Parallel
31+
* @requires os.maxMemory > 2G
32+
* @requires os.family != "aix"
33+
* @library /test/lib
34+
* @build jdk.test.whitebox.WhiteBox
35+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
36+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+UseParallelGC -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
37+
*/
38+
39+
/**
40+
* @test id=SerialCollector
41+
* @summary tests AlwaysPreTouch
42+
* @requires vm.gc.Serial
43+
* @requires os.maxMemory > 2G
44+
* @requires os.family != "aix"
45+
* @library /test/lib
46+
* @build jdk.test.whitebox.WhiteBox
47+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
48+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+UseSerialGC -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
49+
*/
50+
51+
/**
52+
* @test id=Shenandoah
53+
* @summary tests AlwaysPreTouch
54+
* @requires vm.gc.Shenandoah
55+
* @requires os.maxMemory > 2G
56+
* @requires os.family != "aix"
57+
* @library /test/lib
58+
* @build jdk.test.whitebox.WhiteBox
59+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
60+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+UseShenandoahGC -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
61+
*/
62+
63+
/**
64+
* @test id=G1
65+
* @summary tests AlwaysPreTouch
66+
* @requires vm.gc.G1
67+
* @requires os.maxMemory > 2G
68+
* @requires os.family != "aix"
69+
* @library /test/lib
70+
* @build jdk.test.whitebox.WhiteBox
71+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
72+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
73+
*/
74+
75+
/**
76+
* @test id=ZGenerational
77+
* @summary tests AlwaysPreTouch
78+
* @requires vm.gc.ZGenerational
79+
* @requires os.maxMemory > 2G
80+
* @requires os.family != "aix"
81+
* @library /test/lib
82+
* @build jdk.test.whitebox.WhiteBox
83+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
84+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseZGC -XX:+ZGenerational -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
85+
*/
86+
87+
/**
88+
* @test id=ZSinglegen
89+
* @summary tests AlwaysPreTouch
90+
* @requires vm.gc.ZSinglegen
91+
* @requires os.maxMemory > 2G
92+
* @requires os.family != "aix"
93+
* @library /test/lib
94+
* @build jdk.test.whitebox.WhiteBox
95+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
96+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseZGC -XX:-ZGenerational -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
97+
*/
98+
99+
/**
100+
* @test id=Epsilon
101+
* @summary tests AlwaysPreTouch
102+
* @requires vm.gc.Epsilon
103+
* @requires os.maxMemory > 2G
104+
* @requires os.family != "aix"
105+
* @library /test/lib
106+
* @build jdk.test.whitebox.WhiteBox
107+
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
108+
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
109+
*/
110+
111+
112+
import jdk.test.lib.Asserts;
113+
114+
import jdk.test.whitebox.WhiteBox;
115+
116+
public class TestAlwaysPreTouchBehavior {
117+
118+
public static void main(String [] args) {
119+
long rss = WhiteBox.getWhiteBox().rss();
120+
System.out.println("RSS: " + rss);
121+
if (rss == 0) {
122+
System.out.println("cannot get RSS, just skip");
123+
return; // Did not get available RSS, just ignore this test.
124+
}
125+
Runtime runtime = Runtime.getRuntime();
126+
long committedMemory = runtime.totalMemory();
127+
Asserts.assertGreaterThan(rss, committedMemory, "RSS of this process(" + rss + "b) should be bigger than or equal to committed heap mem(" + committedMemory + "b)");
128+
}
129+
}
130+

test/hotspot/jtreg/gc/parallel/TestAlwaysPreTouchBehavior.java

Lines changed: 0 additions & 79 deletions
This file was deleted.

test/lib/jdk/test/whitebox/WhiteBox.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,4 +798,5 @@ public native int validateCgroup(String procCgroups,
798798
public native boolean setVirtualThreadsNotifyJvmtiMode(boolean enabled);
799799

800800
public native void preTouchMemory(long addr, long size);
801+
public native long rss();
801802
}

0 commit comments

Comments
 (0)