test/hotspot/jtreg/testlibrary/ctw/src/sun/hotspot/tools/ctw/CtwRunner.java
author iignatyev
Wed, 30 Jan 2019 09:30:40 -0800
changeset 53577 7d19ac37d7d1
parent 52866 4fd8872aebb4
child 55270 759acbfb9fde
permissions -rw-r--r--
8207922: ctw of jdk.security.auth failed with "Unexpected zero exit codebefore finishing all compilations" Reviewed-by: roland, thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
     1
/*
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
     4
 *
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
     8
 *
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    14
 *
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    18
 *
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    21
 * questions.
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    22
 */
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    23
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    24
package sun.hotspot.tools.ctw;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    25
46392
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
    26
import jdk.test.lib.Asserts;
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    27
import jdk.test.lib.Utils;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    28
import jdk.test.lib.process.ProcessTools;
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
    29
import jdk.test.lib.util.Pair;
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    30
46391
e33ea5371600 8178913: CTW library does not close all opened resources
iignatyev
parents: 46385
diff changeset
    31
import java.io.BufferedReader;
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    32
import java.io.IOException;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    33
import java.nio.file.Files;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    34
import java.nio.file.Path;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    35
import java.nio.file.Paths;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    36
import java.util.ArrayList;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    37
import java.util.List;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    38
import java.util.concurrent.TimeUnit;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    39
import java.util.function.Predicate;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    40
import java.util.regex.Pattern;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    41
import java.util.stream.Collectors;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    42
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    43
/**
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    44
 * Runs CompileTheWorld for exact one target. If an error occurs during
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    45
 * compilation of class N, this driver class saves error information and
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    46
 * restarts CTW from class N + 1. All saved errors are reported at the end.
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    47
 * <pre>
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    48
 * Usage: <target to compile>
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    49
 * </pre>
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    50
 */
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    51
public class CtwRunner {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    52
    private static final Predicate<String> IS_CLASS_LINE = Pattern.compile(
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    53
            "^\\[\\d+\\]\\s*\\S+\\s*$").asPredicate();
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    54
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    55
    private static final String USAGE = "Usage: CtwRunner <artifact to compile> [start[%] stop[%]]";
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    56
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    57
    public static void main(String[] args) throws Exception {
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    58
        CtwRunner runner;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    59
        switch (args.length) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    60
            case 1: runner = new CtwRunner(args[0]); break;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    61
            case 3: runner = new CtwRunner(args[0], args[1], args[2]); break;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    62
            default: throw new Error(USAGE);
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    63
        }
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    64
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    65
        runner.run();
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    66
    }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    67
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    68
    private final List<Throwable> errors;
