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