JDK-8335358 : [premain] Explore alternative ways to trigger the end of training run
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: repo-leyden
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-06-28
  • Updated: 2025-03-13
  • Resolved: 2025-01-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
repo-leydenFixed
Related Reports
Blocks :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
Project Leyden is enhancing CDS to take further advantage of training runs.  Decisions - such as loaded classes, profiling data, etc - are collected during the training run and used to create a CDS archive.

Currently, the training run must exit normally for the data to be reported - either as CDS's current classlist or to execute the _assembly phase_ in the Leyden repo's "premain" branch.

It may be difficult for users to run to normal completion for all training runs - some may prefer to only record data until the application framework has started or prior to some method being invoked.

This RFE is to track other possible triggers for CDS data to be collected and / or for the _assembly phase_ to being.

* JCMD: a new jcmd can be developed to attach to a running JVM and signal the training run has ended.  For classic CDS, this may be the point at which the classlist is dumped to the file.  For premain CDS, this may trigger the start of the assembly phase and the creation of the CDS archive.

* API: a new Leyden-specific API may be created that allows developers to indicate programatically the point at which the training run should end.  This could be as simple as a static method `Leyden.endTraining()` or something that exposes more state such as the name of the CDS file.  Details TBD based on need.

* Commandline: a new option could specify when to trigger the end of the training run.  ie: `-XX:AOTEndTrainingOnMethodEntry=org.foo.bar.someMethod`.  This can be extended beyond single entry to also include a counted entry ie: the 1000 time this method is entered.

This would make it easier to stop training runs at the appropriate place for users who don't otherwise have an easy workload that runs to completion (ie: server applications) or who need to end training before non-framework code is executed so that training would more broadly applicable.
Comments
I added JDK-8351894 as a blocker even though this one is pushed, because I think we need the jl.System API point ASAP in the main line. That way we can begin to get experience with cooperative ETR and the bug tail that will inevitably come along with it. Meanwhile we need to play with this non-cooperative breakpoint like ETR mechanism. Two important bits: 1. figure out the right internal mechanism for "hooking" method entry, and 2. figure out a CLI that does not resemble -XX:CompileCommand=stuff. (No disparagement on this prototype, it is necessary!) I have talked to the Oracle VM team and have some new ideas about how to structure the method entry hook. I think we can merge Mat's mechanism with a pre-existing (rather obscure) mechanism used by the GC for trapping on method entry. In the code it is called nmethod_entry_barrier_stub It is single-client, but can (with more work) be multiplexed to multiple clients. The cmp can be replaced by a test to test a bitmask, with different bits assigned to different clients.
13-03-2025

This RFE has been integrated into the leyden/premain branch - https://github.com/openjdk/leyden/pull/21 - https://github.com/openjdk/leyden/commit/6e6030b917f1dfcd4ea7c6207ce0626bf5452c3f Added interfaces: https://github.com/openjdk/leyden/blob/6e6030b917f1dfcd4ea7c6207ce0626bf5452c3f/README.md (1) -XX:AOTEndTrainingOnMethodEntry=<method1,method2,...>[,count=100] (2) jcmd <pid> AOT.end_training
21-01-2025

Pushed -XX:AOTEndTrainingOnMethodEntry=[methods][count], System.AOTEndTraining(), System.AOTIsTraining() and jcmd AOT.end_training to premain https://github.com/openjdk/leyden/pull/21#issuecomment-2495140178
25-11-2024

Adding ability to trigger some JVM event (upcall) upon Nth entry to a named method that does not require code modification. See https://mail.openjdk.org/pipermail/leyden-dev/2024-August/000868.html for details
28-08-2024

[~iklam] Dan pointed us to this issue but you mentioned in leyden-dev you are working on a jcmd prototype. Shall we assign this to you, can we help with this and/or the non-jcmd parts of this enhancement?
20-08-2024