Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8201516: DebugNonSafepoints generates incorrect information #12806

Closed
wants to merge 8 commits into from

Conversation

TobiHartmann
Copy link
Member

@TobiHartmann TobiHartmann commented Mar 1, 2023

C2 emits incorrect debug information when diagnostic -XX:+DebugNonSafepoints is enabled. The problem is that renumbering of live nodes (-XX:+RenumberLiveNodes) introduced by JDK-8129847 in JDK 8u92 / JDK 9 does not update the _node_note_array side table that links IR node indices to debug information. As a result, after node indices are updated, they point to unrelated debug information.

The reproducer shared by the original reporter @jodzga (@jbachorik also reported this issue separately) does not work anymore with recent JDK versions but with a slight adjustment to trigger node renumbering, I could reproduce the wrong JFR method profile:

Screenshot from 2023-03-01 13-17-48

It suggests that the hottest method of the Test is not the long running loop in Test::arraycopy but several other short running methods. The hot method is not even in the profile. This is obviously wrong.

With the fix, or when running with -XX:-RenumberLiveNodes as a workaround, the correct profile looks like this:

Screenshot from 2023-03-01 13-20-09

With the help of the IR framework, it's easy to create a simple regression test (see testRenumberLiveNodes).

The fix is to create a new node_note_array and copy the debug information to the right index after updating node indices. We do the same in the matcher:

