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

8294370: Fix allocation bug in java_lang_Thread::async_get_stack_trace() #10424

Closed
wants to merge 2 commits into from

Conversation

pchilano
Copy link
Contributor

@pchilano pchilano commented Sep 26, 2022

Please review this small fix in async_get_stack_trace(). The GrowableArrays created to store the bci and Method* of each frame found while traversing the stack are allocated in the resource area of the thread that calls async_get_stack_trace(). But if the handshake is executed by the target and if the number of frames in the stack exceeds the initial size of the GrowableArrays then we will hit an assertion when trying to grow the size of the arrays (see bug description).
Currently we don't see any issues because the initial size of the GrowableArrays is 512 and our tests don't test beyond that (the maximum value of DEPTH in the vmTestbase/nsk/stress/strace/ tests is 500). The issue can be easily reproduced by either decreasing the initial size of the GrowableArrays or by increasing the value of DEPTH in those strace tests.
To fix it I allocated the arrays in the C heap instead. Also I lowered the initial size of the arrays since 512 seemed too much to start with.
Tested it by running all tests in the vmTestbase/nsk/stress/strace/ directory.

Thanks,
Patricio


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-8294370: Fix allocation bug in java_lang_Thread::async_get_stack_trace()

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10424

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 26, 2022

👋 Welcome back pchilanomate! 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 Sep 26, 2022

@pchilano 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 hotspot-runtime hotspot-runtime-dev@openjdk.org label Sep 26, 2022
@openjdk
Copy link

openjdk bot commented Sep 26, 2022

@pchilano
The label hotspot-serviceability is not a valid label.
These labels are valid:

  • serviceability
  • hotspot
  • hotspot-compiler
  • ide-support
  • kulla
  • i18n
  • shenandoah
  • jdk
  • javadoc
  • security
  • hotspot-runtime
  • jmx
  • build
  • nio
  • client
  • core-libs
  • compiler
  • net
  • hotspot-gc
  • hotspot-jfr

@pchilano
Copy link
Contributor Author

/label add serviceability

@openjdk openjdk bot added the serviceability serviceability-dev@openjdk.org label Sep 26, 2022
@openjdk
Copy link

openjdk bot commented Sep 26, 2022

@pchilano
The serviceability label was successfully added.

@pchilano pchilano marked this pull request as ready for review September 26, 2022 15:35
@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 26, 2022
@mlbridge
Copy link

mlbridge bot commented Sep 26, 2022

Webrevs

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Good find! Looks good! A couple of queries at this stage.

Thanks.

@@ -2000,6 +2001,11 @@ oop java_lang_Thread::async_get_stack_trace(oop java_thread, TRAPS) {
const int max_depth = MaxJavaStackTraceDepth;
const bool skip_hidden = !ShowHiddenFrames;

// Pick some initial length
Copy link
Member

Choose a reason for hiding this comment

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

The comment should at least hint at there being some reasonable reason for choosing the value that follows. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about: "Pick minimum length that will cover most cases"?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

Comment on lines +2005 to +2008
int init_length = 64;
_methods = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<Method*>(init_length, mtInternal);
_bcis = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(init_length, mtInternal);

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't you just do this in the constructor? I'm not clear if there is a subtle reason for needing lazy-init as well as moving to the C_Heap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this could have been done in the constructor too. But since there are additional checks in the closure that could fail I move the allocation here to avoid unnecessary allocation/deallocation. The allocation still needs to be done in the C_Heap in case the target executes the handshake. Otherwise if the target allocates the arrays in its resource area they could be deallocated by the time the requester tries to access them after the handshake.

Copy link
Member

Choose a reason for hiding this comment

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

Good point - only allocate when known to be needed.

@pchilano
Copy link
Contributor Author

Good find! Looks good! A couple of queries at this stage.

Thanks.

Thanks for looking at this David.

Copy link
Member

@dholmes-ora dholmes-ora 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.

Thanks

@@ -2000,6 +2001,11 @@ oop java_lang_Thread::async_get_stack_trace(oop java_thread, TRAPS) {
const int max_depth = MaxJavaStackTraceDepth;
const bool skip_hidden = !ShowHiddenFrames;

// Pick some initial length
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

Comment on lines +2005 to +2008
int init_length = 64;
_methods = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<Method*>(init_length, mtInternal);
_bcis = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(init_length, mtInternal);

Copy link
Member

Choose a reason for hiding this comment

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

Good point - only allocate when known to be needed.

@openjdk
Copy link

openjdk bot commented Sep 28, 2022

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

8294370: Fix allocation bug in java_lang_Thread::async_get_stack_trace()

Reviewed-by: dholmes, sspitsyn

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

  • 70d8428: 8294520: Problemlist java/nio/file/Files/CopyProcFile.java
  • 30e3bf9: 8291805: IGV: Improve Zooming
  • 37f83b9: 8294375: test/jdk/java/nio/channels/vthread/BlockingChannelOps.java is slow
  • 60616f2: 8294059: Serial: Refactor GenCollectedHeap::collect
  • ea61671: 8294359: Interpreter(AArch64) intrinsify Thread.currentThread()
  • c42ef70: 7148092: [macosx] When Alt+down arrow key is pressed, the combobox popup does not appear.
  • 94e14da: 8294057: Parallel: Tighten ParallelCompactData::initialize_region_data
  • 1ea0d6b: 8292301: [REDO v2] C2 crash when allocating array of size too large
  • c13e0ef: 8292848: AWT_Mixing and TrayIcon tests fail on el8 with hard-coded isOel7
  • 79ccc79: 8293613: need to properly handle and hide tmp VTMS transitions
  • ... and 35 more: https://git.openjdk.org/jdk/compare/3675f4c2afd10b5042948fc79e62caee5f3874ce...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 Sep 28, 2022
Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

Yes, it is good find!
The fix looks good.
Thanks,
Serguei

@pchilano
Copy link
Contributor Author

Thanks for the reviews David and Serguei!

@pchilano
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Sep 29, 2022

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

  • ce85cac: 8065554: MatchResult should provide values of named-capturing groups
  • 1decdce: 8294492: RISC-V: Use li instead of patchable movptr at non-patchable callsites
  • 8491fd5: 8294551: Put java/io/BufferedInputStream/TransferTo.java on problem list
  • 6f8f28e: 8294160: misc crash dump improvements
  • 8873192: 8293515: heapShared.cpp: rename JavaThread parameter to current
  • 76f1865: 8293563: [macos-aarch64] SA core file tests failing with sun.jvm.hotspot.oops.UnknownOopException
  • 9db95ed: 8215788: Clarify JarInputStream Manifest access
  • 9309786: 8294472: Remove redundant rawtypes suppression in AbstractChronology
  • 3b7fc80: 8294411: SA should provide more useful info when it fails to start up due to "failed to workaround classshareing"
  • 4fb424b: 8293961: Unused ClassPathZipEntry::contents_do
  • ... and 47 more: https://git.openjdk.org/jdk/compare/3675f4c2afd10b5042948fc79e62caee5f3874ce...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Sep 29, 2022

@pchilano Pushed as commit 5d48da4.

💡 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 hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
3 participants