8388410: [Leyden] Improve map file logging to add Embedded Stubs from StubGenBlobs #118
<!-- Welcome message -->
:wave: Welcome back mariasde! A progress list of the required criteria for merging this PR into premain2 will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.
@Delawen This change now passes all automated pre-integration checks.
ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.
After integration, the commit message for the final commit will be:
8388410: [Leyden] Improve map file logging to add Embedded Stubs from StubGenBlobs
Reviewed-by: kvn, adinn, iklam
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.
At the time when this comment was updated there had been 371 new commits pushed to the premain2 branch:
c821bad0ebcea325aaf8ea4a76b17c14d2183566: 8388411: [leyden] Increase memory limit for C2 AOT compilations
558735508c5efce0db1e932ebfee35db22517e2c: Merge
405120e6356fd37a1f196060e931b472c8efde32: Merge master 07-16-2026
... and 368 more: https://git.openjdk.org/leyden/compare/5031301ed5443d85f06522c0a1989d980a23195c...premain2
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.
As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vnkozlov, @adinn, @iklam) but any other Committer may sponsor as well.
➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).
<!-- PullRequestBot merge is ready comment -->
Windows test are failing but I am quite sure it is not my fault (??) It doesn't even finish the configuration.
https://github.com/Delawen/leyden/actions/runs/29523768519/job/87707205844
<!-- mlbridge webrev comment -->
<!-- mlbridge webrev header -->
Webrevs
<!-- mlbridge webrev list -->
08: Full - Incremental (c396c4d5)
07: Full - Incremental (cb613e34)
06: Full - Incremental (5922557b)
05: Full - Incremental (13276190)
04: Full - Incremental (8766a796)
03: Full - Incremental (faacf432)
02: Full - Incremental (77a26f6a)
01: Full - Incremental (222b1d8f)
* 00: Full (4da696d4)
Windows test are failing but I am quite sure it is not my fault (??) It doesn't even finish the configuration.
If I remember correctly I have seen it failing in mainline as well. I don't think it is related to your changes.
Please align (too many spaces)
My concern is the way you find the offset of embedded stubs information is fragile.
May be we should consider adding an other offset field to AOTCodeEntry so you can directly use it. Or may be union with _comp_level and _comp_id and have add separate AOTCodeEntry() constructor for stubs.
May be we should consider adding an other offset field to AOTCodeEntry so you can directly use it. Or may be union with _comp_level and _comp_id and have add separate AOTCodeEntry() constructor for stubs.
Do we need a separated AOTCodeEntry constructor for any other reason? If not, adding an extra offset field seems more clean to me.
It's common for the existing logs to use the first number as the size. E.g.
0x00000008000d3788: @@ TypeArrayU8 96
0x00000008000d3788: 000000000000000b 000000080033a7e8 000000080033a730 000000080033a678 ..........3.....0.3.....x.3.....
0x00000008000d37a8: 000000080033a608 000000080033a598 000000080033a528 000000080033a4b8 ..3.......3.....(.3.......3.....
0x00000008000d37c8: 000000080033a448 000000080033a3d8 000000080033a368 000000080033a2f8 H.3.......3.....h.3.......3.....
0x00000008000d37e8: @@ TypeArrayU8 24
0x00000008000d37e8: 0000000000000002 00000008000dd000 00000008000dc800 ........................
However, the meaning of the other number is not easy to understand.
0x00007fd2fbffefe4: @@ StubGenBlob 24452 73 initial_blob (stub gen)
0x00007fd2dbfff05b: @@ EmbeddedStub 276 73 77 call_stub_stub (stub gen)
I think it's better to do this
0x00007fd2fbffefe4: @@ StubGenBlob 24452 id = 73 initial_blob (stub gen)
0x00007fd2dbfff05b: @@ EmbeddedStub 276 id = 77 blob = 73 call_stub_stub (stub gen)
(I swapped the order of id and blob so the id always appears first.
Also, is (stub gen) always printed?
All looks good.
Do we need a separated AOTCodeEntry constructor for any other reason? If not, adding an extra offset field seems more clean to me.
I agree to new offset field.
Yes, having (stab gen) in all names is strange. @adinn do we really need it?
Yes, having (stab gen) in all names is strange. @adinn do we really need it?
I just print what I get, if it is needed we can also scrap that before printing on the log (hope it won't break things further)
Yes, having (stub gen) in all names is strange. @adinn do we really need it?
Well, yes, we can avoid it but it is not as simple or as clean as it looks. Omitting the(stub gen) suffix has implications for other print contexts.
The need for the suffix is an unfortunate legacy of the way names have been given to stubs/blobs. We have several places where the names used to declare blobs and their associated stubs overlap across different groups of blob/stub.
So, for example, forward_exception is used declare a C1 blob
#define C1_STUBS_DO(do_blob) \
do_blob(dtrace_object_alloc) \
... \
do_blob(forward_exception) \
... \
and also to declare an initial stubgen stub
#define STUBGEN_INITIAL_BLOBS_DO(do_blob, end_blob, \
do_stub, \
do_entry, do_entry_init, \
do_entry_array, \
do_arch_blob, \
do_arch_entry, do_arch_entry_init, \
do_arch_entry_array) \
do_blob(initial) \
do_stub(initial, call_stub) \
do_entry(initial, call_stub, call_stub_entry, call_stub_entry) \
... \
do_stub(initial, forward_exception) \
do_entry(initial, forward_exception, forward_exception_entry, \
forward_exception_entry) \
... \
Another example is new_instance which is use in the declaration of both a C1 blob and its associated stub
#define C1_STUBS_DO(do_blob) \
do_blob(dtrace_object_alloc) \
... \
do_blob(new_instance) \
... \
and a C2 blob and its associate stub
#define C2_STUBS_DO(do_blob, do_stub) \
do_blob(uncommon_trap, UncommonTrapBlob) \
... \
do_stub(new_instance, 0, true, false) \
... \
Note that in the second example in both cases there is a C1 and C2 blob and an associated C1 and C2 stub which need to have a name generated for them both of them starting with the single declaration id new_instance
In order to ensure we have unique stub names (or unique blob names) we have to append the declared stub (or blob) name to the stub category name e.g. for the first case we generate stub names "forward_exception (stub gen)" and"forward_exception (c1)" and for the second case we generate stub (and blob) names "new_instance (c1)" and "new_instance (c2)".
Note that in the first case the clash only occurs in the stub names. The blob names are "initial (stub gen)" and "forward_exception (c1)". In the second case the clash occurs for both the blob name and the stub name (when we have a single stub blob we use the same name for the blob or stub).
So, even though the (stub gen) suffix appears to be redundant in the map printout -- because we only need to print the stub names for stubgen blobs i.e. multi-stub blobs -- it is actually an important element of the stub name that distinguishes it from other occurrences where a different stub is being named.
If we wanted to avoid having the suffix in the name then the way to achieve that would be to ensure that declaration names were unique across stub categories. We could, for example, just add a qualifying tag to the declaration name in the cases where names clash forward_exception_stubgen and forward_exception_c1 -- likewise, new_instance_c1 and new_instance_c2.
However, this would imply a change to the generated stub enum tags, field and accessor names for these cases requiring client code also to be updated. Calls to SharedRuntime::forward_exception() would now need to be written as SharedRuntime::forward_exception_stubgen(). Meanwhile other calls like SharedRuntime::catch_exception() would continue to omit the _stubgen suffix. Likewise, the code that accesses the C2 stub would now need to access OptoRuntime::new_instance_c2_Java() while other calls like OptoRuntime::new-array_Java() would stay as they are.
I don't think this is actually much nicer as a solution. The map printout is slightly simplified but the client calls are now non-uniform.
@vnkozlov I agree the current code that accesses the stub details is rather fragile -- I was thinking about that last night and thought of two ways to deal with it.
Firstly, we should probably move the code in print routine AOTMapLogger::log_embedded_stubs into class AOTCodeCache. That way if the layout gets changed then there is more chance that the print code will also get updated.
Secondly, we could usefully add some asserts to the printing code to ensure the data values read are as expected.
So, for example when we read the sizes for intermediate data to skip over the blob, the relocs and any oop map there should be asserts that the current position is within the bounds of the entry.
Likewise when reading successive stub ids
- the stubid should be checked to ensure that is lies between StubId::NO_STUBID and StubId::NUM_STUBIDS
- it should be an id associated with the current blob id StubInfo::blob(stub_id) == blob_id
- the entry+extras count for the stub read from the file should exceed the declared entry count count >= StubInfo::entry_count(blob_id)
Maria, could you add asserts to the print code as mentioned in my comment to @vnkozlov and also consider moving the print routine into class AOTCodeCache?
Sure. I was already working on adding the offset as a field, I can do the rest too.
@Delawen
Just to confirm what we discussed online . . .
The entry + extras count for the stub that is read from the file always omits the first entry. Every stub must have at least one entry, at offset 0, and may have 0 or more extra entries. So, if you read value count then that value is supposed to represent StubInfo::entry_count(blob_id) - 1 + extras. So the minimum value for count is StubInfo::entry_count(blob_id) - 1 and the asserted condition should be count >= StubInfo::entry_count(blob_id) - 1.
Looks good to me.
@adinn
I am okay with keeping (stub gen). thank you for explaining the situation with it.
Firstly, we should probably move the code in print routine AOTMapLogger::log_embedded_stubs into class AOTCodeCache. That way if the layout gets changed then there is more chance that the print code will also get updated.
Yes, I agree.
Secondly, we could usefully add some asserts to the printing code to ensure the data values read are as expected.
Yes, we can add asserts. At lest check stubs ID.
Do we have an iterator that can be used, instead of doing low level operations here in the AOT code?
For modularity, I would prefer an iterator that lives in the stub management code.
Do we have an iterator that can be used, instead of doing low level operations here in the AOT code?
The nearest thing we have is class AOTStubData, which collects details of the stubs and associated entries as part of a traversal of the full entry contents. It supports full rehydration of the blob so it does a lot more work than we need simply to print details of the stubs.
I tried using AOTStubData but I think it is overkilling. This check on base returns always the nullpointer: https://github.com/openjdk/leyden/blob/premain2/src/hotspot/share/code/aotCodeCache.cpp#L4235-L4238
Which leads me to think we can only use AOTStubData if/when we are loading the cache into memory, not when we are generating it. Modifying it further to be able to have a valid StubAddrRange seems too complex.
The code I'm using is https://github.com/Delawen/leyden/blob/tiriri/src/hotspot/share/cds/aotMapLogger.cpp#L125-L153
So unless you have any other ideas I think this PR is ready to go.
Yes, AOTStubData is built to do a much more complex job than you need.
So unless you have any other ideas I think this PR is ready to go.
You can still relocate the code that iterates over the stub entries in method log_embedded_stub from class AOTMapLogger into class AOTCodeCcache. You will need to refactor it a bit -- just transplanting the method as is moves the printing logic out of class AOTMapLogger. You can avoid that by implementing a method on AOTCodeCache that accepts a StubGen entry and a function pointer or a closure and applies the function to each stub in the entry e.g.
Declare a fn pointer type in aotCodeCache.hpp
typedef void (*stub_printer_t)(BlobId blob_id, StubId stub_id, int base, int code_base, int offset);
Then add a public method to class
AOTCodeCache:void AOTCodeCache::do_print_stub_details(AOTCodeEntry* entry, aot_stub_printer_t printer) {
assert(entry->kind() == StubGen), "invalid call");
BlobId blob_id = (BlobId)entry->id();
int base = entry->offset();
int code_base = entry->code_offset();
//skip forward to entries
. . .
while (stub_id != StubId::NO_STUBID) {
offset = ...;
(*printer)(blob_id, stub_id, base, code_base, offset);
// skip to next id
. . .
}
}
You can then call
AOTCodeCache::do_print_stub_details from AOTMapLogger passing in a pointer to the print function. An alternative to using a fn pointer is to use a lambda or a closure i.e. an instance of a class that implements callback method.
Pushed it http://github.com/openjdk/leyden/pull/118/commits/13276190295fb3922dd1e93fee903aa577504d04
But I am not sure what the NOT_CDS_RETURN or CDS_ONLY macros mean. I guess I should add them to my new functions?
I know @vnkozlov recommended insering this field but I don't really like it. It means every AOTCodeEntry now includes and extra int field even thought the offset is only needed for StubGen stub entries and then only when we are dumping a map.
The point of adding this field is to avoid having to traverse a StubGen entry's blob, relocs and oop map in order to locate the stub data. That was maybe a good idea when the code was outside of class AOTCodeCache as it reduced fragility. However, now that the traversal code is internal to the class (and now also that we have asserts to discover any errors introduced by a change in format) I think it is a better trade-off to omit this extra field and require method loop_over_embedded_stubs to traverse from the start of the entry to the start of the stub data. We will only do that traversal several hundreds of times when we are dumping a map but we will save an extra word for several thousands of nmethods in every cache.
@vnkozlov What do you think?
Looks good apart from a question as to whether we want to preserve the offset to the stub data which I am hoping @vnkozlov will address.
I like field. How about union?:
union {
uint _embedded_stub_offset; // Start of embedded stubs in StubGenBlobs
uint _comp_level; // compilation level
};
You have to check
kind in constructor to assign field to avoid overwriting.Seems to work. @vnkozlov @adinn
Ok, looks good.
The HotSpot convention is to call this function iterate_embedded_stubs().
For consistency, use "... %-17s %d id=%d %s",
Also, we should use id=%d and level=%d for the Nmethod and default cases.
These functions should have precond(_kind == StubGenBlo). Similarly, the comp_level() accessor should assert the opposite.
Extraneous spaces before =.
Looks good to me too. I will wait GHA finished to submit our testing too.
@vnkozlov ready for your tests
LGTM
@vnkozlov ready for your tests
Submitted.
My testing passed.
good
/integrate
Hope the failing windows test job does not interfere with integration...
<!-- Jmerge command reply message (5089414785) -->
@Delawen <!-- integration requested: 'c396c4d5b657944a7bb62b6584096a3de4788193' -->
Your change (at version c396c4d5b657944a7bb62b6584096a3de4788193) is now ready to be sponsored by a Committer.
Can someone sponsor me? @adinn @ashu-mehra @iklam @vnkozlov
/sponsor
<!-- prepush ec0494a48ef17cbf5e3a24ef7f20c99ffbd1bbf7 -->
Going to push as commit ec0494a48ef17cbf5e3a24ef7f20c99ffbd1bbf7.
Since your change was applied there have been 371 commits pushed to the premain2 branch:
c821bad0ebcea325aaf8ea4a76b17c14d2183566: 8388411: [leyden] Increase memory limit for C2 AOT compilations
558735508c5efce0db1e932ebfee35db22517e2c: Merge
405120e6356fd37a1f196060e931b472c8efde32: Merge master 07-16-2026
... and 368 more: https://git.openjdk.org/leyden/compare/5031301ed5443d85f06522c0a1989d980a23195c...premain2
Your commit was automatically rebased without conflicts.
<!-- Jmerge command reply message (5091187421) -->
@adinn @Delawen Pushed as commit ec0494a48ef17cbf5e3a24ef7f20c99ffbd1bbf7.
:bulb: You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.
adinn
Delawen
Continuation of https://github.com/openjdk/leyden/pull/115
Right now, we log StubGenBlobs in premain2: https://github.com/openjdk/leyden/pull/115
Current output example:
But we are skipping logging of the embedded stubs inside those blobs. This PR improves the logging to add the embedded stubs too.
The log line for
EmbeddedStubcontains the following data:- Pointer
- Size of the Embedded Stub
- Id of the StubGenBlob (BlobId) to link back to which StubGenBlob it belongs (although it should be ordered)
- Id of the Embedded Stub
- Name of the Embedded stub
Example of output:
---------
<!-- Anything below this marker will be automatically updated, please do not edit manually! -->
---------
Progress
Issue
JDK-8388410: [Leyden] Improve map file logging to add Embedded Stubs from StubGenBlobs (Sub-task - P4)
Reviewers
Vladimir Kozlov (@vnkozlov - Reviewer)
Andrew Dinn (@adinn - Reviewer)
Ioi Lam (@iklam - Reviewer)
Reviewing
<details><summary>Using <code>git</code></summary>
Checkout this PR locally: \
$ git fetch https://git.openjdk.org/leyden.git pull/118/head:pull/118\$ git checkout pull/118Update a local copy of the PR: \
$ git checkout pull/118\$ git pull https://git.openjdk.org/leyden.git pull/118/head</details>
<details><summary>Using Skara CLI tools</summary>
Checkout this PR locally: \
$ git pr checkout 118View PR using the GUI difftool: \
$ git pr show -t 118</details>
<details><summary>Using diff file</summary>
Download this PR as a diff file: \
<a href="https://git.openjdk.org/leyden/pull/118.diff">https://git.openjdk.org/leyden/pull/118.diff</a>
</details>
<details><summary>Using Webrev</summary>
Link to Webrev Comment
</details>