47766
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    69
    private final String target;
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    70
    private final Path targetPath;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    71
    private final String targetName;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    72
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    73
    private final int start, stop;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    74
    private final boolean isStartStopPercentage;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    75
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    76
    private CtwRunner(String target, String start, String stop) {
47766
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    77
        if (target.startsWith("modules")) {
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    78
            targetPath = Paths
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    79
                    .get(Utils.TEST_JDK)
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    80
                    .resolve("lib")
47766
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    81
                    .resolve("modules");
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    82
            if (target.equals("modules")){
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    83
                target = targetPath.toString();
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    84
            }
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    85
            targetName = target.replace(':', '_')
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    86
                               .replace('.', '_')
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    87
                               .replace(',', '_');
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    88
        } else {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    89
            targetPath = Paths.get(target).toAbsolutePath();
47766
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    90
            targetName = targetPath.getFileName().toString();
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    91
        }
47766
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
    92
        this.target = target;
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
    93
        errors = new ArrayList<>();
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    94
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    95
        if (start.endsWith("%") && stop.endsWith("%")) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    96
            int startPercentage = Integer.parseInt(start.substring(0, start.length() - 1));;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    97
            int stopPercentage = Integer.parseInt(stop.substring(0, stop.length() - 1));
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    98
            if (startPercentage < 0 || startPercentage > 100 ||
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
    99
                stopPercentage < 0 || stopPercentage > 100) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   100
                throw new Error(USAGE);
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   101
            }
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   102
            this.start = startPercentage;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   103
            this.stop = stopPercentage;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   104
            this.isStartStopPercentage = true;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   105
        } else if (!start.endsWith("%") && !stop.endsWith("%")) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   106
            this.start = Integer.parseInt(start);
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   107
            this.stop = Integer.parseInt(stop);
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   108
            this.isStartStopPercentage = false;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   109
        } else {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   110
            throw new Error(USAGE);
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   111
        }
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   112
    }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   113
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   114
    private CtwRunner(String target) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   115
        this(target, "0%", "100%");
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   116
    }
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   117
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   118
    private void run() {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   119
        startCtwforAllClasses();
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   120
        if (!errors.isEmpty()) {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   121
            StringBuilder sb = new StringBuilder();
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   122
            sb.append("There were ")
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   123
              .append(errors.size())
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   124
              .append(" errors:[");
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   125
            System.err.println(sb.toString());
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   126
            for (Throwable e : errors) {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   127
                sb.append("{")
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   128
                  .append(e.getMessage())
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   129
                  .append("}");
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   130
                e.printStackTrace(System.err);
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   131
                System.err.println();
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   132
            }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   133
            sb.append("]");
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   134
            throw new AssertionError(sb.toString());
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   135
        }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   136
    }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   137
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   138
    private long start(long totalClassCount) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   139
        if (isStartStopPercentage) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   140
            return totalClassCount * start / 100;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   141
        } else if (start > totalClassCount) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   142
            System.err.println("WARNING: start [" + start + "] > totalClassCount [" + totalClassCount + "]");
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   143
            return totalClassCount;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   144
        } else {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   145
            return start;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   146
        }
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   147
    }
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   148
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   149
    private long stop(long totalClassCount) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   150
        if (isStartStopPercentage) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   151
            return totalClassCount * stop / 100;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   152
        } else if (stop > totalClassCount) {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   153
            System.err.println("WARNING: stop [" + start + "] > totalClassCount [" + totalClassCount + "]");
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   154
            return totalClassCount;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   155
        } else {
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   156
            return stop;
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   157
        }
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   158
    }
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   159
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   160
    private void startCtwforAllClasses() {
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   161
        long totalClassCount = classCount();
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   162
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   163
        long classStart = start(totalClassCount);
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   164
        long classStop = stop(totalClassCount);
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   165
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   166
        long classCount = classStop - classStart;
46392
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   167
        Asserts.assertGreaterThan(classCount, 0L,
47766
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
   168
                target + "(at " + targetPath + ") does not have any classes");
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   169
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   170
        System.out.printf("Compiling %d classes (of %d total classes) starting at %d and ending at %d\n",
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   171
                          classCount, totalClassCount, classStart, classStop);
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   172
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   173
        boolean done = false;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   174
        while (!done) {
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   175
            String[] cmd = cmd(classStart, classStop);
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   176
            try {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   177
                ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   178
                        /* addTestVmAndJavaOptions = */ true,
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   179
                        cmd);
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   180
                String commandLine = pb.command()
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   181
                        .stream()
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   182
                        .collect(Collectors.joining(" "));
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   183
                String phase = phaseName(classStart);
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   184
                Path out = Paths.get(".", phase + ".out");
48192
e5e07e9361ec 8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents: 47766
diff changeset
   185
                Path err = Paths.get(".", phase + ".err");
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   186
                System.out.printf("%s %dms START : [%s]%n" +
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   187
                        "cout/cerr are redirected to %s%n",
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   188
                        phase, TimeUnit.NANOSECONDS.toMillis(System.nanoTime()),
48192
e5e07e9361ec 8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents: 47766
diff changeset
   189
                        commandLine, phase);
e5e07e9361ec 8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents: 47766
diff changeset
   190
                int exitCode = pb.redirectOutput(out.toFile())
e5e07e9361ec 8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents: 47766
diff changeset
   191
                                 .redirectError(err.toFile())
e5e07e9361ec 8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents: 47766
diff changeset
   192
                                 .start()
e5e07e9361ec 8191273: applications/ctw/modules tests fail intermittently
iignatyev
parents: 47766
diff changeset
   193
                                 .waitFor();
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   194
                System.out.printf("%s %dms END : exit code = %d%n",
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   195
                        phase, TimeUnit.NANOSECONDS.toMillis(System.nanoTime()),
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   196
                        exitCode);
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   197
                Pair<String, Long> lastClass = getLastClass(out);
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   198
                if (exitCode == 0) {
46392
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   199
                    long lastIndex = lastClass == null ? -1 : lastClass.second;
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   200
                    if (lastIndex != classStop) {
46392
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   201
                        errors.add(new Error(phase + ": Unexpected zero exit code"
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   202
                                + "before finishing all compilations."
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   203
                                + " lastClass[" + lastIndex
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   204
                                + "] != classStop[" + classStop + "]"));
46392
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   205
                    } else {
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   206
                        System.out.println("Executed CTW for all " + classCount
47766
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
   207
                                + " classes in " + target + "(at " + targetPath + ")");
46392
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   208
                    }
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   209
                    done = true;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   210
                } else {
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   211
                    if (lastClass == null) {
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   212
                        errors.add(new Error(phase + ": failed during preload"
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   213
                                + " with classStart = " + classStart));
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   214
                        // skip one class
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   215
                        ++classStart;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   216
                    } else {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   217
                        errors.add(new Error(phase + ": failed during"
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   218
                                + " compilation of class #" + lastClass.second
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   219
                                + " : " + lastClass.first));
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   220
                        // continue with the next class
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   221
                        classStart = lastClass.second + 1;
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   222
                    }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   223
                }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   224
            } catch (Exception e) {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   225
                throw new Error("failed to run from " + classStart, e);
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   226
            }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   227
        }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   228
    }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   229
