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

8327769: jcmd GC.heap_dump without options should write to location given by -XX:HeapDumpPath, if set #18190

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Mar 11, 2024

Currently jcmd command GC.heap_dump only works with an additionally provided file name.
Syntax : GC.heap_dump [options]

In case the JVM has the XX - flag HeapDumpPath set, we should support an additional mode where the is optional.
In case the filename is NOT set, we take the HeapDumpPath (file or directory);

new syntax :
GC.heap_dump [options] .. has precedence over second option
GC.heap_dump [options] …in case -XX: HeapDumpPath=p is set

This would be a simplification e.g. for support cases where a filename or directory is set at JVM startup with -XX: HeapDumpPath=p and writing to the path is intended/recommended for usage also in the jcmd case.


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

Warning

 ⚠️ Found leading lowercase letter in issue title for 8327769: jcmd GC.heap_dump without options should write to location given by -XX:HeapDumpPath, if set

Issue

  • JDK-8327769: jcmd GC.heap_dump without options should write to location given by -XX:HeapDumpPath, if set (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 18190

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 11, 2024

👋 Welcome back mbaesken! 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 11, 2024
@openjdk
Copy link

openjdk bot commented Mar 11, 2024

@MBaesken 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 Mar 11, 2024
@mlbridge
Copy link

mlbridge bot commented Mar 11, 2024

@plummercj
Copy link
Contributor

/label add serviceability

@openjdk openjdk bot added the serviceability serviceability-dev@openjdk.org label Mar 11, 2024
@openjdk
Copy link

openjdk bot commented Mar 11, 2024

@plummercj
The serviceability label was successfully added.

@dholmes-ora
Copy link
Member

/label add hotspot-gc

GC folk should be reviewing this not runtime.

@openjdk openjdk bot added the hotspot-gc hotspot-gc-dev@openjdk.org label Mar 12, 2024
@openjdk
Copy link

openjdk bot commented Mar 12, 2024

@dholmes-ora
The hotspot-gc label was successfully added.

@stefank
Copy link
Member

stefank commented Mar 12, 2024

GC folk should be reviewing this not runtime.

I don't fully agree with that. How these serviceability tools work, and their interfaces, are usually not something that we GC devs are directly responsible for. This change could be reviewed by any HotSpot developer that has a stake in the hprof tooling.

Copy link
Contributor

@kevinjwalls kevinjwalls left a comment

Choose a reason for hiding this comment

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

-XX:HeapDumpPath was introduced by -XX:+HeapDumpOnOutOfMemoryError for its use.

globals.hpp documents HeapDumpPath as relating to HeapDumpOnOutOfMemoryError (so that will need changing if this change is happening).

It does look useful to use HeapDumpPath as the default for jcmd, although maybe there's some confusion possible if you're already relying on it for OOM dumps.

jcmd GC.heap_dump has the overwrite flag.
OOM dumping in HeapDumper::dump_heap(bool oome) has a sequence number.

Can it be specified how these will interact? 8-)
Does overwrite mean you don't want to increase sequence number (but we already increased it last iteration)...

I like splitting out alloc_and_create_heapdump_pathname() as this is already a large part of dump_heap.
Should the comment say, "caller must free the returned pointer".

HeapDumper::dump_to_heapdump_path
This new name makes less sense to me, as we already use heapdump path, but maybe you need it to avoid the dcmd having to work out the final filename. 8-)

Does dump_to_heapdump_path() not print the ("Dumping heap to %s ...", path) message? That seems important when the user isn't specifying it directly.

But the policy questions probably important to confirm before worrying about those and any other code comments.

A test would not be a bad thing. 8-)

@MBaesken
Copy link
Member Author

Hi Kevin, thanks for the comments.

globals.hpp documents HeapDumpPath as relating to HeapDumpOnOutOfMemoryError

Yes true, probably we have to adjust the related text.
What do you think about this

old "When HeapDumpOnOutOfMemoryError is on,"
new "When HeapDumpOnOutOfMemoryError is on or a heap dump is trigger by jcmd GC.heap_dump without specifying a path,"

?

@MBaesken
Copy link
Member Author

