Skip to content

Conversation

@stefank
Copy link
Member

@stefank stefank commented Dec 10, 2025

Found this while poking around at Valhalla that turned off heap sharing. The fix is simple, there's a missing HeapShared::is_loading() check that we missed when refactoring the object streaming code.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8373411: Crash when PrintSharedArchiveAndExit is enabled but shared heap is disabled (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28741/head:pull/28741
$ git checkout pull/28741

Update a local copy of the PR:
$ git checkout pull/28741
$ git pull https://git.openjdk.org/jdk.git pull/28741/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28741

View PR using the GUI difftool:
$ git pr show -t 28741

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28741.diff

Using Webrev

Link to Webrev Comment

@stefank
Copy link
Member Author

stefank commented Dec 10, 2025

This is the assert that you get when hitting this issue:

#  assert(_heap_load_mode != HeapArchiveMode::_uninitialized) failed: not initialized yet

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 10, 2025

👋 Welcome back stefank! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 10, 2025

@stefank 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:

8373411: Crash when PrintSharedArchiveAndExit is enabled but shared heap is disabled

Reviewed-by: shade, 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 31 new commits pushed to the master branch:

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.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Dec 10, 2025

@stefank The following label will be automatically applied to this pull request:

  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 10, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 10, 2025

Webrevs

Comment on lines 29 to 30
* @modules java.base/jdk.internal.misc
* java.management
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I copy-n-pasted the code from PrintSharedArchiveAndExit.java and didn't think about it.

*
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:SpecTrapLimitExtraEntries=0 compiler.arguments.TestSpecTrapLimitExtraEntries
* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:SpecTrapLimitExtraEntries=100 compiler.arguments.TestSpecTrapLimitExtraEntries
* @summary Testing -XX:+PrintSharedArchiveAndExit option with no shared heap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add bug ID.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why is that important? I would have guessed that the git history would be sufficient to figure this out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jtreg allows running the tests related to a particular bug ID: https://openjdk.org/jtreg/command-help.html -- although I don't know who uses this feature instead of just running the majority of the tests most of the time :)

    -bug:<bugid>    Run only those tests which apply to the given bugid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I've never felt the need or want to use that :D. I'll add the bugid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I asked for the bug ID:

The usage in this test is not common: java -XX:AOTCacheOutput=... -XX:+PrintSharedArchiveAndExit will not create the specified AOT cache. Having the bug ID will make it easy to understand why the test is written in this way.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I would have used git for that ...

Copy link
Member

@shipilev shipilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hold on, how does it crash? I cannot see right away how this would fail:

size_t StringTable::shared_entry_count() {
  assert(HeapShared::is_loading_mapping_mode(), "should not reach here");
  return _shared_table.entry_count();
}

class SimpleCompactHashtable {
  ...
  inline size_t entry_count() const {
    return _entry_count;
  }
  ...
}

static SharedStringTable _shared_table;

The assert in StringTable::shared_entry_count() is likely incomplete too.

@shipilev
Copy link
Member

Hold on, how does it crash?

Oh, so it fails the assert in the mode checker:

inline bool HeapShared::is_loading_mapping_mode() {
  assert(_heap_load_mode != HeapArchiveMode::_uninitialized, "not initialized yet"); // <---
  return _heap_load_mode == HeapArchiveMode::_mapping;
}

All right. The assert in StringTable::shared_entry_count() needs fixing as well then.

@stefank
Copy link
Member Author

stefank commented Dec 11, 2025

Hold on, how does it crash? I cannot see right away how this would fail:

size_t StringTable::shared_entry_count() {
  assert(HeapShared::is_loading_mapping_mode(), "should not reach here");
  return _shared_table.entry_count();
}

class SimpleCompactHashtable {
  ...
  inline size_t entry_count() const {
    return _entry_count;
  }
  ...
}

static SharedStringTable _shared_table;

The assert in StringTable::shared_entry_count() is likely incomplete too.

That one has been left as-is intentionally. We should never call shared_entry_count without having enabled "heap sharing" and "loading mode of heap sharing". If anyone would try to call it without enabling/initializing "loading mode", then we'll get an appropriate assert that the loading mode has not been initialized.

@stefank
Copy link
Member Author

stefank commented Dec 11, 2025

I could change the code to:

size_t StringTable::shared_entry_count() {
  assert(HeapShared::is_loading(), "should not reach here");
  assert(HeapShared::is_loading_mapping_mode(), "should not reach here");
  return _shared_table.entry_count();
}

Personally, I think it is redundant, because the second assert would catch a failure of the first. But if you all think this is better, then I'll add it.

@shipilev
Copy link
Member

Personally, I think it is redundant, because the second assert would catch a failure of the first. But if you all think this is better, then I'll add it.

Meh, can go either way. I won't quibble for this patch.

Honestly, my expectation is that when HeapShared::is_loading_mapping_mode() == true, then HeapShared::is_loading() == true, and when is_loading_mapping_mode() == false, then is_loading() is undefined/dont-care value. In that sense, current code that checks only HeapShared::is_loading_mapping_mode() would have been correct already. But I am guessing you don't want to miss a bug when is_loading_mapping_mode() returns false, just because we have a lifecycle bug somewhere and loading mode is uninitialized. OTOH, it is literally the same as checking is_loading() explicitly like your PR does, so it gains us nothing safety-wise, and only confuses ourselves. Maybe rethinking the state machinery a bit here would be a good cleanup.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 11, 2025
@stefank
Copy link
Member Author

stefank commented Dec 11, 2025

Personally, I think it is redundant, because the second assert would catch a failure of the first. But if you all think this is better, then I'll add it.

Meh, can go either way. I won't quibble for this patch.

Honestly, my expectation is that when HeapShared::is_loading_mapping_mode() == true, then HeapShared::is_loading() == true, and when is_loading_mapping_mode() == false, then is_loading() is undefined/dont-care value. In that sense, current code that checks only HeapShared::is_loading_mapping_mode() would have been correct already. But I am guessing you don't want to miss a bug when is_loading_mapping_mode() returns false, just because we have a lifecycle bug somewhere and loading mode is uninitialized.

Yes. We have had a few of those bugs at the end of the development cycle for the object streaming JEP.

OTOH, it is literally the same as checking is_loading() explicitly like your PR does, so it gains us nothing safety-wise, and only confuses ourselves. Maybe rethinking the state machinery a bit here would be a good cleanup.

I think Erik had it more like you suggest, but if I understood Ioi correctly he wanted things to be more explicit, and this is what we ended up with. I don't mind if someone wants to take a stab at restructuring this, but I'm not personally volunteering to do this. I would rather take the time to make other refactoring and renaming that we felt would benefit the heap sharing code, and we had hope to get to it after the JEP was delivered. However, the reality is that we're all prioritizing other work at the moment so I don't know if / when we'll get to that.

@stefank
Copy link
Member Author

stefank commented Dec 12, 2025

Thanks for the reviews! Tier1 testing passed.
/integrate

@openjdk
Copy link

openjdk bot commented Dec 12, 2025

Going to push as commit d854a04.
Since your change was applied there have been 42 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 12, 2025
@openjdk openjdk bot closed this Dec 12, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 12, 2025
@openjdk
Copy link

openjdk bot commented Dec 12, 2025

@stefank Pushed as commit d854a04.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-runtime [email protected] integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants