Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/JumbleGC/JumbleGC.java
41159 views
/*1* Copyright (c) 2002, 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 stress randomness26*27* @summary converted from VM Testbase gc/gctests/JumbleGC.28* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]29* VM Testbase readme:30* A vector of 10 elements is filled up with references to31* CicrcularLinkedList and Binary Trees of 0.1 Meg. Once this32* entire structure has been built, all elements in the Vecor are set to null33* creating 1Meg of garbage. The Vector is repopulated once again.34* With ineffective garbage collection, the heap will soon fill up.35* If an OutofMemoryError is thrown, the test fails.36*37* @library /vmTestbase38* /test/lib39* @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.JumbleGC.JumbleGC40*/4142package gc.gctests.JumbleGC;4344import nsk.share.test.*;45import nsk.share.gc.*;46import java.util.Vector;4748public class JumbleGC extends TestBase {49public void run() {50int TreeSize = 1000;51int gc_count;52int randNum;53int num = 0;5455Vector v = new Vector(10);5657// Build a tree containing 100 treeNodes occupying about58// 1Meg of heap space.5960gc_count = 0;61try {62for(int i = 0; i < 10 ; i++) {63if ( i % 2 == 0 )64v.addElement(buildCircularLinkedList());65else66v.addElement(buildTree());67}6869while (gc_count < 10) {7071for (int i = 0; i < 10 ; i++)72v.setElementAt(null, i);7374for (int i = 0; i < 10 ; i++) {75if ( i % 2 == 0 )76v.setElementAt(buildCircularLinkedList(),i);77else78v.setElementAt(buildTree(),i);79}80gc_count ++;81log.info("Finished iteration # " + gc_count);82}8384} catch (OutOfMemoryError e) {85log.error("Test Failed.");86setFailed(true);87}88log.info("Test Passed.");89}9091public static void main(String args[]){92GC.runTest(new JumbleGC(), args);93}9495// build a binary tree of 0.1 Meg.(100 treeNodes in the three, each of 100 bytes9697private Tree buildTree() {98int i, randNum;99100i = 0;101Tree newTree = new Tree(100);102while (i < 100) {103randNum = LocalRandom.nextInt(0, 1000000);104newTree.addElement(randNum);105i++;106}107return newTree;108}109110// build a circular linked list of 0.1 Meg111private CircularLinkedList buildCircularLinkedList() {112CircularLinkedList cl;113cl = new CircularLinkedList(100);114for(int i = 0; i < 1000; i++)115cl.grow();116return cl;117}118}119120121