jcmd GC.heap_dump has the overwrite flag.
OOM dumping in HeapDumper::dump_heap(bool oome) has a sequence number.

There is (with this patch) still just one sequence number and it is incremented by all invocations of alloc_and_create_heapdump_pathname.

@MBaesken
Copy link
Member Author

I like splitting out alloc_and_create_heapdump_pathname() as this is already a large part of dump_heap.
Should the comment say, "caller must free the returned pointer".

Agree, I will adjust the comment.

(and btw regarding your comment on a test, yes I agree there should be a separate test or at least an adjustment/addition to the existing tests)

@MBaesken
Copy link
Member Author

Does dump_to_heapdump_path() not print the ("Dumping heap to %s ...", path) message?
That seems important when the user isn't specifying it directly.

The path is already printed, here is an example (the JVM with pid 219447 was started with-XX:HeapDumpPath=... ).

images/jdk/bin/jcmd 219447 GC.heap_dump
219447:
Dumping heap to /mydir/test/dumpdir/dydumpfile ...
Heap dump file created [3757116 bytes in 0.046 secs]

@kevinjwalls
Copy link
Contributor

The path is already printed, here is an example (the JVM with pid 219447 was started with-XX:HeapDumpPath=... ).

yes of course, when the new method calls dump(), thanks.

@kevinjwalls
Copy link
Contributor

jcmd GC.heap_dump has the overwrite flag.
OOM dumping in HeapDumper::dump_heap(bool oome) has a sequence number.

There is (with this patch) still just one sequence number and it is incremented by all invocations of alloc_and_create_heapdump_pathname.

Right, I was trying to say that previously, sequence numbers were only used by OOM dumping, and now jcmd invocation can use them, if you have it using HeapDumpPath. (But it can't when using a specified filename, that might be a point of confusion.)

HeapDumpOnOutOfMemoryError dumping never overwrites as I read it. That make sense as it could overwrite existing dumps if an OOM happens, and means a sequence of dumps should all have the same origin.

Invoked from jcmd with HeapDumpPath and -overwrite, can you can overwrite part of a sequence.
That's not necessarily wrong, and may not be serious enough to refuse -overwrite when using HeapDumpPath, but we want to find a way of making things clear (I was not going to suggest separate sequence numbers... 8-) )

@MBaesken
Copy link
Member Author

That's not necessarily wrong, and may not be serious enough to refuse -overwrite when using HeapDumpPath, but we want to
find a way of making things clear (I was not going to suggest separate sequence numbers... 8-) )

Thanks for clarifying, maybe we have to describe/document this at some place (comment? or jcmd help ?) .

@dholmes-ora
Copy link
Member

GC folk should be reviewing this not runtime.

I don't fully agree with that. How these serviceability tools work, and their interfaces, are usually not something that we GC devs are directly responsible for. This change could be reviewed by any HotSpot developer that has a stake in the hprof tooling.

Sorry I assumed GC folk had an interest in -XX:HeapDumpPath and so how it might get used.

@openjdk
Copy link

openjdk bot commented Mar 13, 2024

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

Copy link
Member

@y1yang0 y1yang0 left a comment

Choose a reason for hiding this comment

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

Looks reasonable, this is a harmless change, but the name dump_to_heapdump_path looks too details(and somewhat strange) to me

@MBaesken
Copy link
Member Author

Looks reasonable, this is a harmless change, but the name dump_to_heapdump_path looks too details(and somewhat strange) to me

Do you maybe have a good suggestion for a new name ?

@MBaesken
Copy link
Member Author

Hi Kevin,

globals.hpp documents HeapDumpPath as relating to HeapDumpOnOutOfMemoryError (so that will need changing if this change is happening).

I adjusted the related text in globals.hpp . Please check.

@MBaesken
Copy link
Member Author

Hi Kevin,

(and btw regarding your comment on a test, yes I agree there should be a separate test or at least an adjustment/addition to the existing tests)

I added a test HeapDumpJcmdPresetPathTest.java .

@dholmes-ora
Copy link
Member

