Skip to content
Permalink
Browse files
8262080: vmTestbase/nsk/jdi/Event/request/request001/TestDescription.…
…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 57fc8e9b35d714396caaa009a6e9560a6827af1c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
@@ -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
@@ -355,7 +355,7 @@ private void testRun()
vm.resume();

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

Event receivedEvent = eventIterator.nextEvent();
@@ -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) ) {
@@ -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
@@ -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;
@@ -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");

0 comments on commit 57fc8e9

Please sign in to comment.