46392
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   230
    private long classCount() {
47766
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
   231
        List<PathHandler> phs = PathHandler.create(target);
46775
d0af9e47df69 8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents: 46392
diff changeset
   232
        long result = phs.stream()
d0af9e47df69 8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents: 46392
diff changeset
   233
                         .mapToLong(PathHandler::classCount)
d0af9e47df69 8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents: 46392
diff changeset
   234
                         .sum();
d0af9e47df69 8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents: 46392
diff changeset
   235
        phs.forEach(PathHandler::close);
d0af9e47df69 8184738: CTW fails with assert(!method->method_holder()->is_not_initialized()) failed: method holder must be initialized
iignatyev
parents: 46392
diff changeset
   236
        return result;
46392
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   237
    }
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   238
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   239
    private Pair<String, Long> getLastClass(Path errFile) {
46391
e33ea5371600 8178913: CTW library does not close all opened resources
iignatyev
parents: 46385
diff changeset
   240
        try (BufferedReader reader = Files.newBufferedReader(errFile)) {
e33ea5371600 8178913: CTW library does not close all opened resources
iignatyev
parents: 46385
diff changeset
   241
            String line = reader.lines()
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   242
                    .filter(IS_CLASS_LINE)
46391
e33ea5371600 8178913: CTW library does not close all opened resources
iignatyev
parents: 46385
diff changeset
   243
                    .reduce((a, b) -> b)
e33ea5371600 8178913: CTW library does not close all opened resources
iignatyev
parents: 46385
diff changeset
   244
                    .orElse(null);
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   245
            if (line != null) {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   246
                int open = line.indexOf('[') + 1;
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   247
                int close = line.indexOf(']');
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   248
                long index = Long.parseLong(line.substring(open, close));
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   249
                String name = line.substring(close + 1).trim().replace('.', '/');
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   250
                return new Pair<>(name, index);
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   251
            }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   252
        } catch (IOException ioe) {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   253
            throw new Error("can not read " + errFile + " : "
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   254
                    + ioe.getMessage(), ioe);
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   255
        }
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   256
        return null;
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   257
    }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   258
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   259
    private String[] cmd(long classStart, long classStop) {
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   260
        String phase = phaseName(classStart);
46392
d5572756efd6 8178835: CTW Runner should check that all classes have been compiled
iignatyev
parents: 46391
diff changeset
   261
        return new String[] {
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   262
                "-Xbatch",
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   263
                "-XX:-UseCounterDecay",
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   264
                "-XX:-ShowMessageBoxOnError",
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   265
                "-XX:+UnlockDiagnosticVMOptions",
53577
7d19ac37d7d1 8207922: ctw of jdk.security.auth failed with "Unexpected zero exit codebefore finishing all compilations"
iignatyev
parents: 52866
diff changeset
   266
                // redirect VM output to cerr so it won't collide w/ ctw output
7d19ac37d7d1 8207922: ctw of jdk.security.auth failed with "Unexpected zero exit codebefore finishing all compilations"
iignatyev
parents: 52866
diff changeset
   267
                "-XX:+DisplayVMOutputToStderr",
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   268
                // define phase start
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   269
                "-DCompileTheWorldStartAt=" + classStart,
49881
29419b836244 8202169: Reduce ctw_2 duration by parallelizing CtwRunner invocations
mikael
parents: 48192
diff changeset
   270
                "-DCompileTheWorldStopAt=" + classStop,
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   271
                // CTW library uses WhiteBox API
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   272
                "-XX:+WhiteBoxAPI", "-Xbootclasspath/a:.",
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   273
                // export jdk.internal packages used by CTW library
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   274
                "--add-exports", "java.base/jdk.internal.jimage=ALL-UNNAMED",
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   275
                "--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED",
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   276
                "--add-exports", "java.base/jdk.internal.reflect=ALL-UNNAMED",
52866
4fd8872aebb4 8214915: CtwRunner misses export for jdk.internal.access
iignatyev
parents: 49881
diff changeset
   277
                "--add-exports", "java.base/jdk.internal.access=ALL-UNNAMED",
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   278
                // enable diagnostic logging
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   279
                "-XX:+LogCompilation",
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   280
                // use phase specific log, hs_err and ciReplay files
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   281
                String.format("-XX:LogFile=hotspot_%s_%%p.log", phase),
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   282
                String.format("-XX:ErrorFile=hs_err_%s_%%p.log", phase),
46385
6b890c9a717f 8178727: CTW should provide class names in error messages
iignatyev
parents: 46383
diff changeset
   283
                String.format("-XX:ReplayDataFile=replay_%s_%%p.log", phase),
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   284
                // MethodHandle MUST NOT be compiled
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   285
                "-XX:CompileCommand=exclude,java/lang/invoke/MethodHandle.*",
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   286
                // CTW entry point
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   287
                CompileTheWorld.class.getName(),
47766
bfba73a06c8c 8186618: [TESTBUG] Test applications/ctw/Modules.java doesn't have timeout and hang on windows
iignatyev
parents: 47216
diff changeset
   288
                target,
46383
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   289
        };
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   290
    }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   291
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   292
    private String phaseName(long classStart) {
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   293
        return String.format("%s_%d", targetName, classStart);
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   294
    }
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   295
24999171edf9 8178291: Add CTW test for boot module
iignatyev
parents:
diff changeset
   296
}