Notwithstanding that there may be cases where this change would be convenient, I really don't like this coupling between the jcmd behaviour and a -XX flag that is intended for something else. It doesn't completely mesh with the jcmd usage and other options, and the documentation story is quite complicated.

This change can help avoid the need for an additional copy and paste step, which is prone to errors.

To me that is not a sufficient benefit for the complexity this change would add. Further, it is not at all clear to me that a dynamic heap-dump should be using the same destination as that set for the HeapDumpOnOutOfMemory case.

@plummercj
Copy link
Contributor

Sorry maybe it is maybe obvious for you but where should I open a "docs CR", would that be a separate JBS issue with Component name docs ?

You would file a JBS issue with component "docs" and subcategory "hotspot". But let's hold off on that for now until if it is decided if the PR is going to be pushed. My main reason for mentioning it was to point out additional fallout of this change.

Should I include the HeapDumpGzipLevel in the same "docs CR" (but this might be bad for potential backporting) ?

Backporting also came to mind since the trouble shooting guide would need to be updated for each Oracle version this PR is backported to. And yes, HeapDumpGzipLevel docs need to match the actual implementation. I'm not sure if HeapDumpGzipLevel has been backported to 8, 11, and 17 (in the open for for the Oracle release). I'm inclined to say a separate jbs issue should track updating docs for HeapDumpGzipLevel, but then we also have the question of whether or not HeapDumpGzipLevel should impact the jcmd if this PR is to be pushed.

@plummercj
Copy link
Contributor

Notwithstanding that there may be cases where this change would be convenient...

I did get feedback from a couple of our support engineers. One felt it was of no real benefit as it was just as easy to provide the filename as an argument to the jcmd. The other thought it might be of some benefit, but also had a misunderstanding of how the jcmd currently works (thought that with no filename given, it would automatically dump into the current directory). There were no strong arguments for this PR, especially that overcome all the issues it creates.

@tstuefe
Copy link
Member

tstuefe commented Mar 28, 2024

To weight in on the side of this patch, in most customer scenarios I have seen, there is just one location for heap dumps. Using the same location for OOM and for manual heap dumps seems logical to me.

@dholmes-ora

Notwithstanding that there may be cases where this change would be convenient, I really don't like this coupling between the jcmd behaviour and a -XX flag that is intended for something else. It doesn't completely mesh with the jcmd usage and other options, and the documentation story is quite complicated.

Wouldn't this just be a case of changing a flag description? As luck has it, the flag already has a generic name that is not tied to OOMs.

@MBaesken
Copy link
Member Author

Backporting also came to mind since the trouble shooting guide would need to be updated for each Oracle version this PR is backported to. And yes, HeapDumpGzipLevel docs need to match the actual implementation. I'm not sure if HeapDumpGzipLevel has been backported to 8, 11, and 17 (in the open for for the Oracle release). I'm inclined to say a separate jbs issue should track updating docs for HeapDumpGzipLevel, but then we also have the question of whether or not HeapDumpGzipLevel should impact the jcmd if this PR is to be pushed.

HeapDumpGzipLevel is in openjdk17 and openjdk21 .

@MBaesken
Copy link
Member Author

I did get feedback from a couple of our support engineers. One felt it was of no real benefit as it was just as easy to provide the > filename as an argument to the jcmd.

That might be true for this support engineer, but not for others with other setups where it is an issue to find out where to write in cloud/container scenarios .

@MBaesken
Copy link
Member Author

MBaesken commented Mar 28, 2024

Wouldn't this just be a case of changing a flag description? As luck has it, the flag already has a generic name that is not tied to OOMs.

Yes it is some work on documentation (but seems some doc work needs to be done anyway because it was forgotten when HeapDumpGzipLevel was introduced).
And the current name is generic and does not mention the OOM case in the name itself, the current implementation would better match the name if it was HeapDumpPathOnOom or something like this.

@plummercj
Copy link
Contributor

plummercj commented Mar 29, 2024

Wouldn't this just be a case of changing a flag description? As luck has it, the flag already has a generic name that is not tied to OOMs.

