hotspot/test/compiler/testlibrary/rtm/RTMTestBase.java
author gromero
Mon, 19 Dec 2016 18:21:59 -0800
changeset 42882 67a0b78c7b59
parent 41705 332239c052cc
permissions -rw-r--r--
8171236: RTM/HTM jtreg tests regression after transition to the new GNU-style options Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     4
 *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     8
 *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    14
 *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    18
 *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    21
 * questions.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    22
 */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    23
39438
206a712f8f16 8132920: use package in compiler testlibraries
iignatyev
parents: 30604
diff changeset
    24
package compiler.testlibrary.rtm;
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    25
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    26
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    27
import jdk.test.lib.process.ProcessTools;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 28394
diff changeset
    28
import jdk.test.lib.Utils;
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 28394
diff changeset
    29
import jdk.test.lib.cli.CommandLineOptionTest;
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    30
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    31
import java.io.IOException;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    32
import java.nio.file.Files;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    33
import java.nio.file.Paths;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    34
import java.util.Arrays;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    35
import java.util.Collections;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    36
import java.util.LinkedList;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    37
import java.util.List;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    38
import java.util.regex.Matcher;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    39
import java.util.regex.Pattern;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39438
diff changeset
    40
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    41
/**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    42
 * Auxiliary methods used for RTM testing.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    43
 */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    44
