Path: blob/master/test/hotspot/jtreg/gc/shenandoah/jni/TestPinnedGarbage.java
64507 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 id=passive25* @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 id=aggressive42* @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*/5152/* @test id=verify53* @summary Test that garbage in the pinned region does not crash VM54* @key randomness55* @requires vm.gc.Shenandoah56* @library /test/lib57* @run main/othervm/native -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx128m58* -XX:+UseShenandoahGC59* -XX:+ShenandoahVerify60* TestPinnedGarbage61*/6263import java.util.Arrays;64import java.util.Random;65import jdk.test.lib.Utils;6667public class TestPinnedGarbage {68static {69System.loadLibrary("TestPinnedGarbage");70}7172private static final int NUM_RUNS = 1_000;73private static final int OBJS_COUNT = 1 << 10;74private static final int GARBAGE_COUNT = 1 << 18;7576private static native void pin(int[] a);77private static native void unpin(int[] a);7879public static void main(String[] args) {80Random rng = Utils.getRandomInstance();81for (int i = 0; i < NUM_RUNS; i++) {82test(rng);83}84}8586private static void test(Random rng) {87Object[] objs = new Object[OBJS_COUNT];88for (int i = 0; i < OBJS_COUNT; i++) {89objs[i] = new MyClass();90}9192int[] cog = new int[10];93int cogIdx = rng.nextInt(OBJS_COUNT);94objs[cogIdx] = cog;95pin(cog);9697for (int i = 0; i < GARBAGE_COUNT; i++) {98int rIdx = rng.nextInt(OBJS_COUNT);99if (rIdx != cogIdx) {100objs[rIdx] = new MyClass();101}102}103104unpin(cog);105}106107public static class MyClass {108public Object ref = new Object();109}110111}112113114