Skip to content

Commit 57fc8e9

Browse files
author
Alex Menkov
committed
8262080: vmTestbase/nsk/jdi/Event/request/request001/TestDescription.java failed with "ERROR: new event is not ThreadStartEvent"
Reviewed-by: cjplummer, sspitsyn
1 parent 0b5216a commit 57fc8e9

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

test/hotspot/jtreg/vmTestbase/nsk/jdi/Event/request/request001.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2021, 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
@@ -355,7 +355,7 @@ private void testRun()
355355
vm.resume();
356356

357357
log2("......waiting for ThreadStartEvent");
358-
getEventSet();
358+
getEventSetForThreadStartDeath("thread2");
359359
eventSets[10] = eventSet;
360360

361361
Event receivedEvent = eventIterator.nextEvent();
@@ -370,7 +370,7 @@ private void testRun()
370370
vm.resume();
371371

372372
log2("......waiting for ThreadDeathEvent");
373-
getEventSet();
373+
getEventSetForThreadStartDeath("thread2");
374374
eventSets[9] = eventSet;
375375
receivedEvent = eventIterator.nextEvent();
376376
if ( !(receivedEvent instanceof ThreadDeathEvent) ) {

test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIBase.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2021, 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
@@ -34,6 +34,8 @@
3434
import com.sun.jdi.event.EventIterator;
3535
import com.sun.jdi.event.EventQueue;
3636
import com.sun.jdi.event.EventSet;
37+
import com.sun.jdi.event.ThreadDeathEvent;
38+
import com.sun.jdi.event.ThreadStartEvent;
3739
import com.sun.jdi.request.BreakpointRequest;
3840
import com.sun.jdi.request.EventRequest;
3941
import com.sun.jdi.request.EventRequestManager;
@@ -150,6 +152,37 @@ protected final void getEventSet() throws JDITestRuntimeException {
150152
}
151153
}
152154

155+
// Special version of getEventSet for ThreadStartEvent/ThreadDeathEvent.
156+
// When ThreadStartRequest and/or ThreadDeathRequest are enabled,
157+
// we can get the events from system threads unexpected for tests.
158+
// The method skips ThreadStartEvent/ThreadDeathEvent events
159+
// for all threads except the expected one.
160+
protected void getEventSetForThreadStartDeath(String threadName) throws JDITestRuntimeException {
161+
boolean gotDesiredEvent = false;
162+
while (!gotDesiredEvent) {
163+
getEventSet();
164+
Event event = eventIterator.nextEvent();
165+
if (event instanceof ThreadStartEvent evt) {
166+
if (evt.thread().name().equals(threadName)) {
167+
gotDesiredEvent = true;
168+
} else {
169+
log2("Got ThreadStartEvent for wrong thread: " + event);
170+
}
171+
} else if (event instanceof ThreadDeathEvent evt) {
172+
if (evt.thread().name().equals(threadName)) {
173+
gotDesiredEvent = true;
174+
} else {
175+
log2("Got ThreadDeathEvent for wrong thread: " + event);
176+
}
177+
} else {
178+
// not ThreadStartEvent nor ThreadDeathEvent
179+
gotDesiredEvent = true;
180+
}
181+
}
182+
// reset the iterator before return
183+
eventIterator = eventSet.eventIterator();
184+
}
185+
153186
protected void breakpointForCommunication() throws JDITestRuntimeException {
154187

155188
log2("breakpointForCommunication");

0 commit comments

Comments
 (0)