hotspot/test/compiler/compilercontrol/share/scenario/DirectiveBuilder.java
author tpivovarova
Tue, 12 Jul 2016 18:24:48 +0300
changeset 40059 c2304140ed64
parent 34226 db9dea22fbfc
child 40631 ed82623d7831
permissions -rw-r--r--
8132919: Put compiler tests in packages Reviewed-by: vlivanov, dpochepk Contributed-by: igor.ignatyev@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     1
/*
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     4
 *
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     8
 *
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    13
 * accompanied this code).
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    14
 *
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    18
 *
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    21
 * questions.
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    22
 */
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    23
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    24
package compiler.compilercontrol.share.scenario;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    25
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    26
import compiler.compilercontrol.share.JSONFile;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    27
import compiler.compilercontrol.share.method.MethodDescriptor;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    28
import compiler.compilercontrol.share.method.MethodGenerator;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 34226
diff changeset
    29
import compiler.compilercontrol.share.pool.PoolHelper;
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    30
import jdk.test.lib.Pair;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    31
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    32
import java.lang.reflect.Executable;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    33
import java.util.ArrayList;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    34
import java.util.HashMap;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    35
import java.util.LinkedHashMap;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 34226
diff changeset
    36
import java.util.List;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 34226
diff changeset
    37
import java.util.Map;
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    38
import java.util.concurrent.Callable;
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 33452
diff changeset
    39
