changeset 51173:6c62929bd870

8204695: [Graal] vmTestbase/nsk/jdi/ClassPrepareRequest/addSourceNameFilter/addSourceNameFilter002/addSourceNameFilter002.java fails Reviewed-by: sspitsyn, cjplummer
author dtitov
date Thu, 19 Jul 2018 16:53:33 -0700
parents e443c637b238
children bee24106cfc0
files test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassPrepareRequest/addSourceNameFilter/addSourceNameFilter002/addSourceNameFilter002.java
diffstat 1 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassPrepareRequest/addSourceNameFilter/addSourceNameFilter002/addSourceNameFilter002.java	Thu Jul 19 15:13:10 2018 -0700
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/ClassPrepareRequest/addSourceNameFilter/addSourceNameFilter002/addSourceNameFilter002.java	Thu Jul 19 16:53:33 2018 -0700
@@ -70,6 +70,7 @@
 import java.io.*;
 import java.util.ArrayList;
 
+import com.sun.jdi.ThreadReference;
 import com.sun.jdi.event.*;
 import com.sun.jdi.request.*;
 import nsk.share.Consts;
@@ -79,6 +80,9 @@
 import nsk.share.jpda.AbstractDebuggeeTest;
 
 public class addSourceNameFilter002 extends SDEDebugger {
+
+    private static final String DEBUGGEE_MAIN_THREAD = "main";
+
     public static void main(String argv[]) {
         System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);
     }
@@ -87,6 +91,8 @@
         return new addSourceNameFilter002().runIt(argv, out);
     }
 
+    private static volatile int eventReceived;
+
     protected boolean canRunTest() {
         if (!vm.canUseSourceNameFilters()) {
             log.display("TEST CANCELLED due to:  vm.canUseSourceNameFilters() = false");
@@ -124,14 +130,17 @@
 
     // listener counting ClassPrepareEvent
     public class ClassPrepareEventListener extends EventHandler.EventListener {
-        public int eventReceived;
 
         public boolean eventReceived(Event event) {
             if (event instanceof ClassPrepareEvent) {
                 ClassPrepareEvent classPrepareEvent = (ClassPrepareEvent) event;
-                eventReceived++;
+                ThreadReference thread = classPrepareEvent.thread();
+                if (thread != null && DEBUGGEE_MAIN_THREAD.equals(thread.name())) {
+                    eventReceived++;
+                }
 
-                log.display("Event received: " + event + " Class: " + classPrepareEvent.referenceType().name());
+                log.display("Event received: " + event + " Class: " + classPrepareEvent.referenceType().name() +
+                        " Thread:" + (thread != null ? thread.name() : ""));
 
                 vm.resume();
 
@@ -153,12 +162,8 @@
         request.addSourceNameFilter(sourceName);
         request.enable();
 
-        // this listener wait ClassPrepareEvent
-        ClassPrepareEventListener listener = new ClassPrepareEventListener();
-        eventHandler.addListener(listener);
-
-        log.display("Load class: " + className + ", use follows source filter: " + sourceName);
-
+        // Reset event counter
+        eventReceived = 0;
         // force debuggee load class
         pipe.println(AbstractDebuggeeTest.COMMAND_LOAD_CLASS + ":" + className);
 
@@ -167,16 +172,14 @@
 
         request.disable();
 
-        eventHandler.removeListener(listener);
-
         // check is event was correct filtered or not
         if (expectEvent) {
-            if (listener.eventReceived == 0) {
+            if (eventReceived == 0) {
                 setSuccess(false);
                 log.complain("Expected ClassPrepareEvent was not received");
             }
         } else {
-            if (listener.eventReceived > 0) {
+            if (eventReceived > 0) {
                 setSuccess(false);
                 log.complain("Unexpected ClassPrepareEvent was received");
             }
@@ -217,6 +220,11 @@
         eventHandler = new EventHandler(debuggee, log);
         eventHandler.startListening();
 
+        // Add a listener to count ClassPrepare events.
+        // The listener should be added after EventHandler.startListening()
+        // is called to ensure it will be the first to process events.
+        eventHandler.addListener(new ClassPrepareEventListener());
+
         // set valid source name
         testSourceFilter(className, sourceName, true);
         for (int i = 0; i < testStratumSourceNames.length; i++) {