Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/gctests/FinalizeTest04/FinalizeTest04.java
41161 views
/*1* Copyright (c) 2007, 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/FinalizeTest04.28* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent]29*30* @library /vmTestbase31* /test/lib32* @run main/othervm -XX:-UseGCOverheadLimit gc.gctests.FinalizeTest04.FinalizeTest0433*/3435package gc.gctests.FinalizeTest04;3637import nsk.share.test.*;38import nsk.share.gc.*;3940/**41* Test that synchronization between GC and finalizer thread42* (if any) is correct.43*44* This test creates objects that do GC-related work in finalizer,45* e.g. call System.gc(), System.runFinalization(), Algorithms.eatMemory().46*47* @see nsk.share.gc.Algorithms#eatMemory()48* @see java.lang.System#gc()49* @see java.lang.System#runFinalization()50*/51public class FinalizeTest04 extends GCTestBase {5253private int objectSize = 100;54private int objectCount = 100;55private ExecutionController stresser;5657private class FinMemoryObject2 extends FinMemoryObject {5859public FinMemoryObject2(int size) {60super(size);61}6263protected void finalize() {64super.finalize();65System.gc();66Algorithms.eatMemory(stresser);67System.runFinalization();68System.gc();69Algorithms.eatMemory(stresser);70System.gc();71}72}7374public void run() {75stresser = new Stresser(runParams.getStressOptions());76stresser.start(runParams.getIterations());77for (int i = 0; i < objectCount; ++i) {78new FinMemoryObject2(objectSize);79}80Algorithms.eatMemory(stresser);81}8283public static void main(String[] args) {84GC.runTest(new FinalizeTest04(), args);85}86}878889