Path: blob/master/test/hotspot/jtreg/gc/shenandoah/jni/TestPinnedGarbage.java
41153 views
/*1* Copyright (c) 2018, Red Hat, Inc. 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*22*/2324/* @test TestPinnedGarbage25* @summary Test that garbage in the pinned region does not crash VM26* @key randomness27* @requires vm.gc.Shenandoah28* @library /test/lib29*30* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx128m31* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive32* -XX:+ShenandoahVerify -XX:+ShenandoahDegeneratedGC33* TestPinnedGarbage34*35* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx128m36* -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive37* -XX:+ShenandoahVerify -XX:-ShenandoahDegeneratedGC38* TestPinnedGarbage39*/4041/* @test TestPinnedGarbage42* @summary Test that garbage in the pinned region does not crash VM43* @key randomness44* @requires vm.gc.Shenandoah45* @library /test/lib46*47* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx128m48* -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive49* TestPinnedGarbage50*51* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx128m52* -XX:+UseShenandoahGC53* -XX:+ShenandoahVerify54* TestPinnedGarbage55*/5657import java.util.Arrays;58import java.util.Random;59import jdk.test.lib.Utils;6061public class TestPinnedGarbage {62static {63System.loadLibrary("TestPinnedGarbage");64}6566private static final int NUM_RUNS = 1_000;67private static final int OBJS_COUNT = 1 << 10;68private static final int GARBAGE_COUNT = 1 << 18;6970private static native void pin(int[] a);71private static native void unpin(int[] a);7273public static void main(String[] args) {74Random rng = Utils.getRandomInstance();75for (int i = 0; i < NUM_RUNS; i++) {76test(rng);77}78}7980private static void test(Random rng) {81Object[] objs = new Object[OBJS_COUNT];82for (int i = 0; i < OBJS_COUNT; i++) {83objs[i] = new MyClass();84}8586int[] cog = new int[10];87int cogIdx = rng.nextInt(OBJS_COUNT);88objs[cogIdx] = cog;89pin(cog);9091for (int i = 0; i < GARBAGE_COUNT; i++) {92int rIdx = rng.nextInt(OBJS_COUNT);93if (rIdx != cogIdx) {94objs[rIdx] = new MyClass();95}96}9798unpin(cog);99}100101public static class MyClass {102public Object ref = new Object();103}104105}106107108