import java.util.stream.Collectors;
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    40
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    41
/**
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    42
 * Directive file and state builder class
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    43
 */
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    44
public class DirectiveBuilder implements StateBuilder<CompileCommand> {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    45
    private static final List<Pair<Executable, Callable<?>>> METHODS
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    46
            = new PoolHelper().getAllMethods();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    47
    private final Map<Executable, State> stateMap = new HashMap<>();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    48
    private final String fileName;
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    49
    private final Map<MethodDescriptor, List<CompileCommand>> matchBlocks
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    50
            = new LinkedHashMap<>();
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    51
    private final List<CompileCommand> inlines = new ArrayList<>();
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    52
    private boolean isFileValid = true;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    53
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    54
    public DirectiveBuilder(String fileName) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    55
        this.fileName = fileName;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    56
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    57
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    58
    @Override
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    59
    public List<String> getOptions() {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    60
        List<String> options = new ArrayList<>();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    61
        if (!matchBlocks.isEmpty()) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    62
            // add option only if there are any directive available
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    63
            options.add("-XX:CompilerDirectivesFile=" + fileName);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    64
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    65
        return options;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    66
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    67
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    68
    @Override
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    69
    public List<CompileCommand> getCompileCommands() {
34216
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 33452
diff changeset
    70
        return matchBlocks.keySet().stream()
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 33452
diff changeset
    71
                // only method descriptor is required to check print_directives
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 33452
diff changeset
    72
                .map(md -> new CompileCommand(null, md, null, null))
2818af1ce748 8138993: JEP-JDK-8046155: Test task: add check for Compiler.directives_print diagnostic command
ppunegov
parents: 33452
diff changeset
    73
                .collect(Collectors.toList());
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    74
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    75
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    76
    @Override
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    77
    public boolean isValid() {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    78
        // Invalid directives file makes VM exit with error code
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    79
        return isFileValid;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    80
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    81
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    82
    @Override
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
    83
    public Map<Executable, State> getStates() {
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    84
        writeDirectiveFile();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    85
        if (isFileValid) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    86
            // Build states for each method according to match blocks
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    87
            for (Pair<Executable, Callable<?>> pair : METHODS) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    88
                State state = getState(pair);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    89
                if (state != null) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    90
                    stateMap.put(pair.first, state);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    91
                }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    92
            }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    93
            return stateMap;
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    94
        } else {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    95
            // return empty map because invalid file doesn't change states
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    96
            return new HashMap<>();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    97
        }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    98
    }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
    99
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   100
    private void writeDirectiveFile() {
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   101
        try (DirectiveWriter dirFile = new DirectiveWriter(fileName)) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   102
            for (MethodDescriptor matchDescriptor : matchBlocks.keySet()) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   103
                // Write match block with all options converted from commands
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   104
                dirFile.match(matchDescriptor);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   105
                for (CompileCommand compileCommand :
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   106
                        matchBlocks.get(matchDescriptor)) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   107
                    handleCommand(dirFile, compileCommand);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   108
                }
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   109
                if ("Inlinee.caller()".matches(matchDescriptor.getRegexp())
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   110
                        && !inlines.isEmpty()) {
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   111
                    // Got a *.* match block, where inline would be written
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   112
                    writeInlines(dirFile);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   113
                    inlines.clear();
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   114
                }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   115
                dirFile.end(); // ends match block
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   116
            }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   117
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   118
            /*
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   119
             * Write inline directive in the end to the latest match block
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   120
             * if we didn't do this before
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   121
             * Inlinee caller methods should match this block only
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   122
             */
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   123
            if (!inlines.isEmpty()) {
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   124
                Pair<Executable, Callable<?>> pair = METHODS.get(0);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   125
                MethodDescriptor md = MethodGenerator.anyMatchDescriptor(
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   126
                        pair.first);
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   127
                CompileCommand cc = new CompileCommand(Command.QUIET, md,
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   128
                        null, Scenario.Type.DIRECTIVE);
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   129
                List<CompileCommand> commands = new ArrayList<>();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   130
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   131
                // Add appropriate "*.*" match block
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   132
                commands.add(cc);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   133
                matchBlocks.put(md, commands);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   134
                // Add match block for this descriptor with inlines
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   135
                dirFile.match(md);
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   136
                writeInlines(dirFile);
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   137
                dirFile.end();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   138
            }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   139
            if (!matchBlocks.isEmpty()) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   140
                // terminates file
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   141
                dirFile.end();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   142
            }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   143
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   144
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   145
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   146
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   147
    private State getState(Pair<Executable, Callable<?>> pair) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   148
        State state = null;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   149
        MethodDescriptor execDesc = MethodGenerator.commandDescriptor(
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   150
                pair.first);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   151
        boolean isMatchFound = false;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   152
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   153
        if (stateMap.containsKey(pair.first)) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   154
            state = stateMap.get(pair.first);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   155
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   156
        for (MethodDescriptor matchDesc : matchBlocks.keySet()) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   157
            if (execDesc.getCanonicalString().matches(matchDesc.getRegexp())) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   158
                /*
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   159
                 * if executable matches regex
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   160
                 * then apply commands from this match to the state
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   161
                 */
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   162
                for (CompileCommand cc : matchBlocks.get(matchDesc)) {
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   163
                    if (state == null) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   164
                        state = new State();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   165
                    }
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   166
                    if (!isMatchFound) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   167
                        // this is a first found match, apply all commands
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   168
                        state.apply(cc);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   169
                    } else {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   170
                        // apply only inline directives
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   171
                        switch (cc.command) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   172
                            case INLINE:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   173
                            case DONTINLINE:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   174
                                state.apply(cc);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   175
                                break;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   176
                        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   177
                    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   178
                }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   179
                isMatchFound = true;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   180
            }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   181
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   182
        return state;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   183
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   184
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   185
    private void handleCommand(DirectiveWriter dirFile, CompileCommand cmd) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   186
        Command command = cmd.command;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   187
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   188
        switch (command) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   189
            case COMPILEONLY:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   190
                dirFile.excludeCompile(cmd.compiler, false);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   191
                break;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   192
            case EXCLUDE:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   193
                dirFile.excludeCompile(cmd.compiler, true);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   194
                break;
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   195
            case QUIET:
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   196
                /* there are no appropriate directive for this, just make
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   197
                   match be enabled */
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   198
            case INLINE:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   199
            case DONTINLINE:
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   200
                /* Inline commands will be written later.
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   201
                   Just make this match be enabled */
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   202
                dirFile.emitCompiler(Scenario.Compiler.C1);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   203
                dirFile.option(DirectiveWriter.Option.ENABLE, true);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   204
                dirFile.end();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   205
                dirFile.emitCompiler(Scenario.Compiler.C2);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   206
                dirFile.option(DirectiveWriter.Option.ENABLE, true);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   207
                dirFile.end();
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   208
                break;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   209
            case LOG:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   210
                dirFile.option(DirectiveWriter.Option.LOG, true);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   211
                break;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   212
            case PRINT:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   213
                dirFile.option(DirectiveWriter.Option.PRINT_ASSEMBLY, true);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   214
                break;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   215
            case NONEXISTENT:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   216
                dirFile.write(JSONFile.Element.PAIR, command.name);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   217
                dirFile.write(JSONFile.Element.OBJECT);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   218
                dirFile.write(JSONFile.Element.PAIR, command.name);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   219
                dirFile.write(JSONFile.Element.VALUE,
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   220
                        cmd.methodDescriptor.getString());
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   221
                dirFile.end(); // ends object
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   222
                break;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   223
            default:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   224
                throw new Error("TESTBUG: wrong command: " + command);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   225
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   226
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   227
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   228
    private void writeInlines(DirectiveWriter dirFile) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   229
        List<String> c1Block = new ArrayList<>();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   230
        List<String> c2Block = new ArrayList<>();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   231
        List<String> allBlock = new ArrayList<>();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   232
        for (CompileCommand cc : inlines) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   233
            String inlineMethodPattern;
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   234
            switch (cc.command) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   235
                case INLINE:
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   236
                    inlineMethodPattern = "+" + cc.methodDescriptor.getString();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   237
                    break;
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   238
                case DONTINLINE:
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   239
                    inlineMethodPattern = "-" + cc.methodDescriptor.getString();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   240
                    break;
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   241
                default:
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   242
                    throw new Error("TESTBUG: incorrect command got in "
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   243
                            + "the list: " + cc.command);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   244
            }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   245
            if (cc.compiler == Scenario.Compiler.C1) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   246
                c1Block.add(inlineMethodPattern);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   247
            } else if (cc.compiler == Scenario.Compiler.C2) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   248
                c2Block.add(inlineMethodPattern);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   249
            } else {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   250
                allBlock.add(inlineMethodPattern);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   251
            }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   252
        }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   253
        dirFile.emitCompiler(Scenario.Compiler.C1);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   254
        if (!c1Block.isEmpty()) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   255
            dirFile.inline(c1Block);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   256
        } else {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   257
            dirFile.option(DirectiveWriter.Option.ENABLE, true);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   258
        }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   259
        dirFile.end();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   260
        dirFile.emitCompiler(Scenario.Compiler.C2);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   261
        if (!c2Block.isEmpty()) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   262
            dirFile.inline(c2Block);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   263
        } else {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   264
            dirFile.option(DirectiveWriter.Option.ENABLE, true);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   265
        }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   266
        dirFile.end();
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   267
        if (!allBlock.isEmpty()) {
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   268
            dirFile.inline(allBlock);
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   269
        }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   270
    }
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   271
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   272
    @Override
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   273
    public void add(CompileCommand compileCommand) {
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   274
        isFileValid &= compileCommand.isValid();
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   275
        MethodDescriptor methodDescriptor = compileCommand.methodDescriptor;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   276
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   277
        switch (compileCommand.command) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   278
            case INLINE:
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   279
            case DONTINLINE:
34226
db9dea22fbfc 8143308: Add inline checks and tests
ppunegov
parents: 34216
diff changeset
   280
                inlines.add(compileCommand);
33452
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   281
                break;
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   282
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   283
        for (MethodDescriptor md: matchBlocks.keySet()) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   284
            if (methodDescriptor.getCanonicalString().matches(md.getRegexp())) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   285
                matchBlocks.get(md).add(compileCommand);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   286
            }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   287
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   288
        if (!matchBlocks.containsKey(compileCommand.methodDescriptor)) {
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   289
            List<CompileCommand> commands = new ArrayList<>();
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   290
            commands.add(compileCommand);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   291
            matchBlocks.put(compileCommand.methodDescriptor, commands);
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   292
        }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   293
    }
04815c29859c 8066153: JEP-JDK-8046155: Test task: cover existing
ppunegov
parents:
diff changeset
   294
}