Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/gctest03/gctest03.java
41155 views
/*1* Copyright (c) 2002, 2021, 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/* stress testing24Redthreads keep removing new nodes from a binary sort tree(25all nodes of its left subtree is less than itself, all nodes26of its right subtree is large than itself).27Bluethreads keep adding nodes into the binary sort tree.28YellowThreads search the binary sort tree.29The nodes removed from the tree will become garbages immediately30Create 10 Redthreads and 10 Bluethreads to manipulate the31the same binary tree involving excessive memory allocation32to test if memory management module and gc() crash.33*/343536/*37* @test38* @key randomness39*40* @summary converted from VM Testbase gc/gctests/gctest03.41* VM Testbase keywords: [gc]42*43* @library /vmTestbase44* /test/lib45* @compile Tree.java appthread.java46* @run main/othervm gc.gctests.gctest03.gctest03 1000047*/4849package gc.gctests.gctest03;5051import nsk.share.test.*;52import nsk.share.gc.*;53import nsk.share.TestFailure;54import nsk.share.TestBug;5556//import Tree;57//import Redthread;58//import Bluethread;5960public class gctest03 extends TestBase {61private String[] args;6263public gctest03(String[] args) {64this.args = args;65}6667public void run() {68int i = 1;69int dataNodeLimit = 100000;7071if (args.length > 0) {72try {73dataNodeLimit = Integer.valueOf(args[0]).intValue();74} catch (NumberFormatException e) {75throw new TestBug("Bad input to gctest03. Expected integer, " +76" got: ->" + args[0] + "<-", e);77}78}7980for (int j = 0; j < 10; j++) {81DataNode.setDataNodeLimit(dataNodeLimit);82DataNode.clearDataNodeCount();8384Tree tr = new Tree();85for (i =2; i < 100; i++) {86try {87DataNode d = new DataNode(i);88TreeNode t = new TreeNode(d);89tr.insert(t);90} catch (DataNodeException e) {91throw new TestFailure("DataNodeException caught in gctest03.main()", e);92}93}9495int sz = 10;9697//create 10 threads adding data into binary tree.98// each thread only adds the multiple of its key99//(1, 2, 3, 4, 5, 6, 7, 8, 9 , 10). No duplication100101Redthread rth[] = new Redthread[sz];102103for(i=0; i < sz; i++) {104rth[i] = new Redthread(tr, i+1);105rth[i].setName("Redthread" + i);106rth[i].start();107}108109//create 10 threads removing data from the tree.110111Bluethread bth[] = new Bluethread[sz];112113for(i=0; i < sz; i++) {114bth[i] = new Bluethread(tr, i+1);115bth[i].setName("Bluethread" + i);116bth[i].start();117}118119120//create 10 threads inquiring data from the tree121122Yellowthread yth[] = new Yellowthread[sz];123for(i=0; i < sz; i++) {124yth[i] = new Yellowthread(tr, i+1);125yth[i].setName("Yellowthread" + i);126yth[i].start();127}128129for (i = 0; i < sz; i++) {130try {131rth[i].join();132bth[i].join();133yth[i].join();134} catch (InterruptedException e) {135System.err.println("Error joining with threads in gctest03.main()");136System.err.println("Loop count: " + i);137}138}139}140141}142143public static void main(String args[]) {144GC.runTest(new gctest03(args), args);145}146}147148149