hotspot/test/compiler/testlibrary/rtm/RTMTestBase.java
author fzhinkin
Tue, 30 Dec 2014 11:09:42 +0300
changeset 28394 6d382dc493e5
parent 24005 6841a4be0faa
child 30604 b8d532cb6420
permissions -rw-r--r--
8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization Reviewed-by: kvn, iignatyev
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
/*
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
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
 */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    24
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    25
package rtm;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    26
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    27
import java.io.IOException;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    28
import java.nio.file.Files;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    29
import java.nio.file.Paths;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    30
import java.util.List;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    31
import java.util.LinkedList;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    32
import java.util.Arrays;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    33
import java.util.Collections;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    34
import java.util.regex.Matcher;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    35
import java.util.regex.Pattern;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    36
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    37
import com.oracle.java.testlibrary.OutputAnalyzer;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    38
import com.oracle.java.testlibrary.ProcessTools;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    39
import com.oracle.java.testlibrary.Utils;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    40
import com.oracle.java.testlibrary.cli.CommandLineOptionTest;
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
/**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    43
 * Auxiliary methods used for RTM testing.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    44
 */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    45
public class RTMTestBase {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    46
    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
    47
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    48
     * 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
    49
     * 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
    50
     * malformed.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    51
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    52
    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
    53
            = "<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
    54
    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
    55
            = "<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
    56
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    57
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    58
     * 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
    59
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    60
     * @param test test case to execute.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    61
     * @param options additional options for VM
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    62
     * @throws Exception when something went wrong.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    63
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    64
    public static OutputAnalyzer executeRTMTest(CompilableTest test,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    65
            String... options) throws Exception {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    66
        ProcessBuilder processBuilder
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    67
                = ProcessTools.createJavaProcessBuilder(
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    68
                RTMTestBase.prepareTestOptions(test, options));
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    69
        OutputAnalyzer outputAnalyzer
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    70
                = new OutputAnalyzer(processBuilder.start());
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    71
        System.out.println(outputAnalyzer.getOutput());
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    72
        return outputAnalyzer;
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
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    76
     * 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
    77
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    78
     * @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
    79
     * @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
    80
     * @param options additional options to VM
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    81
     * @return OutputAnalyzer for started test case
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    82
     * @throws Exception when something went wrong
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    83
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    84
    public static OutputAnalyzer executeRTMTest(String logFileName,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    85
            CompilableTest test, String... options) throws Exception {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    86
        ProcessBuilder processBuilder
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    87
                = ProcessTools.createJavaProcessBuilder(
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    88
                RTMTestBase.prepareTestOptions(logFileName, test, options));
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    89
        OutputAnalyzer outputAnalyzer
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    90
                = new OutputAnalyzer(processBuilder.start());
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    91
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    92
        System.out.println(outputAnalyzer.getOutput());
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    93
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    94
        return outputAnalyzer;
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
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
    98
     * 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
    99
     * during compilation.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   100
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   101
     * @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
   102
     * @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
   103
     * @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
   104
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   105
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   106
    public static int installedUncommonTraps(String compilationLogFile,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   107
            String reason)throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   108
        String pattern = String.format(
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   109
                RTMTestBase.INSTALLED_UNCOMMON_TRAP_PATTERN_TEMPLATE,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   110
                reason);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   111
        return RTMTestBase.findTraps(compilationLogFile, pattern);
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
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   115
     * 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
   116
     * installed during compilation.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   117
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   118
     * @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
   119
     * @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
   120
     *         <i>rtm_state_change</i>.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   121
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   122
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   123
    public static int installedRTMStateChangeTraps(String compilationLogFile)
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   124
            throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   125
        return RTMTestBase.installedUncommonTraps(compilationLogFile,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   126
                RTMTestBase.RTM_STATE_CHANGE_REASON);
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
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   130
     * 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
   131
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   132
     * @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
   133
     * @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
   134
     * @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
   135
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   136
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   137
    public static int firedUncommonTraps(String compilationLogFile,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   138
            String reason) throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   139
        String pattern = String.format(
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   140
                RTMTestBase.FIRED_UNCOMMON_TRAP_PATTERN_TEMPLATE,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   141
                reason);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   142
        return RTMTestBase.findTraps(compilationLogFile, pattern);
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
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   146
     * 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
   147
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   148
     * @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
   149
     * @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
   150
     *         <i>rtm_state_change</i>.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   151
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   152
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   153
    public static int firedRTMStateChangeTraps(String compilationLogFile)
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   154
            throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   155
        return RTMTestBase.firedUncommonTraps(compilationLogFile,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   156
                RTMTestBase.RTM_STATE_CHANGE_REASON);
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
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   160
     * 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
   161
     * expression in {@code re}.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   162
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   163
     * @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
   164
     * @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
   165
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   166
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   167
    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
   168
            throws IOException {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   169
        String compilationLog = RTMTestBase.fileAsString(compilationLogFile);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   170
        Pattern pattern = Pattern.compile(re);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   171
        Matcher matcher = pattern.matcher(compilationLog);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   172
        int traps = 0;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   173
        while (matcher.find()) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   174
            traps++;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   175
        }
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   176
        return traps;
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
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   180
     * 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
   181
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   182
     * @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
   183
     * @return string with content of file.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   184
     * @throws IOException
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   185
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   186
    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
   187
        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
   188
        return new String(fileAsBytes);
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
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   192
     * Prepares VM options for test execution.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   193
     * 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
   194
     * 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
   195
     * 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
   196
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   197
     * @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
   198
     *             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
   199
     *             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
   200
     * @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
   201
     * @return Array with VM options.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   202
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   203
    private static String[] prepareTestOptions(CompilableTest test,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   204
            String... vmOpts) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   205
        return RTMTestBase.prepareFilteredTestOptions(test, null, vmOpts);
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
    /**
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   209
     * Prepares VM options for test execution.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   210
     * 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
   211
     * 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
   212
     * 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
   213
     * 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
   214
     *
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   215
     * @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
   216
     *             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
   217
     *             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
   218
     * @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
   219
     *                          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
   220
     *                          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
   221
     *                          will be used.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   222
     * @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
   223
     * @return array with VM options.
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   224
     */
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   225
    private static String[] prepareFilteredTestOptions(CompilableTest test,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   226
            String[] additionalFilters, String... vmOpts) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   227
        List<String> finalVMOpts = new LinkedList<>();
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   228
        String[] filters;
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   229
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   230
        if (additionalFilters != null) {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   231
            filters = Arrays.copyOf(additionalFilters,
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   232
                    additionalFilters.length + 1);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   233
        } else {
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   234
            filters = new String[1];
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
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   237
        filters[filters.length - 1] = "RTM";
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   238
        String[] filteredVMOpts = Utils.getFilteredTestJavaOpts(filters);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   239
        Collections.addAll(finalVMOpts, filteredVMOpts);
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   240
        Collections.addAll(finalVMOpts, "-Xcomp", "-server",
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   241
                "-XX:-TieredCompilation", "-XX:+UseRTMLocking",
6841a4be0faa 8039499: Add all common classes used by tests on RTM support to testlibrary
iignatyev
parents:
diff changeset
   242
                CommandLineOptionTest.UNLOCK_DIAGNOSTIC_VM_OPTIONS,
28394
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   243
                CommandLineOptionTest.UNLOCK_EXPERIMENTAL_VM_OPTIONS,
6d382dc493e5 8050486: compiler/rtm/ tests fail due to monitor deflation at safepoint synchronization
fzhinkin
parents: 24005
diff changeset
   244
                "-Xbootclasspath/a:.", "-XX:+WhiteBoxAPI");
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
}