Skip to content

Commit

Permalink
8262080: vmTestbase/nsk/jdi/Event/request/request001/TestDescription.…
Browse files Browse the repository at this point in the history
…java failed with "ERROR: new event is not ThreadStartEvent"

Reviewed-by: cjplummer, sspitsyn
  • Loading branch information
Alex Menkov committed Mar 19, 2021
1 parent 0b5216a commit 57fc8e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -355,7 +355,7 @@ private void testRun()
vm.resume();

log2("......waiting for ThreadStartEvent");
getEventSet();
getEventSetForThreadStartDeath("thread2");
eventSets[10] = eventSet;

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

log2("......waiting for ThreadDeathEvent");
getEventSet();
getEventSetForThreadStartDeath("thread2");
eventSets[9] = eventSet;
receivedEvent = eventIterator.nextEvent();
if ( !(receivedEvent instanceof ThreadDeathEvent) ) {
Expand Down
35 changes: 34 additions & 1 deletion test/hotspot/jtreg/vmTestbase/nsk/share/jdi/JDIBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -34,6 +34,8 @@
import com.sun.jdi.event.EventIterator;
import com.sun.jdi.event.EventQueue;
import com.sun.jdi.event.EventSet;
import com.sun.jdi.event.ThreadDeathEvent;
import com.sun.jdi.event.ThreadStartEvent;
import com.sun.jdi.request.BreakpointRequest;
import com.sun.jdi.request.EventRequest;
import com.sun.jdi.request.EventRequestManager;
Expand Down Expand Up @@ -150,6 +152,37 @@ protected final void getEventSet() throws JDITestRuntimeException {
}
}

// Special version of getEventSet for ThreadStartEvent/ThreadDeathEvent.
// When ThreadStartRequest and/or ThreadDeathRequest are enabled,
// we can get the events from system threads unexpected for tests.
// The method skips ThreadStartEvent/ThreadDeathEvent events
// for all threads except the expected one.
protected void getEventSetForThreadStartDeath(String threadName) throws JDITestRuntimeException {
boolean gotDesiredEvent = false;
while (!gotDesiredEvent) {
getEventSet();
Event event = eventIterator.nextEvent();
if (event instanceof ThreadStartEvent evt) {
if (evt.thread().name().equals(threadName)) {
gotDesiredEvent = true;
} else {
log2("Got ThreadStartEvent for wrong thread: " + event);
}
} else if (event instanceof ThreadDeathEvent evt) {
if (evt.thread().name().equals(threadName)) {
gotDesiredEvent = true;
} else {
log2("Got ThreadDeathEvent for wrong thread: " + event);
}
} else {
// not ThreadStartEvent nor ThreadDeathEvent
gotDesiredEvent = true;
}
}
// reset the iterator before return
eventIterator = eventSet.eventIterator();
}

protected void breakpointForCommunication() throws JDITestRuntimeException {

log2("breakpointForCommunication");
Expand Down

1 comment on commit 57fc8e9

@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.