mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-15 16:44:36 +02:00
8355249: Remove the use of WMIC from the entire source code
Reviewed-by: erikj, ihse, asemenyuk
This commit is contained in:
parent
772c97039e
commit
4458719a10
4 changed files with 30 additions and 26 deletions
|
@ -217,9 +217,9 @@ else ifeq ($(OPENJDK_TARGET_OS), macosx)
|
||||||
else ifeq ($(OPENJDK_TARGET_OS), windows)
|
else ifeq ($(OPENJDK_TARGET_OS), windows)
|
||||||
NUM_CORES := $(NUMBER_OF_PROCESSORS)
|
NUM_CORES := $(NUMBER_OF_PROCESSORS)
|
||||||
MEMORY_SIZE := $(shell \
|
MEMORY_SIZE := $(shell \
|
||||||
$(EXPR) `wmic computersystem get totalphysicalmemory -value \
|
$(EXPR) `powershell -Command \
|
||||||
| $(GREP) = | $(SED) 's/\\r//g' \
|
"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory" \
|
||||||
| $(CUT) -d "=" -f 2-` / 1024 / 1024 \
|
| $(SED) 's/\\r//g' ` / 1024 / 1024 \
|
||||||
)
|
)
|
||||||
endif
|
endif
|
||||||
ifeq ($(NUM_CORES), )
|
ifeq ($(NUM_CORES), )
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -75,7 +75,8 @@ AC_DEFUN([BPERF_CHECK_MEMORY_SIZE],
|
||||||
FOUND_MEM=yes
|
FOUND_MEM=yes
|
||||||
elif test "x$OPENJDK_BUILD_OS" = xwindows; then
|
elif test "x$OPENJDK_BUILD_OS" = xwindows; then
|
||||||
# Windows, but without cygwin
|
# Windows, but without cygwin
|
||||||
MEMORY_SIZE=`wmic computersystem get totalphysicalmemory -value | grep = | cut -d "=" -f 2-`
|
MEMORY_SIZE=`powershell -Command \
|
||||||
|
"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory" | $SED 's/\\r//g' `
|
||||||
MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
|
MEMORY_SIZE=`expr $MEMORY_SIZE / 1024 / 1024`
|
||||||
FOUND_MEM=yes
|
FOUND_MEM=yes
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
|
# Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
#
|
#
|
||||||
# This code is free software; you can redistribute it and/or modify it
|
# This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -22,10 +22,10 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
config.execSuffix=.exe
|
config.execSuffix=.exe
|
||||||
config.getChildren.app=bash
|
config.getChildren.app=powershell
|
||||||
config.getChildren.pattern=%p
|
config.getChildren.pattern=%p
|
||||||
config.getChildren.args=-c\0wmic process where ParentProcessId=%p get ProcessId | tail -n+2
|
|
||||||
config.getChildren.args.delimiter=\0
|
config.getChildren.args.delimiter=\0
|
||||||
|
config.getChildren.args=-NoLogo\0-Command\0"Get-CimInstance Win32_Process -Filter \\\"ParentProcessId = %p\\\" | Select-Object ProcessId" | tail -n+4
|
||||||
################################################################################
|
################################################################################
|
||||||
# process info to gather
|
# process info to gather
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -39,8 +39,9 @@ native.pattern=%p
|
||||||
native.javaOnly=false
|
native.javaOnly=false
|
||||||
native.args=%p
|
native.args=%p
|
||||||
|
|
||||||
native.info.app=wmic
|
native.info.app=powershell
|
||||||
native.info.args=process where processId=%p list full
|
native.info.delimiter=\0
|
||||||
|
native.info.args=-NoLogo\0-Command\0"Get-WmiObject Win32_Process -Filter \\\"ProcessId = %p\\\" | Format-List -Property *"
|
||||||
|
|
||||||
native.pmap.app=pmap
|
native.pmap.app=pmap
|
||||||
native.pmap.normal.args=%p
|
native.pmap.normal.args=%p
|
||||||
|
@ -96,8 +97,9 @@ system.events.delimiter=\0
|
||||||
system.events.system.args=-NoLogo\0-Command\0Get-EventLog System -After (Get-Date).AddDays(-1) | Format-List
|
system.events.system.args=-NoLogo\0-Command\0Get-EventLog System -After (Get-Date).AddDays(-1) | Format-List
|
||||||
system.events.application.args=-NoLogo\0-Command\0Get-EventLog Application -After (Get-Date).AddDays(-1) | Format-List
|
system.events.application.args=-NoLogo\0-Command\0Get-EventLog Application -After (Get-Date).AddDays(-1) | Format-List
|
||||||
|
|
||||||
system.os.app=wmic
|
system.os.app=powershell
|
||||||
system.os.args=os get /format:list
|
system.os.delimiter=\0
|
||||||
|
system.os.args=-NoLogo\0-Command\0Get-WmiObject Win32_OperatingSystem | Format-List -Property *
|
||||||
|
|
||||||
process.top.app=top
|
process.top.app=top
|
||||||
process.top.args=-b -n 1
|
process.top.args=-b -n 1
|
||||||
|
|
|
@ -322,32 +322,33 @@ public class WindowsHelper {
|
||||||
|
|
||||||
private static long[] findAppLauncherPIDs(JPackageCommand cmd, String launcherName) {
|
private static long[] findAppLauncherPIDs(JPackageCommand cmd, String launcherName) {
|
||||||
// Get the list of PIDs and PPIDs of app launcher processes. Run setWinRunWithEnglishOutput(true) for JDK-8344275.
|
// Get the list of PIDs and PPIDs of app launcher processes. Run setWinRunWithEnglishOutput(true) for JDK-8344275.
|
||||||
// wmic process where (name = "foo.exe") get ProcessID,ParentProcessID
|
// powershell -NoLogo -NoProfile -NonInteractive -Command
|
||||||
final var result = Executor.of("wmic", "process", "where", "(name",
|
// "Get-CimInstance Win32_Process -Filter \"Name = 'foo.exe'\" | select ProcessID,ParentProcessID"
|
||||||
"=",
|
String command = "Get-CimInstance Win32_Process -Filter \\\"Name = '"
|
||||||
"\"" + cmd.appLauncherPath(launcherName).getFileName().toString() + "\"",
|
+ cmd.appLauncherPath(launcherName).getFileName().toString()
|
||||||
")", "get", "ProcessID,ParentProcessID").dumpOutput(true).saveOutput().
|
+ "'\\\" | select ProcessID,ParentProcessID";
|
||||||
setWinRunWithEnglishOutput(true).execute();
|
List<String> output = Executor.of("powershell", "-NoLogo", "-NoProfile", "-NonInteractive", "-Command", command)
|
||||||
if ("No Instance(s) Available.".equals(result.stderr().findFirstLineOfOutput().map(String::trim).orElse(""))) {
|
.dumpOutput(true).saveOutput().setWinRunWithEnglishOutput(true).executeAndGetOutput();
|
||||||
|
|
||||||
|
if (output.size() < 1) {
|
||||||
return new long[0];
|
return new long[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
final var stdout = result.stdout();
|
String[] headers = Stream.of(output.get(1).split("\\s+", 2)).map(
|
||||||
String[] headers = Stream.of(stdout.getFirstLineOfOutput().split("\\s+", 2)).map(
|
|
||||||
String::trim).map(String::toLowerCase).toArray(String[]::new);
|
String::trim).map(String::toLowerCase).toArray(String[]::new);
|
||||||
final Pattern pattern;
|
Pattern pattern;
|
||||||
if (headers[0].equals("parentprocessid") && headers[1].equals(
|
if (headers[0].equals("parentprocessid") && headers[1].equals(
|
||||||
"processid")) {
|
"processid")) {
|
||||||
pattern = Pattern.compile("^(?<ppid>\\d+)\\s+(?<pid>\\d+)\\s+$");
|
pattern = Pattern.compile("^\\s+(?<ppid>\\d+)\\s+(?<pid>\\d+)$");
|
||||||
} else if (headers[1].equals("parentprocessid") && headers[0].equals(
|
} else if (headers[1].equals("parentprocessid") && headers[0].equals(
|
||||||
"processid")) {
|
"processid")) {
|
||||||
pattern = Pattern.compile("^(?<pid>\\d+)\\s+(?<ppid>\\d+)\\s+$");
|
pattern = Pattern.compile("^\\s+(?<pid>\\d+)\\s+(?<ppid>\\d+)$");
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Unrecognizable output of \'wmic process\' command");
|
"Unrecognizable output of \'Get-CimInstance Win32_Process\' command");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<long[]> processes = stdout.getOutput().stream().skip(1).map(line -> {
|
List<long[]> processes = output.stream().skip(3).map(line -> {
|
||||||
Matcher m = pattern.matcher(line);
|
Matcher m = pattern.matcher(line);
|
||||||
long[] pids = null;
|
long[] pids = null;
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue