test/langtools/tools/javac/T7093325.java
author jlahoda
Fri, 01 Sep 2017 14:04:20 +0200
changeset 47350 d65c3b21081c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8186694: JShell: speed-up compilation by reusing compiler instances Summary: Generalizing ReusableContext and using it in JShell to speed up processing. Reviewed-by: mcimadamore, rfield
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 20236
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
     4
 *
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
     8
 *
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    14
 *
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    18
 *
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    21
 * questions.
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    22
 */
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    23
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    24
/*
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    25
 * @test
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    26
 * @bug 7093325 8006694 8129962
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    27
 * @summary Redundant entry in bytecode exception table
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    28
 *  temporarily workaround combo tests are causing time out in several platforms
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    29
 * @library /tools/javac/lib
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    30
 * @modules jdk.jdeps/com.sun.tools.classfile
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    31
 *          jdk.compiler/com.sun.tools.javac.api
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    32
 *          jdk.compiler/com.sun.tools.javac.code
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    33
 *          jdk.compiler/com.sun.tools.javac.comp
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    34
 *          jdk.compiler/com.sun.tools.javac.main
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    35
 *          jdk.compiler/com.sun.tools.javac.tree
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    36
 *          jdk.compiler/com.sun.tools.javac.util
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    37
 * @build combo.ComboTestHelper
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    38
 * @run main T7093325
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    39
 */
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    40
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    41
import java.io.IOException;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    42
import java.io.InputStream;
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    43
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    44
import com.sun.tools.classfile.Attribute;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    45
import com.sun.tools.classfile.ClassFile;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    46
import com.sun.tools.classfile.Code_attribute;
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    47
import com.sun.tools.classfile.ConstantPoolException;
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    48
import com.sun.tools.classfile.Method;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    49
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    50
import javax.tools.JavaFileObject;
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    51
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    52
import combo.ComboInstance;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    53
import combo.ComboParameter;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    54
import combo.ComboTask.Result;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    55
import combo.ComboTestHelper;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    56
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    57
public class T7093325 extends ComboInstance<T7093325> {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    58
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    59
    enum StatementKind implements ComboParameter {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    60
        NONE(null, false, false),
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    61
        THROW("throw new RuntimeException();", false, false),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    62
        RETURN_NONEMPTY("System.out.println(); return;", true, false),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    63
        RETURN_EMPTY("return;", true, true),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    64
        APPLY("System.out.println();", true, false);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    65
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    66
        String stmt;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    67
        boolean canInline;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    68
        boolean empty;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    69
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    70
        StatementKind(String stmt, boolean canInline, boolean empty) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    71
            this.stmt = stmt;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    72
            this.canInline = canInline;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    73
            this.empty = empty;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    74
        }
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    75
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    76
        @Override
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    77
        public String expand(String optParameter) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    78
            return stmt;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    79
        }
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    80
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    81
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    82
    enum CatchArity implements ComboParameter {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    83
        NONE(""),
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    84
        ONE("catch (A a) { #{STMT[1]} }"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    85
        TWO("catch (B b) { #{STMT[2]} }"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    86
        THREE("catch (C c) { #{STMT[3]} }"),
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    87
        FOUR("catch (D d) { #{STMT[4]} }");
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    88
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    89
        String catchStr;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    90
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    91
        CatchArity(String catchStr) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    92
            this.catchStr = catchStr;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    93
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    94
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    95
        @Override
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
    96
        public String expand(String optParameter) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    97
            if (this.ordinal() == 0) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    98
                return catchStr;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    99
            } else {
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   100
                return CatchArity.values()[this.ordinal() - 1].expand(optParameter) +
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   101
                        catchStr;
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   102
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   103
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   104
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   105
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   106
    public static void main(String... args) throws Exception {
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   107
        new ComboTestHelper<T7093325>()
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   108
                .withFilter(T7093325::testFilter)
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   109
                .withDimension("CATCH", (x, ca) -> x.ca = ca, CatchArity.values())
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   110
                .withArrayDimension("STMT", (x, stmt, idx) -> x.stmts[idx] = stmt, 5, StatementKind.values())
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   111
                .run(T7093325::new);
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   112
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   113
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   114
    /** instance decls **/
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   115
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   116
    CatchArity ca;
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   117
    StatementKind[] stmts = new StatementKind[5];
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   118
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   119
    boolean testFilter() {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   120
        int lastPos = ca.ordinal() + 1;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   121
        for (int i = 0; i < stmts.length ; i++) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   122
            boolean shouldBeSet = i < lastPos;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   123
            boolean isSet = stmts[i] != StatementKind.NONE;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   124
            if (shouldBeSet != isSet) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   125
                return false;
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   126
            }
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   127
        }
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   128
        return true;
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   129
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   130
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   131
    @Override
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   132
    public void doWork() throws IOException {
47350
d65c3b21081c 8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents: 47216
diff changeset
   133
        newCompilationTask()
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   134
                .withSourceFromTemplate(source_template)
47350
d65c3b21081c 8186694: JShell: speed-up compilation by reusing compiler instances
jlahoda
parents: 47216
diff changeset
   135
                .generate(this::verifyBytecode);
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   136
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   137
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   138
    void verifyBytecode(Result<Iterable<? extends JavaFileObject>> result) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   139
        boolean lastInlined = false;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   140
        boolean hasCode = false;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   141
        int gapsCount = 0;
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   142
        for (int i = 0; i < ca.ordinal() + 1 ; i++) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   143
            lastInlined = stmts[i].canInline;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   144
            hasCode = hasCode || !stmts[i].empty;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   145
            if (lastInlined && hasCode) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   146
                hasCode = false;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   147
                gapsCount++;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   148
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   149
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   150
        if (!lastInlined) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   151
            gapsCount++;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   152
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   153
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   154
        try (InputStream is = result.get().iterator().next().openInputStream()) {
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   155
            ClassFile cf = ClassFile.read(is);
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   156
            if (cf == null) {
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   157
                fail("Classfile not found: " + result.compilationInfo());
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   158
                return;
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   159
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   160
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   161
            Method test_method = null;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   162
            for (Method m : cf.methods) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   163
                if (m.getName(cf.constant_pool).equals("test")) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   164
                    test_method = m;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   165
                    break;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   166
                }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   167
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   168
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   169
            if (test_method == null) {
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   170
                fail("Method test() not found in class Test" + result.compilationInfo());
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   171
                return;
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   172
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   173
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   174
            Code_attribute code = null;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   175
            for (Attribute a : test_method.attributes) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   176
                if (a.getName(cf.constant_pool).equals(Attribute.Code)) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   177
                    code = (Code_attribute)a;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   178
                    break;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   179
                }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   180
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   181
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   182
            if (code == null) {
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   183
                fail("Code attribute not found in method test()");
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   184
                return;
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   185
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   186
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   187
            int actualGapsCount = 0;
20236
32da2c913ac4 8024127: javac, Code_attribute.exception_table_langth should be Code_attribute.exception_table_length
alundblad
parents: 15384
diff changeset
   188
            for (int i = 0; i < code.exception_table_length ; i++) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   189
                int catchType = code.exception_table[i].catch_type;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   190
                if (catchType == 0) { //any
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   191
                    actualGapsCount++;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   192
                }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   193
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   194
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   195
            if (actualGapsCount != gapsCount) {
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   196
                fail("Bad exception table for test()\n" +
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   197
                            "expected gaps: " + gapsCount + "\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   198
                            "found gaps: " + actualGapsCount + "\n" +
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   199
                        result.compilationInfo());
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   200
                return;
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   201
            }
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   202
        } catch (IOException | ConstantPoolException e) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   203
            e.printStackTrace();
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   204
            fail("error reading classfile: " + e);
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   205
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   206
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   207
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   208
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   209
    static final String source_template =
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   210
                "class Test {\n" +
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   211
                "   void test() {\n" +
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   212
                "   try { #{STMT[0]} } #{CATCH} finally { System.out.println(); }\n" +
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   213
                "   }\n" +
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   214
                "}\n" +
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   215
                "class A extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   216
                "class B extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   217
                "class C extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   218
                "class D extends RuntimeException {} \n" +
32454
b0ac04e0fefe 8129962: Investigate performance improvements in langtools combo tests
mcimadamore
parents: 30846
diff changeset
   219
                "class E extends RuntimeException {}";
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   220
}