One of the issues with this PR is that there are 7 places where some sort of doc/help update is needed. The help output for the filename option does not work well, because currently it is required a option and has no default. This PR sort of gives it a default, but not always, so the default needs to be given in descriptive way , but jcmd help is not really setup to handle descriptive defaults, so we end up with this:

_filename("filename","Name of the dump file", "STRING", false, "if no filename was specified, but -XX:HeapDumpPath=hdp is set, path hdp is taken"),

And even this is not complete. HeapDumpPath can be a directory, in which case a filename is generated using the PID and a dump sequence number. Probably all this belongs in the argument description, which currently just says "Name of dump file", but you still need to put something in for the default. If the description is complete, maybe just using "See description" would be better.

@plummercj
Copy link
Contributor

Yes it is some work on documentation (but seems some doc work needs to be done anyway because it was forgotten when HeapDumpGzipLevel was introduced).

That currently only impacts 3 documents. Having HeapDumpGzipLevel apply to the jcmd impacts 4 more, and if it doesn't apply to the jcmd then you have an inconsistency with how HeapDumpXXX options are applied.

There's also a question of whether currently missing doc updates for HeapDumpGzipLevel should be made part of this PR because it complicates back porting. We need to make sure we don't backport HeapDumpGzipLevel changes to a JDK version that has HeapDumpPath but not HeapDumpGzipLevel. I think as of right now HeapDumpPath is in 11 but HeapDumpGzipLevel is only backported to 17.

And the current name is generic and does not mention the OOM case in the name itself, the current implementation would better match the name if it was HeapDumpPathOnOom or something like this.

There's still the question of whether or not it is even appropriate to have -XX options taking the place of jcmd options.

@MBaesken
Copy link
Member Author

MBaesken commented Apr 3, 2024

There's also a question of whether currently missing doc updates for HeapDumpGzipLevel should be made part of this PR
because it complicates back porting.

It should most likely be a separate PR (the title of this one does not match, and there are different backporting needs).

@MBaesken
Copy link
Member Author

MBaesken commented Apr 3, 2024

There's still the question of whether or not it is even appropriate to have -XX options taking the place of jcmd options.

Some people (like our cloud support colleagues and also some who commented) would like this approach, some find it not very useful.
Seems there are also already other globals flags playing a role in diagnosticCommand coding (e.g. RecordDynamicDumpInfo, maybe more) so it is not completely 'new' that the jcmd commands are influenced by globals flag.
Looking at just the names of HeapDumpPath and also HeapDumpGzipLevel I would think that they play a role for all heap dumps and not just some.

@RealCLanger
Copy link
Contributor

RealCLanger commented Apr 3, 2024

Couldn't we just have an unconditional default for the GC.heap_dump filename option? This would simplify the documentation. E.g. we could write If not specified, defaults to java_pid<pid>.hprof in the working directory or value configured through -XX:HeapDumpPath

As for the general value of this feature, I think it can simplify the handling of certain (cloud) deployment configurations where you have a dedicated filesystem that you want to write these kind of dumps to. It might also be nice if there was a default value for filename instead of the obligation to specify something. And, for those who can't see the upside of it all, I at least can't see no harm...

@plummercj
Copy link
Contributor

plummercj commented Apr 3, 2024

There's also a question of whether currently missing doc updates for HeapDumpGzipLevel should be made part of this PR
because it complicates back porting.

It should most likely be a separate PR (the title of this one does not match, and there are different backporting needs).

Then you end up with the same issue that this PR has with 7 docs to update (and the "descriptive" default for the jcmd). I'm not advocating one approach over the other. I'm just pointing out that either approach has its warts, and they are rooted in the changes done for this PR.

@plummercj
Copy link
Contributor

plummercj commented Apr 3, 2024

There's still the question of whether or not it is even appropriate to have -XX options taking the place of jcmd options.

Some people (like our cloud support colleagues and also some who commented) would like this approach, some find it not very useful. Seems there are also already other globals flags playing a role in diagnosticCommand coding (e.g. RecordDynamicDumpInfo, maybe more) so it is not completely 'new' that the jcmd commands are influenced by globals flag. Looking at just the names of HeapDumpPath and also HeapDumpGzipLevel I would think that they play a role for all heap dumps and not just some.

