<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Apple Color Emoji";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="en-CZ" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">To separate Classfile API improvements from
</span><span lang="EN-US" style="font-size:11.0pt"><a href="https://github.com/openjdk/jdk/pull/10991">https://github.com/openjdk/jdk/pull/10991</a>
</span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">I’ve created
<a href="https://bugs.openjdk.org/browse/JDK-8306842">https://bugs.openjdk.org/browse/JDK-8306842</a> with following list of improvements (independent on the upcoming Constants API changes):<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:#172B4D;background:white">- Switch over `String` patterns can be replaced with switch over single char in some case to prevent calculation of `String` hash.<span class="apple-converted-space"> </span></span><span style="font-size:10.5pt;font-family:"Arial",sans-serif;color:#172B4D"><br>
<span style="background:white">- `ClassDesc` and `MethodTypeDesc` symbols can be cached and shared inside relevant CP entries to prevent repeated construction and validation of the symbols.<span class="apple-converted-space"> </span></span><br>
<span style="background:white">- `StackMapGenerator` can benefit from the cached symbols to prevent repeated construction and validation of the symbols.<span class="apple-converted-space"> </span></span><br>
<span style="background:white">- `StackMapGenerator::getFrameIndexFromOffset` can use binary search for improved performance<span class="apple-converted-space"> </span></span><br>
<span style="background:white">- `StackMapGenerator.exceptionTable` can pre-calculate offsets to avoid repeated labels resolutions.<span class="apple-converted-space"> </span></span><br>
<span style="background:white">- `StackMapGenerator::processExceptionHandlerTargets` can skip execution for try block bodies when unchanged locals.<span class="apple-converted-space"> </span></span></span><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Second batch of improvements including use of `ClassDesc::internalName` and other benefits of the improved Constants API can follow.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt;mso-fareast-language:EN-US">Adam<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">classfile-api-dev <classfile-api-dev-retn@openjdk.org> on behalf of Adam Sotona <adam.sotona@oracle.com><br>
<b>Date: </b>Tuesday, 25 April 2023 11:06<br>
<b>To: </b>liangchenblue@gmail.com <liangchenblue@gmail.com>, classfile-api-dev <classfile-api-dev@openjdk.org><br>
<b>Subject: </b>Re: Caching symbolic descriptors for the constant pool<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt;mso-fareast-language:EN-US"> </span><o:p></o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:36.0pt">
<b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">classfile-api-dev <classfile-api-dev-retn@openjdk.org> on behalf of liangchenblue@gmail.com <liangchenblue@gmail.com><br>
<b>Date: </b>Tuesday, 25 April 2023 1:18<br>
<b>To: </b>classfile-api-dev <classfile-api-dev@openjdk.org><br>
<b>Subject: </b>Caching symbolic descriptors for the constant pool</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt">First, thanks for the feedback on my cache proposal a few days ago!<br>
I've prepared two patches under 8306697<br>
<a href="https://github.com/openjdk/jdk/pull/13598and">https://github.com/openjdk/jdk/pull/13598and</a> 8306698<br>
<a href="https://github.com/openjdk/jdk/pull/13599">https://github.com/openjdk/jdk/pull/13599</a>, which will hopefully make<br>
the Constant API more useful with classfiles.<br>
<br>
I wish to cache symbolic descriptors in classfile API itself. One of<br>
the prime candidates identified by Adam in his migration of<br>
java.lang.invoke to classfile API is ClassEntry.asSymbol, which from<br>
my search, appears to be frequently used in stack map generation. In<br>
addition, a MethodTypeDesc is passed to stack map generator<br>
constructor via ofDescriptor (which has slow parsing even after Adam's<br>
optimization), but the parsing can totally be averted if we can reuse<br>
the MethodTypeDesc passed in withMethod(). Thus, I wish to add<br>
accessors like typeSymbol() and cachedTypeSymbol() for MethodInfo to<br>
speed up StackMapGenerator initialization.<br>
<br>
In addition, the stack map generator has a custom bitset-based tool to<br>
split a descriptor on the fly (See<br>
StackMapGenerator.processInvokeInstructions). I believe they can<br>
benefit from reusing a parsed MethodTypeDesc as well, especially if<br>
the invoke instructions were originally built with MethodTypeDesc.</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:11.0pt"><br>
Chen Liang</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">There is definitely a lot to re-consider in the Classfile API implementation to boost performance based on the proposed changes in the Constants API.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">I’ve set <a href="https://github.com/openjdk/jdk/pull/10991">
https://github.com/openjdk/jdk/pull/10991</a> back to draft. It should first split into one or more Classfile API implementation performance improvements and wait before re-proposing it for review (at least fine tune caching of symbols and
</span><span style="font-size:11.0pt">StackMapGenerator</span><span lang="EN-US" style="font-size:11.0pt">).</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">I’m looking forward to see all the improvements merged in one place
</span><span lang="EN-US" style="font-size:11.0pt;font-family:"Apple Color Emoji"">😊</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">Thanks,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt">Adam</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.0pt"> </span><o:p></o:p></p>
</div>
</div>
</body>
</html>