Skip to content

8335836: serviceability/jvmti/StartPhase/AllowedFunctions/AllowedFunctions.java fails with unexpected exit code: 112 #20397

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

Closed
wants to merge 6 commits into from

Conversation

sspitsyn
Copy link
Contributor

@sspitsyn sspitsyn commented Jul 30, 2024

The test has been fixed to:

  • add a guard against JVMTI_ERROR_WRONG_PHASE
  • replace exit(err) with abort() in the check_jvmti_error()

The JVMTI VMDeath event is enabled and a RawMonitor is introduced to serialize ClassPrepare and VMDeath events, and so, to prevent JVMTI_ERROR_WRONG_PHASE in the ClassPrepare events.

Testing:

  • run the test AllowedFunctions.java locally
  • TBD: submit a mach5 run for fixed test

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-8335836: serviceability/jvmti/StartPhase/AllowedFunctions/AllowedFunctions.java fails with unexpected exit code: 112 (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 20397

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

Using diff file

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

Webrev

Link to Webrev Comment

…tions.java fails with unexpected exit code: 112
@bridgekeeper
Copy link

bridgekeeper bot commented Jul 30, 2024

👋 Welcome back sspitsyn! 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 Jul 30, 2024

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

8335836: serviceability/jvmti/StartPhase/AllowedFunctions/AllowedFunctions.java fails with unexpected exit code: 112

Reviewed-by: cjplummer, amenkov

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

  • 7146dae: 8337783: Use THROW_NULL instead of THROW_0 in pointer contexts in misc runtime code
  • 431d4f7: 8337785: Fix simple -Wzero-as-null-pointer-constant warnings in x86 code
  • e2c07d5: 8337299: vmTestbase/nsk/jdb/stop_at/stop_at002/stop_at002.java failure goes undetected
  • 08f697f: 8337819: Update GHA JDKs to 22.0.2
  • 42652b2: 8337787: Fix -Wzero-as-null-pointer-constant warnings when JVMTI feature is disabled
  • 807186f: 8337784: Fix simple -Wzero-as-null-pointer-constant warnings in linux/posix code
  • e68df52: 8337054: JDK 23 RDP2 L10n resource files update
  • 9856216: 8336928: GHA: Bundle artifacts removal broken
  • 219e1eb: 8337712: Wrong javadoc in java.util.Date#toString(): "61" and right parenthesis
  • 97afbd9: 8336410: runtime/NMT/TotalMallocMmapDiffTest.java Total malloc diff is incorrect. Expected malloc diff range
  • ... and 43 more: https://git.openjdk.org/jdk/compare/6c3ba5a6c47d29908ddaf58582ee8d26bb8779f9...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 rfr Pull request is ready for review label Jul 30, 2024
@openjdk
Copy link

openjdk bot commented Jul 30, 2024

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

  • serviceability

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 serviceability serviceability-dev@openjdk.org label Jul 30, 2024
@mlbridge
Copy link

mlbridge bot commented Jul 30, 2024

Webrevs

@sspitsyn
Copy link
Contributor Author

Converting the native agent to C++ would simplify the test and allow to use utility functions from the jvmti_common.hpp.
But I wanted to make the WRONG_PHASE related fix to be clear for reviewers.
So, this conversion can be done as a separate step or as a part of a separate effort covered by an enhancement.

Comment on lines 357 to 359
// Block VMDeath event and other ClassPrepare events while this callback is executed.
// Sync with VMDeath event guards agains JVMTI_ERROR WRONG_PHASE.
err = (*jvmti)->RawMonitorEnter(jvmti, event_mon);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see how this fixes the problem. You can be exiting VMDeath when this monitor is entered. This does not block the get_thread_local() call below, which is what leads to the WRONG_PHASE. I think using a raw monitor is the right approach, but I was expecting to see VMDeath set a flag after grabbing the monitor that indicated VMDeath had been called. Then ClassPrepare should check this flag after grabbing the monitor and ignore the event if it is set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the comment.
Fixed the get_thread_local() issue and corrected phase check.
New flag is not really needed as the phase == JVMTI_PHASE_DEAD can play its role.
Please, let me know if you are not okay with that.

jvmtiError err;

// Block VMDeath event and other ClassPrepare events while this callback is executed.
// Sync with VMDeath event guards agains JVMTI_ERROR WRONG_PHASE.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Sync with VMDeath event guards agains JVMTI_ERROR WRONG_PHASE.
// Sync with VMDeath event guards agains JVMTI_ERROR_WRONG_PHASE.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed now, thanks!


get_phase(jvmti, &phase);
if (phase != JVMTI_PHASE_START && phase != JVMTI_PHASE_LIVE) {
printf(" ## Error: unexpected phase: %d, expected: %d or %d\n",
phase, JVMTI_PHASE_START, JVMTI_PHASE_LIVE);
if (phase != JVMTI_PHASE_DEAD) {
Copy link
Contributor

Choose a reason for hiding this comment

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

After this check is made, what prevents JVMTI from moving to the JVMTI_PHASE_DEAD before the get_cur_thread() call below? I'm not sure if the phase is changed to JVMTI_PHASE_DEAD before or after calling VMDeath, but it seems in either case you can end up with the phase changing after making this check. There is nothing that stops the phase from changing while holding the raw monitor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, Chris.
The JvmtiExport::post_vm_death() posts the VMDeath before changing the phase to JVMTI_PHASE_DEAD.
The VMDeath callback is blocked on the RawMonitor while it is grabbed by the ClassPrepare event callback.
But you are right, there is a sync gap in JvmtiExport::post_vm_death() between the VMDeath callback execution and phase changing. So, I'll go with your suggestion and introduce a flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added is_vm_dead flag.


if (is_vm_dead == JNI_TRUE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (is_vm_dead == JNI_TRUE) {
if (is_vm_dead) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, updated now.

Copy link
Contributor

@plummercj plummercj 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.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Aug 5, 2024
@sspitsyn
Copy link
Contributor Author

sspitsyn commented Aug 5, 2024

Thank you for review, Chris!

@sspitsyn
Copy link
Contributor Author

sspitsyn commented Aug 5, 2024

Thank you for review, Alex!

@sspitsyn
Copy link
Contributor Author

sspitsyn commented Aug 5, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Aug 5, 2024

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

  • 7146dae: 8337783: Use THROW_NULL instead of THROW_0 in pointer contexts in misc runtime code
  • 431d4f7: 8337785: Fix simple -Wzero-as-null-pointer-constant warnings in x86 code
  • e2c07d5: 8337299: vmTestbase/nsk/jdb/stop_at/stop_at002/stop_at002.java failure goes undetected
  • 08f697f: 8337819: Update GHA JDKs to 22.0.2
  • 42652b2: 8337787: Fix -Wzero-as-null-pointer-constant warnings when JVMTI feature is disabled
  • 807186f: 8337784: Fix simple -Wzero-as-null-pointer-constant warnings in linux/posix code
  • e68df52: 8337054: JDK 23 RDP2 L10n resource files update
  • 9856216: 8336928: GHA: Bundle artifacts removal broken
  • 219e1eb: 8337712: Wrong javadoc in java.util.Date#toString(): "61" and right parenthesis
  • 97afbd9: 8336410: runtime/NMT/TotalMallocMmapDiffTest.java Total malloc diff is incorrect. Expected malloc diff range
  • ... and 43 more: https://git.openjdk.org/jdk/compare/6c3ba5a6c47d29908ddaf58582ee8d26bb8779f9...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Aug 5, 2024

@sspitsyn Pushed as commit 965d6b9.

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

@sspitsyn sspitsyn deleted the b37 branch August 14, 2024 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

3 participants