That's a little different. For some reason (I'm not sure of the details) it was decided to not allow a dynamic dump with VM.cds unless it was explicitly enabled on the command line with the -XX:+ RecordDynamicDumpInfo option. This is different than having a jvm option that is used in place of an omitted jcmd option.

@plummercj
Copy link
Contributor

Couldn't we just have an unconditional default for the GC.heap_dump filename option? This would simplify the documentation. E.g. we could write If not specified, defaults to java_pid<pid>.hprof in the working directory or value configured through -XX:HeapDumpPath

I've had similar thoughts while considering this PR. I'm not sure why currently there is no default. HeapDumpPath is not quite as simple as you document it above. It can be a filename or a directory, and when it is a directory it has its own default file naming. This should be captured in the jcmd help.

@spayne8
Copy link

spayne8 commented Apr 5, 2024

I disagree with the premise of this entire request that jcmd GC.heap_dump should follow -XX:HeapDumpPath.
Many customers may see such a change as a regression, as they rely on separation of location for heap dumps generated by the JVM at OOME and heap dumps manually pulled by various other processes attaching to the JVM.

I've been testing this on on JDK 8 and JDK 21 and confirmed in both versions that jcmd requires the filename argument that must be a file, not a directory. Supplying just a directory will fail with either "file exists" or "is a directory", and supplying just a filename without a preceding directory will create the dump in the current working directory (cwd).

Currently, the documentation isn't clear that filename is required. This should be corrected and also suggest to add %p and %d to the filename, which is useful when you don't want them overwritten with the -overwrite option (JDK 21) or when running heap dumps on multiple processes at once (with a 0 pid or with main-class specified instead of pid).

Regarding this justification:

In a cloud environment using containers, the HeapDumpPath is automatically set to a file system service to persist the heapdump. However, if a support engineer or DevOps detects high or increasing memory usage and wants to trigger a heapdump via jcmd, they would need to specify the filename. This requires retrieving the set HeapDumpPath from the app environment and copying it to the jcmd to use the persistent file system. This change can help avoid the need for an additional copy and paste step, which is prone to errors.

It's too weak an argument to justify such a change. Simple scripts can capture and propagate the HeapDumpPath value, if you really want to go that route.

However, I recommend using separate directories for manual heap dumps. Keeping them separate from JVM-initiated heap dumps, either through filename convention or separate directories, is a best practice. When you have a severity 1 down situation due to OOME crashes, you don't want to have a bunch of manually pulled heap dumps cluttering up your view of the JVM initiated ones. You want to be able to get your hands on the exact heap dumps you need very quickly to have them analyzed for root cause.

For this reason I also disagree with setting a default filename convention equivalent to the default HeapDumpPath filename. Manual heap dumps require specifying a filename for a reason, and those filenames (and separate directories for those who define them) should be unique based on what triggered the heap dump. Consider the numerous Support cases of multiple monitoring scripts kicking off jcmd processes to pull heap dumps at various resource usage thresholds, as well as multiple Java agents that may do so, e.g. for various performance reasons.

@MBaesken
Copy link
Member Author

MBaesken commented Apr 5, 2024

Many customers may see such a change as a regression, as they rely on separation of location for heap dumps generated by the > JVM at OOME and heap dumps manually pulled by various other processes attaching to the JVM.

With this change it is still possible to have separation (nobody stops users from using jcmd with the filename option, this is still available).
Or do you think that some tool/script developers would maybe (with this change) in future more use the -XX:HeapDumpPath for both OOME and jcmd, so that customers would run into this scenario ?

@spayne8
Copy link

spayne8 commented Apr 5, 2024

Yes, exactly the latter. With this change, it opens the door for the above scenario to unwittingly occur, either through user error (simple omission of a previously used parameter) or lack of understanding of the impact not using the parameter will have.

@RealCLanger
Copy link
Contributor

Hi @spayne8,

thanks for your elaborate answer. Let me comment on your points:

