test/com/sun/jdi/NativeInstanceFilter.java

Print this page

        

@@ -55,10 +55,11 @@
         super();
     }
 
     static EventRequestManager requestManager = null;
     static MethodExitRequest request = null;
+    static ThreadReference mainThread = null;
 
     private void listen() {
         TargetAdapter adapter = new TargetAdapter() {
             EventSet set = null;
             ObjectReference instance = null;

@@ -75,10 +76,11 @@
                     System.out.println("Setting up instance filter");
                     instance = (ObjectReference)event.returnValue();
                     requestManager.deleteEventRequest(request);
                     request = requestManager.createMethodExitRequest();
                     request.addInstanceFilter(instance);
+                    request.addThreadFilter(mainThread);
                     request.enable();
                 } else if (instance != null && name.equals("intern")) {
                     // If not for the filter, this will be called twice
                     System.out.println("method exit event (String.intern())");
                     ++unfilteredEvents;

@@ -99,14 +101,16 @@
         connect(args);
         waitForVMStart();
 
         // VM has started, but hasn't started running the test program yet.
         requestManager = vm().eventRequestManager();
-        ReferenceType referenceType =
-            resumeToPrepareOf("NativeInstanceFilterTarg").referenceType();
+        ClassPrepareEvent e = resumeToPrepareOf("NativeInstanceFilterTarg");
+        ReferenceType referenceType = e.referenceType();
+        mainThread = e.thread();
 
         request = requestManager.createMethodExitRequest();
+        request.addThreadFilter(mainThread);
         request.enable();
 
         listen();
 
         vm().resume();