<div dir="ltr"><div>Hi!</div><div><br></div><div>Note that there are MethodCounters added on the assembly run that don't have a MethodTrainingData associated. Maybe because those MethodCounters were created during the assembly? And then they don't reflect behaviour during training run but during assembly run? Or they are added via some other link? I don't know. But in any case, if we don't want MethodCounters with a low count value/with no MethodTrainingData, and we are excluding them from the AOT, we should be consistent with that.</div><div><br></div><div>Example:</div><div><br></div><div>$ grep -r "boolean java.lang.Class.isHidden()" aot.map*<br>target/aot.map:0x00000008014c6340: @@ Method 104 boolean java.lang.Class.isHidden()<br>target/aot.map:0x00000008014c63a8: @@ MethodCounters 64 boolean java.lang.Class.isHidden()<br>target/aot.map:0x0000000803149908: @@ ConstMethod 64 boolean java.lang.Class.isHidden()<br>target/aot.map.0:0x00000008015b23f0: @@ Method 104 boolean java.lang.Class.isHidden()<br>target/aot.map.0:0x00000008015b2458: @@ MethodCounters 64 boolean java.lang.Class.isHidden()<br>target/aot.map.0:0x00000008031d5430: @@ ConstMethod 64 boolean java.lang.Class.isHidden()<br><br></div><div>It appears in both aot.map files (outputs of training and assembly).</div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><br></div><div dir="ltr">Cheers!<br>María.</div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Dec 4, 2025 at 4:55 AM Ashutosh Mehra <<a href="mailto:asmehra@redhat.com" target="_blank">asmehra@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi,</div><div>While working on the leyden-analyzer tool Maria mentioned that MethodCounters for a particular method is present in the preimage generated by the training run but not in the final AOT Cache generated by the assembly phase. In fact the number of MethodCounters in the preimage is way more than that in the final image. For an app that Maria was using, map file for training phase shows:</div><div><br></div><div><span style="color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;font-variant-ligatures:none;background-color:rgba(29,28,29,0.04)">$ grep "@@ MethodCounters " t.map |wc -l
22495</span></div><div><br></div><div>and the map file for assembly phase shows:</div><div><br></div><div><span style="color:rgb(29,28,29);font-family:Monaco,Menlo,Consolas,"Courier New",monospace;font-size:12px;font-variant-ligatures:none;background-color:rgba(29,28,29,0.04)">$ grep "@@ MethodCounters " a.map |wc -l
8701</span></div><div><br></div><div>I checked the code and realized there are two ways MethodCounters can get into the cache:</div><div>1. through Method (see Method::metaspace_pointers_do)</div><div>2. through MethodTrainingData (see MethodTrainingData::metaspace_pointers_do)</div><div><br></div><div>The first point explains the presence of so many MethodCounters, because any method that gets executed would have its MethodCounters added to the cache.</div><div>Interestingly the link between Method and MethodCounters is then severed in Method::unlink_method(). That means the Methods adopted from the preimage in the assembly phase do not have MethodCounters. And since we don't execute the application, we don't create MethodCounters for the Methods loaded from the preimage. Only the MethodCounters discoverable via MethodTrainingData seep into the AOTCache. </div><div><br></div><div>From the above explanation it looks like not every MethodCounters added to the preimage is useful. Probably we should only be adding MethodCounters through the MethodTrainingData and not through Method. This would also reduce the size of the preimage a bit. In this particular case MethodCounters size was 1437824 bytes in preimage and 551552 bytes in the AOT Cache.</div><div><br></div><div>Does this make sense?</div><div><br></div><div>Thanks,</div><div>- Ashutosh Mehra</div></div>
</div>
</div>
</blockquote></div>