StackMapGenerator debug output

Michael van Acken michael.van.acken at gmail.com
Wed Aug 3 16:51:49 UTC 2022


Am Mi., 3. Aug. 2022 um 17:59 Uhr schrieb Adam Sotona <
adam.sotona at oracle.com>:

> StackMapGenerator is now providing more detailed info about root cause of
> the failure and appends bytecode print directly in the exception.
>
> All the critical information should be now visible in the provided
> exception message.
>
> Alternatively, a system variable switch can enable debug print, or it can
> be printed to a logger (which may cause issues with JDK bootstrap), or
> attached as another suppressed exception.
>

Using the prior example of CodeBuilder.ifThenElse() inserting a GOTO to
nowhere,
I now get this extremely helpful output:

 ERROR  at tcljc.switch-test/int-cmp-test:45
java.lang.VerifyError: Detected branch target out of bytecode range at
bytecode offset 26 of method fnbody~1(int)
  - max stack: 65535
    max locals: 65535
    attributes: []
    //stack map frame @0: {locals: [int], stack: []}
    0: {opcode: ILOAD_0, slot: 0}
    1: {opcode: ICONST_1, constant value: 1}
    2: {opcode: IADD}
    3: {opcode: ISTORE_1, slot: 1}
    4: {opcode: ILOAD_0, slot: 0}
    5: {opcode: ICONST_2, constant value: 2}
    6: {opcode: IADD}
    7: {opcode: ISTORE_2, slot: 2}
    8: {opcode: ILOAD_0, slot: 0}
    9: {opcode: ICONST_3, constant value: 3}
    10: {opcode: IADD}
    11: {opcode: ISTORE_3, slot: 3}
    12: {opcode: ILOAD_1, slot: 1}
    13: {opcode: ILOAD_2, slot: 2}
    14: {opcode: IF_ICMPGE, target: 29}
    17: {opcode: ILOAD_2, slot: 2}
    18: {opcode: ILOAD_3, slot: 3}
    19: {opcode: IF_ICMPGE, target: 24}
    22: {opcode: ICONST_1, constant value: 1}
    23: {opcode: IRETURN}
    24: {opcode: ICONST_0, constant value: 0}
    25: {opcode: IRETURN}
    26: {opcode: GOTO, target: 31}
    29: {opcode: ICONST_0, constant value: 0}
    30: {opcode: IRETURN}

at
java.base/jdk.classfile.impl.StackMapGenerator.generatorError(StackMapGenerator.java:867)
at
java.base/jdk.classfile.impl.StackMapGenerator.detectFrameOffsets(StackMapGenerator.java:932)
at
java.base/jdk.classfile.impl.StackMapGenerator.generate(StackMapGenerator.java:284)
[...]

Thank you very much!

-- mva



>
>
> Please test it and send me your feedback.
>
>
>
> Thanks,
>
> Adam
>
>
>
>
>
> On 21.07.2022 13:21, "Michael van Acken" <michael.van.acken at gmail.com>
> wrote:
>
>
>
> Related but geared towards the builder side of things:
>
>
>
> Is there a way to print out a trace of parts fed to CodeBuilder instances?
>
>
>
> Just this morning I had Classfile die on me because of a stack underflow,
>
> and it was quite hard to find out which parts were missing from the Code
>
> attribute.  And that with a Code totalling just 5 instructions...
>
>
>
> If there would have been bytes output, then I could have inspected the
>
> situation with javap.  But if I mess up and pass inconsistent data to
>
> CodeBuilder, causing it to throw instead of producing a byte array, then
>
> I have an observability gap.
>
>
>
> -- mva
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20220803/a5a9c64b/attachment-0001.htm>


More information about the classfile-api-dev mailing list