Request for review (M / Verifier Error messages)

Keith McGuigan keith.mcguigan at oracle.com
Thu Jul 26 15:02:27 PDT 2012


Hello,

Would appreciate any review of the following code:
http://cr.openjdk.java.net/~kamg/7116786/

This code adds additional information to VerifyError messages to make it 
easier to diagnose bytecode problems in the field.  It may be a full (or 
partial) solution for JEP 136 (http://openjdk.java.net/jeps/136).

The basic idea is to create an ErrorContext object when a verification 
error occurs and populate it with context information so that things 
like the current frame, stackmaps, and bytecodes can be included in the 
VerifyError's message.  In addition a diagnostic flag, 
-XX:+VerifyVerbose is added which prints out the details of the 
verification as it occurs.

The included test case has a 'testcases.jar' file that contains 
hand-modified classfiles that trigger VerifyErrors in each possible 
location in the verifier.  Some cases appeared unreachable so those 
cases are missing.  I'm attaching the output of the test so you may see 
the resulting error message format.

--
- Keith
-------------- next part --------------
******** case00 ********
Operand stack underflow
Exception Details:
  Location:
    case00.f()I @0: pop
  Reason:
    Attempt to pop empty stack.
  Current Frame:
    bci: @0
    flags: { }
    locals: { 'case00' }
    stack: { }
  Bytecode:
    0000000: 57ac                                   
++ PASS
******** case01 ********
Bad type on operand stack
Exception Details:
  Location:
    case01.f()I @2: iadd
  Reason:
    Type float (current frame, stack[1]) is not assignable to integer
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case01' }
    stack: { integer, float }
  Bytecode:
    0000000: 030b 60ac                              
++ PASS
******** case02 ********
Local variable table overflow
Exception Details:
  Location:
    case02.f()I @0: aload_3
  Reason:
    Local index 3 is invalid
  Bytecode:
    0000000: 2dac                                   
++ PASS
******** case03 ********
Bad local variable type
Exception Details:
  Location:
    case03.f()I @0: iload_0
  Reason:
    Type 'case03' (current frame, locals[0]) is not assignable to integer
  Current Frame:
    bci: @0
    flags: { }
    locals: { 'case03' }
    stack: { }
  Bytecode:
    0000000: 1aac                                   
++ PASS
******** case04 ********
get long/double overflows locals
Exception Details:
  Location:
    case04.f()I @0: dload_0
  Reason:
    Local index 0 is invalid
  Bytecode:
    0000000: 26ac                                   
++ PASS
******** case05 ********
Bad local variable type
Exception Details:
  Location:
    case05.f()I @2: dload_0
  Reason:
    Type 'case05' (current frame, locals[0]) is not assignable to double
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case05', 'case05' }
    stack: { }
  Bytecode:
    0000000: 2a4c 26ac                              
++ PASS
******** case06 ********
++ SKIPPED
******** case07 ********
Local variable table overflow
Exception Details:
  Location:
    case07.f()I @1: istore_3
  Reason:
    Local index 3 is invalid
  Bytecode:
    0000000: 033e ac                                
++ PASS
******** case08 ********
Local variable table overflow
Exception Details:
  Location:
    case08.f()I @1: dstore_3
  Reason:
    Local index 3 is invalid
  Bytecode:
    0000000: 0e4a ac                                
++ PASS
******** case09 ********
Operand stack overflow
Exception Details:
  Location:
    case09.f()I @1: iconst_0
  Reason:
    Exceeded max stack size.
  Current Frame:
    bci: @1
    flags: { }
    locals: { 'case09' }
    stack: { integer }
  Bytecode:
    0000000: 0303 ac                                
++ PASS
******** case10 ********
Operand stack overflow
Exception Details:
  Location:
    case10.f()I @0: dconst_0
  Reason:
    Exceeded max stack size.
  Current Frame:
    bci: @0
    flags: { }
    locals: { 'case10' }
    stack: { }
  Bytecode:
    0000000: 0e0e ac                                
++ PASS
******** case11 ********
Operand stack underflow
Exception Details:
  Location:
    case11.f()I @0: pop
  Reason:
    Attempt to pop empty stack.
  Current Frame:
    bci: @0
    flags: { }
    locals: { 'case11' }
    stack: { }
  Bytecode:
    0000000: 57ac                                   
++ PASS
******** case12 ********
StackMapTable error: bad offset
Exception Details:
  Location:
    case12.f()I @0: getstatic
  Reason:
    Invalid stackmap specification.
  Current Frame:
    bci: @62
    flags: { }
    locals: { 'case12' }
    stack: { }
  Bytecode:
    0000000: b200 02b6 0003 9900 0703 a700 0404 ac  
  Stackmap Table:
    same_frame(@62)
    same_locals_1_stack_item_frame(@63,Integer)
++ PASS
******** case13 ********
Expecting a stackmap frame at branch target 13
Exception Details:
  Location:
    case13.f()I @6: ifeq
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: b200 02b6 0003 9900 0703 a700 0404 ac  
  Stackmap Table:
    same_frame(@14)
++ PASS
******** case14 ********
Inconsistent stackmap frames at branch target 13
Exception Details:
  Location:
    case14.f()I @6: ifeq
  Reason:
    Current frame's stack size doesn't match stackmap.
  Current Frame:
    bci: @6
    flags: { }
    locals: { 'case14' }
    stack: { integer }
  Stackmap Frame:
    bci: @13
    flags: { }
    locals: { 'case14' }
    stack: { integer }
  Bytecode:
    0000000: b200 02b6 0003 9900 0703 a700 0404 ac  
  Stackmap Table:
    same_locals_1_stack_item_frame(@13,Integer)
++ PASS
******** case15 ********
Uninitialized object exists on backward branch 0
Exception Details:
  Location:
    case15.f()I @4: goto
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: bb00 024c a7ff fc                      
  Stackmap Table:
    same_frame(@0)
++ PASS
******** case16 ********
++ SKIPPED
******** case17 ********
Bad type on operand stack in iaload
Exception Details:
  Location:
    case17.f()I @2: iaload
  Reason:
    Type 'case17' (current frame, stack[0]) is not assignable to '[I'
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case17' }
    stack: { 'case17', integer }
  Bytecode:
    0000000: 2a03 2e                                
++ PASS
******** case18 ********
Bad type on operand stack in baload
Exception Details:
  Location:
    case18.f()I @2: baload
  Reason:
    Invalid type: 'case18' (current frame, stack[0])
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case18' }
    stack: { 'case18', integer }
  Bytecode:
    0000000: 2a03 33                                
++ PASS
******** case19 ********
Bad type on operand stack in caload
Exception Details:
  Location:
    case19.f()I @2: caload
  Reason:
    Type 'case19' (current frame, stack[0]) is not assignable to '[C'
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case19' }
    stack: { 'case19', integer }
  Bytecode:
    0000000: 2a03 34                                
++ PASS
******** case20 ********
Bad type on operand stack in saload
Exception Details:
  Location:
    case20.f()I @2: saload
  Reason:
    Type 'case20' (current frame, stack[0]) is not assignable to '[S'
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case20' }
    stack: { 'case20', integer }
  Bytecode:
    0000000: 2a03 35                                
++ PASS
******** case21 ********
Bad type on operand stack in laload
Exception Details:
  Location:
    case21.f()I @2: laload
  Reason:
    Type 'case21' (current frame, stack[0]) is not assignable to '[J'
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case21' }
    stack: { 'case21', integer }
  Bytecode:
    0000000: 2a03 2f                                
++ PASS
******** case22 ********
Bad type on operand stack in faload
Exception Details:
  Location:
    case22.f()I @2: faload
  Reason:
    Type 'case22' (current frame, stack[0]) is not assignable to '[F'
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case22' }
    stack: { 'case22', integer }
  Bytecode:
    0000000: 2a03 30                                
++ PASS
******** case23 ********
Bad type on operand stack in daload
Exception Details:
  Location:
    case23.f()I @2: daload
  Reason:
    Type 'case23' (current frame, stack[0]) is not assignable to '[D'
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case23' }
    stack: { 'case23', integer }
  Bytecode:
    0000000: 2a03 31                                
++ PASS
******** case24 ********
Bad type on operand stack in aaload
Exception Details:
  Location:
    case24.f()I @2: aaload
  Reason:
    Type 'case24' (current frame, stack[0]) is not assignable to reference type
  Current Frame:
    bci: @2
    flags: { }
    locals: { 'case24' }
    stack: { 'case24', integer }
  Bytecode:
    0000000: 2a03 32                                
++ PASS
******** case25 ********
Bad type on operand stack in iastore
Exception Details:
  Location:
    case25.f()I @3: iastore
  Reason:
    Type 'case25' (current frame, stack[0]) is not assignable to '[I'
  Current Frame:
    bci: @3
    flags: { }
    locals: { 'case25' }
    stack: { 'case25', integer, integer }
  Bytecode:
    0000000: 2a03 034f                              
++ PASS
******** case26 ********
Bad type on operand stack in bastore
Exception Details:
  Location:
    case26.f()I @3: bastore
  Reason:
    Invalid type: 'case26' (current frame, stack[0])
  Current Frame:
    bci: @3
    flags: { }
    locals: { 'case26' }
    stack: { 'case26', integer, integer }
  Bytecode:
    0000000: 2a03 0354                              
++ PASS
******** case27 ********
Bad type on operand stack in castore
Exception Details:
  Location:
    case27.f()I @3: castore
  Reason:
    Type 'case27' (current frame, stack[0]) is not assignable to '[C'
  Current Frame:
    bci: @3
    flags: { }
    locals: { 'case27' }
    stack: { 'case27', integer, integer }
  Bytecode:
    0000000: 2a03 0355                              
++ PASS
******** case28 ********
Bad type on operand stack in sastore
Exception Details:
  Location:
    case28.f()I @3: sastore
  Reason:
    Type 'case28' (current frame, stack[0]) is not assignable to '[S'
  Current Frame:
    bci: @3
    flags: { }
    locals: { 'case28' }
    stack: { 'case28', integer, integer }
  Bytecode:
    0000000: 2a03 0356                              
++ PASS
******** case29 ********
Bad type on operand stack in lastore
Exception Details:
  Location:
    case29.f()I @3: lastore
  Reason:
    Type 'case29' (current frame, stack[0]) is not assignable to '[J'
  Current Frame:
    bci: @3
    flags: { }
    locals: { 'case29' }
    stack: { 'case29', integer, long, long_2nd }
  Bytecode:
    0000000: 2a03 0950                              
++ PASS
******** case30 ********
Bad type on operand stack in fastore
Exception Details:
  Location:
    case30.f()I @3: fastore
  Reason:
    Type 'case30' (current frame, stack[0]) is not assignable to '[F'
  Current Frame:
    bci: @3
    flags: { }
    locals: { 'case30' }
    stack: { 'case30', integer, float }
  Bytecode:
    0000000: 2a03 0b51                              
++ PASS
******** case31 ********
Bad type on operand stack in dastore
Exception Details:
  Location:
    case31.f()I @3: dastore
  Reason:
    Type 'case31' (current frame, stack[0]) is not assignable to '[D'
  Current Frame:
    bci: @3
    flags: { }
    locals: { 'case31' }
    stack: { 'case31', integer, double, double_2nd }
  Bytecode:
    0000000: 2a03 0e52                              
++ PASS
******** case32 ********
Bad type on operand stack in aastore
Exception Details:
  Location:
    case32.f()I @3: aastore
  Reason:
    Type 'case32' (current frame, stack[0]) is not assignable to reference type
  Current Frame:
    bci: @3
    flags: { }
    locals: { 'case32' }
    stack: { 'case32', integer, null }
  Bytecode:
    0000000: 2a03 0153                              
++ PASS
******** case33 ********
++ SKIPPED
******** case34 ********
++ SKIPPED
******** case35 ********
++ SKIPPED
******** case36 ********
++ SKIPPED
******** case37 ********
++ SKIPPED
******** case38 ********
++ SKIPPED
******** case39 ********
Method expects a return value
Exception Details:
  Location:
    case39.f()I @0: return
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: b1                                     
++ PASS
******** case40 ********
Constructor must call super() or this() before return
Exception Details:
  Location:
    case40.<init>()V @0: return
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: b1                                     
++ PASS
******** case41 ********
Illegal new instruction
Exception Details:
  Location:
    case41.f()I @0: new
  Reason:
    Invalid type: '[I' (constant pool 9)
  Bytecode:
    0000000: bb00 09                                
++ PASS
******** case42 ********
Bad type on operand stack in arraylength
Exception Details:
  Location:
    case42.f()I @1: arraylength
  Reason:
    Invalid type: 'case42' (current frame, stack[0])
  Current Frame:
    bci: @1
    flags: { }
    locals: { 'case42' }
    stack: { 'case42' }
  Bytecode:
    0000000: 2abe                                   
++ PASS
******** case43 ********
Illegal constant pool index in multianewarray instruction
Exception Details:
  Location:
    case43.f()I @0: multianewarray
  Reason:
    Invalid type: 'case43' (constant pool 2)
  Bytecode:
    0000000: c500 0201                              
++ PASS
******** case44 ********
Illegal dimension in multianewarray instruction: 0
Exception Details:
  Location:
    case44.f()I @0: multianewarray
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: c500 0c00                              
++ PASS
******** case45 ********
Bad instruction: a8
Exception Details:
  Location:
    case45.f()I @0: jsr
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: a800 00                                
++ PASS
******** case46 ********
Control flow falls through code end
Exception Details:
  Location:
    case46.f()I @1: nop
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: 2a                                     
++ PASS
******** case47 ********
Bad instruction: ca
Exception Details:
  Location:
    case47.f()I @0: breakpoint
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: ca                                     
++ PASS
******** case48 ********
Bad instruction
Exception Details:
  Location:
    case48.f()I @0: fast_bputfield
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: d4                                     
++ PASS
******** case49 ********
Catch type is not a subclass of Throwable in exception handler 2
Exception Details:
  Location:
    case49.f()I @2: astore_1
  Reason:
    Type 'case49' (constant pool 3) is not assignable to 'java/lang/Throwable'
  Bytecode:
    0000000: 03ac 4c02 ac                           
  Exception Handler Table:
    bci [0, 1] => handler: 2
  Stackmap Table:
    same_locals_1_stack_item_frame(@2,Object[#11])
++ PASS
******** case50 ********
Expecting a stack map frame
Exception Details:
  Location:
    case50.f()I @11: aload_0
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: 2ab6 0002 5700 0003 a700 092a b600 0204
    0000010: 60ac                                   
  Stackmap Table:
    same_frame(@12)
    same_locals_1_stack_item_frame(@17,Integer)
++ PASS
******** case51 ********
Instruction type does not match stack map
Exception Details:
  Location:
    case51.f()I @1: ireturn
  Reason:
    Current frame's stack size doesn't match stackmap.
  Current Frame:
    bci: @1
    flags: { }
    locals: { 'case51' }
    stack: { integer }
  Stackmap Frame:
    bci: @1
    flags: { }
    locals: { 'case51' }
    stack: { }
  Bytecode:
    0000000: 03ac                                   
  Stackmap Table:
    same_frame(@1)
++ PASS
******** case52 ********
Expecting a stack map frame
Exception Details:
  Location:
    case52.f()I @11: aload_0
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: 2ab6 0002 5700 0003 a700 092a b600 0204
    0000010: 60ac                                   
  Stackmap Table:
    same_locals_1_stack_item_frame(@17,Integer)
++ PASS
******** case53 ********
Stack map does not match the one at exception handler 2
Exception Details:
  Location:
    case53.f()I @2: astore_1
  Reason:
    Type 'case53' (current frame, locals[0]) is not assignable to 'java/lang/Exception' (stack map, locals[0])
  Current Frame:
    bci: @0
    flags: { }
    locals: { 'case53' }
    stack: { 'java/lang/Exception' }
  Stackmap Frame:
    bci: @2
    flags: { }
    locals: { 'java/lang/Exception' }
    stack: { 'java/lang/Exception' }
  Bytecode:
    0000000: 04ac 4c03 ac                           
  Exception Handler Table:
    bci [0, 1] => handler: 2
  Stackmap Table:
    full_frame(@2,{Object[#11]},{Object[#11]})
++ PASS
******** case54 ********
Illegal constant pool index 40 in class case54
Exception Details:
  Location:
    case54.f()I @0: ldc
  Reason:
    Constant pool index 40 is invalid
  Bytecode:
    0000000: 1228                                   
++ PASS
******** case55 ********
Illegal type at constant pool entry 9 in class case55
Exception Details:
  Location:
    case55.f()I @0: ldc
  Reason:
    Constant pool index 9 is invalid
  Bytecode:
    0000000: 1209                                   
++ PASS
******** case56 ********
Illegal type at constant pool entry 9 in class case56
Exception Details:
  Location:
    case56.f()I @0: checkcast
  Reason:
    Constant pool index 9 is invalid
  Bytecode:
    0000000: c000 09                                
++ PASS
******** case57 ********
++ SKIPPED
******** case58 ********
Nonzero padding byte in lookswitch or tableswitch
Exception Details:
  Location:
    case58.f()I @4: tableswitch
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: 2ab6 0002 aa00 0001 0000 0028 0000 0000
    0000010: 0000 0003 0000 0020 0000 0022 0000 0024
    0000020: 0000 0026 03ac 04ac 05ac 06ac 07ac     
  Stackmap Table:
    same_frame(@36)
    same_frame(@38)
    same_frame(@40)
    same_frame(@42)
    same_frame(@44)
++ PASS
******** case59 ********
low must be less than or equal to high in tableswitch
Exception Details:
  Location:
    case59.f()I @4: tableswitch
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: 2ab6 0002 aa00 0000 0000 0028 0000 0003
    0000010: 0000 0000 0000 0020 0000 0022 0000 0024
    0000020: 0000 0026 03ac 04ac 05ac 06ac 07ac     
  Stackmap Table:
    same_frame(@36)
    same_frame(@38)
    same_frame(@40)
    same_frame(@42)
    same_frame(@44)
++ PASS
******** case60 ********
++ SKIPPED
******** case61 ********
++ SKIPPED
******** case62 ********
Bad lookupswitch instruction
Exception Details:
  Location:
    case62.f()I @1: lookupswitch
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: 03ab 0000 0000 0000 0000 0002 0000 0004
    0000010: 0000 0000 0000 0000 0000 0000 0000 00  
  Stackmap Table:
    same_locals_1_stack_item_frame(@1,Integer)
++ PASS
******** case63 ********
++ SKIPPED
******** case64 ********
Bad type on operand stack in putfield
Exception Details:
  Location:
    case64.f()I @8: putfield
  Reason:
    Type 'java/lang/Object' (current frame, stack[0]) is not assignable to 'case64' (constant pool 12)
  Current Frame:
    bci: @8
    flags: { }
    locals: { 'case64' }
    stack: { 'java/lang/Object', integer }
  Bytecode:
    0000000: bb00 0359 b700 0103 b500 0c            
++ PASS
******** case65 ********
Bad access to protected data in getfield
Exception Details:
  Location:
    case65.foo()V @10: putfield
  Reason:
    Type 'B/case65_peer' (current frame, stack[0]) is not assignable to 'case65'
  Current Frame:
    bci: @10
    flags: { }
    locals: { 'case65', 'B/case65_peer' }
    stack: { 'B/case65_peer', integer }
  Bytecode:
    0000000: bb00 0259 b700 034c 2b07 b500 04b1     
++ PASS
******** case66 ********
Bad <init> method call
Exception Details:
  Location:
    case66.<init>()V @1: invokespecial
  Reason:
    Type 'java/lang/String' is not assignable to 'case66'
  Bytecode:
    0000000: 2ab7 0001                              
++ PASS
******** case67 ********
++ SKIPPED
******** case68 ********
Call to wrong <init> method
Exception Details:
  Location:
    case68.f()I @3: invokespecial
  Reason:
    Type 'java/lang/Object' (constant pool 3) is not assignable to 'case68' (constant pool 1)
  Bytecode:
    0000000: bb00 03b7 0001                         
++ PASS
******** case69 ********
Bad access to protected <init> method
Exception Details:
  Location:
    case69.<init>()V @3: invokespecial
  Reason:
    Type 'A/case69_super' (constant pool 3) is not assignable to 'case69'
  Bytecode:
    0000000: bb00 03b7 0001 b1                      
++ PASS
******** case70 ********
Bad operand type when invoking <init>
Exception Details:
  Location:
    case70.f()I @1: invokespecial
  Reason:
    Invalid type: 'case70' (current frame, stack[0])
  Current Frame:
    bci: @1
    flags: { }
    locals: { 'case70' }
    stack: { 'case70' }
  Bytecode:
    0000000: 2ab7 0001                              
++ PASS
******** case71 ********
Inconsistent args count operand in invokeinterface
Exception Details:
  Location:
    case71.f()I @1: invokeinterface
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: 2ab9 0001 0000                         
++ PASS
******** case72 ********
Fourth operand byte of invokeinterface must be zero
Exception Details:
  Location:
    case72.f()I @1: invokeinterface
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: 2ab9 0001 0101                         
++ PASS
******** case73 ********
Third and fourth operand bytes of invokedynamic must be zero
Exception Details:
  Location:
    case73.f()I @0: invokedynamic
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: ba00 0101 00                           
++ PASS
******** case74 ********
Illegal call to internal method
Exception Details:
  Location:
    case74.f()I @1: invokevirtual
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: 2ab6 0001                              
++ PASS
******** case75 ********
Bad invokespecial instruction: current class isn't assignable to reference class.
Exception Details:
  Location:
    case75.f()I @1: invokespecial
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: 2ab7 0001                              
++ PASS
******** case76 ********
Bad access to protected data in invokevirtual
Exception Details:
  Location:
    case76.f()V @7: invokevirtual
  Reason:
    Type 'A/case76_super' (current frame, stack[0]) is not assignable to 'case76'
  Current Frame:
    bci: @7
    flags: { }
    locals: { 'case76' }
    stack: { 'A/case76_super' }
  Bytecode:
    0000000: bb00 0359 b700 0db6 0001 b1            
++ PASS
******** case77 ********
++ SKIPPED
******** case78 ********
Illegal newarray instruction
Exception Details:
  Location:
    case78.f()I @0: newarray
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: bc03                                   
++ PASS
******** case79 ********
Method expects a return value
Exception Details:
  Location:
    case79.f()I @0: return
  Reason:
    Error exists in the bytecode
  Bytecode:
    0000000: b1                                     
++ PASS
******** case80 ********
Bad return type
Exception Details:
  Location:
    case80.f()I @1: freturn
  Reason:
    Type float (current frame, stack[0]) is not assignable to integer (from method signature)
  Current Frame:
    bci: @1
    flags: { }
    locals: { 'case80' }
    stack: { float }
  Bytecode:
    0000000: 0bae                                   
++ PASS


More information about the hotspot-runtime-dev mailing list