Path: blob/master/test/hotspot/jtreg/gc/shenandoah/TestReferenceShortcutCycle.java
40942 views
/*1* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.shenandoah;2425/* @test26* @requires vm.gc.Shenandoah27* @library /test/lib28* @build sun.hotspot.WhiteBox29* @modules java.base30* @run main jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox31* @run main/othervm32* -Xbootclasspath/a:.33* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI34* -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=satb -XX:ShenandoahGarbageThreshold=100 -Xmx100m35* gc.shenandoah.TestReferenceShortcutCycle36*/3738/* @test39* @requires vm.gc.Shenandoah40* @library /test/lib41* @build sun.hotspot.WhiteBox42* @modules java.base43* @run main jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox44* @run main/othervm45* -Xbootclasspath/a:.46* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI47* -XX:+UnlockExperimentalVMOptions -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGarbageThreshold=100 -Xmx100m48* gc.shenandoah.TestReferenceShortcutCycle49*/5051import java.lang.ref.PhantomReference;52import java.lang.ref.Reference;53import java.lang.ref.ReferenceQueue;54import java.lang.ref.WeakReference;55import sun.hotspot.WhiteBox;5657public class TestReferenceShortcutCycle {58private static final int NUM_ITEMS = 100000;5960private static final WhiteBox WB = WhiteBox.getWhiteBox();6162private static final class TestObject {63public final int value;6465public TestObject(int value) {66this.value = value;67}68}6970private static WeakReference[] refs;7172private static void setup() {73refs = new WeakReference[NUM_ITEMS];74for (int i = 0; i < NUM_ITEMS; i++) {75refs[i] = new WeakReference<>(new TestObject(i));76}77}7879private static void fail(String msg) throws Exception {80throw new RuntimeException(msg);81}8283private static void testConcurrentCollection() throws Exception {84setup();85WB.concurrentGCAcquireControl();86try {87WB.concurrentGCRunToIdle();88WB.concurrentGCRunTo(WB.AFTER_CONCURRENT_REFERENCE_PROCESSING_STARTED);89for (int i = 0; i < NUM_ITEMS; i++) {90if (refs[i].get() != null) {91fail("resurrected referent");92}93}94} finally {95WB.concurrentGCReleaseControl();96}97}98public static void main(String[] args) throws Exception {99testConcurrentCollection();100}101}102103104