<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="direction: ltr; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Rafael, thanks for your adoption!</div>
<ol start="1" data-editing-info="{"orderedStyleType":1,"unorderedStyleType":1}" data-listchain="__List_Chain_3" style="direction: ltr; margin-top: 0px; margin-bottom: 0px; list-style-type: decimal;">
<li style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div class="elementToProof" style="direction: ltr;">In fact, ClassFile API has quite a few non-standard (JVMS) attributes: CharacterRangeTable, CompilationID, ModuleHashes, ModuleResolution, ModuleTarget, SourceDebugExtension, SourceID, and seems there's little
information available about these attributes. I think you can treat them as if they are unknown attributes in your translations to ASM.</div>
</li><li style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div class="elementToProof" style="direction: ltr;">Line numbers are naturally streamed just like labels. If an ASM user is streaming line numbers late, an alternative way is to buffer the other elements into an ASM tree first, then inject the line number tokens
on the second round. (If LineNumberTableAttribute supports using Labels, then we can probably just write that attribute at last, too)</div>
</li><li style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div class="elementToProof" style="direction: ltr;">Unknown attributes are troubling the ClassFile API too. We have a stability() in AttributeMapper to indicate if we should retain or drop attributes. You can always copy any attribute over as-is by calling
XxxBuilder::with(attribute). You should always handle the unknown attributes with a default branch in a switch if you wish to be forward compatible, or an exhaustive switch if you wish to fail fast on newer known attributes.</div>
</li><li style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div class="elementToProof" style="direction: ltr;">For stack map frames, you can use StackMapsOption.DROP_STACK_MAPS and pass a StackMapsTableAttribute in CodeBuilder.with; this is already how ProxyGenerator does it. However we don't allow users to specify
max stacks and locals, which can be hurting performance sensitive use cases.</div>
</li></ol>
<div class="elementToProof" style="direction: ltr; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="direction: ltr; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regards,</div>
<div class="elementToProof" style="direction: ltr; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Chen Liang</div>
<div id="x_appendonsend"></div>
<hr style="direction: ltr; display: inline-block; width: 98%;">
<div id="x_divRplyFwdMsg" dir="ltr"><span style="font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);"><b>From:</b> classfile-api-dev <classfile-api-dev-retn@openjdk.org> on behalf of Rafael Winterhalter <rafael.wth@gmail.com><br>
<b>Sent:</b> Tuesday, August 13, 2024 4:51 AM<br>
<b>To:</b> classfile-api-dev <classfile-api-dev@openjdk.org><br>
<b>Subject:</b> ASM to OpenJDK ClassReader/ClassWriter bridge: experiences and questions</span>
<div> </div>
</div>
<div style="direction: ltr;">Hello!</div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">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.</div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">The code can be found here: <a href="https://github.com/raphw/asm-jdk-bridge" id="OWA2740785e-b87c-54ec-3710-3f68e8ade305" class="OWAAutoLink" data-auth="NotApplicable">
https://github.com/raphw/asm-jdk-bridge</a></div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">A few notes and questions I have:</div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">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?</div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">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?</div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">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.</div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">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.</div>
<div style="direction: ltr;"><br>
</div>
<div style="direction: ltr;">Thanks! Rafael</div>
</body>
</html>