1 /*
  2  * Copyright (c) 2017, 2018, Red Hat, Inc. 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 
 25 /*
 26  * @test id=passive
 27  * @summary Check that Shenandoah cleans up interned strings
 28  * @requires vm.gc.Shenandoah
 29  *
 30  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 31  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 32  *      -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 33  *      TestStringInternCleanup
 34  *
 35  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 36  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 37  *      -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 38  *      TestStringInternCleanup
 39  *
 40  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 41  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 42  *      -XX:+ShenandoahDegeneratedGC
 43  *      TestStringInternCleanup
 44  *
 45  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 46  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 47  *      -XX:-ShenandoahDegeneratedGC
 48  *      TestStringInternCleanup
 49  */
 50 
 51 /*
 52  * @test id=default
 53  * @summary Check that Shenandoah cleans up interned strings
 54  * @requires vm.gc.Shenandoah
 55  *
 56  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 57  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 58  *      TestStringInternCleanup
 59  *
 60  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 61  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 62  *      -XX:+ShenandoahVerify
 63  *      TestStringInternCleanup
 64  *
 65  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 66  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 67  *      TestStringInternCleanup
 68  *
 69  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 70  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
 71  *      TestStringInternCleanup
 72  *
 73  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:-ClassUnloadingWithConcurrentMark
 74  *      -XX:+UseShenandoahGC
 75  *      TestStringInternCleanup
 76  */
 77 
 78 /*
 79  * @test id=iu
 80  * @summary Check that Shenandoah cleans up interned strings
 81  * @requires vm.gc.Shenandoah
 82  *
 83  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 84  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
 85  *      -XX:+ShenandoahVerify
 86  *      TestStringInternCleanup
 87  *
 88  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 89  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
 90  *      -XX:+ShenandoahVerify
 91  *      TestStringInternCleanup
 92  *
 93  * @run main/othervm -Xmx64m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -XX:+ClassUnloadingWithConcurrentMark
 94  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
 95  *      TestStringInternCleanup
 96  */
 97 
 98 public class TestStringInternCleanup {
 99 
100     static final int COUNT = 1_000_000;
101     static final int WINDOW = 1_000;
102 
103     static final String[] reachable = new String[WINDOW];
104 
105     public static void main(String[] args) throws Exception {
106         int rIdx = 0;
107         for (int c = 0; c < COUNT; c++) {
108             reachable[rIdx] = ("LargeInternedString" + c).intern();
109             rIdx++;
110             if (rIdx >= WINDOW) {
111                 rIdx = 0;
112             }
113         }
114     }
115 
116 }