I disagree with the premise of this entire request that jcmd GC.heap_dump should follow -XX:HeapDumpPath. Many customers may see such a change as a regression, as they rely on separation of location for heap dumps generated by the JVM at OOME and heap dumps manually pulled by various other processes attaching to the JVM.

I at least can't see the regression here, because it's still possible to separate the locations of automatic and manual heap dumps by setting a value to the jcmd call.

Regarding this justification:

In a cloud environment using containers, the HeapDumpPath is automatically set to a file system service to persist the heapdump. However, if a support engineer or DevOps detects high or increasing memory usage and wants to trigger a heapdump via jcmd, they would need to specify the filename. This requires retrieving the set HeapDumpPath from the app environment and copying it to the jcmd to use the persistent file system. This change can help avoid the need for an additional copy and paste step, which is prone to errors.

It's too weak an argument to justify such a change. Simple scripts can capture and propagate the HeapDumpPath value, if you really want to go that route.

Sure but we want to avoid that need and have it more comfortable without having to write scripts.

However, I recommend using separate directories for manual heap dumps. Keeping them separate from JVM-initiated heap dumps, either through filename convention or separate directories, is a best practice. When you have a severity 1 down situation due to OOME crashes, you don't want to have a bunch of manually pulled heap dumps cluttering up your view of the JVM initiated ones. You want to be able to get your hands on the exact heap dumps you need very quickly to have them analyzed for root cause.

Sure, but the change requested here does not go against that best practice. You still can have different location for manual heap dumps and the file systems should probably cleaned up from old heap dumps anyway.

For this reason I also disagree with setting a default filename convention equivalent to the default HeapDumpPath filename. Manual heap dumps require specifying a filename for a reason, and those filenames (and separate directories for those who define them) should be unique based on what triggered the heap dump. Consider the numerous Support cases of multiple monitoring scripts kicking off jcmd processes to pull heap dumps at various resource usage thresholds, as well as multiple Java agents that may do so, e.g. for various performance reasons.

Well, I guess, after all it's a bit of a matter of taste. I personally would think having a default for hprof files obtained by jcmd should provide some kind of comfort. Maybe/probably that default should be different from the one for the JVM initiated automatic heapdumps but still it would be helpful if it could be configured, maybe by another XX option.

@alexmenkov
Copy link

