8333769: Pretouching tests dont test pretouching

Reviewed-by: stuefe, asmehra
This commit is contained in:
Sonia Zaldana Calles 2024-06-18 14:05:11 +00:00 committed by Thomas Stuefe
parent 91bd85d65d
commit 8bc2fbe578
9 changed files with 178 additions and 79 deletions

View File

@ -287,6 +287,8 @@ julong os::physical_memory() {
return Aix::physical_memory();
}
size_t os::rss() { return (size_t)0; }
// Cpu architecture string
#if defined(PPC32)
static char cpu_arch[] = "ppc";

View File

@ -210,6 +210,22 @@ julong os::physical_memory() {
return Bsd::physical_memory();
}
size_t os::rss() {
size_t rss = 0;
#ifdef __APPLE__
mach_task_basic_info info;
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
kern_return_t ret = task_info(mach_task_self(), MACH_TASK_BASIC_INFO,
(task_info_t)&info, &count);
if (ret == KERN_SUCCESS) {
rss = info.resident_size;
}
#endif // __APPLE__
return rss;
}
// Cpu architecture string
#if defined(ZERO)
static char cpu_arch[] = ZERO_LIBARCH;

View File

@ -359,6 +359,15 @@ julong os::physical_memory() {
return phys_mem;
}
size_t os::rss() {
size_t size = 0;
os::Linux::meminfo_t info;
if (os::Linux::query_process_memory_info(&info)) {
size = info.vmrss * K;
}
return size;
}
static uint64_t initial_total_ticks = 0;
static uint64_t initial_steal_ticks = 0;
static bool has_initial_tick_info = false;

View File

