hotspot/test/compiler/compilercontrol/parser/HugeDirectiveUtil.java
author dsamersoff
Sun, 01 May 2016 12:47:00 +0300
changeset 38152 80e5da81fb2c
parent 35129 8b93709bf4e5
child 40631 ed82623d7831
permissions -rw-r--r--
8154258: [TESTBUG] Various serviceability tests fail compilation Summary: Replace sun.misc.Unsafe with jdk.internal.misc.Unsafe Reviewed-by: chegar, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34214
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
     1
/*
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
     4
 *
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
     8
 *
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    13
 * accompanied this code).
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    14
 *
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    18
 *
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    21
 * questions.
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    22
 */
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    23
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    24
package compiler.compilercontrol.parser;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    25
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    26
import compiler.compilercontrol.share.JSONFile;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    27
import compiler.compilercontrol.share.method.MethodDescriptor;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    28
import compiler.compilercontrol.share.scenario.DirectiveWriter;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    29
import compiler.compilercontrol.share.scenario.Scenario;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    30
import jdk.test.lib.OutputAnalyzer;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    31
import jdk.test.lib.ProcessTools;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    32
import jdk.test.lib.Utils;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    33
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34214
diff changeset
    34
import java.util.EnumSet;
34214
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    35
import java.util.List;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    36
import java.util.Random;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    37
import java.util.stream.Collectors;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    38
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    39
/**
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    40
 * Creates a huge directive file
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    41
 */
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    42
public final class HugeDirectiveUtil {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    43
    private static final Random RANDOM = Utils.getRandomInstance();
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    44
    protected static final String EXPECTED_ERROR_STRING = "Parsing of compiler "
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    45
            + "directives failed";
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    46
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    47
    private HugeDirectiveUtil() { }
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    48
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    49
    /**
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    50
     * Creates huge file with specified amount of directives
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    51
     *
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    52
     * @param descriptors a list of descriptors to be randomly used
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    53
     *                    in match and inline blocks
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    54
     * @param fileName    a directives file name to be created
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    55
     * @param amount      an amount of match objects
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    56
     */
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    57
    public static void createHugeFile(List<MethodDescriptor> descriptors,
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    58
            String fileName, int amount) {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    59
        try (DirectiveWriter file = new DirectiveWriter(fileName)) {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    60
            file.write(JSONFile.Element.ARRAY);
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    61
            for (int i = 0; i < amount; i++) {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    62
                createMatchObject(descriptors, file, 1);
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    63
            }
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    64
            file.end();
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    65
        }
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    66
    }
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    67
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    68
    /**
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    69
     * Creates match object in the given file with specified size
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    70
     *
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    71
     * @param descriptors a list of method descriptors to be used
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    72
     * @param file        a directive file to write at
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    73
     * @param objectSize  a size of the match object
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    74
     */
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    75
    public static void createMatchObject(List<MethodDescriptor> descriptors,
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    76
            DirectiveWriter file, int objectSize) {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    77
        // get random amount of methods for the match
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    78
        List<String> methods = getRandomDescriptors(descriptors);
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    79
        file.match(methods.toArray(new String[methods.size()]));
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    80
        for (int i = 0; i < objectSize; i++) {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    81
            // emit compiler block
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    82
            file.emitCompiler(Utils.getRandomElement(
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    83
                    Scenario.Compiler.values()));
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34214
diff changeset
    84
            // add option inside the compiler block
34214
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    85
            file.option(Utils.getRandomElement(DirectiveWriter.Option.values()),
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    86
                    RANDOM.nextBoolean());
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    87
            file.end(); // ends compiler block
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    88
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34214
diff changeset
    89
            // add standalone option, enable can't be used standalone
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34214
diff changeset
    90
            EnumSet<DirectiveWriter.Option> options = EnumSet.complementOf(
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34214
diff changeset
    91
                    EnumSet.of(DirectiveWriter.Option.ENABLE));
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34214
diff changeset
    92
            file.option(Utils.getRandomElement(options), RANDOM.nextBoolean());
34214
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    93
        }
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    94
        // add inline block with random inlinees
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    95
        methods = getRandomDescriptors(descriptors).stream()
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    96
                .map(s -> (RANDOM.nextBoolean() ? "+" : "-") + s)
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    97
                .collect(Collectors.toList());
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34214
diff changeset
    98
        file.inline(methods);
34214
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
    99
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   100
        // end match block
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   101
        file.end();
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   102
    }
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   103
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   104
    private static List<String> getRandomDescriptors(
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   105
            List<MethodDescriptor> descriptors) {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   106
        int amount = 1 + RANDOM.nextInt(descriptors.size() - 1);
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   107
        int skipAmount = RANDOM.nextInt(descriptors.size() - amount);
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   108
        return descriptors.stream()
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   109
                .skip(skipAmount)
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   110
                .limit(amount)
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   111
                .map(MethodDescriptor::getString)
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   112
                .collect(Collectors.toList());
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   113
    }
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   114
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   115
    protected static OutputAnalyzer execute(String fileName) {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   116
        OutputAnalyzer output;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   117
        try {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   118
            output = ProcessTools.executeTestJvm(
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   119
                    "-XX:+UnlockDiagnosticVMOptions",
35129
8b93709bf4e5 8144246: adding lots of directives via jcmd may produce OOM crash
neliasso
parents: 34226
diff changeset
   120
                    "-XX:CompilerDirectivesLimit=1000",
34214
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   121
                    "-XX:CompilerDirectivesFile=" + fileName,
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   122
                    "-version");
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   123
        } catch (Throwable thr) {
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   124
            throw new Error("Execution failed with: " + thr, thr);
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   125
        }
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   126
        return output;
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   127
    }
41286f248795 8066154: JEP-JDK-8046155: Test task: huge directive file
ppunegov
parents:
diff changeset
   128
}