Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/GcPointerCheckTest/GcPointerCheckTest.java
41159 views
/*1* Copyright (c) 2011, 2020, 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*/2223/*24* @test25* @key stress26*27* @summary converted from VM Testbase gc/gctests/GcPointerCheckTest.28* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]29* VM Testbase readme:30* DESCRIPTION31* Test that no pointers are broken.32*33* COMMENTS34* This test was ported from JRockit test suite.35*36* @library /vmTestbase37* /test/lib38* @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.GcPointerCheckTest.GcPointerCheckTest39*/4041package gc.gctests.GcPointerCheckTest;4243import nsk.share.TestFailure;44import nsk.share.gc.GC;45import nsk.share.gc.ThreadedGCTest;46import nsk.share.test.ExecutionController;4748/**49* Test that no pointers are broken.50*/51public class GcPointerCheckTest extends ThreadedGCTest {5253@Override54protected Runnable createRunnable(int i) {55return new Test();56}5758class Test implements Runnable {5960/**61* Helper class for linking objects together.62*/63private class PointerHelper {6465public PointerHelper next;66}67private PointerHelper first;68ExecutionController stresser;6970@Override71public void run() {72if (stresser == null) {73stresser = getExecutionController();74}75while (stresser.continueExecution()) {76testGcPointers();77}78}7980/**81* Create a lot of objects and link them together, then verify82* that the pointers are pointing to the correct type of objects.83*84* @return success if all references points to the correct type85* of object.86*/87public void testGcPointers() {8889int innerIters = 1;90int outerIters = 200;9192PointerHelper tmp1;93PointerHelper tmp2;9495while (outerIters > 0) {96int i = 0;97tmp1 = new PointerHelper();98this.first = tmp1;99100while (i != innerIters) {101i++;102tmp2 = new PointerHelper();103tmp1.next = tmp2;104tmp1 = tmp2;105tmp2 = new PointerHelper();106}107108outerIters--;109110if (!checkRefs()) {111throw new TestFailure("Some references were bad");112}113}114}115116private boolean checkRefs() {117PointerHelper iter = this.first;118119for (int i = 0; iter != null; iter = iter.next) {120i++;121122if (iter.getClass() != PointerHelper.class) {123//("GC causer bad ref on " + i);124return false;125}126}127128return true;129}130}131132public static void main(String[] args) {133GC.runTest(new GcPointerCheckTest(), args);134}135}136137138