< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jdi/ArrayType/newInstance/newinstance002.java

Print this page

        

@@ -144,12 +144,26 @@
     //------------------------------------------------------  testing section
         log1("      TESTING BEGINS");
 
         for (int i = 0; ; i++) {
         pipe.println("newcheck");
+
+            // There are potentially other non-test Java threads allocating objects and triggering
+            // GC's so we need to suspend the target VM to avoid the objects created in the test
+            // from being accidentally GC'ed. However, we need the target VM temporary resumed
+            // while reading its response. Below we resume the target VM (if required) and suspend
+            // it only after pipe.readln() returns.
+
+            // On the first iteration the target VM is not suspended yet.
+            if (i > 0) {
+                debuggee.resume();
+            }
             line = pipe.readln();
 
+            // Suspending target VM to prevent other non-test Java threads from triggering GCs.
+            debuggee.suspend();
+
             if (line.equals("checkend")) {
                 log2("     : returned string is 'checkend'");
                 break ;
             } else if (!line.equals("checkready")) {
                 log3("ERROR: returned string is not 'checkready'");

@@ -230,10 +244,11 @@
         log1("      TESTING ENDS");
 
     //--------------------------------------------------   test summary section
     //-------------------------------------------------    standard end section
 
+        debuggee.resume();
         pipe.println("quit");
         log2("waiting for the debuggee to finish ...");
         debuggee.waitFor();
 
         int status = debuggee.getStatus();
< prev index next >