@ -858,6 +858,19 @@ julong os::physical_memory() {
return win32::physical_memory();
}
size_t os::rss() {
size_t rss = 0;
PROCESS_MEMORY_COUNTERS_EX pmex;
ZeroMemory(&pmex, sizeof(PROCESS_MEMORY_COUNTERS_EX));
pmex.cb = sizeof(pmex);
BOOL ret = GetProcessMemoryInfo(
GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS *)&pmex, sizeof(pmex));
if (ret) {
rss = pmex.WorkingSetSize;
}
return rss;
}
bool os::has_allocatable_memory_limit(size_t* limit) {
MEMORYSTATUSEX ms;
ms.dwLength = sizeof(ms);

View File

@ -2657,6 +2657,11 @@ WB_ENTRY(void, WB_CleanMetaspaces(JNIEnv* env, jobject target))
ClassLoaderDataGraph::safepoint_and_clean_metaspaces();
WB_END
// Reports resident set size (RSS) in bytes
WB_ENTRY(jlong, WB_Rss(JNIEnv* env, jobject o))
return os::rss();
WB_END
#define CC (char*)
static JNINativeMethod methods[] = {
@ -2944,6 +2949,7 @@ static JNINativeMethod methods[] = {
{CC"setVirtualThreadsNotifyJvmtiMode", CC"(Z)Z", (void*)&WB_SetVirtualThreadsNotifyJvmtiMode},
{CC"preTouchMemory", CC"(JJ)V", (void*)&WB_PreTouchMemory},
{CC"cleanMetaspaces", CC"()V", (void*)&WB_CleanMetaspaces},
{CC"rss", CC"()J", (void*)&WB_Rss},
};

View File

@ -344,6 +344,7 @@ class os: AllStatic {
static julong physical_memory();
static bool has_allocatable_memory_limit(size_t* limit);
static bool is_server_class_machine();
static size_t rss();
// Returns the id of the processor on which the calling thread is currently executing.
// The returned value is guaranteed to be between 0 and (os::processor_count() - 1).

View File

@ -0,0 +1,130 @@
/*
* Copyright (c) 2014, 2024, Alibaba Group Holding Limited. All rights reserved.
* Copyright (c) 2024, Red Hat Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package gc;
/**
* @test id=ParallelCollector
* @summary tests AlwaysPreTouch
* @requires vm.gc.Parallel
* @requires os.maxMemory > 2G
* @requires os.family != "aix"
* @library /test/lib
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+UseParallelGC -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
*/
/**
* @test id=SerialCollector
* @summary tests AlwaysPreTouch
* @requires vm.gc.Serial
* @requires os.maxMemory > 2G
* @requires os.family != "aix"
* @library /test/lib
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+UseSerialGC -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
*/
/**
* @test id=Shenandoah
* @summary tests AlwaysPreTouch
* @requires vm.gc.Shenandoah
* @requires os.maxMemory > 2G
* @requires os.family != "aix"
* @library /test/lib
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+UseShenandoahGC -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
*/
/**
* @test id=G1
* @summary tests AlwaysPreTouch
* @requires vm.gc.G1
* @requires os.maxMemory > 2G
* @requires os.family != "aix"
* @library /test/lib
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
*/
/**
* @test id=ZGenerational
* @summary tests AlwaysPreTouch
* @requires vm.gc.ZGenerational
* @requires os.maxMemory > 2G
* @requires os.family != "aix"
* @library /test/lib
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseZGC -XX:+ZGenerational -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
*/
/**
* @test id=ZSinglegen
* @summary tests AlwaysPreTouch
* @requires vm.gc.ZSinglegen
* @requires os.maxMemory > 2G
* @requires os.family != "aix"
* @library /test/lib
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UseZGC -XX:-ZGenerational -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
*/
/**
* @test id=Epsilon
* @summary tests AlwaysPreTouch
* @requires vm.gc.Epsilon
* @requires os.maxMemory > 2G
* @requires os.family != "aix"
* @library /test/lib
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xmx512m -Xms512m -XX:+AlwaysPreTouch gc.TestAlwaysPreTouchBehavior
*/
import jdk.test.lib.Asserts;
import jdk.test.whitebox.WhiteBox;
public class TestAlwaysPreTouchBehavior {
public static void main(String [] args) {
long rss = WhiteBox.getWhiteBox().rss();
System.out.println("RSS: " + rss);
if (rss == 0) {
System.out.println("cannot get RSS, just skip");
return; // Did not get available RSS, just ignore this test.
}
Runtime runtime = Runtime.getRuntime();
long committedMemory = runtime.totalMemory();
Asserts.assertGreaterThan(rss, committedMemory, "RSS of this process(" + rss + "b) should be bigger than or equal to committed heap mem(" + committedMemory + "b)");
}
}

View File

@ -1,79 +0,0 @@
/*
* Copyright (c) 2014, 2024, Alibaba Group Holding Limited. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package gc.parallel;
/**
* @test TestAlwaysPreTouchBehavior
* @summary Tests AlwaysPreTouch Bahavior, pages of java heap should be pretouched with AlwaysPreTouch enabled. This test reads RSS of test process, which should be bigger than heap size(1g) with AlwaysPreTouch enabled.
* @requires vm.gc.Parallel
* @requires vm.debug != true
* @requires os.family == "linux"
* @requires os.maxMemory > 2G
* @library /test/lib
* @run main/othervm -Xmx1g -Xms1g -XX:+UseParallelGC -XX:+AlwaysPreTouch -XX:+UnlockDiagnosticVMOptions -XX:-UseMadvPopulateWrite gc.parallel.TestAlwaysPreTouchBehavior
*/
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.IOException;
import java.util.*;
import javax.management.*;
import java.lang.management.*;
import jdk.test.lib.Utils;
import jdk.test.lib.Asserts;
import java.lang.management.*;
import java.util.stream.*;
import java.io.*;
public class TestAlwaysPreTouchBehavior {
public static long getProcessRssInKb() throws IOException {
String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
// Read RSS from /proc/$pid/status. Only available on Linux.
String processStatusFile = "/proc/" + pid + "/status";
BufferedReader reader = new BufferedReader(new FileReader(processStatusFile));
String line = null;
while ((line = reader.readLine()) != null) {
if (line.startsWith("VmRSS:")) {
break;
}
}
reader.close();
return Long.valueOf(line.split("\\s+")[1].trim());
}
public static void main(String [] args) {
long rss = 0;
Runtime runtime = Runtime.getRuntime();
long committedMemory = runtime.totalMemory() / 1024; // in kb
try {
rss = getProcessRssInKb();
} catch (Exception e) {
System.out.println("cannot get RSS, just skip");
return; // Did not get avaiable RSS, just ignore this test
}
Asserts.assertGreaterThanOrEqual(rss, committedMemory, "RSS of this process(" + rss + "kb) should be bigger than or equal to committed heap mem(" + committedMemory + "kb)");
}
}

View File

@ -798,4 +798,5 @@ public class WhiteBox {
public native boolean setVirtualThreadsNotifyJvmtiMode(boolean enabled);
public native void preTouchMemory(long addr, long size);
public native long rss();
}