Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/vector/SimpleGC/SimpleGC.java
41155 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/vector/SimpleGC.28* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, monitoring]29*30* @library /vmTestbase31* /test/lib32* @run main/othervm gc.vector.SimpleGC.SimpleGC -ms high33*/3435package gc.vector.SimpleGC;3637import nsk.share.gc.GC;38import nsk.share.gc.GCTestBase;39import nsk.share.gc.gp.GarbageProducer;40import nsk.share.gc.gp.GarbageProducerAware;41import nsk.share.gc.gp.GarbageUtils;42import nsk.share.gc.gp.MemoryStrategy;43import nsk.share.gc.gp.MemoryStrategyAware;44import nsk.share.runner.RunParams;45import nsk.share.test.Stresser;4647/**48* Test that fills out a certain amount of memory with objects of a given type.49* The test accepts MemoryStrategy, type of objects and stress options50* as command line args.51*/52public class SimpleGC extends GCTestBase implements GarbageProducerAware, MemoryStrategyAware {5354private GarbageProducer garbageProducer;55private MemoryStrategy memoryStrategy;5657/**58* Garbage link.59* The field is static to prevent possible compiler optimizations.60*/61public static Object[] array;6263@Override64public void run() {6566long memoryAmount = runParams.getTestMemory();67long size = GarbageUtils.getArraySize(memoryAmount, memoryStrategy);68int length = GarbageUtils.getArrayCount(memoryAmount, memoryStrategy);69Object[] garbage = new Object[length];70array = garbage;71log.info("Memory to fill out: " + memoryAmount);72log.info("Array lenght: " + garbage.length);73log.info("Object size: " + size);74log.info("Garbage producer: " + garbageProducer.getClass().getCanonicalName());75log.info("Memory Strategy: " + memoryStrategy);76Stresser stresser = new Stresser(runParams.getStressOptions());77stresser.start(10 * garbage.length);7879int iteration = 0;80try {81while (stresser.iteration()) {82for (int i = 0; i < garbage.length && stresser.continueExecution(); ++i) {83garbage[i] = garbageProducer.create(size);84}85for (int i = 0; i < garbage.length; ++i) {86garbage[i] = null;87}88iteration++;89if (iteration % 1000 == 0) {90log.info(" iteration # " + iteration);91}92}93} catch (OutOfMemoryError oom) {94// normally that should never be thrown95log.info("OutOfMemory after " + iteration + " iterations");96throw oom;97} finally {98stresser.finish();99}100log.info("Success. Total iterations: " + iteration);101}102103@Override104public final void setGarbageProducer(GarbageProducer garbageProducer) {105this.garbageProducer = garbageProducer;106}107108@Override109public final void setMemoryStrategy(MemoryStrategy memoryStrategy) {110this.memoryStrategy = memoryStrategy;111}112113public static void main(String[] args) {114RunParams.getInstance().setRunMemDiagThread(true);115GC.runTest(new SimpleGC(), args);116}117}118119120