jdk/test/tools/launcher/TestSpecialArgs.java
author ksrini
Sat, 07 Mar 2015 15:21:36 -0800
changeset 29373 8f41a04d1a02
parent 29114 a9b39a645e85
child 37540 e92d95400f31
permissions -rw-r--r--
8074373: NMT is not enabled if NMT option is specified after class path specifiers Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     1
/*
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     4
 *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     7
 * published by the Free Software Foundation.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     8
 *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    13
 * accompanied this code).
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    14
 *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    18
 *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    21
 * questions.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    22
 */
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    23
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    24
/*
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    25
 * @test
29373
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
    26
 * @bug 7124089 7131021 8042469 8066185 8074373
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    27
 * @summary Checks for Launcher special flags, such as MacOSX specific flags,
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    28
 *          and JVM NativeMemoryTracking flags.
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    29
 * @compile -XDignore.symbol.file TestSpecialArgs.java EnvironmentVariables.java
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    30
 * @run main TestSpecialArgs
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    31
 */
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    32
import java.io.File;
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    33
import java.io.FileNotFoundException;
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    34
import java.util.HashMap;
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    35
import java.util.HashSet;
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    36
import java.util.Map;
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    37
import java.util.Set;
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    38
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    39
public class TestSpecialArgs extends TestHelper {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    40
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    41
    public static void main(String... args) throws Exception {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    42
        new TestSpecialArgs().run(args);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    43
    }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    44
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    45
    @Test
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    46
    void testDocking() {
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    47
        final Map<String, String> envMap = new HashMap<>();
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    48
        envMap.put("_JAVA_LAUNCHER_DEBUG", "true");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    49
        TestResult tr = doExec(envMap, javaCmd, "-XstartOnFirstThread", "-version");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    50
        if (isMacOSX) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    51
            if (!tr.contains("In same thread")) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    52
                System.out.println(tr);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    53
                throw new RuntimeException("Error: not running in the same thread ?");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    54
            }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    55
            if (!tr.isOK()) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    56
                System.out.println(tr);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    57
                throw new RuntimeException("Error: arg was rejected ????");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    58
            }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    59
        } else {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    60
            if (tr.isOK()) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    61
                System.out.println(tr);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    62
                throw new RuntimeException("Error: argument was accepted ????");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    63
            }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    64
        }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    65
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    66
        tr = doExec(javaCmd, "-Xdock:/tmp/not-available", "-version");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    67
        if (isMacOSX) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    68
            if (!tr.isOK()) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    69
                System.out.println(tr);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    70
                throw new RuntimeException("Error: arg was rejected ????");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    71
            }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    72
        } else {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    73
            if (tr.isOK()) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    74
                System.out.println(tr);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    75
                throw new RuntimeException("Error: argument was accepted ????");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    76
            }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    77
        }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    78
        // MacOSX specific tests ensue......
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    79
        if (!isMacOSX) {
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    80
            return;
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
    81
        }
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    82
        Set<String> envToRemove = new HashSet<>();
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    83
        Map<String, String> map = System.getenv();
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    84
        for (String s : map.keySet()) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    85
            if (s.startsWith("JAVA_MAIN_CLASS_")
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    86
                    || s.startsWith("APP_NAME_")
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    87
                    || s.startsWith("APP_ICON_")) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    88
                envToRemove.add(s);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    89
            }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    90
        }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    91
        runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    92
                "EnvironmentVariables", "JAVA_MAIN_CLASS_*",
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    93
                "EnvironmentVariables");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    94
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    95
        runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    96
                "-Xdock:name=TestAppName", "EnvironmentVariables",
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    97
                "APP_NAME_*", "TestAppName");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    98
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
    99
        runTest(envToRemove, javaCmd, "-cp", TEST_CLASSES_DIR.getAbsolutePath(),
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   100
                "-Xdock:icon=TestAppIcon", "EnvironmentVariables",
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   101
                "APP_ICON_*", "TestAppIcon");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   102
    }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   103
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   104
    void runTest(Set<String> envToRemove, String... args) {
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   105
        TestResult tr = doExec(null, envToRemove, args);
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   106
        if (!tr.isOK()) {
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   107
            System.err.println(tr.toString());
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   108
            throw new RuntimeException("Test Fails");
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   109
        }
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   110
    }
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   111
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   112
    @Test
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   113
    void testNativeMemoryTracking() {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   114
        final Map<String, String> envMap = new HashMap<>();
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   115
        envMap.put("_JAVA_LAUNCHER_DEBUG", "true");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   116
        TestResult tr;
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   117
        /*
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   118
         * test argument : -XX:NativeMemoryTracking=value
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   119
         * A JVM flag, comsumed by the JVM, but requiring launcher
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   120
         * to set an environmental variable if and only if value is supplied.
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   121
         * Test and order:
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   122
         * 1) execute with valid parameter: -XX:NativeMemoryTracking=MyValue
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   123
         *    a) check for correct env variable name: "NMT_LEVEL_" + pid
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   124
         *    b) check that "MyValue" was found in local env.
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   125
         * 2) execute with invalid parameter: -XX:NativeMemoryTracking=
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   126
         *    !) Won't find "NativeMemoryTracking:"
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   127
         *       Code to create env variable not executed.
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   128
         * 3) execute with invalid parameter: -XX:NativeMemoryTracking
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   129
         *    !) Won't find "NativeMemoryTracking:"
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   130
         *       Code to create env variable not executed.
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   131
         * 4) give and invalid value and check to make sure JVM commented
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   132
         */
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   133
        String launcherPidString = "launcher.pid=";
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   134
        String envVarPidString = "TRACER_MARKER: NativeMemoryTracking: env var is NMT_LEVEL_";
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   135
        String NMT_Option_Value = "off";
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   136
        String myClassName = "helloworld";
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   137
        boolean haveLauncherPid = false;
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   138
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   139
        // === Run the tests ===
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   140
        // ---Test 1a
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   141
        tr = doExec(envMap, javaCmd, "-XX:NativeMemoryTracking=" + NMT_Option_Value,
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   142
                "-version");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   143
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   144
        // get the PID from the env var we set for the JVM
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   145
        String envVarPid = null;
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   146
        for (String line : tr.testOutput) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   147
            if (line.contains(envVarPidString)) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   148
                int sindex = envVarPidString.length();
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   149
                envVarPid = line.substring(sindex);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   150
                break;
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   151
            }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   152
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   153
        // did we find envVarPid?
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   154
        if (envVarPid == null) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   155
            System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   156
            throw new RuntimeException("Error: failed to find env Var Pid in tracking info");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   157
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   158
        // we think we found the pid string.  min test, not "".
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   159
        if (envVarPid.length() < 1) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   160
            System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   161
            throw new RuntimeException("Error: env Var Pid in tracking info is empty string");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   162
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   163
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   164
        /*
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   165
         * On Linux, Launcher Tracking will print the PID.  Use this info
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   166
         * to validate what we got as the PID in the Launcher itself.
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   167
         * Linux is the only one that prints this, and trying to get it
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   168
         * here for win is awful.  So let the linux test make sure we get
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   169
         * the valid pid, and for non-linux, just make sure pid string is
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   170
         * non-zero.
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   171
         */
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   172
        if (isLinux) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   173
            // get what the test says is the launcher pid
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   174
            String launcherPid = null;
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   175
            for (String line : tr.testOutput) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   176
                int index = line.indexOf(launcherPidString);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   177
                if (index >= 0) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   178
                    int sindex = index + launcherPidString.length();
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   179
                    int tindex = sindex + line.substring(sindex).indexOf("'");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   180
                    System.out.println("DEBUG INFO: sindex = " + sindex);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   181
                    System.out.println("DEBUG INFO: searching substring: " + line.substring(sindex));
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   182
                    System.out.println("DEBUG INFO: tindex = " + tindex);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   183
                    // DEBUG INFO
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   184
                    System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   185
                    launcherPid = line.substring(sindex, tindex);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   186
                    break;
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   187
                }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   188
            }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   189
            if (launcherPid == null) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   190
                System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   191
                throw new RuntimeException("Error: failed to find launcher Pid in launcher tracking info");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   192
            }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   193
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   194
            // did we create the env var with the correct pid?
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   195
            if (!launcherPid.equals(envVarPid)) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   196
                System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   197
                System.out.println("Error: wrong pid in creating env var");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   198
                System.out.println("Error Info: launcherPid = " + launcherPid);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   199
                System.out.println("Error Info: envVarPid   = " + envVarPid);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   200
                throw new RuntimeException("Error: wrong pid in creating env var");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   201
            }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   202
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   203
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   204
        // --- Test 1b
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   205
        if (!tr.contains("NativeMemoryTracking: got value " + NMT_Option_Value)) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   206
            System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   207
            throw new RuntimeException("Error: Valid param failed to set env variable");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   208
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   209
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   210
        // --- Test 2
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   211
        tr = doExec(envMap, javaCmd, "-XX:NativeMemoryTracking=",
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   212
                "-version");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   213
        if (tr.contains("NativeMemoryTracking:")) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   214
            System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   215
            throw new RuntimeException("Error: invalid param caused env variable to be erroneously created");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   216
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   217
        if (!tr.contains("Syntax error, expecting -XX:NativeMemoryTracking=")) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   218
            System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   219
            throw new RuntimeException("Error: invalid param not checked by JVM");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   220
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   221
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   222
        // --- Test 3
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   223
        tr = doExec(envMap, javaCmd, "-XX:NativeMemoryTracking",
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   224
                "-version");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   225
        if (tr.contains("NativeMemoryTracking:")) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   226
            System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   227
            throw new RuntimeException("Error: invalid param caused env variable to be erroneously created");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   228
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   229
        if (!tr.contains("Syntax error, expecting -XX:NativeMemoryTracking=")) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   230
            System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   231
            throw new RuntimeException("Error: invalid param not checked by JVM");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   232
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   233
        // --- Test 4
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   234
        tr = doExec(envMap, javaCmd, "-XX:NativeMemoryTracking=BADVALUE",
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   235
                "-version");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   236
        if (!tr.contains("expecting -XX:NativeMemoryTracking")) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   237
            System.out.println(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   238
            throw new RuntimeException("Error: invalid param did not get JVM Syntax error message");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   239
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   240
    }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   241
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   242
    @Test
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   243
    void testNMArgumentProcessing() throws FileNotFoundException {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   244
        TestResult tr = null;
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   245
        // the direct invokers of the VM
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   246
        String options[] = {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   247
            "-version", "-fullversion", "-help", "-?", "-X"
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   248
        };
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   249
        for (String option : options) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   250
            tr = doExec(javaCmd, option, "-XX:NativeMemoryTracking=summary");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   251
            checkTestResult(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   252
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   253
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   254
        // create a test jar
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   255
        File jarFile = new File("test.jar");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   256
        createJar(jarFile, "public static void main(String... args){}");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   257
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   258
        // ones that involve main-class of some sort
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   259
        tr = doExec(javaCmd, "-jar", jarFile.getName(),
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   260
                "-XX:NativeMemoryTracking=summary");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   261
        checkTestResult(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   262
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   263
        tr = doExec(javaCmd, "-cp", jarFile.getName(), "Foo",
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   264
                "-XX:NativeMemoryTracking=summary");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   265
        checkTestResult(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   266
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   267
        final Map<String, String> envMap = new HashMap<>();
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   268
        // checkwith CLASSPATH set ie. no -cp or -classpath
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   269
        envMap.put("CLASSPATH", ".");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   270
        tr = doExec(envMap, javaCmd, "Foo", "-XX:NativeMemoryTracking=summary");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   271
        checkTestResult(tr);
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   272
29373
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   273
        // should accept with no warnings
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   274
        tr = doExec(javaCmd, "-cp", jarFile.getName(),
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   275
                    "-XX:NativeMemoryTracking=summary", "Foo");
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   276
        ensureNoWarnings(tr);
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   277
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   278
        // should accept with no warnings
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   279
        tr = doExec(javaCmd, "-classpath", jarFile.getName(),
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   280
                    "-XX:NativeMemoryTracking=summary", "Foo");
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   281
        ensureNoWarnings(tr);
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   282
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   283
        // make sure a missing class is handled correctly, because the class
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   284
        // resolution is performed by the JVM.
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   285
        tr = doExec(javaCmd, "AbsentClass", "-XX:NativeMemoryTracking=summary");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   286
        if (!tr.contains("Error: Could not find or load main class AbsentClass")) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   287
            throw new RuntimeException("Test Fails");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   288
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   289
    }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   290
29373
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   291
    void ensureNoWarnings(TestResult tr) {
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   292
        checkTestResult(tr);
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   293
        if (tr.contains("warning: Native Memory Tracking")) {
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   294
            System.err.println(tr.toString());
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   295
            throw new RuntimeException("Test Fails");
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   296
        }
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   297
    }
8f41a04d1a02 8074373: NMT is not enabled if NMT option is specified after class path specifiers
ksrini
parents: 29114
diff changeset
   298
29114
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   299
    void checkTestResult(TestResult tr) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   300
        if (!tr.isOK()) {
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   301
            System.err.println(tr.toString());
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   302
            throw new RuntimeException("Test Fails");
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   303
        }
a9b39a645e85 8066185: VM crashed with SIGSEGV VirtualMemoryTracker::add_reserved_region
ksrini
parents: 25816
diff changeset
   304
    }
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents:
diff changeset
   305
}