public class RTMTestBase {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    45
    private static final String RTM_STATE_CHANGE_REASON = "rtm_state_change";
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    46
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    47
     * We don't parse compilation log as XML-document and use regular
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    48
     * expressions instead, because in some cases it could be
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    49
     * malformed.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    50
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    51
    private static final String FIRED_UNCOMMON_TRAP_PATTERN_TEMPLATE
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    52
            = "<uncommon_trap thread='[0-9]+' reason='%s'";
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    53
    private static final String INSTALLED_UNCOMMON_TRAP_PATTERN_TEMPLATE
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    54
            = "<uncommon_trap bci='[0-9]+' reason='%s'";
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    55
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    56
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    57
     * Executes RTM test in a new JVM started with {@code options} cli options.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    58
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    59
     * @param test test case to execute.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    60
     * @param options additional options for VM
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    61
     * @throws Exception when something went wrong.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    62
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    63
    public static OutputAnalyzer executeRTMTest(CompilableTest test,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    64
            String... options) throws Exception {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    65
        ProcessBuilder processBuilder
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    66
                = ProcessTools.createJavaProcessBuilder(
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    67
                RTMTestBase.prepareTestOptions(test, options));
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    68
        OutputAnalyzer outputAnalyzer
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    69
                = new OutputAnalyzer(processBuilder.start());
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    70
        System.out.println(outputAnalyzer.getOutput());
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    71
        return outputAnalyzer;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    72
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    73
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    74
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    75
     * Executes test case and save compilation log to {@code logFileName}.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    76
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    77
     * @param logFileName a name of compilation log file
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    78
     * @param test a test case to execute case to execute
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    79
     * @param options additional options to VM
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    80
     * @return OutputAnalyzer for started test case
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    81
     * @throws Exception when something went wrong
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    82
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    83
    public static OutputAnalyzer executeRTMTest(String logFileName,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    84
            CompilableTest test, String... options) throws Exception {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    85
        ProcessBuilder processBuilder
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    86
                = ProcessTools.createJavaProcessBuilder(
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    87
                RTMTestBase.prepareTestOptions(logFileName, test, options));
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    88
        OutputAnalyzer outputAnalyzer
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    89
                = new OutputAnalyzer(processBuilder.start());
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    90
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    91
        System.out.println(outputAnalyzer.getOutput());
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    92
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    93
        return outputAnalyzer;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    94
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    95
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    96
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    97
     * Finds count of uncommon traps with reason {@code reason} installed
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    98
     * during compilation.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    99
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   100
     * @param compilationLogFile a path to file with LogCompilation output.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   101
     * @param reason reason of installed uncommon traps.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   102
     * @return count of installed uncommon traps with reason {@code reason}.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   103
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   104
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   105
    public static int installedUncommonTraps(String compilationLogFile,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   106
            String reason)throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   107
        String pattern = String.format(
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   108
                RTMTestBase.INSTALLED_UNCOMMON_TRAP_PATTERN_TEMPLATE,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   109
                reason);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   110
        return RTMTestBase.findTraps(compilationLogFile, pattern);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   111
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   112
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   113
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   114
     * Finds count of uncommon traps with reason <i>rtm_state_change</i>
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   115
     * installed during compilation.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   116
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   117
     * @param compilationLogFile a path to file with LogCompilation output.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   118
     * @return count of installed uncommon traps with reason
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   119
     *         <i>rtm_state_change</i>.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   120
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   121
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   122
    public static int installedRTMStateChangeTraps(String compilationLogFile)
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   123
            throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   124
        return RTMTestBase.installedUncommonTraps(compilationLogFile,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   125
                RTMTestBase.RTM_STATE_CHANGE_REASON);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   126
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   127
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   128
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   129
     * Finds count of fired uncommon traps with reason {@code reason}.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   130
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   131
     * @param compilationLogFile a path to file with LogCompilation output.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   132
     * @param reason a reason of fired uncommon traps.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   133
     * @return count of fired uncommon traps with reason {@code reason}.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   134
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   135
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   136
    public static int firedUncommonTraps(String compilationLogFile,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   137
            String reason) throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   138
        String pattern = String.format(
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   139
                RTMTestBase.FIRED_UNCOMMON_TRAP_PATTERN_TEMPLATE,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   140
                reason);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   141
        return RTMTestBase.findTraps(compilationLogFile, pattern);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   142
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   143
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   144
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   145
     * Finds count of fired uncommon traps with reason <i>rtm_state_change</i>.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   146
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   147
     * @param compilationLogFile a path to file with LogCompilation output.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   148
     * @return count of fired uncommon traps with reason
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   149
     *         <i>rtm_state_change</i>.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   150
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   151
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   152
    public static int firedRTMStateChangeTraps(String compilationLogFile)
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   153
            throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   154
        return RTMTestBase.firedUncommonTraps(compilationLogFile,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   155
                RTMTestBase.RTM_STATE_CHANGE_REASON);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   156
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   157
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   158
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   159
     * Finds count of uncommon traps that matches regular
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   160
     * expression in {@code re}.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   161
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   162
     * @param compilationLogFile a path to file with LogCompilation output.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   163
     * @param re regular expression to match uncommon traps.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   164
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   165
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   166
    private static int findTraps(String compilationLogFile, String re)
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   167
            throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   168
        String compilationLog = RTMTestBase.fileAsString(compilationLogFile);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   169
        Pattern pattern = Pattern.compile(re);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   170
        Matcher matcher = pattern.matcher(compilationLog);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   171
        int traps = 0;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   172
        while (matcher.find()) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   173
            traps++;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   174
        }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   175
        return traps;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   176
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   177
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   178
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   179
     * Returns file's content as a string.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   180
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   181
     * @param path a path to file to operate on.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   182
     * @return string with content of file.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   183
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   184
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   185
    private static String fileAsString(String path) throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   186
        byte[] fileAsBytes = Files.readAllBytes(Paths.get(path));
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   187
        return new String(fileAsBytes);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   188
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   189
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   190
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   191
     * Prepares VM options for test execution.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   192
     * This method get test java options, filter out all RTM-related options,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   193
     * adds CompileCommand=compileonly,method_name options for each method
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   194
     * from {@code methodToCompile} and finally appends all {@code vmOpts}.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   195
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   196
     * @param test test case whose methods that should be compiled.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   197
     *             If {@code null} then no additional <i>compileonly</i>
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   198
     *             commands will be added to VM options.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   199
     * @param vmOpts additional options to pass to VM.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   200
     * @return Array with VM options.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   201
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   202
    private static String[] prepareTestOptions(CompilableTest test,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   203
            String... vmOpts) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   204
        return RTMTestBase.prepareFilteredTestOptions(test, null, vmOpts);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   205
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   206
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   207
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   208
     * Prepares VM options for test execution.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   209
     * This method get test java options, filter out all RTM-related options
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   210
     * and all options that matches regexps in {@code additionalFilters},
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   211
     * adds CompileCommand=compileonly,method_name options for each method
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   212
     * from {@code methodToCompile} and finally appends all {@code vmOpts}.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   213
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   214
     * @param test test case whose methods that should be compiled.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   215
     *             If {@code null} then no additional <i>compileonly</i>
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   216
     *             commands will be added to VM options.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   217
     * @param additionalFilters array with regular expression that will be
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   218
     *                          used to filter out test java options.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   219
     *                          If {@code null} then no additional filters
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   220
     *                          will be used.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   221
     * @param vmOpts additional options to pass to VM.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   222
     * @return array with VM options.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   223
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   224
    private static String[] prepareFilteredTestOptions(CompilableTest test,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   225
            String[] additionalFilters, String... vmOpts) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   226
        List<String> finalVMOpts = new LinkedList<>();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   227
        String[] filters;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   228
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   229
        if (additionalFilters != null) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   230
            filters = Arrays.copyOf(additionalFilters,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   231
                    additionalFilters.length + 1);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   232
        } else {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   233
            filters = new String[1];
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   234
        }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   235
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   236
        filters[filters.length - 1] = "RTM";
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   237
        String[] filteredVMOpts = Utils.getFilteredTestJavaOpts(filters);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   238
        Collections.addAll(finalVMOpts, filteredVMOpts);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   239
        Collections.addAll(finalVMOpts, "-Xcomp", "-server",
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   240
                "-XX:-TieredCompilation", "-XX:+UseRTMLocking",
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   241
                CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
28394
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   242
                CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
41320
01ba89ffe494 8164987: RTM jtreg tests failing due to unnamed module unable to access class jdk.internal.misc.Unsafe
gromero
parents: 40631
diff changeset
   243
                "-Xbootclasspath/a:.", "-XX:+WhiteBoxAPI",
42882
67a0b78c7b59 8171236: RTM/HTM jtreg tests regression after transition to the new GNU-style options
gromero
parents: 41705
diff changeset
   244
                "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED");
24005
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   245
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   246
        if (test != null) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   247
            for (String method : test.getMethodsToCompileNames()) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   248
                finalVMOpts.add("-XX:CompileCommand=compileonly," + method);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   249
            }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   250
        }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   251
        Collections.addAll(finalVMOpts, vmOpts);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   252
        return finalVMOpts.toArray(new String[finalVMOpts.size()]);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   253
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   254
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   255
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   256
     * Adds additional options for VM required for successful execution of test.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   257
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   258
     * @param logFileName a name of compilation log file
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   259
     * @param test a test case to execute
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   260
     * @param options additional options to VM
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   261
     * @return an array with VM options
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   262
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   263
    private static String[] prepareTestOptions(String logFileName,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   264
            CompilableTest test, String... options) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   265
        String[] preparedOptions = RTMTestBase.prepareFilteredTestOptions(
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   266
                test,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   267
                new String[] {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   268
                        "LogCompilation",
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   269
                        "LogFile"
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   270
                });
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   271
        List<String> updatedOptions = new LinkedList<>();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   272
        Collections.addAll(updatedOptions, preparedOptions);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   273
        Collections.addAll(updatedOptions,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   274
                "-XX:+LogCompilation",
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   275
                "-XX:LogFile=" + logFileName);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   276
        Collections.addAll(updatedOptions, options);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   277
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   278
        return updatedOptions.toArray(new String[updatedOptions.size()]);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   279
    }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   280
}