Skip to content

Commit 6a2ed7c

Browse files
Taizo KurashigePaul Hohensee
authored andcommitted
8355249: Remove the use of WMIC from the entire source code
Reviewed-by: asemenyuk, phh Backport-of: 4458719a108f45d3744d47a6ea081fe9ec3e675e
1 parent c90978b commit 6a2ed7c

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

make/RunTestsPrebuilt.gmk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ else ifeq ($(OPENJDK_TARGET_OS), macosx)
216216
else ifeq ($(OPENJDK_TARGET_OS), windows)
217217
NUM_CORES := $(NUMBER_OF_PROCESSORS)
218218
MEMORY_SIZE := $(shell \
219-
$(EXPR) `wmic computersystem get totalphysicalmemory -value \
220-
| $(GREP) = | $(SED) 's/\\r//g' \
221-
| $(CUT) -d "=" -f 2-` / 1024 / 1024 \
219+
$(EXPR) `powershell -Command \
220+
"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory" \
221+
| $(SED) 's/\\r//g' ` / 1024 / 1024 \
222222
)
223223
endif
224224
ifeq ($(NUM_CORES), )

make/autoconf/build-performance.m4

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -85,7 +85,8 @@ AC_DEFUN([BPERF_CHECK_MEMORY_SIZE],
8585
FOUND_MEM=yes
8686
elif test "x$OPENJDK_BUILD_OS" = xwindows; then
8787
# Windows, but without cygwin
88-
MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-`
88+
MEMORY_SIZE=`powershell -Command \
89+
"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory" | $SED 's/\\r//g' `
8990
MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
9091
FOUND_MEM=yes
9192
fi

test/failure_handler/src/share/conf/windows.properties

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -22,10 +22,10 @@
2222
#
2323

2424
config.execSuffix=.exe
25-
config.getChildren.app=bash
25+
config.getChildren.app=powershell
2626
config.getChildren.pattern=%p
27-
config.getChildren.args=-c\0wmic process where ParentProcessId=%p get ProcessId | tail -n+2
2827
config.getChildren.args.delimiter=\0
28+
config.getChildren.args=-NoLogo\0-Command\0"Get-CimInstance Win32_Process -Filter \\\"ParentProcessId = %p\\\" | Select-Object ProcessId" | tail -n+4
2929
################################################################################
3030
# process info to gather
3131
################################################################################
@@ -39,8 +39,9 @@ native.pattern=%p
3939
native.javaOnly=false
4040
native.args=%p
4141

42-
native.info.app=wmic
43-
native.info.args=process where processId=%p list full
42+
native.info.app=powershell
43+
native.info.delimiter=\0
44+
native.info.args=-NoLogo\0-Command\0"Get-WmiObject Win32_Process -Filter \\\"ProcessId = %p\\\" | Format-List -Property *"
4445

4546
native.pmap.app=pmap
4647
native.pmap.normal.args=%p
@@ -96,8 +97,9 @@ system.events.delimiter=\0
9697
system.events.system.args=-NoLogo\0-Command\0Get-EventLog System -After (Get-Date).AddDays(-1) | Format-List
9798
system.events.application.args=-NoLogo\0-Command\0Get-EventLog Application -After (Get-Date).AddDays(-1) | Format-List
9899

99-
system.os.app=wmic
100-
system.os.args=os get /format:list
100+
system.os.app=powershell
101+
system.os.delimiter=\0
102+
system.os.args=-NoLogo\0-Command\0Get-WmiObject Win32_OperatingSystem | Format-List -Property *
101103

102104
process.top.app=top
103105
process.top.args=-b -n 1

test/jdk/tools/jpackage/windows/Win8301247Test.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.IOException;
2525
import java.time.Duration;
2626
import java.util.List;
27-
import java.util.NoSuchElementException;
2827
import java.util.Objects;
2928
import java.util.Optional;
3029
import java.util.concurrent.ExecutorService;
@@ -100,40 +99,36 @@ public void test() throws IOException, InterruptedException {
10099

101100
private static Optional<Long> findMainAppLauncherPID(JPackageCommand cmd,
102101
int expectedCount) {
103-
// Get the list of PIDs and PPIDs of app launcher processes.
104-
// wmic process where (name = "foo.exe") get ProcessID,ParentProcessID
105-
List<String> output = Executor.of("wmic", "process", "where", "(name",
106-
"=",
107-
"\"" + cmd.appLauncherPath().getFileName().toString() + "\"",
108-
")", "get", "ProcessID,ParentProcessID").dumpOutput(true).
109-
saveOutput().executeAndGetOutput();
110-
111-
if (output.isEmpty()) {
112-
throw new NoSuchElementException();
113-
}
114-
String first = output.get(0);
102+
// Get the list of PIDs and PPIDs of app launcher processes. Run setWinRunWithEnglishOutput(true) for JDK-8344275.
103+
// powershell -NoLogo -NoProfile -NonInteractive -Command
104+
// "Get-CimInstance Win32_Process -Filter \"Name = 'foo.exe'\" | select ProcessID,ParentProcessID"
105+
String command = "Get-CimInstance Win32_Process -Filter \\\"Name = '"
106+
+ cmd.appLauncherPath().getFileName().toString()
107+
+ "'\\\" | select ProcessID,ParentProcessID";
108+
List<String> output = Executor.of("powershell", "-NoLogo", "-NoProfile", "-NonInteractive", "-Command", command)
109+
.dumpOutput(true).saveOutput().executeAndGetOutput();
115110

116111
if (expectedCount == 0) {
117-
TKit.assertEquals("No Instance(s) Available.", first.
118-
trim(), "Check no app launcher processes found running");
119-
return Optional.empty();
112+
if (output.size() < 1) {
113+
return Optional.empty();
114+
}
120115
}
121116

122-
String[] headers = Stream.of(first.split("\\s+", 2)).map(
117+
String[] headers = Stream.of(output.get(1).split("\\s+", 2)).map(
123118
String::trim).map(String::toLowerCase).toArray(String[]::new);
124119
Pattern pattern;
125120
if (headers[0].equals("parentprocessid") && headers[1].equals(
126121
"processid")) {
127-
pattern = Pattern.compile("^(?<ppid>\\d+)\\s+(?<pid>\\d+)\\s+$");
122+
pattern = Pattern.compile("^\\s+(?<ppid>\\d+)\\s+(?<pid>\\d+)$");
128123
} else if (headers[1].equals("parentprocessid") && headers[0].equals(
129124
"processid")) {
130-
pattern = Pattern.compile("^(?<pid>\\d+)\\s+(?<ppid>\\d+)\\s+$");
125+
pattern = Pattern.compile("^\\s+(?<pid>\\d+)\\s+(?<ppid>\\d+)$");
131126
} else {
132127
throw new RuntimeException(
133-
"Unrecognizable output of \'wmic process\' command");
128+
"Unrecognizable output of \'Get-CimInstance Win32_Process\' command");
134129
}
135130

136-
List<long[]> processes = output.stream().skip(1).map(line -> {
131+
List<long[]> processes = output.stream().skip(3).map(line -> {
137132
Matcher m = pattern.matcher(line);
138133
long[] pids = null;
139134
if (m.matches()) {

0 commit comments

Comments
 (0)