< prev index next >

test/hotspot/jtreg/gc/shenandoah/TestReferenceRefersToShenandoah.java

Print this page

  1 /*
  2  * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 package gc.shenandoah;
 25 
 26 /* @test id=satb
 27  * @requires vm.gc.Shenandoah
 28  * @library /test/lib
 29  * @build jdk.test.whitebox.WhiteBox
 30  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 31  * @run main/othervm
 32  *      -Xbootclasspath/a:.
 33  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 34  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb
 35  *      gc.shenandoah.TestReferenceRefersToShenandoah
 36  */
 37 
 38 /* @test id=iu













 39  * @requires vm.gc.Shenandoah
 40  * @library /test/lib
 41  * @build jdk.test.whitebox.WhiteBox
 42  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 43  * @run main/othervm
 44  *      -Xbootclasspath/a:.
 45  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 46  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
 47  *      gc.shenandoah.TestReferenceRefersToShenandoah
 48  */
 49 
 50 /* @test id=satb-100
 51  * @requires vm.gc.Shenandoah
 52  * @library /test/lib
 53  * @build jdk.test.whitebox.WhiteBox
 54  * @modules java.base
 55  * @run main jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 56  * @run main/othervm
 57  *      -Xbootclasspath/a:.
 58  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 59  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb -XX:ShenandoahGarbageThreshold=100 -Xmx100m












 60  *      gc.shenandoah.TestReferenceRefersToShenandoah
 61  */
 62 
 63 /* @test id=iu-100
 64  * @requires vm.gc.Shenandoah
 65  * @library /test/lib
 66  * @build jdk.test.whitebox.WhiteBox
 67  * @modules java.base
 68  * @run main jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 69  * @run main/othervm
 70  *      -Xbootclasspath/a:.
 71  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 72  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGarbageThreshold=100 -Xmx100m
 73  *      gc.shenandoah.TestReferenceRefersToShenandoah
 74  */
 75 
 76 import java.lang.ref.PhantomReference;
 77 import java.lang.ref.Reference;
 78 import java.lang.ref.ReferenceQueue;
 79 import java.lang.ref.WeakReference;

107     private static void setup() {
108         testObjectNone = new TestObject(0);
109         testObject1 = new TestObject(1);
110         testObject2 = new TestObject(2);
111         testObject3 = new TestObject(3);
112         testObject4 = new TestObject(4);
113 
114         queue = new ReferenceQueue<TestObject>();
115 
116         testPhantom1 = new PhantomReference<TestObject>(testObject1, queue);
117 
118         testWeak2 = new WeakReference<TestObject>(testObject2, queue);
119         testWeak3 = new WeakReference<TestObject>(testObject3, queue);
120         testWeak4 = new WeakReference<TestObject>(testObject4, queue);
121     }
122 
123     private static void gcUntilOld(Object o) throws Exception {
124         if (!WB.isObjectInOldGen(o)) {
125             WB.fullGC();
126             if (!WB.isObjectInOldGen(o)) {
127                 fail("object not promoted by full gc");




128             }
129         }
130     }
131 
132     private static void gcUntilOld() throws Exception {
133         gcUntilOld(testObjectNone);
134         gcUntilOld(testObject1);
135         gcUntilOld(testObject2);
136         gcUntilOld(testObject3);
137         gcUntilOld(testObject4);
138 
139         gcUntilOld(testPhantom1);
140 
141         gcUntilOld(testWeak2);
142         gcUntilOld(testWeak3);
143         gcUntilOld(testWeak4);
144     }
145 
146     private static void progress(String msg) {
147         System.out.println(msg);
148     }
149 
150     private static void fail(String msg) throws Exception {
151         throw new RuntimeException(msg);
152     }
153 




