<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>