Skip to content

Commit 80b00ca

Browse files
Amos ShiGoeLin
Amos Shi
authored andcommitted
8209595: MonitorVmStartTerminate.java timed out
Backport-of: a045258ae2eb02daa17a9a9799a666f42daa7e20
1 parent 3a0c820 commit 80b00ca

File tree

1 file changed

+41
-18
lines changed

1 file changed

+41
-18
lines changed

test/jdk/sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.java

+41-18
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public static void main(String... args) throws Exception {
9898
System.out.println("Waiting for all processes to get started notification");
9999
listener.started.acquire(PROCESS_COUNT);
100100

101+
System.out.println("Terminating all processes");
101102
for (JavaProcess javaProcess : javaProcesses) {
102103
javaProcess.terminate();
103104
}
@@ -138,7 +139,7 @@ public void disconnected(HostEvent arg0) {
138139
}
139140

140141
private void releaseStarted(Set<Integer> ids) {
141-
System.out.println("realeaseStarted(" + ids + ")");
142+
System.out.println("releaseStarted(" + ids + ")");
142143
for (Integer id : ids) {
143144
releaseStarted(id);
144145
}
@@ -149,11 +150,12 @@ private void releaseStarted(Integer id) {
149150
if (hasMainArgs(id, jp.getMainArgsIdentifier())) {
150151
// store id for terminated identification
151152
jp.setId(id);
152-
System.out.println("RELEASED (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
153+
System.out.println("RELEASED started (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
153154
started.release();
154155
return;
155156
}
156157
}
158+
System.out.println("releaseStarted: not a test pid: " + id);
157159
}
158160

159161
private void releaseTerminated(Set<Integer> ids) {
@@ -166,23 +168,44 @@ private void releaseTerminated(Set<Integer> ids) {
166168
private void releaseTerminated(Integer id) {
167169
for (JavaProcess jp : processes) {
168170
if (id.equals(jp.getId())) {
169-
System.out.println("RELEASED (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
171+
System.out.println("RELEASED terminated (id=" + jp.getId() + ", args=" + jp.getMainArgsIdentifier() + ")");
170172
terminated.release();
171173
return;
172174
}
173175
}
174176
}
175177

178+
private static final int ARGS_ATTEMPTS = 3;
179+
176180
private boolean hasMainArgs(Integer id, String args) {
181+
VmIdentifier vmid = null;
177182
try {
178-
VmIdentifier vmid = new VmIdentifier("//" + id.intValue());
179-
MonitoredVm target = host.getMonitoredVm(vmid);
180-
String monitoredArgs = MonitoredVmUtil.mainArgs(target);
181-
if (monitoredArgs != null && monitoredArgs.contains(args)) {
182-
return true;
183+
vmid = new VmIdentifier("//" + id.intValue());
184+
} catch (URISyntaxException e) {
185+
System.out.println("hasMainArgs(" + id + "): " + e);
186+
return false;
187+
}
188+
// Retry a failing attempt to check arguments for a match,
189+
// as not recognizing a test process will cause timeout and failure.
190+
for (int i = 0; i < ARGS_ATTEMPTS; i++) {
191+
try {
192+
MonitoredVm target = host.getMonitoredVm(vmid);
193+
String monitoredArgs = MonitoredVmUtil.mainArgs(target);
194+
System.out.println("hasMainArgs(" + id + "): has main args: '" + monitoredArgs + "'");
195+
if (monitoredArgs == null || monitoredArgs.equals("Unknown")) {
196+
System.out.println("hasMainArgs(" + id + "): retry" );
197+
takeNap();
198+
continue;
199+
} else if (monitoredArgs.contains(args)) {
200+
return true;
201+
} else {
202+
return false;
203+
}
204+
} catch (MonitorException e) {
205+
// Process probably not running or not ours, e.g.
206+
// sun.jvmstat.monitor.MonitorException: Could not attach to PID
207+
System.out.println("hasMainArgs(" + id + "): " + e);
183208
}
184-
} catch (URISyntaxException | MonitorException e) {
185-
// ok. process probably not running
186209
}
187210
return false;
188211
}
@@ -247,14 +270,6 @@ private static void waitForRemoval(Path path) {
247270
}
248271
}
249272

250-
private static void takeNap() {
251-
try {
252-
Thread.sleep(100);
253-
} catch (InterruptedException e) {
254-
// ignore
255-
}
256-
}
257-
258273
private final String mainArgsIdentifier;
259274
private final ShutdownHook shutdownHook;
260275
private volatile Integer id;
@@ -323,4 +338,12 @@ public String getMainArgsIdentifier() {
323338
return mainArgsIdentifier;
324339
}
325340
}
341+
342+
public static void takeNap() {
343+
try {
344+
Thread.sleep(1000);
345+
} catch (InterruptedException e) {
346+
// ignore
347+
}
348+
}
326349
}

0 commit comments

Comments
 (0)