Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/BigChains/BigChains.java
41155 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/BigChains.28* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, jrockit]29* VM Testbase readme:30* DESCRIPTION31* Creates big chains of allocated objects, with a mix of objects32* with and without finalizers.33*34* COMMENTS35* This test was ported from JRockit test suite.36*37* @library /vmTestbase38* /test/lib39* @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.BigChains.BigChains40*/4142package gc.gctests.BigChains;4344import nsk.share.gc.GC;45import nsk.share.gc.ThreadedGCTest;4647/**48* Test ported from dev test suite. Creates big chains of49* allocated objects, with a mix of objects with and without50* finalizers.51*/52public class BigChains extends ThreadedGCTest {5354public static void main(String[] args) {55GC.runTest(new BigChains(), args);56}5758@Override59protected Runnable createRunnable(int i) {6061return new Runnable() {6263/**64* Create a big chain of mixed objects and make sure nothing65* crashes.66*67* @return success if the program test could run without any68* problems.69*/70public void run() {7172createChain(100000, true);737475int i = 0;7677while (i++ < 100) {78createChain(10000, false);79}80}8182private void createChain(int noof, boolean firstIsFinalizable) {83BaseClass first;8485if (firstIsFinalizable) {86first = new FinalizerYes();87} else {88first = new FinalizerNo();89}9091BaseClass current = first;9293for (int i = 0; i < noof; i++) {94current.next = new FinalizerNo();95current = current.next;96}9798current.next = first;99}100};101}102}103104/**105* Helper base class for the BigChains test.106*/107class BaseClass {108109/**110* Base class.111*/112public BaseClass next;113}114115/**116* Helper class withfinalizer and counter for number of117* calls to the finalize() method.118*/119class FinalizerYes extends BaseClass {120121private static int noOfFinalized = 0;122123/**124* Finalizer for the help class, that increments a counter125* for each call to this method.126*/127public final void finalize() {128synchronized (this.getClass()) {129FinalizerYes.noOfFinalized++;130}131}132}133134/**135* Helper class without finalizer.136*/137class FinalizerNo extends BaseClass {138}139140141