154     private static void expectCleared(Reference<TestObject> ref,
155                                       String which) throws Exception {
156         expectNotValue(ref, testObjectNone, which);
157         if (!ref.refersTo(null)) {
158             fail("expected " + which + " to be cleared");
159         }
160     }
161 
162     private static void expectNotCleared(Reference<TestObject> ref,
163                                          String which) throws Exception {
164         expectNotValue(ref, testObjectNone, which);
165         if (ref.refersTo(null)) {
166             fail("expected " + which + " to not be cleared");
167         }
168     }
169 
170     private static void expectValue(Reference<TestObject> ref,
171                                     TestObject value,
172                                     String which) throws Exception {
173         expectNotValue(ref, testObjectNone, which);

  1 /*
  2  * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 package gc.shenandoah;
 25 
 26 /* @test id=satb
 27  * @requires vm.gc.Shenandoah
 28  * @library /test/lib
 29  * @build jdk.test.whitebox.WhiteBox
 30  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 31  * @run main/othervm
 32  *      -Xbootclasspath/a:.
 33  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 34  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb
 35  *      gc.shenandoah.TestReferenceRefersToShenandoah
 36  */
 37 
 38 /* @test id=satb-100
 39  * @requires vm.gc.Shenandoah
 40  * @library /test/lib
 41  * @build jdk.test.whitebox.WhiteBox
 42  * @modules java.base
 43  * @run main jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 44  * @run main/othervm
 45  *      -Xbootclasspath/a:.
 46  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 47  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb -XX:ShenandoahGarbageThreshold=100 -Xmx100m
 48  *      gc.shenandoah.TestReferenceRefersToShenandoah
 49  */
 50 
 51 /* @test id=generational
 52  * @requires vm.gc.Shenandoah
 53  * @library /test/lib
 54  * @build jdk.test.whitebox.WhiteBox
 55  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 56  * @run main/othervm
 57  *      -Xbootclasspath/a:.
 58  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 59  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational
 60  *      gc.shenandoah.TestReferenceRefersToShenandoah
 61  */
 62 
 63 /* @test id=generational-100
 64  * @requires vm.gc.Shenandoah
 65  * @library /test/lib
 66  * @build jdk.test.whitebox.WhiteBox
 67  * @modules java.base
 68  * @run main jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 69  * @run main/othervm
 70  *      -Xbootclasspath/a:.
 71  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 72  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=generational -XX:ShenandoahGarbageThreshold=100 -Xmx100m
 73  *      gc.shenandoah.TestReferenceRefersToShenandoah
 74  */
 75 
 76 /* @test id=iu
 77  * @requires vm.gc.Shenandoah
 78  * @library /test/lib
 79  * @build jdk.test.whitebox.WhiteBox
 80  * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 81  * @run main/othervm
 82  *      -Xbootclasspath/a:.
 83  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 84  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
 85  *      gc.shenandoah.TestReferenceRefersToShenandoah
 86  */
 87 
 88 /* @test id=iu-100
 89  * @requires vm.gc.Shenandoah
 90  * @library /test/lib
 91  * @build jdk.test.whitebox.WhiteBox
 92  * @modules java.base
 93  * @run main jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
 94  * @run main/othervm
 95  *      -Xbootclasspath/a:.
 96  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
 97  *      -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGarbageThreshold=100 -Xmx100m
 98  *      gc.shenandoah.TestReferenceRefersToShenandoah
 99  */
100 
101 import java.lang.ref.PhantomReference;
102 import java.lang.ref.Reference;
103 import java.lang.ref.ReferenceQueue;
104 import java.lang.ref.WeakReference;

132     private static void setup() {
133         testObjectNone = new TestObject(0);
134         testObject1 = new TestObject(1);
135         testObject2 = new TestObject(2);
136         testObject3 = new TestObject(3);
137         testObject4 = new TestObject(4);
138 
139         queue = new ReferenceQueue<TestObject>();
140 
141         testPhantom1 = new PhantomReference<TestObject>(testObject1, queue);
142 
143         testWeak2 = new WeakReference<TestObject>(testObject2, queue);
144         testWeak3 = new WeakReference<TestObject>(testObject3, queue);
145         testWeak4 = new WeakReference<TestObject>(testObject4, queue);
146     }
147 
148     private static void gcUntilOld(Object o) throws Exception {
149         if (!WB.isObjectInOldGen(o)) {
150             WB.fullGC();
151             if (!WB.isObjectInOldGen(o)) {
152                 // This is just a warning, because failing would
153                 // be overspecifying for generational shenandoah,
154                 // which need not necessarily promote objects upon
155                 // a full GC.
156                 warn("object not promoted by full gc");
157             }
158         }
159     }
160 
161     private static void gcUntilOld() throws Exception {
162         gcUntilOld(testObjectNone);
163         gcUntilOld(testObject1);
164         gcUntilOld(testObject2);
165         gcUntilOld(testObject3);
166         gcUntilOld(testObject4);
167 
168         gcUntilOld(testPhantom1);
169 
170         gcUntilOld(testWeak2);
171         gcUntilOld(testWeak3);
172         gcUntilOld(testWeak4);
173     }
174 
175     private static void progress(String msg) {
176         System.out.println(msg);
177     }
178 
179     private static void fail(String msg) throws Exception {
180         throw new RuntimeException(msg);
181     }
182 
183     private static void warn(String msg) {
184         System.out.println("Warning: " + msg);
185     }
186 
187     private static void expectCleared(Reference<TestObject> ref,
188                                       String which) throws Exception {
189         expectNotValue(ref, testObjectNone, which);
190         if (!ref.refersTo(null)) {
191             fail("expected " + which + " to be cleared");
192         }
193     }
194 
195     private static void expectNotCleared(Reference<TestObject> ref,
196                                          String which) throws Exception {
197         expectNotValue(ref, testObjectNone, which);
198         if (ref.refersTo(null)) {
199             fail("expected " + which + " to not be cleared");
200         }
201     }
202 
203     private static void expectValue(Reference<TestObject> ref,
204                                     TestObject value,
205                                     String which) throws Exception {
206         expectNotValue(ref, testObjectNone, which);
< prev index next >