8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads
authorsla
Tue, 15 Oct 2013 12:53:54 +0200
changeset 21355 c53a16ac1969
parent 21354 fc38b5f28a90
child 21356 ad2735d41496
8009681: TEST_BUG: MethodExitReturnValuesTest.java may fail when there are unexpected background threads Reviewed-by: sla, allwin Contributed-by: mikael.auno@oracle.com
jdk/test/com/sun/jdi/MethodEntryExitEvents.java
jdk/test/com/sun/jdi/MethodExitReturnValuesTest.java
--- a/jdk/test/com/sun/jdi/MethodEntryExitEvents.java	Wed Oct 23 22:30:35 2013 -0700
+++ b/jdk/test/com/sun/jdi/MethodEntryExitEvents.java	Tue Oct 15 12:53:54 2013 +0200
@@ -108,14 +108,11 @@
     final int expectedExitCount = 1 + (15 * 3);
     int methodExitCount = 0;
 
-    /*
-     * Class patterns for which we don't want events (copied
-     * from the "Trace.java" example):
-     *     http://java.sun.com/javase/technologies/core/toolsapis/jpda/
-     */
-    private String[] excludes = {"java.*", "javax.*", "sun.*",
-                                 "com.sun.*", "com.oracle.*",
-                                 "oracle.*", "jdk.internal.*"};
+    // Classes which we are interested in
+    private List includes = Arrays.asList(new String[] {
+        "MethodEntryExitEventsDebugee",
+        "t2"
+    });
 
     MethodEntryExitEvents (String args[]) {
         super(args);
@@ -161,6 +158,10 @@
         str.disable();
     }
     public void methodEntered(MethodEntryEvent event) {
+        if (!includes.contains(event.method().declaringType().name())) {
+            return;
+        }
+
         if (! finishedCounting) {
             // We have to count the entry to loopComplete, but
             // not the exit
@@ -176,6 +177,10 @@
     }
 
     public void methodExited(MethodExitEvent event) {
+        if (!includes.contains(event.method().declaringType().name())) {
+            return;
+        }
+
         if (! finishedCounting){
             methodExitCount++;
             System.out.print  (" Method exit  number: ");
@@ -214,6 +219,10 @@
         connect((String[]) argList.toArray(args2));
         waitForVMStart();
 
+        // Determine main thread
+        ClassPrepareEvent e = resumeToPrepareOf("MethodEntryExitEventsDebugee");
+        mainThread = e.thread();
+
         try {
 
             /*
@@ -223,6 +232,7 @@
                 eventRequestManager().createExceptionRequest(null, // refType (null == all instances)
                                                              true, // notifyCaught
                                                              true);// notifyUncaught
+            exceptionRequest.addThreadFilter(mainThread);
             exceptionRequest.setSuspendPolicy(EventRequest.SUSPEND_ALL);
             exceptionRequest.enable();
 
@@ -231,9 +241,7 @@
              */
             MethodEntryRequest entryRequest =
                eventRequestManager().createMethodEntryRequest();
-            for (int i=0; i<excludes.length; ++i) {
-                entryRequest.addClassExclusionFilter(excludes[i]);
-            }
+            entryRequest.addThreadFilter(mainThread);
             entryRequest.setSuspendPolicy(sessionSuspendPolicy);
             entryRequest.enable();
 
@@ -242,10 +250,7 @@
              */
             MethodExitRequest exitRequest =
                 eventRequestManager().createMethodExitRequest();
-
-            for (int i=0; i<excludes.length; ++i) {
-                exitRequest.addClassExclusionFilter(excludes[i]);
-            }
+            exitRequest.addThreadFilter(mainThread);
             exitRequest.setSuspendPolicy(sessionSuspendPolicy);
             exitRequest.enable();
 
--- a/jdk/test/com/sun/jdi/MethodExitReturnValuesTest.java	Wed Oct 23 22:30:35 2013 -0700
+++ b/jdk/test/com/sun/jdi/MethodExitReturnValuesTest.java	Tue Oct 15 12:53:54 2013 +0200
@@ -209,18 +209,13 @@
 
 
 public class MethodExitReturnValuesTest extends TestScaffold {
-
-    /*
-     * Class patterns for which we don't want events (copied
-     * from the "Trace.java" example):
-     *     http://java.sun.com/javase/technologies/core/toolsapis/jpda/
-     */
-    private String[] excludes = {
-        "javax.*",
-        "sun.*",
-        "com.sun.*",
-        "com.oracle.*",
-        "oracle.*"};
+    // Classes which we are interested in
+    private List includes = Arrays.asList(new String[] {
+        "MethodExitReturnValuesTarg",
+        "java.lang.reflect.Array",
+        "java.lang.StrictMath",
+        "java.lang.String"
+    });
 
     static VirtualMachineManager vmm ;
     ClassType targetClass;
@@ -487,6 +482,11 @@
     // This is the MethodExitEvent handler.
     public void methodExited(MethodExitEvent event) {
         String origMethodName = event.method().name();
+
+        if (!includes.contains(event.method().declaringType().name())) {
+            return;
+        }
+
         if (vmm.majorInterfaceVersion() >= 1 &&
             vmm.minorInterfaceVersion() >= 6 &&
             vm().canGetMethodReturnValues()) {
@@ -560,10 +560,8 @@
          */
         MethodExitRequest exitRequest =
             eventRequestManager().createMethodExitRequest();
+        exitRequest.addThreadFilter(mainThread);
 
-        for (int i=0; i<excludes.length; ++i) {
-            exitRequest.addClassExclusionFilter(excludes[i]);
-        }
         int sessionSuspendPolicy = EventRequest.SUSPEND_ALL;
         //sessionSuspendPolicy = EventRequest.SUSPEND_EVENT_THREAD;
         //sessionSuspendPolicy = EventRequest.SUSPEND_NONE;