RFR: 8373114: Redundant MethodCounters in the preimage generated by training run [v2]
Ashutosh Mehra
asmehra at openjdk.org
Tue Dec 9 02:39:42 UTC 2025
On Tue, 9 Dec 2025 02:16:11 GMT, Ashutosh Mehra <asmehra at openjdk.org> wrote:
>> Details are mentioned in the bug report and this mail thread https://mail.openjdk.org/pipermail/leyden-dev/2025-December/002843.html
>> After this patch the number of MethodCounters in the preimage are much less than before this patch. Also the number of MethodCounters in the preimage is the same as in the final AOTCache (these numbers are obtained using -Xlog:aot=trace).
>>
>> Before this patch for the training run:
>>
>> [18.610s][debug ][aot ] ro_cnt ro_bytes % | rw_cnt rw_bytes % | all_cnt all_bytes %
>> [18.610s][debug ][aot ] MethodCounters : 0 0 0.0 | 22471 1438144 6.2 | 22471 1438144 2.6
>>
>> Before this patch for the assembly phase:
>>
>> [6.680s][debug][aot ] ro_cnt ro_bytes % | rw_cnt rw_bytes % | all_cnt all_bytes %
>> [6.680s][debug][aot ] MethodCounters : 0 0 0.0 | 8588 549632 2.5 | 8588 549632 1.0
>>
>>
>> After this patch for the training run:
>>
>> [49.371s][debug ][aot ] ro_cnt ro_bytes % | rw_cnt rw_bytes % | all_cnt all_bytes %
>> [49.371s][debug ][aot ] MethodTrainingData : 0 0 0.0 | 4658 521696 2.1 | 4658 521696 0.9
>>
>>
>> After this patch for the assembly phase:
>>
>> [12.580s][debug][aot ] ro_cnt ro_bytes % | rw_cnt rw_bytes % | all_cnt all_bytes %
>> [12.580s][debug][aot ] MethodTrainingData : 0 0 0.0 | 4658 521696 2.1 | 4658 521696 0.9
>
> Ashutosh Mehra has updated the pull request incrementally with two additional commits since the last revision:
>
> - Update fix
>
> Signed-off-by: Ashutosh Mehra <asmehra at redhat.com>
> - Update
>
> Signed-off-by: Ashutosh Mehra <asmehra at redhat.com>
Okay, I updated the fix. Idea is the same as before - add MethodCounters reachable from MethodTrainingData, not from Method. But the new fix relies on updating `ArchiveBuilder::get_follow_mode` to add the filter instead of changing Metadata traversal. The filter relies on the assumption that only the MethodCounters that are associated with MethodTrainingData need to be stored in the AOT cache.
This additional filtering was not enough as I noticed number of MCS were still more than number of MTD. This is because some new MCS are created during the assembly phase and they get linked to the existing MTD. This situation was fixed by updating `MethodTrainingData::make()` to avoid doing any lookup in the assembly phase when the JVM is outside AOT safepoint. This makes sense because we shouldn't be using training data for compilations that happen outside of AOT safe point in the assembly phase.
Another approach I thought of was to add the filtering in `ArchiveBuilder::get_follow_mode` such that only the MethodCounters referenced by MTDs are stored in the AOTCache. It is possible to get the enclosing MetaspaceObj but not I couldn't find an easy way to get the type of the enclosing object.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/28670#issuecomment-3629940217
More information about the hotspot-dev
mailing list