langtools/test/tools/javac/T7093325.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 20236 32da2c913ac4
child 30730 d3ce7619db2c
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
     1
/*
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
     2
 * Copyright (c) 2011, 2013, 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
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    26
 * @bug 7093325 8006694
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
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    29
 * @library lib
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    30
 * @build JavacTestingAbstractThreadedTest
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    31
 * @run main/othervm T7093325
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    32
 */
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    33
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    34
// use /othervm to avoid jtreg timeout issues (CODETOOLS-7900047)
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    35
// see JDK-8006746
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    36
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    37
import java.io.File;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    38
import java.net.URI;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    39
import java.util.Arrays;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    40
import javax.tools.JavaCompiler;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    41
import javax.tools.JavaFileObject;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    42
import javax.tools.SimpleJavaFileObject;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    43
import javax.tools.ToolProvider;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    44
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    45
import com.sun.source.util.JavacTask;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    46
import com.sun.tools.classfile.Attribute;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    47
import com.sun.tools.classfile.ClassFile;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    48
import com.sun.tools.classfile.Code_attribute;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    49
import com.sun.tools.classfile.ConstantPool.*;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    50
import com.sun.tools.classfile.Method;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    51
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    52
public class T7093325
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    53
    extends JavacTestingAbstractThreadedTest
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    54
    implements Runnable {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    55
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    56
    enum StatementKind {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    57
        THROW("throw new RuntimeException();", false, false),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    58
        RETURN_NONEMPTY("System.out.println(); return;", true, false),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    59
        RETURN_EMPTY("return;", true, true),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    60
        APPLY("System.out.println();", true, false);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    61
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    62
        String stmt;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    63
        boolean canInline;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    64
        boolean empty;
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
        private StatementKind(String stmt, boolean canInline, boolean empty) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    67
            this.stmt = stmt;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    68
            this.canInline = canInline;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    69
            this.empty = empty;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    70
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    71
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    72
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    73
    enum CatchArity {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    74
        NONE(""),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    75
        ONE("catch (A a) { #S1 }"),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    76
        TWO("catch (B b) { #S2 }"),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    77
        THREE("catch (C c) { #S3 }"),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    78
        FOUR("catch (D d) { #S4 }");
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    79
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    80
        String catchStr;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    81
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    82
        private CatchArity(String catchStr) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    83
            this.catchStr = catchStr;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    84
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    85
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    86
        String catchers() {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    87
            if (this.ordinal() == 0) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    88
                return catchStr;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    89
            } else {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    90
                return CatchArity.values()[this.ordinal() - 1].catchers() +
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    91
                        catchStr;
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    92
            }
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
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    95
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    96
    public static void main(String... args) throws Exception {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    97
        for (CatchArity ca : CatchArity.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    98
            for (StatementKind stmt0 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    99
                if (ca.ordinal() == 0) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   100
                    pool.execute(new T7093325(ca, stmt0));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   101
                    continue;
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
                for (StatementKind stmt1 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   104
                    if (ca.ordinal() == 1) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   105
                        pool.execute(new T7093325(ca, stmt0, stmt1));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   106
                        continue;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   107
                    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   108
                    for (StatementKind stmt2 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   109
                        if (ca.ordinal() == 2) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   110
                            pool.execute(new T7093325(ca, stmt0, stmt1, stmt2));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   111
                            continue;
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
                        for (StatementKind stmt3 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   114
                            if (ca.ordinal() == 3) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   115
                                pool.execute(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   116
                                    new T7093325(ca, stmt0, stmt1, stmt2, stmt3));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   117
                                continue;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   118
                            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   119
                            for (StatementKind stmt4 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   120
                                if (ca.ordinal() == 4) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   121
                                    pool.execute(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   122
                                        new T7093325(ca, stmt0, stmt1,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   123
                                                     stmt2, stmt3, stmt4));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   124
                                    continue;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   125
                                }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   126
                                for (StatementKind stmt5 : StatementKind.values()) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   127
                                    pool.execute(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   128
                                        new T7093325(ca, stmt0, stmt1, stmt2,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   129
                                                     stmt3, stmt4, stmt5));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   130
                                }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   131
                            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   132
                        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   133
                    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   134
                }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   135
            }
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
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   138
        checkAfterExec();
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   139
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   140
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   141
    /** instance decls **/
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   142
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   143
    CatchArity ca;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   144
    StatementKind[] stmts;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   145
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   146
    public T7093325(CatchArity ca, StatementKind... stmts) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   147
        this.ca = ca;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   148
        this.stmts = stmts;
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
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   151
    @Override
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   152
    public void run() {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   153
        int id = checkCount.incrementAndGet();
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   154
        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   155
        JavaSource source = new JavaSource(id);
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   156
        JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), null,
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   157
                null, null, Arrays.asList(source));
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   158
        ct.call();
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   159
        verifyBytecode(source, id);
10811
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
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   162
    void verifyBytecode(JavaSource source, int id) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   163
        boolean lastInlined = false;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   164
        boolean hasCode = false;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   165
        int gapsCount = 0;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   166
        for (int i = 0; i < stmts.length ; i++) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   167
            lastInlined = stmts[i].canInline;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   168
            hasCode = hasCode || !stmts[i].empty;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   169
            if (lastInlined && hasCode) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   170
                hasCode = false;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   171
                gapsCount++;
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
        if (!lastInlined) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   175
            gapsCount++;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   176
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   177
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   178
        File compiledTest = new File(String.format("Test%s.class", id));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   179
        try {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   180
            ClassFile cf = ClassFile.read(compiledTest);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   181
            if (cf == null) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   182
                throw new Error("Classfile not found: " +
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   183
                                compiledTest.getName());
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   184
            }
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
            Method test_method = null;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   187
            for (Method m : cf.methods) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   188
                if (m.getName(cf.constant_pool).equals("test")) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   189
                    test_method = m;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   190
                    break;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   191
                }
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
            if (test_method == null) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   195
                throw new Error("Method test() not found in class Test");
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   196
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   197
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   198
            Code_attribute code = null;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   199
            for (Attribute a : test_method.attributes) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   200
                if (a.getName(cf.constant_pool).equals(Attribute.Code)) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   201
                    code = (Code_attribute)a;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   202
                    break;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   203
                }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   204
            }
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
            if (code == null) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   207
                throw new Error("Code attribute not found in method test()");
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   208
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   209
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   210
            int actualGapsCount = 0;
20236
32da2c913ac4 8024127: javac, Code_attribute.exception_table_langth should be Code_attribute.exception_table_length
alundblad
parents: 15384
diff changeset
   211
            for (int i = 0; i < code.exception_table_length ; i++) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   212
                int catchType = code.exception_table[i].catch_type;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   213
                if (catchType == 0) { //any
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   214
                    actualGapsCount++;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   215
                }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   216
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   217
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   218
            if (actualGapsCount != gapsCount) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   219
                throw new Error("Bad exception table for test()\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   220
                            "expected gaps: " + gapsCount + "\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   221
                            "found gaps: " + actualGapsCount + "\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   222
                            source);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   223
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   224
        } catch (Exception e) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   225
            e.printStackTrace();
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   226
            throw new Error("error reading " + compiledTest +": " + e);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   227
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   228
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   229
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   230
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   231
    class JavaSource extends SimpleJavaFileObject {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   232
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   233
        static final String source_template =
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   234
                "class A extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   235
                "class B extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   236
                "class C extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   237
                "class D extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   238
                "class E extends RuntimeException {} \n" +
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   239
                "class Test#ID {\n" +
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   240
                "   void test() {\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   241
                "   try { #S0 } #C finally { System.out.println(); }\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   242
                "   }\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   243
                "}";
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   244
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   245
        String source;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   246
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   247
        public JavaSource(int id) {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   248
            super(URI.create(String.format("myfo:/Test%s.java", id)),
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   249
                  JavaFileObject.Kind.SOURCE);
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   250
            source = source_template.replace("#C", ca.catchers());
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   251
            source = source.replace("#S0", stmts[0].stmt);
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   252
            source = source.replace("#ID", String.valueOf(id));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   253
            for (int i = 1; i < ca.ordinal() + 1; i++) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   254
                source = source.replace("#S" + i, stmts[i].stmt);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   255
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   256
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   257
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   258
        @Override
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   259
        public String toString() {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   260
            return source;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   261
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   262
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   263
        @Override
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   264
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   265
            return source;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   266
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   267
    }
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   268
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   269
}