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