Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/MTasyncGC/MTasyncGC.java
41155 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*26* @summary converted from VM Testbase gc/gctests/MTasyncGC.27* VM Testbase keywords: [gc]28* VM Testbase readme:29* This test creates 1000 threads that run in a sequential30* fashion with each thread in turn generating 1Meg of garbage.31* The test relies upon the garbage collector asynchrnonously32* reclaiming garbage.33* The test fails if an OutOfMemoryError is thrown and passes34* if the test proceeds to completion without an exception being35* thrown.36*37* @library /vmTestbase38* /test/lib39* @run main/othervm gc.gctests.MTasyncGC.MTasyncGC40*/4142package gc.gctests.MTasyncGC;4344import java.util.Vector;45import nsk.share.TestFailure;4647// Each thread creates 1Meg of garbage in the run() method.4849class MemEvil extends Thread {50static Vector v = new Vector();51static {52for(int i = 0; i < 10; i++)53v.addElement(new char [100000]);54}5556public void run () {57int i = 0;58while(i < 10) {59v.setElementAt(new char[100000], i);60i++;61}62}63}646566public class MTasyncGC {6768public static void main(String args[] ){69int i;70int memory_reserve[] = new int [10000];71Thread threadsHolder[] = new Thread[1000];7273for(i = 0; i < threadsHolder.length; i++)74threadsHolder[i] = new MemEvil();7576i = 0;77while(i < threadsHolder.length ){78try {79threadsHolder[i].start();80threadsHolder[i].join();81} catch ( Exception e ) {82memory_reserve = null;83System.gc();84throw new TestFailure("Test Failed.", e);85}86threadsHolder[i] = null;87i++;88}89}90}919293