Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/launcher/Settings.java
38833 views
/*1* Copyright (c) 2010, 2012, 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*/22import java.io.File;23import java.io.IOException;2425/*26* @test27* @bug 6994753 712358228* @summary tests -XshowSettings options29* @compile -XDignore.symbol.file Settings.java30* @run main Settings31* @author ksrini32*/33public class Settings extends TestHelper {34private static File testJar = null;3536static void init() throws IOException {37if (testJar != null) {38return;39}40testJar = new File("test.jar");41StringBuilder tsrc = new StringBuilder();42tsrc.append("public static void main(String... args) {\n");43tsrc.append(" for (String x : args) {\n");44tsrc.append(" System.out.println(x);\n");45tsrc.append(" }\n");46tsrc.append("}\n");47createJar(testJar, tsrc.toString());48}4950static void checkContains(TestResult tr, String str) {51if (!tr.contains(str)) {52System.out.println(tr);53throw new RuntimeException(str + " not found");54}55}5657static void checkNoContains(TestResult tr, String str) {58if (tr.contains(str)) {59System.out.println(tr.status);60throw new RuntimeException(str + " found");61}62}6364private static final String VM_SETTINGS = "VM settings:";65private static final String PROP_SETTINGS = "Property settings:";66private static final String LOCALE_SETTINGS = "Locale settings:";67private static final String STACKSIZE_SETTINGS = "Stack Size:";68private static final String SYSTEM_SETTINGS = "Operating System Metrics:";6970static void containsAllOptions(TestResult tr) {71checkContains(tr, VM_SETTINGS);72checkContains(tr, PROP_SETTINGS);73checkContains(tr, LOCALE_SETTINGS);74if (System.getProperty("os.name").contains("Linux")) {75checkContains(tr, SYSTEM_SETTINGS);76}77}7879static void runTestOptionDefault() throws IOException {80String stackSize = "256"; // in kb81if (getArch().equals("ppc64") || getArch().equals("ppc64le")) {82stackSize = "800";83} else if (getArch().equals("aarch64")) {84/*85* The max value of minimum stack size allowed for aarch64 can be estimated as86* such: suppose the vm page size is 64KB and the test runs with a debug build,87* the initial _java_thread_min_stack_allowed defined in os_linux_aarch64.cpp is88* 72K, stack guard zones could take 192KB, and the shadow zone needs 128KB,89* after aligning up all parts to the page size, the final size would be 448KB.90* See details in JDK-816336391*/92stackSize = "448";93}94TestResult tr = null;95tr = doExec(javaCmd, "-Xms64m", "-Xmx512m",96"-Xss" + stackSize + "k", "-XshowSettings", "-jar", testJar.getAbsolutePath());97// Check the stack size logs printed by -XshowSettings to verify -Xss meaningfully.98checkContains(tr, STACKSIZE_SETTINGS);99containsAllOptions(tr);100if (!tr.isOK()) {101System.out.println(tr.status);102throw new RuntimeException("test fails");103}104tr = doExec(javaCmd, "-Xms65536k", "-Xmx712m",105"-Xss" + stackSize + "000", "-XshowSettings", "-jar", testJar.getAbsolutePath());106checkContains(tr, STACKSIZE_SETTINGS);107containsAllOptions(tr);108if (!tr.isOK()) {109System.out.println(tr.status);110throw new RuntimeException("test fails");111}112}113114static void runTestOptionSystem() throws IOException {115TestResult tr = doExec(javaCmd, "-XshowSettings:system");116if (System.getProperty("os.name").contains("Linux")) {117checkNoContains(tr, VM_SETTINGS);118checkNoContains(tr, PROP_SETTINGS);119checkNoContains(tr, LOCALE_SETTINGS);120checkContains(tr, SYSTEM_SETTINGS);121} else {122// -XshowSettings prints all available settings when123// settings argument is not recognized.124containsAllOptions(tr);125}126}127128static void runTestOptionAll() throws IOException {129init();130TestResult tr = null;131tr = doExec(javaCmd, "-XshowSettings:all");132containsAllOptions(tr);133}134135static void runTestOptionVM() throws IOException {136TestResult tr = null;137tr = doExec(javaCmd, "-XshowSettings:vm");138checkContains(tr, VM_SETTINGS);139checkNoContains(tr, PROP_SETTINGS);140checkNoContains(tr, LOCALE_SETTINGS);141}142143static void runTestOptionProperty() throws IOException {144TestResult tr = null;145tr = doExec(javaCmd, "-XshowSettings:properties");146checkNoContains(tr, VM_SETTINGS);147checkContains(tr, PROP_SETTINGS);148checkNoContains(tr, LOCALE_SETTINGS);149}150151static void runTestOptionLocale() throws IOException {152TestResult tr = null;153tr = doExec(javaCmd, "-XshowSettings:locale");154checkNoContains(tr, VM_SETTINGS);155checkNoContains(tr, PROP_SETTINGS);156checkContains(tr, LOCALE_SETTINGS);157}158159static void runTestBadOptions() throws IOException {160TestResult tr = null;161tr = doExec(javaCmd, "-XshowSettingsBadOption");162checkNoContains(tr, VM_SETTINGS);163checkNoContains(tr, PROP_SETTINGS);164checkNoContains(tr, LOCALE_SETTINGS);165checkContains(tr, "Unrecognized option: -XshowSettingsBadOption");166}167168static void runTest7123582() throws IOException {169TestResult tr = null;170tr = doExec(javaCmd, "-XshowSettings", "-version");171if (!tr.isOK()) {172System.out.println(tr.status);173throw new RuntimeException("test fails");174}175containsAllOptions(tr);176}177178public static void main(String... args) {179try {180runTestOptionAll();181runTestOptionDefault();182runTestOptionVM();183runTestOptionProperty();184runTestOptionLocale();185runTestOptionSystem();186runTestBadOptions();187runTest7123582();188} catch (IOException ioe) {189throw new RuntimeException(ioe);190}191}192}193194195