// Save debug and profile information for nodes in old space:
_old_node_note_array = C->node_note_array();
if (_old_node_note_array != NULL) {
C->set_node_note_array(new(C->comp_arena()) GrowableArray<Node_Notes*>
(C->comp_arena(), _old_node_note_array->length(),
0, NULL));

Another problem is that Parse::Parse calls C->set_default_node_notes(caller_nn) before do_exits, which resets the JVMState to the caller state. We then set the bci to InvocationEntryBci in the caller JVMState. Any new node that is emitted in do_exits, for example a MemBarRelease, will have that JVMState attached and NonSafepointEmitter::observe_instruction -> DebugInformationRecorder::describe_scope will then use that information when emitting debug info. The resulting debug info is misleading because it suggests that we are at the beginning of the caller method. The tests testFinalFieldInit and testSynchronized reproduce that scenario.

The fix is to move set_default_node_notes down to after do_exits.

I find it also misleading that we often emit "synchronization entry" for InvocationEntryBci at method entry/exit in the debug info, although there is no synchronization happening. I filed JDK-8303451 to fix that.

Thanks,
Tobias


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-8201516: DebugNonSafepoints generates incorrect information

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12806

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 1, 2023

👋 Welcome back thartmann! 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 openjdk bot added the rfr Pull request is ready for review label Mar 1, 2023
@openjdk
Copy link

openjdk bot commented Mar 1, 2023

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

  • hotspot-compiler

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 hotspot-compiler hotspot-compiler-dev@openjdk.org label Mar 1, 2023
@mlbridge
Copy link

mlbridge bot commented Mar 1, 2023

Webrevs

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

I have few comments.

Comment on lines 473 to 474
if (old_node_note_array != NULL) {
C->set_node_note_array(new (C->comp_arena()) GrowableArray<Node_Notes*> (C->comp_arena(), 8, 0, NULL));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use nullptr in these lines.
Can you use _useful.size() as initial array length?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review, Vladimir. I updated the NULL usages.

Can you use _useful.size() as initial array length?

The node_note_array uses buckets/blocks of size C->_node_notes_block_size == 256. So the actual required size would be ceil((double)useful.size() / (double)256) but we could simply use 1 + (useful.size() / 256).

Now even when initializing the GrowableArray to that size, setting notes will then still call Compile::grow_node_notes multiple times to create the Node_Notes buckets and since it always at least doubles the backing array size, we actually end up with an array that is larger than what is required:

if (grow_by < num_blocks) grow_by = num_blocks;
int num_notes = grow_by * _node_notes_block_size;
Node_Notes* notes = NEW_ARENA_ARRAY(node_arena(), Node_Notes, num_notes);
Copy::zero_to_bytes(notes, num_notes * sizeof(Node_Notes));
while (num_notes > 0) {
arr->append(notes);

I updated the code to properly pre-size the structure by calling grow_node_notes. This also has the advantage that the Node_Notes arena is one big chunk instead of incrementally allocating small ones.

What do you think?

@@ -484,6 +489,11 @@ PhaseRenumberLive::PhaseRenumberLive(PhaseGVN* gvn,
assert(_old2new_map.at(n->_idx) == -1, "already seen");
_old2new_map.at_put(n->_idx, current_idx);

if (old_node_note_array != NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nullptr

@@ -469,6 +469,13 @@ PhaseRenumberLive::PhaseRenumberLive(PhaseGVN* gvn,

uint worklist_size = worklist->size();

GrowableArray<Node_Notes*>* old_node_note_array = C->node_note_array();
if (old_node_note_array != nullptr) {
int new_size = (_useful.size() >> 8) + 1; // The node note array uses blocks, see C->_log2_node_notes_block_size
Copy link
Contributor

Choose a reason for hiding this comment

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

You should call new_size = MAX2(8, new_size) to make sure that we have at least 8 elements for initial allocation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I added that. The 8 seems arbitrary to me but since we already use that for initial allocation of the array, we can as well be consistent here. Just note that since we are calling C->grow_node_notes, we will also initialize with Node_Notes* right away.

Copy link
Member

Choose a reason for hiding this comment

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

Why don't we just use C->_log2_node_notes_block_size directly in (_useful.size() >> 8)?

I don't understand why we have to add MAX2(8, new_size) either. It looks like c2 doesn't want to have node-level accuracy. It drops the lowest 8bits of node_idx as block_id. I think the minimal number of "block" is 1, or arr is NULL.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why don't we just use C->_log2_node_notes_block_size directly in (_useful.size() >> 8)?

Because it's private in Compile. We could make it public but I thought it's not worth it.

I don't understand why we have to add MAX2(8, new_size) either. It looks like c2 doesn't want to have node-level accuracy. It drops the lowest 8bits of node_idx as block_id. I think the minimal number of "block" is 1, or arr is NULL.

I think you are misinterpreting the code in Compile::locate_node_notes. It first determines the block_idx by idx >> _log2_node_notes_block_size and then the position in that block by idx & (_node_notes_block_size-1).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the clarification. yes, I understanding was wrong.

A block is an array of 256 Node_Note. Is it a particular reason that Compile needs at least 8 blocks? It can grow automatically anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it a particular reason that Compile needs at least 8 blocks?

It's the value that is used when creating the array:

set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
(comp_arena(), 8, 0, NULL));
set_default_node_notes(Node_Notes::make(this));

I don't think there is a particular reason for 8 but it's just one of those more or less reasonable default values/sizes that we use all over the place when creating containers.

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Choose a reason for hiding this comment

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

Good

@openjdk
Copy link

openjdk bot commented Mar 3, 2023

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

8201516: DebugNonSafepoints generates incorrect information

Reviewed-by: kvn, roland

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 100 new commits pushed to the master branch:

  • 8e20145: 8300654: Remove JVMFlag::flag_error_str as it is unused
  • bdffe46: 8301222: Generalize check_release_entry in OopStorage
  • ec4e8aa: 8303244: G1: call CardTable::clear_MemRegion directly
  • 5753ab5: 8297454: javax/swing/JComponent/7154030/bug7154030.java failed with "Exception: Failed to show opaque button"
  • fa1cebe: 8303266: Prefer ArrayList to LinkedList in JImageTask
  • 5f153e0: 8302780: Add support for vectorized arraycopy GC barriers
  • d00a767: 8295737: macOS: Print content cut off when width > height with portrait orientation
  • 15c76e4: 8301254: UNIX sun/font coding does not detect SuSE in openSUSE Leap distribution
  • 3eff1a0: 8303630: Move nsk/jvmti/AttachOnDemand/attach002a/TestDescription.java back to general problem list
  • 10d6a8e: 8299518: HotSpotVirtualMachine shared code across different platforms
  • ... and 90 more: https://git.openjdk.org/jdk/compare/a2c5a4ac9ee10281470f291f5a8f8393acea02cc...master

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 openjdk bot added the ready Pull request is ready to be integrated label Mar 3, 2023
Copy link
Contributor

@rwestrel rwestrel left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@TobiHartmann
Copy link
Member Author

Thanks for the review, Vladimir and Roland!

@TobiHartmann
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Mar 7, 2023

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

  • c51d40c: 8303607: SunMSCAPI provider leaks memory and keys
  • f64ed09: 8303540: Eliminate unnecessary reference to javac internal class
  • ccfe167: 8298939: Refactor open/test/jdk/javax/rmi/ssl/SSLSocketParametersTest.sh to jtreg java test
  • cfb0a25: 8303440: The "ZonedDateTime.parse" may not accept the "UTC+XX" zone id
  • a97271e: 8301793: AlgorithmId should not encode a missing parameters field as NULL unless hardcoded
  • cac81dd: 8303577: [JVMCI] OOME causes crash while translating exceptions
  • 877ab65: 8303264: Refactor nsk/stress/strace to extract shared and remove redundant code
  • ae8730f: 8303486: [REDO] Update ProcessTools.startProcess(...) to exit early if process exit before linePredicate is printed.
  • 5977f26: 8303604: Passing by-value structs whose size is not power of 2 doesn't work on all platforms (mainline)
  • dccfe8a: 8303582: Reduce duplication in jdk/java/foreign tests
  • ... and 100 more: https://git.openjdk.org/jdk/compare/a2c5a4ac9ee10281470f291f5a8f8393acea02cc...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Mar 7, 2023

@TobiHartmann Pushed as commit 94eda53.

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

@apangin
Copy link

apangin commented Apr 17, 2023

/backport jdk17u-dev

@openjdk
Copy link

openjdk bot commented Apr 17, 2023

@apangin the backport was successfully created on the branch apangin-backport-94eda53d in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 94eda53d from the openjdk/jdk repository.

The commit being backported was authored by Tobias Hartmann on 7 Mar 2023 and was reviewed by Vladimir Kozlov and Roland Westrelin.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git apangin-backport-94eda53d:apangin-backport-94eda53d
$ git checkout apangin-backport-94eda53d
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git apangin-backport-94eda53d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants