Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/gc/GC.java
41161 views
/*1* Copyright (c) 2005, 2018, 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*/2223package nsk.share.gc;2425import nsk.share.test.*;26import nsk.share.runner.*;27import nsk.share.gc.gp.GarbageProducer;28import nsk.share.gc.gp.GarbageProducerAware;29import nsk.share.gc.gp.GarbageProducer1Aware;30import nsk.share.gc.gp.MemoryStrategy;31import nsk.share.gc.gp.MemoryStrategyAware;32import nsk.share.gc.gp.GarbageUtils;33import nsk.share.gc.lock.Lockers;34import nsk.share.gc.lock.LockersAware;35import nsk.share.gc.lock.LockerUtils;3637/**38* Utility methods for GC tests.39*/40public class GC extends nsk.share.test.Tests {41protected static class GCTestRunner extends TestRunner {42private GCParams gcParams;43private GarbageProducer garbageProducer;44private GarbageProducer garbageProducer1;45private MemoryStrategy memoryStrategy;46private Lockers lockers;4748public GCTestRunner(Test test, String[] args) {49super(test, args);50}5152private GCParams getGCParams(String[] args) {53if (gcParams == null) {54gcParams = GCParams.getInstance();55gcParams.parseCommandLine(args);56}57return gcParams;58}5960private GarbageProducer getGarbageProducer(String[] args) {61if (garbageProducer == null) {62garbageProducer = GarbageUtils.getGarbageProducer(getGCParams(args).getGarbageProducerId());63configure(garbageProducer);64}65return garbageProducer;66}6768private GarbageProducer getGarbageProducer1(String[] args) {69if (garbageProducer1 == null) {70garbageProducer1 = GarbageUtils.getGarbageProducer(getGCParams(args).getGarbageProducer1Id());71configure(garbageProducer1);72}73return garbageProducer1;74}7576private MemoryStrategy getMemoryStrategy(String[] args) {77if (memoryStrategy == null) {78memoryStrategy = MemoryStrategy.fromString(getGCParams(args).getMemoryStrategyId());79configure(memoryStrategy);80}81return memoryStrategy;82}8384private Lockers getLockers(String[] args) {85if (lockers == null) {86lockers = LockerUtils.getLockers(getGCParams(args).getLockersId());87configure(lockers);88}89return lockers;90}9192public void configure(Object test) {93super.configure(test);94if (test instanceof GCParamsAware)95((GCParamsAware) test).setGCParams(getGCParams(args));96if (test instanceof GarbageProducerAware)97((GarbageProducerAware) test).setGarbageProducer(getGarbageProducer(args));98if (test instanceof GarbageProducer1Aware)99((GarbageProducer1Aware) test).setGarbageProducer1(getGarbageProducer1(args));100if (test instanceof MemoryStrategyAware)101((MemoryStrategyAware) test).setMemoryStrategy(getMemoryStrategy(args));102if (test instanceof LockersAware)103((LockersAware) test).setLockers(getLockers(args));104}105106107}108109private GC() {110}111112public static void runTest(Test test, String[] args) {113new GCTestRunner(test, args).run();114}115}116117118