/* * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package compiler.testlibrary; import jdk.test.lib.Asserts; import jdk.test.lib.Platform; import java.util.stream.IntStream; import sun.hotspot.WhiteBox; public class CompilerUtils { /** {@code CompLevel::CompLevel_none} -- Interpreter */ public static final int COMP_LEVEL_NONE = 0; /** {@code CompLevel::CompLevel_any}, {@code CompLevel::CompLevel_all} */ public static final int COMP_LEVEL_ANY = -1; /** {@code CompLevel::CompLevel_simple} -- C1 */ public static final int COMP_LEVEL_SIMPLE = 1; /** {@code CompLevel::CompLevel_limited_profile} -- C1, invocation & backedge counters */ public static final int COMP_LEVEL_LIMITED_PROFILE = 2; /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation & backedge counters + mdo */ public static final int COMP_LEVEL_FULL_PROFILE = 3; /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */ public static final int COMP_LEVEL_FULL_OPTIMIZATION = 4; /** Maximal value for CompLevel */ public static final int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION; private CompilerUtils() { // to prevent from instantiation } /** * Returns available compilation levels * * @return int array with compilation levels */ public static int[] getAvailableCompilationLevels() { if (!WhiteBox.getWhiteBox().getBooleanVMFlag("UseCompiler")) { return new int[0]; } if (WhiteBox.getWhiteBox().getBooleanVMFlag("TieredCompilation")) { Long flagValue = WhiteBox.getWhiteBox() .getIntxVMFlag("TieredStopAtLevel"); int maxLevel = flagValue.intValue(); Asserts.assertEQ(new Long(maxLevel), flagValue, "TieredStopAtLevel has value out of int capacity"); return IntStream.rangeClosed(1, maxLevel).toArray(); } else { if (Platform.isServer()) { return new int[]{4}; } if (Platform.isClient() || Platform.isMinimal()) { return new int[]{1}; } } return new int[0]; } }