RFR: 8301703: java.base jdk.internal.foreign.abi.BindingSpecializer uses ASM to generate classes [v2]

Chen Liang liach at openjdk.org
Fri Mar 31 02:37:19 UTC 2023


On Thu, 30 Mar 2023 22:09:24 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> This seems to be caught without running the verifier as well:
>> 
>> 
>> Caused by: java.lang.IllegalStateException: Operand stack underflow at bytecode offset 79 of method invoke(SegmentAllocator,MemorySegment,MemorySegment)
>>   ...
>>         at java.base/jdk.internal.classfile.impl.StackMapGenerator.generatorError(StackMapGenerator.java:876)
>>         at java.base/jdk.internal.classfile.impl.StackMapGenerator.generatorError(StackMapGenerator.java:832)
>>         at java.base/jdk.internal.classfile.impl.StackMapGenerator$Frame.decStack(StackMapGenerator.java:1024)
>>         at java.base/jdk.internal.classfile.impl.StackMapGenerator.processBlock(StackMapGenerator.java:600)
>>         at java.base/jdk.internal.classfile.impl.StackMapGenerator.processMethod(StackMapGenerator.java:420)
>>         at java.base/jdk.internal.classfile.impl.StackMapGenerator.generate(StackMapGenerator.java:293)
>>         at java.base/jdk.internal.classfile.impl.StackMapGenerator.<init>(StackMapGenerator.java:232)
>>         at java.base/jdk.internal.classfile.impl.DirectCodeBuilder$4.writeBody(DirectCodeBuilder.java:333)
>>         at java.base/jdk.internal.classfile.impl.UnboundAttribute$AdHocAttribute.writeTo(UnboundAttribute.java:914)
>>         at java.base/jdk.internal.classfile.impl.AttributeHolder.writeTo(AttributeHolder.java:56)
>>         at java.base/jdk.internal.classfile.impl.DirectMethodBuilder.writeTo(DirectMethodBuilder.java:136)
>>         at java.base/jdk.internal.classfile.impl.BufWriterImpl.writeList(BufWriterImpl.java:194)
>>         at java.base/jdk.internal.classfile.impl.DirectClassBuilder.build(DirectClassBuilder.java:176)
>>         at java.base/jdk.internal.classfile.Classfile.build(Classfile.java:218)
>>         at java.base/jdk.internal.classfile.Classfile.build(Classfile.java:200)
>>         at java.base/jdk.internal.classfile.Classfile.build(Classfile.java:186)
>>         at java.base/jdk.internal.foreign.abi.BindingSpecializer.specializeHelper(BindingSpecializer.java:186)
>>         ...
>> 
>> 
>> (I think ASM will just throw an array index OOB exception when processing a subsequent frame)
>
> Just to clarify: I'm looking for the kind of errors that don't get caught by just generating the class, but are also more informative than the default VerifyError you would get from loading an invalid class.

Classfile API does have some sort of error reporting mechanism in verification; at least it tracks the error context.
https://github.com/openjdk/jdk/blob/83cf28f99639d80e62c4031c4c9752460de5f36c/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/VerifierImpl.java#L1810-L1828
The method dumping is providing a yaml tree representation of the class file to the provided Consumer, and the VerifyError itself already includes the error context. What exact specific information are you looking for that's provided by ASM? We might be able to add it to Classfile API too.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13247#discussion_r1153954352


More information about the core-libs-dev mailing list