I don't have strong opinion if it's good to have default file path for jcmd GC.heap_dump, just some thoughts.
We have several ways to heap dump:

  1. -XX:+HeapDumpOnOutOfMemoryError
  2. -XX:+HeapDumpBeforeFullGC, -XX:+HeapDumpAfterFullGC
    in the case HeapDumpPath and HeapDumpGzipLevel are used (this is not mentioned in the options' description, need to fix it)
  3. jcmd GC.heap_dump
  4. jmap -dump
    it uses "dumpheap" Attach operation, implemented by AttachListener directly
  5. HotSpotDiagnosticMXBean.dumpHeap();

Current patch looks inconsistent:
If HeapDumpPath is used as default, HeapDumpGzipLevel should be used as default too (note that default path has different extension depending on HeapDumpGzipLevel);
If (3) has defaults, why (4) and (maybe) (5) don't have the same defaults?

@MBaesken
Copy link
Member Author

MBaesken commented Apr 8, 2024

I don't have strong opinion if it's good to have default file path for jcmd GC.heap_dump, just some thoughts. We have several ways to heap dump:

  1. -XX:+HeapDumpOnOutOfMemoryError
  2. -XX:+HeapDumpBeforeFullGC, -XX:+HeapDumpAfterFullGC
    in the case HeapDumpPath and HeapDumpGzipLevel are used (this is not mentioned in the options' description, need to fix it)

Was that ever a problem raised by users that the OOME and the GC related heap dumps end up at the same location ?

  1. jcmd GC.heap_dump
  2. jmap -dump
    it uses "dumpheap" Attach operation, implemented by AttachListener directly
  3. HotSpotDiagnosticMXBean.dumpHeap();

Current patch looks inconsistent: If HeapDumpPath is used as default, HeapDumpGzipLevel should be used as default too (note that default path has different extension depending on HeapDumpGzipLevel); If (3) has defaults, why (4) and (maybe) (5) don't have the same defaults?

Yes , probably with 1. + 2, and now (with the patch) 3. using HeapDumpPath the others should use it most likely too.
(but our users just asked for 3. that's why the patch).
About HeapDumpGzipLevel , I could add this (I think this was already mentioned), but before adding it I wanted to be sure that there the change is supported.

@MBaesken
Copy link
Member Author

MBaesken commented Apr 8, 2024

If (3) has defaults, why (4) and (maybe) (5) don't have the same defaults?

I could open a separate JBS issue (or issues) for scenario 4 and 5 , if this is desired.

@plummercj
Copy link
Contributor

plummercj commented Apr 10, 2024

One other thing I just realized is that if we go through with this change, then we can't in the future change VM.heap_dump so it can be used without any filename (make it use a default filename when no filename is specified). Setting HeapDumpPath would override this default filename, and it would be really confusing to the user when suddenly heap dumps are not appearing in the default location with the default name because someone decided to specify HeapDumpPath when launching the JVM.

@MBaesken
Copy link
Member Author

One other thing I just realized is that if we go through with this change, then we can't in the future change VM.heap_dump so it can be used without any filename (make it use a default filename when no filename is specified). Setting HeapDumpPath would override this default filename, and it would be really confusing to the user when suddenly heap dumps are not appearing in the default location with the default name because someone decided to specify HeapDumpPath when launching the JVM.

Isn't this the case already for the -XX:+HeapDumpBeforeFullGC, -XX:+HeapDumpAfterFullGC scenarios?
But probably it should be decided first if such a default is planned for VM.heap_dump .

@plummercj
Copy link
Contributor

One other thing I just realized is that if we go through with this change, then we can't in the future change VM.heap_dump so it can be used without any filename (make it use a default filename when no filename is specified). Setting HeapDumpPath would override this default filename, and it would be really confusing to the user when suddenly heap dumps are not appearing in the default location with the default name because someone decided to specify HeapDumpPath when launching the JVM.

Isn't this the case already for the -XX:+HeapDumpBeforeFullGC, -XX:+HeapDumpAfterFullGC scenarios? But probably it should be decided first if such a default is planned for VM.heap_dump .

I don't think so, but maybe I'm misunderstanding your point. It may be desirable to have VM.heap_dump support not specifying a filename and instead just have it choose a default name and path, probably the current working directory with a name something like java_pid.hprof. However, having this default and also using HeapDumpPath if set conflict with each other. Someone could be relying on the VM.heap_dump default, and then suddenly that default is no longer honored because HeapDumpPath was added to the command line. I don't see -XX:+HeapDumpBeforeFullGC or -XX:+HeapDumpAfterFullGC playing a roll in this scenario.

@openjdk openjdk bot changed the title JDK-8327769: jcmd GC.heap_dump without options should write to location given by -XX:HeapDumpPath, if set 8327769: jcmd GC.heap_dump without options should write to location given by -XX:HeapDumpPath, if set Apr 10, 2024
@MBaesken
Copy link
Member Author

It may be desirable to have VM.heap_dump support not specifying a filename and instead just have it choose a default name
and path, probably the current working directory with a name something like java_pid.hprof.

So is there some intention to decide to have such a default now or in the near future ?
Otherwise it is a rather theoretical discussion .

@plummercj
Copy link
Contributor

So is there some intention to decide to have such a default now or in the near future ?
Otherwise it is a rather theoretical discussion .

No decision on having a default has been made. My point was that implementing this PR equates to making a decision NOT to ever support a default. It doesn't leave it to be decided some time in the future.

@MBaesken
Copy link
Member Author

MBaesken commented May 8, 2024

Another option would be to implement an additional jcmd command where jcmd GC.heap_dump_other_command_name without options writes to location given by -XX:HeapDumpPath, if set. This would avoid all the compatibility concerns raised by changing jcmd GC.heap_dump; would this be a welcome change ?

@plummercj
Copy link
Contributor

That might be acceptable, although coming up with a good name will be a challenge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-gc hotspot-gc-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org rfr Pull request is ready for review serviceability serviceability-dev@openjdk.org