Skip to content

Commit

Permalink
8209595: MonitorVmStartTerminate.java timed out
Browse files Browse the repository at this point in the history
Backport-of: a045258ae2eb02daa17a9a9799a666f42daa7e20
  • Loading branch information
Amos Shi authored and GoeLin committed Jan 30, 2024
1 parent 3a0c820 commit 80b00ca
Showing 1 changed file with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static void main(String... args) throws Exception {
System.out.println("Waiting for all processes to get started notification");
listener.started.acquire(PROCESS_COUNT);

System.out.println("Terminating all processes");
for (JavaProcess javaProcess : javaProcesses) {
javaProcess.terminate();
}
Expand Down Expand Up @@ -138,7 +139,7 @@ public void disconnected(HostEvent arg0) {
}

private void releaseStarted(Set<Integer> ids) {
System.out.println("realeaseStarted(" + ids + ")");
System.out.println("releaseStarted(" + ids + ")");
for (Integer id : ids) {
releaseStarted(id);
}
Expand All @@ -149,11 +150,12 @@ private void releaseStarted(Integer id) {
if (hasMainArgs(id, jp.getMainArgsIdentifier())) {
// store id for terminated identification
jp.setId(id);
System.out.println("RELEASED (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
System.out.println("RELEASED started (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
started.release();
return;
}
}
System.out.println("releaseStarted: not a test pid: " + id);
}

private void releaseTerminated(Set<Integer> ids) {
Expand All @@ -166,23 +168,44 @@ private void releaseTerminated(Set<Integer> ids) {
private void releaseTerminated(Integer id) {
for (JavaProcess jp : processes) {
if (id.equals(jp.getId())) {
System.out.println("RELEASED (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
System.out.println("RELEASED terminated (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
terminated.release();
return;
}
}
}

private static final int ARGS_ATTEMPTS = 3;

private boolean hasMainArgs(Integer id, String args) {
VmIdentifier vmid = null;
try {
VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
MonitoredVm target = host.getMonitoredVm(vmid);
String monitoredArgs = MonitoredVmUtil.mainArgs(target);
if (monitoredArgs != null && monitoredArgs.contains(args)) {
return true;
vmid = new VmIdentifier("//" + id.intValue());
} catch (URISyntaxException e) {
System.out.println("hasMainArgs(" + id + "): " + e);
return false;
}
// Retry a failing attempt to check arguments for a match,
// as not recognizing a test process will cause timeout and failure.
for (int i = 0; i < ARGS_ATTEMPTS; i++) {
try {
MonitoredVm target = host.getMonitoredVm(vmid);
String monitoredArgs = MonitoredVmUtil.mainArgs(target);
System.out.println("hasMainArgs(" + id + "): has main args: '" + monitoredArgs + "'");
if (monitoredArgs == null || monitoredArgs.equals("Unknown")) {
System.out.println("hasMainArgs(" + id + "): retry" );
takeNap();
continue;
} else if (monitoredArgs.contains(args)) {
return true;
} else {
return false;
}
} catch (MonitorException e) {
// Process probably not running or not ours, e.g.
// sun.jvmstat.monitor.MonitorException: Could not attach to PID
System.out.println("hasMainArgs(" + id + "): " + e);
}
} catch (URISyntaxException | MonitorException e) {
// ok. process probably not running
}
return false;
}
Expand Down Expand Up @@ -247,14 +270,6 @@ private static void waitForRemoval(Path path) {
}
}

private static void takeNap() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// ignore
}
}

private final String mainArgsIdentifier;
private final ShutdownHook shutdownHook;
private volatile Integer id;
Expand Down Expand Up @@ -323,4 +338,12 @@ public String getMainArgsIdentifier() {
return mainArgsIdentifier;
}
}

public static void takeNap() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// ignore
}
}
}

1 comment on commit 80b00ca

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.