langtools/test/tools/javac/T7093325.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 30730 d3ce7619db2c
child 32454 b0ac04e0fefe
permissions -rw-r--r--
8074432: Move jdeps and javap to jdk.jdeps module Reviewed-by: jjg, alanb, erikj
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
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
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    30
 * @modules jdk.jdeps/com.sun.tools.classfile
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    31
 * @build JavacTestingAbstractThreadedTest
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    32
 * @run main/othervm T7093325
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    33
 */
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    34
15384
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    35
// 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
    36
// see JDK-8006746
5a8d00abf076 8006694: temporarily workaround combo tests are causing time out in several platforms
vromero
parents: 15040
diff changeset
    37
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    38
import java.io.File;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    39
import java.net.URI;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    40
import java.util.Arrays;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    41
import javax.tools.JavaCompiler;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    42
import javax.tools.JavaFileObject;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    43
import javax.tools.SimpleJavaFileObject;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    44
import javax.tools.ToolProvider;
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    45
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    46
import com.sun.source.util.JavacTask;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    47
import com.sun.tools.classfile.Attribute;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    48
import com.sun.tools.classfile.ClassFile;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    49
import com.sun.tools.classfile.Code_attribute;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    50
import com.sun.tools.classfile.ConstantPool.*;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    51
import com.sun.tools.classfile.Method;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    52
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    53
public class T7093325
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    54
    extends JavacTestingAbstractThreadedTest
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    55
    implements Runnable {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    56
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    57
    enum StatementKind {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    58
        THROW("throw new RuntimeException();", false, false),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    59
        RETURN_NONEMPTY("System.out.println(); return;", true, false),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    60
        RETURN_EMPTY("return;", true, true),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    61
        APPLY("System.out.println();", true, false);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    62
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    63
        String stmt;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    64
        boolean canInline;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    65
        boolean empty;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    66
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    67
        private StatementKind(String stmt, boolean canInline, boolean empty) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    68
            this.stmt = stmt;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    69
            this.canInline = canInline;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    70
            this.empty = empty;
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    74
    enum CatchArity {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    75
        NONE(""),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    76
        ONE("catch (A a) { #S1 }"),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    77
        TWO("catch (B b) { #S2 }"),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    78
        THREE("catch (C c) { #S3 }"),
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    79
        FOUR("catch (D d) { #S4 }");
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
        String catchStr;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    82
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    83
        private CatchArity(String catchStr) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    84
            this.catchStr = catchStr;
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    87
        String catchers() {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    88
            if (this.ordinal() == 0) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    89
                return catchStr;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    90
            } else {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    91
                return CatchArity.values()[this.ordinal() - 1].catchers() +
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
    92
                        catchStr;
10811
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    97
    public static void main(String... args) throws Exception {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    98
        for (CatchArity ca : CatchArity.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
    99
            for (StatementKind stmt0 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   100
                if (ca.ordinal() == 0) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   101
                    pool.execute(new T7093325(ca, stmt0));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   102
                    continue;
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
                for (StatementKind stmt1 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   105
                    if (ca.ordinal() == 1) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   106
                        pool.execute(new T7093325(ca, stmt0, stmt1));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   107
                        continue;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   108
                    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   109
                    for (StatementKind stmt2 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   110
                        if (ca.ordinal() == 2) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   111
                            pool.execute(new T7093325(ca, stmt0, stmt1, stmt2));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   112
                            continue;
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
                        for (StatementKind stmt3 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   115
                            if (ca.ordinal() == 3) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   116
                                pool.execute(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   117
                                    new T7093325(ca, stmt0, stmt1, stmt2, stmt3));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   118
                                continue;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   119
                            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   120
                            for (StatementKind stmt4 : StatementKind.values()) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   121
                                if (ca.ordinal() == 4) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   122
                                    pool.execute(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   123
                                        new T7093325(ca, stmt0, stmt1,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   124
                                                     stmt2, stmt3, stmt4));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   125
                                    continue;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   126
                                }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   127
                                for (StatementKind stmt5 : StatementKind.values()) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   128
                                    pool.execute(
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   129
                                        new T7093325(ca, stmt0, stmt1, stmt2,
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   130
                                                     stmt3, stmt4, stmt5));
10811
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
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   138
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   139
        checkAfterExec();
10811
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   142
    /** instance decls **/
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   143
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   144
    CatchArity ca;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   145
    StatementKind[] stmts;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   146
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   147
    public T7093325(CatchArity ca, StatementKind... stmts) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   148
        this.ca = ca;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   149
        this.stmts = stmts;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   150
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   151
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   152
    @Override
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   153
    public void run() {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   154
        int id = checkCount.incrementAndGet();
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   155
        final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   156
        JavaSource source = new JavaSource(id);
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   157
        JavacTask ct = (JavacTask)tool.getTask(null, fm.get(), null,
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   158
                null, null, Arrays.asList(source));
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   159
        ct.call();
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   160
        verifyBytecode(source, id);
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   161
    }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   162
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   163
    void verifyBytecode(JavaSource source, int id) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   164
        boolean lastInlined = false;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   165
        boolean hasCode = false;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   166
        int gapsCount = 0;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   167
        for (int i = 0; i < stmts.length ; i++) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   168
            lastInlined = stmts[i].canInline;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   169
            hasCode = hasCode || !stmts[i].empty;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   170
            if (lastInlined && hasCode) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   171
                hasCode = false;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   172
                gapsCount++;
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
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   175
        if (!lastInlined) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   176
            gapsCount++;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   177
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   178
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   179
        File compiledTest = new File(String.format("Test%s.class", id));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   180
        try {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   181
            ClassFile cf = ClassFile.read(compiledTest);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   182
            if (cf == null) {
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   183
                throw new Error("Classfile not found: " +
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   184
                                compiledTest.getName());
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
            Method test_method = null;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   188
            for (Method m : cf.methods) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   189
                if (m.getName(cf.constant_pool).equals("test")) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   190
                    test_method = m;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   191
                    break;
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 (test_method == null) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   196
                throw new Error("Method test() not found in class Test");
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   199
            Code_attribute code = null;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   200
            for (Attribute a : test_method.attributes) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   201
                if (a.getName(cf.constant_pool).equals(Attribute.Code)) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   202
                    code = (Code_attribute)a;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   203
                    break;
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   207
            if (code == null) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   208
                throw new Error("Code attribute not found in method test()");
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   211
            int actualGapsCount = 0;
20236
32da2c913ac4 8024127: javac, Code_attribute.exception_table_langth should be Code_attribute.exception_table_length
alundblad
parents: 15384
diff changeset
   212
            for (int i = 0; i < code.exception_table_length ; i++) {
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   213
                int catchType = code.exception_table[i].catch_type;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   214
                if (catchType == 0) { //any
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   215
                    actualGapsCount++;
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   219
            if (actualGapsCount != gapsCount) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   220
                throw new Error("Bad exception table for test()\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   221
                            "expected gaps: " + gapsCount + "\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   222
                            "found gaps: " + actualGapsCount + "\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   223
                            source);
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   224
            }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   225
        } catch (Exception e) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   226
            e.printStackTrace();
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   227
            throw new Error("error reading " + compiledTest +": " + e);
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   232
    class JavaSource extends SimpleJavaFileObject {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   233
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   234
        static final String source_template =
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   235
                "class A extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   236
                "class B extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   237
                "class C extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   238
                "class D extends RuntimeException {} \n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   239
                "class E extends RuntimeException {} \n" +
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   240
                "class Test#ID {\n" +
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   241
                "   void test() {\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   242
                "   try { #S0 } #C finally { System.out.println(); }\n" +
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   243
                "   }\n" +
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   246
        String source;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   247
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   248
        public JavaSource(int id) {
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   249
            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
   250
                  JavaFileObject.Kind.SOURCE);
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   251
            source = source_template.replace("#C", ca.catchers());
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   252
            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
   253
            source = source.replace("#ID", String.valueOf(id));
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   254
            for (int i = 1; i < ca.ordinal() + 1; i++) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   255
                source = source.replace("#S" + i, stmts[i].stmt);
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   259
        @Override
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   260
        public String toString() {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   261
            return source;
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
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   264
        @Override
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   265
        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   266
            return source;
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   267
        }
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   268
    }
15040
99fd9483d3f0 8005167: execution time of combo tests in javac should be improved
vromero
parents: 10811
diff changeset
   269
10811
4d4ed480210e 7093325: Redundant entry in bytecode exception table
mcimadamore
parents:
diff changeset
   270
}