Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/MTsyncGC/MTsyncGC.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*/222324/*25* @test26*27* @summary converted from VM Testbase gc/gctests/MTsyncGC.28* VM Testbase keywords: [gc]29* VM Testbase readme:30* This test creates 1000 threads that run in a sequential31* fashion with each thread in turn generating 1Meg of garbage.32* Before exiting, each of these threads synchronously calls33* the garbage collector in another thread.34* The test fails if an OutOfMemoryError is thrown and passes35* if nothing happens.36*37* @library /vmTestbase38* /test/lib39* @run main/othervm gc.gctests.MTsyncGC.MTsyncGC40*/4142package gc.gctests.MTsyncGC;4344import nsk.share.TestFailure;45import java.util.Vector;4647484950// Each thread creates 1Meg of garbage in the run() method.5152class MemEvil extends Thread {53static Vector v = new Vector();54static {55for(int i = 0; i < 10; i++)56v.addElement(new char [100000]);57}5859public void run () {60int i = 0;61while(i < 10) {62v.setElementAt(new char[100000], i);63i++;64}65try {66//synchronously invoke the garbage67// collector in another thread68MTsyncGC.reclaimer.start();69MTsyncGC.reclaimer.join();70}catch (Exception e) {}71}72}737475class Reclaimer extends Thread{76public void run() {77System.gc();78}79}8081public class MTsyncGC {82static Reclaimer reclaimer = new Reclaimer();83public static void main(String args[] ){84int i;85int memory_reserve[] = new int [10000];86Thread threadsHolder[] = new Thread[1000];8788for(i = 0; i < threadsHolder.length; i++)89threadsHolder[i] = new MemEvil();9091i = 0;92while(i < threadsHolder.length ){93try {94threadsHolder[i].start();95threadsHolder[i].join();96} catch ( Exception e ) {97memory_reserve = null;98System.gc();99throw new TestFailure("Test Failed.", e);100}101threadsHolder[i] = null;102i++;103}104}105}106107108