Path: blob/master/test/hotspot/jtreg/vmTestbase/gc/ArrayJuggle/Juggle01/Juggle01.java
40948 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*/222324/*25* @test26* @key stress randomness27*28* @summary converted from VM Testbase gc/ArrayJuggle/Juggle01.29* VM Testbase keywords: [gc, stress, stressopt, nonconcurrent, quick]30*31* @library /vmTestbase32* /test/lib33* @run main/othervm -Xlog:gc=debug:gc.log gc.ArrayJuggle.Juggle01.Juggle01 -gp byteArr -ms low34*/3536package gc.ArrayJuggle.Juggle01;3738import nsk.share.test.*;39import nsk.share.gc.*;40import nsk.share.gc.gp.*;4142/**43* This test randomly replaces elements of an array with new44* objects using given garbage producer and memory strategy.45*/46public class Juggle01 extends ThreadedGCTest implements GarbageProducerAware, MemoryStrategyAware {47private GarbageProducer garbageProducer;48private MemoryStrategy memoryStrategy;49private Object[] array;50long objectSize;5152private class Juggler implements Runnable {53public void run() {54synchronized (this) {55int index = LocalRandom.nextInt(array.length);56array[index] = garbageProducer.create(objectSize);57}58}59}6061protected Runnable createRunnable(int i) {62return new Juggler();63}6465public void run() {66log.debug("Garbage producer: " + garbageProducer);67log.debug("Memory strategy: " + memoryStrategy);68long memory = runParams.getTestMemory();69int objectCount = memoryStrategy.getCount(memory);70objectSize = memoryStrategy.getSize(memory);71log.debug("Object count: " + objectCount);72log.debug("Object size: " + objectSize);73array = new Object[objectCount - 1];74super.run();75}7677public void setGarbageProducer(GarbageProducer garbageProducer) {78this.garbageProducer = garbageProducer;79}8081public void setMemoryStrategy(MemoryStrategy memoryStrategy) {82this.memoryStrategy = memoryStrategy;83}8485public static void main(String[] args) {86GC.runTest(new Juggle01(), args);87}88}899091