< prev index next >

test/hotspot/jtreg/vmTestbase/nsk/jdi/ReferenceType/instances/instances003/instances003.java

Print this page




  24 /*
  25  * @test
  26  *
  27  * @summary converted from VM Testbase nsk/jdi/ReferenceType/instances/instances003.
  28  * VM Testbase keywords: [jpda, jdi, feature_jdk6_jpda, vm6]
  29  * VM Testbase readme:
  30  * DESCRIPTION
  31  *      The test scenario is following:
  32  *         - Debugger VM
  33  *         for refererence_type in <Strong, JNI_Local_Ref, JNI_Global_Ref, JNI_Weak_Ref, PhantomReference, SoftReference, WeakReference>
  34  *                 - initiate creation test class instances  of type 'refererence_type' in debuggee VM
  35  *                 - prevent some instances from being garbage collected using ObjectReference.disableCollection
  36  *                 - initiate GarbageCollection in Debuggee VM
  37  *                 - check the number of instances is left is correct
  38  *                 - enables Garbage Collection for instances for which it were previously disabled using ObjectReference.enableCollection
  39  *                 - initiate GarbageCollection in Debuggee VM
  40  *                 - check the number of instances is 0
  41  *         done
  42  *         Test is executed for following sublcasses of ObjectReference: StringReference, ThreadReference, ClassLoaderReference
  43  *

  44  * @library /vmTestbase
  45  *          /test/lib
  46  * @run driver jdk.test.lib.FileInstaller . .
  47  * @build nsk.jdi.ReferenceType.instances.instances003.instances003
  48  * @run main/othervm/native PropertyResolvingWrapper
  49  *      nsk.jdi.ReferenceType.instances.instances003.instances003
  50  *      -verbose
  51  *      -arch=${os.family}-${os.simpleArch}
  52  *      -waittime=5
  53  *      -debugee.vmkind=java
  54  *      -transport.address=dynamic
  55  *      "-debugee.vmkeys=-Xmx128M ${test.vm.opts} ${test.java.opts}"
  56  *      -testClassNames nsk.jdi.ReferenceType.instances.instances003.instances003$TestClassLoader:java.lang.String:java.lang.Thread
  57  */
  58 
  59 package nsk.jdi.ReferenceType.instances.instances003;
  60 
  61 import java.io.PrintStream;
  62 import java.util.*;
  63 


 107         return new instances003().runIt(argv, out);
 108     }
 109 
 110     protected String debuggeeClassName() {
 111         return nsk.share.jdi.HeapwalkingDebuggee.class.getName();
 112     }
 113 
 114     protected void testClass(String className, String referrerType) {
 115         final int createInstanceCount = 50;
 116         final int referrerCount = 1;
 117 
 118         List<ObjectReference> objectsToFilter = HeapwalkingDebugger.getObjectReferences(className, vm);
 119 
 120         // create 'createInstanceCount' instances of test class
 121 
 122         // create temporary strong references to prevent the weakly referred instances being GCed
 123         // during the time between creating them and disabling collection on them
 124         pipe.println(HeapwalkingDebuggee.COMMAND_CREATE_INSTANCES + ":" + className + ":" + createInstanceCount +
 125             ":" + referrerCount + ":" + referrerType +
 126             (referrerType.equals(ObjectInstancesManager.WEAK_REFERENCE) ? "|" + ObjectInstancesManager.STRONG_REFERENCE : ""));





 127 
 128         // the instance counts should not be affected by creating multiple references
 129         checkDebugeeAnswer_instanceCounts(className, createInstanceCount, objectsToFilter);
 130 
 131         ReferenceType referenceType = debuggee.classByName(className);
 132         List<ObjectReference> instances = HeapwalkingDebugger.filterObjectReferrence(objectsToFilter, referenceType.instances(0));
 133 
 134         for (ObjectReference or : instances) {
 135             or.disableCollection();
 136         }
 137 
 138         // remove the temporary strong references so the weak references can be properly tested
 139         if (referrerType.equals(ObjectInstancesManager.WEAK_REFERENCE)) {
 140             pipe.println(HeapwalkingDebuggee.COMMAND_DELETE_REFERRERS + ":" + className + ":" + referrerCount + ":" + ObjectInstancesManager.STRONG_REFERENCE);
 141             if (!isDebuggeeReady()) {
 142                 return;
 143             }
 144         }
 145 
 146         // prevent half of instances from GC, delete references and force GC




  24 /*
  25  * @test
  26  *
  27  * @summary converted from VM Testbase nsk/jdi/ReferenceType/instances/instances003.
  28  * VM Testbase keywords: [jpda, jdi, feature_jdk6_jpda, vm6]
  29  * VM Testbase readme:
  30  * DESCRIPTION
  31  *      The test scenario is following:
  32  *         - Debugger VM
  33  *         for refererence_type in <Strong, JNI_Local_Ref, JNI_Global_Ref, JNI_Weak_Ref, PhantomReference, SoftReference, WeakReference>
  34  *                 - initiate creation test class instances  of type 'refererence_type' in debuggee VM
  35  *                 - prevent some instances from being garbage collected using ObjectReference.disableCollection
  36  *                 - initiate GarbageCollection in Debuggee VM
  37  *                 - check the number of instances is left is correct
  38  *                 - enables Garbage Collection for instances for which it were previously disabled using ObjectReference.enableCollection
  39  *                 - initiate GarbageCollection in Debuggee VM
  40  *                 - check the number of instances is 0
  41  *         done
  42  *         Test is executed for following sublcasses of ObjectReference: StringReference, ThreadReference, ClassLoaderReference
  43  *
  44  * @requires vm.gc != "Z"
  45  * @library /vmTestbase
  46  *          /test/lib
  47  * @run driver jdk.test.lib.FileInstaller . .
  48  * @build nsk.jdi.ReferenceType.instances.instances003.instances003
  49  * @run main/othervm/native PropertyResolvingWrapper
  50  *      nsk.jdi.ReferenceType.instances.instances003.instances003
  51  *      -verbose
  52  *      -arch=${os.family}-${os.simpleArch}
  53  *      -waittime=5
  54  *      -debugee.vmkind=java
  55  *      -transport.address=dynamic
  56  *      "-debugee.vmkeys=-Xmx128M ${test.vm.opts} ${test.java.opts}"
  57  *      -testClassNames nsk.jdi.ReferenceType.instances.instances003.instances003$TestClassLoader:java.lang.String:java.lang.Thread
  58  */
  59 
  60 package nsk.jdi.ReferenceType.instances.instances003;
  61 
  62 import java.io.PrintStream;
  63 import java.util.*;
  64 


 108         return new instances003().runIt(argv, out);
 109     }
 110 
 111     protected String debuggeeClassName() {
 112         return nsk.share.jdi.HeapwalkingDebuggee.class.getName();
 113     }
 114 
 115     protected void testClass(String className, String referrerType) {
 116         final int createInstanceCount = 50;
 117         final int referrerCount = 1;
 118 
 119         List<ObjectReference> objectsToFilter = HeapwalkingDebugger.getObjectReferences(className, vm);
 120 
 121         // create 'createInstanceCount' instances of test class
 122 
 123         // create temporary strong references to prevent the weakly referred instances being GCed
 124         // during the time between creating them and disabling collection on them
 125         pipe.println(HeapwalkingDebuggee.COMMAND_CREATE_INSTANCES + ":" + className + ":" + createInstanceCount +
 126             ":" + referrerCount + ":" + referrerType +
 127             (referrerType.equals(ObjectInstancesManager.WEAK_REFERENCE) ? "|" + ObjectInstancesManager.STRONG_REFERENCE : ""));
 128 
 129         // Note! This test is broken, in the sense that it incorrectly assumes
 130         // that no GC can happen before it walks the heap. In practice, it seems
 131         // to only affect this test when using ZGC. However, this test will also
 132         // fail when using other GCs if an explicit GC is done here.
 133 
 134         // the instance counts should not be affected by creating multiple references
 135         checkDebugeeAnswer_instanceCounts(className, createInstanceCount, objectsToFilter);
 136 
 137         ReferenceType referenceType = debuggee.classByName(className);
 138         List<ObjectReference> instances = HeapwalkingDebugger.filterObjectReferrence(objectsToFilter, referenceType.instances(0));
 139 
 140         for (ObjectReference or : instances) {
 141             or.disableCollection();
 142         }
 143 
 144         // remove the temporary strong references so the weak references can be properly tested
 145         if (referrerType.equals(ObjectInstancesManager.WEAK_REFERENCE)) {
 146             pipe.println(HeapwalkingDebuggee.COMMAND_DELETE_REFERRERS + ":" + className + ":" + referrerCount + ":" + ObjectInstancesManager.STRONG_REFERENCE);
 147             if (!isDebuggeeReady()) {
 148                 return;
 149             }
 150         }
 151 
 152         // prevent half of instances from GC, delete references and force GC


< prev index next >