Path: blob/master/test/hotspot/jtreg/compiler/codecache/cli/common/CodeCacheOptions.java
41154 views
/*1* Copyright (c) 2014, 2015, 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 compiler.codecache.cli.common;2324import jdk.test.lib.cli.CommandLineOptionTest;25import sun.hotspot.code.BlobType;2627import java.util.ArrayList;28import java.util.Collections;29import java.util.EnumSet;30import java.util.List;3132public class CodeCacheOptions {33public static final String SEGMENTED_CODE_CACHE = "SegmentedCodeCache";3435private static final EnumSet<BlobType> NON_SEGMENTED_HEAPS36= EnumSet.of(BlobType.All);37private static final EnumSet<BlobType> ALL_SEGMENTED_HEAPS38= EnumSet.complementOf(NON_SEGMENTED_HEAPS);39private static final EnumSet<BlobType> SEGMENTED_HEAPS_WO_PROFILED40= EnumSet.of(BlobType.NonNMethod, BlobType.MethodNonProfiled);41private static final EnumSet<BlobType> ONLY_NON_METHODS_HEAP42= EnumSet.of(BlobType.NonNMethod);4344public final long reserved;45public final long nonNmethods;46public final long nonProfiled;47public final long profiled;48public final boolean segmented;4950public static long mB(long val) {51return CodeCacheOptions.kB(val) * 1024L;52}5354public static long kB(long val) {55return val * 1024L;56}5758public CodeCacheOptions(long reserved) {59this.reserved = reserved;60this.nonNmethods = 0;61this.nonProfiled = 0;62this.profiled = 0;63this.segmented = false;64}6566public CodeCacheOptions(long reserved, long nonNmethods, long nonProfiled,67long profiled) {68this.reserved = reserved;69this.nonNmethods = nonNmethods;70this.nonProfiled = nonProfiled;71this.profiled = profiled;72this.segmented = true;73}7475public long sizeForHeap(BlobType heap) {76switch (heap) {77case All:78return this.reserved;79case NonNMethod:80return this.nonNmethods;81case MethodNonProfiled:82return this.nonProfiled;83case MethodProfiled:84return this.profiled;85default:86throw new Error("Unknown heap: " + heap.name());87}88}8990public String[] prepareOptions(String... additionalOptions) {91List<String> options = new ArrayList<>();92Collections.addAll(options, additionalOptions);93Collections.addAll(options,94CommandLineOptionTest.prepareBooleanFlag(95SEGMENTED_CODE_CACHE, segmented),96CommandLineOptionTest.prepareNumericFlag(97BlobType.All.sizeOptionName, reserved));9899if (segmented) {100Collections.addAll(options,101CommandLineOptionTest.prepareNumericFlag(102BlobType.NonNMethod.sizeOptionName, nonNmethods),103CommandLineOptionTest.prepareNumericFlag(104BlobType.MethodNonProfiled.sizeOptionName,105nonProfiled),106CommandLineOptionTest.prepareNumericFlag(107BlobType.MethodProfiled.sizeOptionName, profiled));108}109return options.toArray(new String[options.size()]);110}111112public CodeCacheOptions mapOptions(EnumSet<BlobType> involvedCodeHeaps) {113if (involvedCodeHeaps.isEmpty()114|| involvedCodeHeaps.equals(NON_SEGMENTED_HEAPS)115|| involvedCodeHeaps.equals(ALL_SEGMENTED_HEAPS)) {116return this;117} else if (involvedCodeHeaps.equals(SEGMENTED_HEAPS_WO_PROFILED)) {118return new CodeCacheOptions(reserved, nonNmethods,119profiled + nonProfiled, 0L);120} else if (involvedCodeHeaps.equals(ONLY_NON_METHODS_HEAP)) {121return new CodeCacheOptions(reserved, nonNmethods + profiled122+ nonProfiled, 0L, 0L);123} else {124throw new Error("Test bug: unexpected set of code heaps involved "125+ "into test.");126}127}128}129130131