Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/gc/containers/ContainerDescription.java
41155 views
/*1* Copyright (c) 2010, 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*/22package vm.gc.containers;2324import nsk.share.TestBug;25import nsk.share.gc.gp.GarbageProducer;26import nsk.share.gc.gp.GarbageUtils;27import nsk.share.gc.gp.MemoryStrategy;2829/**30* This is a description which is parsed from command-line string.31* It contains the container type, garbage producer, memory strategy,32* speed of objects renovations and count of threads to work with33* container. The conatainer should be MT safe if threadsCount more then 1.34*/35public class ContainerDescription {3637/*38* The container description is next:39* containerName(garbageProucer,numberOfThreads,speed,MemoryStrategy)40* all parameters except containerName are optional41* containerName is the Name of class from java.util or java.util.concurrent42*/43static ContainerDescription parseFromString(String string) {44int params = string.indexOf('(');45String gp;46Speed speed = Speed.MEDIUM;47MemoryStrategy ms = null;48int count = 1;4950if (params == -1) {51ContainerDescription descr = new ContainerDescription(string);52descr.setSpeed(speed);53descr.setThreadsCount(count);54return descr;55}56if (!string.endsWith(")")) {57throw new TestBug("Incorrect syntax of container description.");58}59String name = string.substring(0, string.indexOf('('));60String parameters = string.substring(string.indexOf("(") + 1, string.length() - 1);61final int closedBracket = parameters.lastIndexOf(')');62int del = parameters.indexOf(',', closedBracket + 1);63if (del == -1) {64gp = parameters;65} else {66gp = parameters.substring(0, del).trim();67String[] other = parameters.substring(del + 1).split(",");68switch (other.length) {69case 3:70ms = MemoryStrategy.fromString(other[2].trim());71case 2:72speed = Speed.fromString(other[1].trim());73case 1:74count = Integer.parseInt(other[0].trim());75break;76default:77throw new TestBug("Unexpected size of parameters: " + other.length + 1);78}79}80ContainerDescription descr = new ContainerDescription(name);81descr.setGarbageProducer(GarbageUtils.getGarbageProducer(gp));82descr.setSpeed(speed);83descr.setThreadsCount(count);84descr.setMemoryStrategy(ms);85return descr;86}8788protected ContainerDescription(String name) {89this.name = name;90}91protected GarbageProducer garbageProducer;9293/**94* Get the value of garbageProducer95*96* @return the value of garbageProducer97*/98public GarbageProducer getGarbageProducer() {99return garbageProducer;100}101102/**103* Set the value of garbageProducer104*105* @param garbageProducer new value of garbageProducer106*/107public void setGarbageProducer(GarbageProducer garbageProducer) {108this.garbageProducer = garbageProducer;109}110protected MemoryStrategy memoryStrategy;111112/**113* Get the value of memoryStrategy114*115* @return the value of memoryStrategy116*/117public MemoryStrategy getMemoryStrategy() {118return memoryStrategy;119}120121/**122* Set the value of memoryStrategy123*124* @param memoryStrategy new value of memoryStrategy125*/126public void setMemoryStrategy(MemoryStrategy memoryStrategy) {127this.memoryStrategy = memoryStrategy;128}129protected String name;130131/**132* Get the value of Type133*134* @return the value of Type135*/136public String getName() {137return name;138}139protected Speed speed = Speed.MEDIUM;140141/**142* Get the value of speed143*144* @return the value of speed145*/146public Speed getSpeed() {147return speed;148}149150/**151* Set the value of speed152*153* @param speed new value of speed154*/155public void setSpeed(Speed speed) {156this.speed = speed;157}158protected int threadsCount;159160/**161* Get the value of threadsCount162*163* @return the value of threadsCount164*/165public int getThreadsCount() {166return threadsCount;167}168169/**170* Set the value of threadsCount171*172* @param threadsCount new value of threadsCount173*/174public void setThreadsCount(int threadsCount) {175this.threadsCount = threadsCount;176}177}178179180