ASM to OpenJDK ClassReader/ClassWriter bridge: experiences and questions
Rafael Winterhalter
rafael.wth at gmail.com
Tue Aug 13 09:51:38 UTC 2024
Hello!
It's been a while since I last tried, but I now managed to implement both a
JDK-based ClassReader and ClassWriter for ASM. This seems to work really
well for a range of tests that I did as it allows me to avoid major
rewrites of ASM-based code while still having forward-compatibility as long
as there are no new language constructs as the JDK bundles parser and
serializer.
The code can be found here: https://github.com/raphw/asm-jdk-bridge
A few notes and questions I have:
1. The OpenJDK API supports CharacterRangeTable which is a non-standard
attribute that is not described in the specification. By introducing it to
the official API, isn't the attribute in a way formalized? Is there a plan
to standardize the attribute?
2. One thing that cannot be mapped directly from OpenJDK to ASM are line
numbers. In ASM, they can be added later using a Label. In OpenJDK they
have to be visited at "the right time". Using labels is otherwise common
for other attributes, both in ASM and OpenJDK, but line numbers are the
exception. Is there a reason for this?
3. It would be nice if there was a way to flag what attributes should be
treated as UnknownAttributes. Right now, I retain UnknownAttributes as they
are. But if a future release of the OpenJDK promotes an UnknownAttribute to
a known one, I might miss it when copying them over as raw arrays.
4. I take it so that there are no plans to add support for manually
defining StackMapFrame and method sizes? Sometimes, the OpenJDK erases
information, for example if a local variable is never assigned a value, it
will simply be treated as "N" value. This is not a big issue, but it can
make slight transformations that can have very subtle implications when for
example writing Java agents, so I would still hope for an option for this
to be used by advanced users.
Thanks! Rafael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20240813/c55aaaaf/attachment.htm>
More information about the classfile-api-dev
mailing list