3955N/A/*
3955N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3955N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3955N/A *
3955N/A * This code is free software; you can redistribute it and/or modify it
3955N/A * under the terms of the GNU General Public License version 2 only, as
3955N/A * published by the Free Software Foundation.
3955N/A *
3955N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3955N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3955N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3955N/A * version 2 for more details (a copy is included in the LICENSE file that
3955N/A * accompanied this code).
3955N/A *
3955N/A * You should have received a copy of the GNU General Public License version
3955N/A * 2 along with this work; if not, write to the Free Software Foundation,
3955N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3955N/A *
3955N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3955N/A * or visit www.oracle.com if you need additional information or have any
3955N/A * questions.
3955N/A *
3955N/A */
3955N/A
3955N/A/*
3955N/A * @test Test7116786
3955N/A * @summary verify that VerifyError messages are as expected
3955N/A * @library testcases.jar
3955N/A * @run main/othervm -Xverify:all Test7116786
3955N/A */
3955N/A
3955N/A
3955N/A/**
3955N/A * This class contains information regarding when a VerifyError is thrown
3955N/A * in the verifier. Most of the data is informational-only, and can be
3955N/A * used to track down where and why VerifyErrors are thrown. As such it
3955N/A * is possible the information may go out-of-date.
3955N/A *
3955N/A * The only fields used for the purpose of testing is the 'caseName' and
3955N/A * the 'message'. The 'caseName' corresponds to a classfile which exhibits
3955N/A * the VerifyError, and the 'message' is a regular expression which we expect
3955N/A * to match the verify error message. If the 'message' doesn't match what
3955N/A * we expect, it warrents investigation to see if we are still triggering
3955N/A * the VerifyError that we expect. It could simply just be that the message
3955N/A * changed, which is fine.
3955N/A *
3955N/A * Some cases are not testable, either because the code is probably unreachable
3955N/A * or the test classfile would be too onerous to create. These cases are
3955N/A * marked with 'testable' == false, and the test runner will skip them.
3955N/A */
3955N/Aclass Case {
3955N/A private String caseName; // Name of the case
3955N/A private String file; // Source file where VerifyError is thrown
3955N/A private String location; // enclosing function or switch case
3955N/A private String description; // What causes this VerifyError
3955N/A private String message; // The VerifyError message used.
3955N/A
3955N/A private boolean testable; // Whether this case is testable or not.
3955N/A
3955N/A public Case(String caseName, String file, boolean testable,
3955N/A String location, String description, String message) {
3955N/A this.caseName = caseName;
3955N/A this.file = file;
3955N/A this.testable = testable;
3955N/A this.location = location;
3955N/A this.description = description;
3955N/A this.message = message;
3955N/A }
3955N/A
3955N/A String getCaseName() { return this.caseName; }
3955N/A String getFile() { return this.file; }
3955N/A String getLocation() { return this.location; }
3955N/A String getDescription() { return this.description; }
3955N/A String getMessage() { return this.message; }
3955N/A
3955N/A boolean isTestable() { return this.testable; }
3955N/A}
3955N/A
3955N/A/**
3955N/A * These are the locations in the source code where VerifyErrors are thrown
3955N/A * as of today, 2012/07/18. These may change as the verification code is
3955N/A * modified, which is ok. This test is trying to provide coverage for all
3955N/A * VerifyErrors (just to make sure there are no crashes) and it's probably
3955N/A * not necessary to update it every time the VM changes.
3955N/A */
3955N/Aclass VerifyErrorCases {
3955N/A public static final Case[] cases = {
3955N/A
3955N/A new Case("case00", "stackMapFrame.cpp", true, "pop_stack_ex",
3955N/A "stack underflow",
3955N/A "Operand stack underflow"),
3955N/A
3955N/A new Case("case01", "stackMapFrame.cpp", true, "pop_stack_ex",
3955N/A "stack pop not assignable to expected",
3955N/A "Bad type on operand stack"),
3955N/A
3955N/A new Case("case02", "stackMapFrame.cpp", true, "get_local",
3955N/A "local index out-of-bounds",
3955N/A "Local variable table overflow"),
3955N/A
3955N/A new Case("case03", "stackMapFrame.cpp", true, "get_local",
3955N/A "local not assignable to expected",
3955N/A "Bad local variable type"),
3955N/A
3955N/A new Case("case04", "stackMapFrame.cpp", true, "get_local_2",
3955N/A "local index out-of-bounds [type2]",
3955N/A "get long/double overflows locals"),
3955N/A
3955N/A new Case("case05", "stackMapFrame.cpp", true, "get_local_2",
3955N/A "local not assignabled to expected [type2]",
3955N/A "Bad local variable type"),
3955N/A
3955N/A /* Unreachable: Can't split long/double on stack */
3955N/A new Case("case06", "stackMapFrame.cpp", false, "get_local_2",
3955N/A "local second-word not assignabled to expected",
3955N/A "Bad local variable type"),
3955N/A
3955N/A new Case("case07", "stackMapFrame.cpp", true, "set_local",
3955N/A "local index out-of-bounds",
3955N/A "Local variable table overflow"),
3955N/A
3955N/A new Case("case08", "stackMapFrame.cpp", true, "set_local_2",
3955N/A "local index out-of-bounds [type2]",
3955N/A "Local variable table overflow"),
3955N/A
3955N/A new Case("case09", "stackMapFrame.hpp", true, "push_stack",
3955N/A "stack overflow",
3955N/A "Operand stack overflow"),
3955N/A
3955N/A new Case("case10", "stackMapFrame.hpp", true, "push_stack_2",
3955N/A "stack overflow [type2]",
3955N/A "Operand stack overflow"),
3955N/A
3955N/A new Case("case11", "stackMapFrame.hpp", true, "pop_stack",
3955N/A "stack underflow",
3955N/A "Operand stack underflow"),
3955N/A
3955N/A new Case("case12", "stackMapTable.cpp", true, "StackMapTable ctor",
3955N/A "stackmap offset beyond code size",
3955N/A "StackMapTable error: bad offset"),
3955N/A
3955N/A new Case("case13", "stackMapTable.cpp", true, "match_stackmap",
3955N/A "no stackmap frame at expected location",
3955N/A "Expecting a stackmap frame at branch target "),
3955N/A
3955N/A new Case("case14", "stackMapTable.cpp", true, "check_jump_target",
3955N/A "no stackmap frame at jump location or bad jump",
3955N/A "Inconsistent stackmap frames at branch target "),
3955N/A
3955N/A new Case("case15", "stackMapTable.cpp", true, "check_new_object",
3955N/A "backward jump with uninit",
3955N/A "Uninitialized object exists on backward branch "),
3955N/A
3955N/A /* Unreachable: wide instructions verified during bytecode analysis */
3955N/A new Case("case16", "verifier.cpp", false, "loop header",
3955N/A "bad op in wide instruction",
3955N/A "Bad wide instruction"),
3955N/A
3955N/A new Case("case17", "verifier.cpp", true, "case iaload",
3955N/A "TOS not X array",
3955N/A "Bad type on operand stack in iaload"),
3955N/A
3955N/A new Case("case18", "verifier.cpp", true, "case baload",
3955N/A "TOS not X array",
3955N/A "Bad type on operand stack in baload"),
3955N/A
3955N/A new Case("case19", "verifier.cpp", true, "case caload",
3955N/A "TOS not X array",
3955N/A "Bad type on operand stack in caload"),
3955N/A
3955N/A new Case("case20", "verifier.cpp", true, "case saload",
3955N/A "TOS not X array",
3955N/A "Bad type on operand stack in saload"),
3955N/A
3955N/A new Case("case21", "verifier.cpp", true, "case laload",
3955N/A "TOS not X array",
3955N/A "Bad type on operand stack in laload"),
3955N/A
3955N/A new Case("case22", "verifier.cpp", true, "case faload",
3955N/A "TOS not X array",
3955N/A "Bad type on operand stack in faload"),
3955N/A
3955N/A new Case("case23", "verifier.cpp", true, "case daload",
3955N/A "TOS not X array",
3955N/A "Bad type on operand stack in daload"),
3955N/A
3955N/A new Case("case24", "verifier.cpp", true, "case aaload",
3955N/A "TOS not X array",
3955N/A "Bad type on operand stack in aaload"),
3955N/A
3955N/A new Case("case25", "verifier.cpp", true, "case iastore",
3955N/A "TOS not int array",
3955N/A "Bad type on operand stack in iastore"),
3955N/A
3955N/A new Case("case26", "verifier.cpp", true, "case bastore",
3955N/A "TOS not byte array",
3955N/A "Bad type on operand stack in bastore"),
3955N/A
3955N/A new Case("case27", "verifier.cpp", true, "case castore",
3955N/A "TOS not char array",
3955N/A "Bad type on operand stack in castore"),
3955N/A
3955N/A new Case("case28", "verifier.cpp", true, "case sastore",
3955N/A "TOS not short array",
3955N/A "Bad type on operand stack in sastore"),
3955N/A
3955N/A new Case("case29", "verifier.cpp", true, "case lastore",
3955N/A "TOS not long array",
3955N/A "Bad type on operand stack in lastore"),
3955N/A
3955N/A new Case("case30", "verifier.cpp", true, "case fastore",
3955N/A "TOS not float array",
3955N/A "Bad type on operand stack in fastore"),
3955N/A
3955N/A new Case("case31", "verifier.cpp", true, "case dastore",
3955N/A "TOS not double array",
3955N/A "Bad type on operand stack in dastore"),
3955N/A
3955N/A new Case("case32", "verifier.cpp", true, "case aastore",
3955N/A "TOS not object array",
3955N/A "Bad type on operand stack in aastore"),
3955N/A
3955N/A /* Unreachable: In order to hit this case, we would need a
3955N/A * category2_1st at TOS which is not possible. */
3955N/A new Case("case33", "verifier.cpp", false, "case pop2",
3955N/A "TOS is category2_1st (would split)",
3955N/A "Bad type on operand stack in pop2"),
3955N/A
3955N/A /* Unreachable: In order to hit this case, we would need a
3955N/A * category2_1st at stack depth 2 with category_1 on TOS which is not
3955N/A * possible. */
3955N/A new Case("case34", "verifier.cpp", false, "case dup_x2",
3955N/A "TOS-1 is category2_1st (would split)",
3955N/A "Bad type on operand stack in dup_x2"),
3955N/A
3955N/A /* Unreachable: In order to hit this case, we would need a
3955N/A * category2_1st at TOS which is not possible. */
3955N/A new Case("case35", "verifier.cpp", false, "case dup2",
3955N/A "TOS-1 is category2_1st (would split)",
3955N/A "Bad type on operand stack in dup2"),
3955N/A
3955N/A /* Unreachable: In order to hit this case, we would need a
3955N/A * category2_1st at TOS which is not possible. */
3955N/A new Case("case36", "verifier.cpp", false, "case dup2_x1",
3955N/A "TOS-1 is category2_1st (would split)",
3955N/A "Bad type on operand stack in dup2_x1"),
3955N/A
3955N/A /* Unreachable: In order to hit this case, we would need a
3955N/A * category2_1st at TOS which is not possible. */
3955N/A new Case("case37", "verifier.cpp", false, "case dup2_x2",
3955N/A "TOS-1 is category2_1st (would split)",
3955N/A "Bad type on operand stack in dup2_x2"),
3955N/A
3955N/A /* Unreachable: In order to hit this case, we would need a
3955N/A * category2_1st at stack depth 3 with either 2 category_1 or 1
3955N/A * category_2 on TOS, which is not possible. */
3955N/A new Case("case38", "verifier.cpp", false, "case dup2_x2",
3955N/A "TOS-3 is category2_1st (would split)",
3955N/A "Bad type on operand stack in dup2_x2"),
3955N/A
3955N/A new Case("case39", "verifier.cpp", true, "case return",
3955N/A "return type of method is not void",
3955N/A "Method expects a return value"),
3955N/A
3955N/A new Case("case40", "verifier.cpp", true, "case return",
3955N/A "return with uninitialized this ",
3955N/A "Constructor must call super() or this() before return"),
3955N/A
3955N/A new Case("case41", "verifier.cpp", true, "case new",
3955N/A "cp index not a class type",
3955N/A "Illegal new instruction"),
3955N/A
3955N/A new Case("case42", "verifier.cpp", true, "case arraylength",
3955N/A "TOS is not an array",
3955N/A "Bad type on operand stack in arraylength"),
3955N/A
3955N/A new Case("case43", "verifier.cpp", true, "case multianewarray",
3955N/A "CP index does not refer to array type",
3955N/A "Illegal constant pool index in multianewarray instruction"),
3955N/A
3955N/A new Case("case44", "verifier.cpp", true, "case multianewarray",
3955N/A "Bad dimension (<1) or does not match CP signature",
3955N/A "Illegal dimension in multianewarray instruction: "),
3955N/A
3955N/A new Case("case45", "verifier.cpp", true, "case default",
3955N/A "Unrecognized bytecode",
3955N/A "Bad instruction: "),
3955N/A
3955N/A new Case("case46", "verifier.cpp", true, "loop end",
3955N/A "control flow falls off method",
3955N/A "Control flow falls through code end"),
3955N/A
3955N/A new Case("case47", "verifier.cpp", true, "generate_code_data",
3955N/A "illegal bytecode via RawBytecodeStream (breakpoint)",
3955N/A "Bad instruction"),
3955N/A
3955N/A new Case("case48", "verifier.cpp", true, "generate_code_data",
3955N/A "illegal bytecode via RawBytecodeStream (other illegal)",
3955N/A "Bad instruction"),
3955N/A
3955N/A new Case("case49", "verifier.cpp", true,
3955N/A "verify_exception_handler_table",
3955N/A "catch_type is not throwable",
3955N/A "Catch type is not a subclass of Throwable in " +
3955N/A "exception handler "),
3955N/A
3955N/A new Case("case50", "verifier.cpp", true, "verify_stackmap_table",
3955N/A "missing a stack map frame @ target location (mid table)",
3955N/A "Expecting a stack map frame"),
3955N/A
3955N/A new Case("case51", "verifier.cpp", true, "verify_stackmap_table",
3955N/A "stack map does not match?",
3955N/A "Instruction type does not match stack map"),
3955N/A
3955N/A new Case("case52", "verifier.cpp", true, "verify_stackmap_table",
3955N/A "missing a stack map frame @ target location (end of table)",
3955N/A "Expecting a stack map frame"),
3955N/A
3955N/A new Case("case53", "verifier.cpp", true,
3955N/A "verify_exception_handler_targets",
3955N/A "stackmap mismatch at exception handler",
3955N/A "Stack map does not match the one at exception handler "),
3955N/A
3955N/A new Case("case54", "verifier.cpp", true, "verify_cp_index",
3955N/A "constant pool index is out-of-bounds",
3955N/A "Illegal constant pool index "),
3955N/A
3955N/A new Case("case55", "verifier.cpp", true, "verify_cp_type",
3955N/A "constant pool entry is not expected type",
3955N/A "Illegal type at constant pool entry "),
3955N/A
3955N/A new Case("case56", "verifier.cpp", true, "verify_cp_class_type",
3955N/A "constant pool entry is not an object type",
3955N/A "Illegal type at constant pool entry "),
3955N/A
3955N/A /* Unreachable: verify_cp_type gates this case */
3955N/A new Case("case57", "verifier.cpp", false, "verify_ldc",
3955N/A "invalid constant pool index in ldc",
3955N/A "Invalid index in ldc"),
3955N/A
3955N/A new Case("case58", "verifier.cpp", true, "verify_switch",
3955N/A "bad switch padding",
3955N/A "Nonzero padding byte in lookswitch or tableswitch"),
3955N/A
3955N/A new Case("case59", "verifier.cpp", true, "verify_switch",
3955N/A "tableswitch low is greater than high",
3955N/A "low must be less than or equal to high in tableswitch"),
3955N/A
3955N/A /* Unreachable on 64-bit? Only way to get here is to overflow
3955N/A * the 'keys' variable which can't happen on 64-bit since we're dealing
3955N/A * with 32-bit values. Perhaps reachable on 32-bit but the
3955N/A * triggering class would be quite large */
3955N/A new Case("case60", "verifier.cpp", false, "verify_switch",
3955N/A "high - low + 1 < 0 (overflow?)",
3955N/A "too many keys in tableswitch"),
3955N/A
3955N/A /* Would have to create a 16G classfile to trip this. Possible but
3955N/A * not reasonable to do in a test. */
3955N/A new Case("case61", "verifier.cpp", false, "verify_switch",
3955N/A "lookupswitch keys < 0",
3955N/A "number of keys in lookupswitch less than 0"),
3955N/A
3955N/A new Case("case62", "verifier.cpp", true, "verify_switch",
3955N/A "lookupswitch keys out-of-order",
3955N/A "Bad lookupswitch instruction"),
3955N/A
3955N/A /* Unreachable: Class file parser verifies Fieldref contents */
3955N/A new Case("case63", "verifier.cpp", false, "verify_field_instructions",
3955N/A "referenced class is not an CP object",
3955N/A "Expecting reference to class in class "),
3955N/A
3955N/A new Case("case64", "verifier.cpp", true, "verify_field_instructions",
3955N/A "TOS not assignable to field type in putfield",
3955N/A "Bad type on operand stack in putfield"),
3955N/A
3955N/A new Case("case65", "verifier.cpp", true, "verify_field_instructions",
3955N/A "TOS not assignable to class when accessing protected field",
3955N/A "Bad access to protected data in getfield"),
3955N/A
3955N/A new Case("case66", "verifier.cpp", true, "verify_invoke_init",
3955N/A "Uninit_this is not of the current type or it's supertype",
3955N/A "Bad <init> method call"),
3955N/A
3955N/A /* Unreachable: Stack map parsing ensures valid type and new
3955N/A * instructions have a valid BCI. */
3955N/A new Case("case67", "verifier.cpp", false, "verify_invoke_init",
3955N/A "Uninit type with bad new instruction index",
3955N/A "Expecting new instruction"),
3955N/A
3955N/A new Case("case68", "verifier.cpp", true, "verify_invoke_init",
3955N/A "calling other class's <init> method",
3955N/A "Call to wrong <init> method"),
3955N/A
3955N/A new Case("case69", "verifier.cpp", true, "verify_invoke_init",
3955N/A "Calling protected <init> and type unassignable from current",
3955N/A "Bad access to protected <init> method"),
3955N/A
3955N/A new Case("case70", "verifier.cpp", true, "verify_invoke_init",
3955N/A "TOS is not an uninitialized (or Uninit_this) type",
3955N/A "Bad operand type when invoking <init>"),
3955N/A
3955N/A new Case("case71", "verifier.cpp", true, "verify_invoke_instructions",
3955N/A "Arg count in instruction doesn't match signature",
3955N/A "Inconsistent args count operand in invokeinterface"),
3955N/A
3955N/A new Case("case72", "verifier.cpp", true, "verify_invoke_instructions",
3955N/A "Non-zero pad in invokeinterface",
3955N/A "Fourth operand byte of invokeinterface must be zero"),
3955N/A
3955N/A new Case("case73", "verifier.cpp", true, "verify_invoke_instructions",
3955N/A "Non-zero pad in invokedynamic",
3955N/A "Third and fourth operand bytes of " +
3955N/A "invokedynamic must be zero"),
3955N/A
3955N/A new Case("case74", "verifier.cpp", true, "verify_invoke_instructions",
3955N/A "Non-invokespecial trying to invoke a '<' method",
3955N/A "Illegal call to internal method"),
3955N/A
3955N/A new Case("case75", "verifier.cpp", true, "verify_invoke_instructions",
3955N/A "invokespecial and current unassignable from referenced type",
3955N/A "Bad invokespecial instruction: current class isn't " +
3955N/A "assignable to reference class."),
3955N/A
3955N/A new Case("case76", "verifier.cpp", true, "verify_invoke_instructions",
3955N/A "TOS not assignable to current when calling protected method",
3955N/A "Bad access to protected data in invokevirtual"),
3955N/A
3955N/A /* Unreachable: class file parser enforces void signature */
3955N/A new Case("case77", "verifier.cpp", false, "verify_invoke_instructions",
3955N/A "<init> method is not void return",
3955N/A "Return type must be void in <init> method"),
3955N/A
3955N/A new Case("case78", "verifier.cpp", true, "get_newarray_type",
3955N/A "newarray type invalid",
3955N/A "Illegal newarray instruction"),
3955N/A
3955N/A new Case("case79", "verifier.cpp", true, "verify_return_value",
3955N/A "void return from method which has a return value",
3955N/A "Method expects a return value"),
3955N/A
3955N/A new Case("case80", "verifier.cpp", true, "verify_return_value",
3955N/A "TOS type does not match signature",
3955N/A "Bad return type"),
3955N/A
3955N/A new Case("case81", "verifier.cpp", true, "verify_stackmap_table",
3955N/A "stack map does not match (flags)",
3955N/A "Instruction type does not match stack map")
3955N/A };
3955N/A}
3955N/A
3955N/Apublic class Test7116786 {
3955N/A public static void main(String argv[]) throws Exception {
3955N/A for (Case c : VerifyErrorCases.cases) {
3955N/A System.out.println("******** " + c.getCaseName() + " ********");
3955N/A if (c.isTestable()) {
3955N/A try {
3955N/A ClassLoader cl = Test7116786.class.getClassLoader();
3955N/A Class<?> cls = Class.forName(c.getCaseName(), true, cl);
3955N/A throw new RuntimeException(
3955N/A "++ FAIL: No verify error encountered");
3955N/A } catch (VerifyError ve) {
3955N/A String message = c.getMessage();
3955N/A String veMessage = ve.getMessage();
3955N/A System.out.print(veMessage);
3955N/A if (!veMessage.startsWith(message)) {
3955N/A // We're not seeing the message we expect. Could be
3955N/A // that we've gotten the wrong VerifyError case, or
3955N/A // maybe the message changed.
3955N/A System.out.println("++ FAIL? " +
3955N/A "Message does not match what was expected: " +
3955N/A message);
3955N/A continue;
3955N/A }
3955N/A if (!veMessage.contains("Exception Details:") &&
3955N/A !veMessage.contains("Reason:")) {
3955N/A System.out.println("++ FAIL: No details found");
3955N/A throw new RuntimeException("FAIL: No details found");
3955N/A }
3955N/A System.out.println("++ PASS");
3955N/A }
3955N/A } else {
3955N/A System.out.println("++ SKIPPED");
3955N/A }
3955N/A }
3955N/A }
3955N/A}