Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/runtime/7116786/Test7116786.java
32284 views
/*1* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324/*25* @test Test711678626* @summary verify that VerifyError messages are as expected27* @library testcases.jar28* @run main/othervm -Xverify:all Test711678629*/303132/**33* This class contains information regarding when a VerifyError is thrown34* in the verifier. Most of the data is informational-only, and can be35* used to track down where and why VerifyErrors are thrown. As such it36* is possible the information may go out-of-date.37*38* The only fields used for the purpose of testing is the 'caseName' and39* the 'message'. The 'caseName' corresponds to a classfile which exhibits40* the VerifyError, and the 'message' is a regular expression which we expect41* to match the verify error message. If the 'message' doesn't match what42* we expect, it warrents investigation to see if we are still triggering43* the VerifyError that we expect. It could simply just be that the message44* changed, which is fine.45*46* Some cases are not testable, either because the code is probably unreachable47* or the test classfile would be too onerous to create. These cases are48* marked with 'testable' == false, and the test runner will skip them.49*/50class Case {51private String caseName; // Name of the case52private String file; // Source file where VerifyError is thrown53private String location; // enclosing function or switch case54private String description; // What causes this VerifyError55private String message; // The VerifyError message used.5657private boolean testable; // Whether this case is testable or not.5859public Case(String caseName, String file, boolean testable,60String location, String description, String message) {61this.caseName = caseName;62this.file = file;63this.testable = testable;64this.location = location;65this.description = description;66this.message = message;67}6869String getCaseName() { return this.caseName; }70String getFile() { return this.file; }71String getLocation() { return this.location; }72String getDescription() { return this.description; }73String getMessage() { return this.message; }7475boolean isTestable() { return this.testable; }76}7778/**79* These are the locations in the source code where VerifyErrors are thrown80* as of today, 2012/07/18. These may change as the verification code is81* modified, which is ok. This test is trying to provide coverage for all82* VerifyErrors (just to make sure there are no crashes) and it's probably83* not necessary to update it every time the VM changes.84*/85class VerifyErrorCases {86public static final Case[] cases = {8788new Case("case00", "stackMapFrame.cpp", true, "pop_stack_ex",89"stack underflow",90"Operand stack underflow"),9192new Case("case01", "stackMapFrame.cpp", true, "pop_stack_ex",93"stack pop not assignable to expected",94"Bad type on operand stack"),9596new Case("case02", "stackMapFrame.cpp", true, "get_local",97"local index out-of-bounds",98"Local variable table overflow"),99100new Case("case03", "stackMapFrame.cpp", true, "get_local",101"local not assignable to expected",102"Bad local variable type"),103104new Case("case04", "stackMapFrame.cpp", true, "get_local_2",105"local index out-of-bounds [type2]",106"get long/double overflows locals"),107108new Case("case05", "stackMapFrame.cpp", true, "get_local_2",109"local not assignabled to expected [type2]",110"Bad local variable type"),111112/* Unreachable: Can't split long/double on stack */113new Case("case06", "stackMapFrame.cpp", false, "get_local_2",114"local second-word not assignabled to expected",115"Bad local variable type"),116117new Case("case07", "stackMapFrame.cpp", true, "set_local",118"local index out-of-bounds",119"Local variable table overflow"),120121new Case("case08", "stackMapFrame.cpp", true, "set_local_2",122"local index out-of-bounds [type2]",123"Local variable table overflow"),124125new Case("case09", "stackMapFrame.hpp", true, "push_stack",126"stack overflow",127"Operand stack overflow"),128129new Case("case10", "stackMapFrame.hpp", true, "push_stack_2",130"stack overflow [type2]",131"Operand stack overflow"),132133new Case("case11", "stackMapFrame.hpp", true, "pop_stack",134"stack underflow",135"Operand stack underflow"),136137new Case("case12", "stackMapTable.cpp", true, "StackMapTable ctor",138"stackmap offset beyond code size",139"StackMapTable error: bad offset"),140141new Case("case13", "stackMapTable.cpp", true, "match_stackmap",142"no stackmap frame at expected location",143"Expecting a stackmap frame at branch target "),144145new Case("case14", "stackMapTable.cpp", true, "check_jump_target",146"no stackmap frame at jump location or bad jump",147"Inconsistent stackmap frames at branch target "),148149/* Backward jump with uninit is allowed starting with JDK 8 */150new Case("case15", "stackMapTable.cpp", false, "check_new_object",151"backward jump with uninit",152"Uninitialized object exists on backward branch "),153154/* Unreachable: wide instructions verified during bytecode analysis */155new Case("case16", "verifier.cpp", false, "loop header",156"bad op in wide instruction",157"Bad wide instruction"),158159new Case("case17", "verifier.cpp", true, "case iaload",160"TOS not X array",161"Bad type on operand stack in iaload"),162163new Case("case18", "verifier.cpp", true, "case baload",164"TOS not X array",165"Bad type on operand stack in baload"),166167new Case("case19", "verifier.cpp", true, "case caload",168"TOS not X array",169"Bad type on operand stack in caload"),170171new Case("case20", "verifier.cpp", true, "case saload",172"TOS not X array",173"Bad type on operand stack in saload"),174175new Case("case21", "verifier.cpp", true, "case laload",176"TOS not X array",177"Bad type on operand stack in laload"),178179new Case("case22", "verifier.cpp", true, "case faload",180"TOS not X array",181"Bad type on operand stack in faload"),182183new Case("case23", "verifier.cpp", true, "case daload",184"TOS not X array",185"Bad type on operand stack in daload"),186187new Case("case24", "verifier.cpp", true, "case aaload",188"TOS not X array",189"Bad type on operand stack in aaload"),190191new Case("case25", "verifier.cpp", true, "case iastore",192"TOS not int array",193"Bad type on operand stack in iastore"),194195new Case("case26", "verifier.cpp", true, "case bastore",196"TOS not byte array",197"Bad type on operand stack in bastore"),198199new Case("case27", "verifier.cpp", true, "case castore",200"TOS not char array",201"Bad type on operand stack in castore"),202203new Case("case28", "verifier.cpp", true, "case sastore",204"TOS not short array",205"Bad type on operand stack in sastore"),206207new Case("case29", "verifier.cpp", true, "case lastore",208"TOS not long array",209"Bad type on operand stack in lastore"),210211new Case("case30", "verifier.cpp", true, "case fastore",212"TOS not float array",213"Bad type on operand stack in fastore"),214215new Case("case31", "verifier.cpp", true, "case dastore",216"TOS not double array",217"Bad type on operand stack in dastore"),218219new Case("case32", "verifier.cpp", true, "case aastore",220"TOS not object array",221"Bad type on operand stack in aastore"),222223/* Unreachable: In order to hit this case, we would need a224* category2_1st at TOS which is not possible. */225new Case("case33", "verifier.cpp", false, "case pop2",226"TOS is category2_1st (would split)",227"Bad type on operand stack in pop2"),228229/* Unreachable: In order to hit this case, we would need a230* category2_1st at stack depth 2 with category_1 on TOS which is not231* possible. */232new Case("case34", "verifier.cpp", false, "case dup_x2",233"TOS-1 is category2_1st (would split)",234"Bad type on operand stack in dup_x2"),235236/* Unreachable: In order to hit this case, we would need a237* category2_1st at TOS which is not possible. */238new Case("case35", "verifier.cpp", false, "case dup2",239"TOS-1 is category2_1st (would split)",240"Bad type on operand stack in dup2"),241242/* Unreachable: In order to hit this case, we would need a243* category2_1st at TOS which is not possible. */244new Case("case36", "verifier.cpp", false, "case dup2_x1",245"TOS-1 is category2_1st (would split)",246"Bad type on operand stack in dup2_x1"),247248/* Unreachable: In order to hit this case, we would need a249* category2_1st at TOS which is not possible. */250new Case("case37", "verifier.cpp", false, "case dup2_x2",251"TOS-1 is category2_1st (would split)",252"Bad type on operand stack in dup2_x2"),253254/* Unreachable: In order to hit this case, we would need a255* category2_1st at stack depth 3 with either 2 category_1 or 1256* category_2 on TOS, which is not possible. */257new Case("case38", "verifier.cpp", false, "case dup2_x2",258"TOS-3 is category2_1st (would split)",259"Bad type on operand stack in dup2_x2"),260261new Case("case39", "verifier.cpp", true, "case return",262"return type of method is not void",263"Method expects a return value"),264265new Case("case40", "verifier.cpp", true, "case return",266"return with uninitialized this ",267"Constructor must call super() or this() before return"),268269new Case("case41", "verifier.cpp", true, "case new",270"cp index not a class type",271"Illegal new instruction"),272273new Case("case42", "verifier.cpp", true, "case arraylength",274"TOS is not an array",275"Bad type on operand stack in arraylength"),276277new Case("case43", "verifier.cpp", true, "case multianewarray",278"CP index does not refer to array type",279"Illegal constant pool index in multianewarray instruction"),280281new Case("case44", "verifier.cpp", true, "case multianewarray",282"Bad dimension (<1) or does not match CP signature",283"Illegal dimension in multianewarray instruction: "),284285new Case("case45", "verifier.cpp", true, "case default",286"Unrecognized bytecode",287"Bad instruction: "),288289new Case("case46", "verifier.cpp", true, "loop end",290"control flow falls off method",291"Control flow falls through code end"),292293new Case("case47", "verifier.cpp", true, "generate_code_data",294"illegal bytecode via RawBytecodeStream (breakpoint)",295"Bad instruction"),296297new Case("case48", "verifier.cpp", true, "generate_code_data",298"illegal bytecode via RawBytecodeStream (other illegal)",299"Bad instruction"),300301new Case("case49", "verifier.cpp", true,302"verify_exception_handler_table",303"catch_type is not throwable",304"Catch type is not a subclass of Throwable in " +305"exception handler "),306307new Case("case50", "verifier.cpp", true, "verify_stackmap_table",308"missing a stack map frame @ target location (mid table)",309"Expecting a stack map frame"),310311new Case("case51", "verifier.cpp", true, "verify_stackmap_table",312"stack map does not match?",313"Instruction type does not match stack map"),314315new Case("case52", "verifier.cpp", true, "verify_stackmap_table",316"missing a stack map frame @ target location (end of table)",317"Expecting a stack map frame"),318319new Case("case53", "verifier.cpp", true,320"verify_exception_handler_targets",321"stackmap mismatch at exception handler",322"Stack map does not match the one at exception handler "),323324new Case("case54", "verifier.cpp", true, "verify_cp_index",325"constant pool index is out-of-bounds",326"Illegal constant pool index "),327328new Case("case55", "verifier.cpp", true, "verify_cp_type",329"constant pool entry is not expected type",330"Illegal type at constant pool entry "),331332new Case("case56", "verifier.cpp", true, "verify_cp_class_type",333"constant pool entry is not an object type",334"Illegal type at constant pool entry "),335336/* Unreachable: verify_cp_type gates this case */337new Case("case57", "verifier.cpp", false, "verify_ldc",338"invalid constant pool index in ldc",339"Invalid index in ldc"),340341/* No longer a valid test case for bytecode version >= 51. Nonzero342* padding bytes are permitted with lookupswitch and tableswitch343* bytecodes as of JVMS 3d edition */344new Case("case58", "verifier.cpp", false, "verify_switch",345"bad switch padding",346"Nonzero padding byte in lookupswitch or tableswitch"),347348new Case("case59", "verifier.cpp", true, "verify_switch",349"tableswitch low is greater than high",350"low must be less than or equal to high in tableswitch"),351352/* Unreachable on 64-bit? Only way to get here is to overflow353* the 'keys' variable which can't happen on 64-bit since we're dealing354* with 32-bit values. Perhaps reachable on 32-bit but the355* triggering class would be quite large */356new Case("case60", "verifier.cpp", false, "verify_switch",357"high - low + 1 < 0 (overflow?)",358"too many keys in tableswitch"),359360/* Would have to create a 16G classfile to trip this. Possible but361* not reasonable to do in a test. */362new Case("case61", "verifier.cpp", false, "verify_switch",363"lookupswitch keys < 0",364"number of keys in lookupswitch less than 0"),365366new Case("case62", "verifier.cpp", true, "verify_switch",367"lookupswitch keys out-of-order",368"Bad lookupswitch instruction"),369370/* Unreachable: Class file parser verifies Fieldref contents */371new Case("case63", "verifier.cpp", false, "verify_field_instructions",372"referenced class is not an CP object",373"Expecting reference to class in class "),374375new Case("case64", "verifier.cpp", true, "verify_field_instructions",376"TOS not assignable to field type in putfield",377"Bad type on operand stack in putfield"),378379new Case("case65", "verifier.cpp", true, "verify_field_instructions",380"TOS not assignable to class when accessing protected field",381"Bad access to protected data in getfield"),382383new Case("case66", "verifier.cpp", true, "verify_invoke_init",384"Uninit_this is not of the current type or it's supertype",385"Bad <init> method call"),386387/* Unreachable: Stack map parsing ensures valid type and new388* instructions have a valid BCI. */389new Case("case67", "verifier.cpp", false, "verify_invoke_init",390"Uninit type with bad new instruction index",391"Expecting new instruction"),392393new Case("case68", "verifier.cpp", true, "verify_invoke_init",394"calling other class's <init> method",395"Call to wrong <init> method"),396397new Case("case69", "verifier.cpp", true, "verify_invoke_init",398"Calling protected <init> and type unassignable from current",399"Bad access to protected <init> method"),400401new Case("case70", "verifier.cpp", true, "verify_invoke_init",402"TOS is not an uninitialized (or Uninit_this) type",403"Bad operand type when invoking <init>"),404405new Case("case71", "verifier.cpp", true, "verify_invoke_instructions",406"Arg count in instruction doesn't match signature",407"Inconsistent args count operand in invokeinterface"),408409new Case("case72", "verifier.cpp", true, "verify_invoke_instructions",410"Non-zero pad in invokeinterface",411"Fourth operand byte of invokeinterface must be zero"),412413new Case("case73", "verifier.cpp", true, "verify_invoke_instructions",414"Non-zero pad in invokedynamic",415"Third and fourth operand bytes of " +416"invokedynamic must be zero"),417418new Case("case74", "verifier.cpp", true, "verify_invoke_instructions",419"Non-invokespecial trying to invoke a '<' method",420"Illegal call to internal method"),421422new Case("case75", "verifier.cpp", true, "verify_invoke_instructions",423"invokespecial and current unassignable from referenced type",424"Bad invokespecial instruction: current class isn't " +425"assignable to reference class."),426427new Case("case76", "verifier.cpp", true, "verify_invoke_instructions",428"TOS not assignable to current when calling protected method",429"Bad access to protected data in invokevirtual"),430431/* Unreachable: class file parser enforces void signature */432new Case("case77", "verifier.cpp", false, "verify_invoke_instructions",433"<init> method is not void return",434"Return type must be void in <init> method"),435436new Case("case78", "verifier.cpp", true, "get_newarray_type",437"newarray type invalid",438"Illegal newarray instruction"),439440new Case("case79", "verifier.cpp", true, "verify_return_value",441"void return from method which has a return value",442"Method expects a return value"),443444new Case("case80", "verifier.cpp", true, "verify_return_value",445"TOS type does not match signature",446"Bad return type"),447448new Case("case81", "verifier.cpp", true, "verify_stackmap_table",449"stack map does not match (flags)",450"Instruction type does not match stack map")451};452}453454public class Test7116786 {455public static void main(String argv[]) throws Exception {456for (Case c : VerifyErrorCases.cases) {457System.out.println("******** " + c.getCaseName() + " ********");458if (c.isTestable()) {459try {460ClassLoader cl = Test7116786.class.getClassLoader();461Class<?> cls = Class.forName(c.getCaseName(), true, cl);462throw new RuntimeException(463"++ FAIL: No verify error encountered");464} catch (VerifyError ve) {465String message = c.getMessage();466String veMessage = ve.getMessage();467System.out.print(veMessage);468if (!veMessage.startsWith(message)) {469// We're not seeing the message we expect. Could be470// that we've gotten the wrong VerifyError case, or471// maybe the message changed.472System.out.println("++ FAIL? " +473"Message does not match what was expected: " +474message);475continue;476}477if (!veMessage.contains("Exception Details:") &&478!veMessage.contains("Reason:")) {479System.out.println("++ FAIL: No details found");480throw new RuntimeException("FAIL: No details found");481}482System.out.println("++ PASS");483}484} else {485System.out.println("++ SKIPPED");486}487}488}489}490491492