Skip to content

Commit 87db152

Browse files
committed
backport cf8cfec3f149cb6bb27d0d31bb1c6817feb266f6
1 parent 8bdebb0 commit 87db152

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

src/hotspot/share/prims/whitebox.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,13 @@ WB_ENTRY(jint, WB_ValidateCgroup(JNIEnv* env,
22322232
return ret;
22332233
WB_END
22342234

2235+
// Available cpus of the host machine, Linux only.
2236+
// Used in container testing.
2237+
WB_ENTRY(jint, WB_HostCPUs(JNIEnv* env, jobject o))
2238+
LINUX_ONLY(return os::Linux::active_processor_count();)
2239+
return -1; // Not used/implemented on other platforms
2240+
WB_END
2241+
22352242
WB_ENTRY(void, WB_PrintOsInfo(JNIEnv* env, jobject o))
22362243
os::print_os_info(tty);
22372244
WB_END
@@ -2610,6 +2617,7 @@ static JNINativeMethod methods[] = {
26102617
(void*)&WB_ValidateCgroup },
26112618
{CC"hostPhysicalMemory", CC"()J", (void*)&WB_HostPhysicalMemory },
26122619
{CC"hostPhysicalSwap", CC"()J", (void*)&WB_HostPhysicalSwap },
2620+
{CC"hostCPUs", CC"()I", (void*)&WB_HostCPUs },
26132621
{CC"printOsInfo", CC"()V", (void*)&WB_PrintOsInfo },
26142622
{CC"disableElfSectionCache", CC"()V", (void*)&WB_DisableElfSectionCache },
26152623
{CC"resolvedMethodItemsCount", CC"()J", (void*)&WB_ResolvedMethodItemsCount },

test/hotspot/jtreg/TEST.ROOT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ requires.properties= \
7979
vm.musl \
8080
vm.flagless \
8181
docker.support \
82+
systemd.support \
8283
jdk.containerized
8384

8485
# Minimum jtreg version

test/jdk/TEST.ROOT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ requires.properties= \
9494
vm.jvmci \
9595
vm.jvmci.enabled \
9696
docker.support \
97+
systemd.support \
9798
release.implementor \
9899
jdk.containerized
99100

test/jtreg-ext/requires/VMProps.java

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public Map<String, String> call() {
128128
map.put("vm.compiler1.enabled", this::isCompiler1Enabled);
129129
map.put("vm.compiler2.enabled", this::isCompiler2Enabled);
130130
map.put("docker.support", this::dockerSupport);
131+
map.put("systemd.support", this::systemdSupport);
131132
map.put("vm.musl", this::isMusl);
132133
map.put("release.implementor", this::implementor);
133134
map.put("jdk.containerized", this::jdkContainerized);
@@ -484,7 +485,7 @@ protected String dockerSupport() {
484485

485486
if (isSupported) {
486487
try {
487-
isSupported = checkDockerSupport();
488+
isSupported = checkProgramSupport("checkDockerSupport()", Container.ENGINE_COMMAND);
488489
} catch (Exception e) {
489490
isSupported = false;
490491
}
@@ -494,6 +495,27 @@ protected String dockerSupport() {
494495
return "" + isSupported;
495496
}
496497

498+
/**
499+
* A simple check for systemd support
500+
*
501+
* @return true if systemd is supported in a given environment
502+
*/
503+
protected String systemdSupport() {
504+
log("Entering systemdSupport()");
505+
506+
boolean isSupported = Platform.isLinux();
507+
if (isSupported) {
508+
try {
509+
isSupported = checkProgramSupport("checkSystemdSupport()", "systemd-run");
510+
} catch (Exception e) {
511+
isSupported = false;
512+
}
513+
}
514+
515+
log("systemdSupport(): returning isSupported = " + isSupported);
516+
return "" + isSupported;
517+
}
518+
497519
// Configures process builder to redirect process stdout and stderr to a file.
498520
// Returns file names for stdout and stderr.
499521
private Map<String, String> redirectOutputToLogFile(String msg, ProcessBuilder pb, String fileNameBase) {
@@ -528,17 +550,17 @@ private void printLogfileContent(Map<String, String> logFileNames) {
528550
});
529551
}
530552

531-
private boolean checkDockerSupport() throws IOException, InterruptedException {
532-
log("checkDockerSupport(): entering");
533-
ProcessBuilder pb = new ProcessBuilder("which", Container.ENGINE_COMMAND);
553+
private boolean checkProgramSupport(String logString, String cmd) throws IOException, InterruptedException {
554+
log(logString + ": entering");
555+
ProcessBuilder pb = new ProcessBuilder("which", cmd);
534556
Map<String, String> logFileNames =
535-
redirectOutputToLogFile("checkDockerSupport(): which <container-engine>",
536-
pb, "which-container");
557+
redirectOutputToLogFile(logString + ": which " + cmd,
558+
pb, "which-cmd");
537559
Process p = pb.start();
538560
p.waitFor(10, TimeUnit.SECONDS);
539561
int exitValue = p.exitValue();
540562

541-
log(String.format("checkDockerSupport(): exitValue = %s, pid = %s", exitValue, p.pid()));
563+
log(String.format("%s: exitValue = %s, pid = %s", logString, exitValue, p.pid()));
542564
if (exitValue != 0) {
543565
printLogfileContent(logFileNames);
544566
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ public native int validateCgroup(String procCgroups,
633633
public native void printOsInfo();
634634
public native long hostPhysicalMemory();
635635
public native long hostPhysicalSwap();
636+
public native int hostCPUs();
636637

637638
// Decoder
638639
public native void disableElfSectionCache();

0 commit comments

Comments
 (0)