Skip to content

Conversation

@thswlsqls
Copy link
Contributor

@thswlsqls thswlsqls commented Dec 30, 2025

Summary

MemoryUsage.toString() now displays "N/A" for undefined init and max values (-1) instead of "-1(-1K)".

This addresses the first of three issues in JDK-8374395.

Description

When init or max is -1 (undefined), toString() outputs "-1(-1K)". The Javadoc states that -1 means undefined, but the output does not clearly indicate this.

toString() checks if init or max equals -1 and outputs "init = N/A" or "max = N/A" respectively. Output format for valid values remains unchanged.

Added test cases to the existing jtreg test file. All tests pass.

Bug-ID : JDK-8374395

https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8374395


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-8374395: Improve MemoryUsage.toString() and constructor error messages for better clarity (Enhancement - P3)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 29009

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 30, 2025

👋 Welcome back thswlsqls! 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 30, 2025

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

@openjdk
Copy link

openjdk bot commented Dec 30, 2025

@thswlsqls 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 rfr Pull request is ready for review label Dec 30, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 30, 2025

Webrevs

@AlanBateman
Copy link
Contributor

AlanBateman commented Dec 31, 2025

This addresses the first of three issues in JDK-8374395.

Note that you can't use the same JBS issue for different PRs/commits. If there are other changes proposed then they will need their own JBS issues. If this issue is only for changing MemoryUsage::toString then it should be renamed as it is confusing to see "constructor error messages" in the title when there is no change to the constructor.

MemoryUsage's methods are specified to return -1 for undefined so I don't think it's too surprising that the toString method includes "-1" values.

BTW: test/jdk/java/lang/management/MemoryUsage would be a better place for unit tests for this API.

@openjdk
Copy link

openjdk bot commented Dec 31, 2025

@thswlsqls core-libs has been added to this pull request based on files touched in new commit(s).

@thswlsqls
Copy link
Contributor Author

thswlsqls commented Dec 31, 2025

@AlanBateman Thanks for the review. Addressed.

Would it be possible to review this PR for the first issue of JDK-8374395 only?
Should I create separate JBS issues for the remaining two?

@AlanBateman
Copy link
Contributor

/label remove core-libs

@openjdk
Copy link

openjdk bot commented Jan 1, 2026

@AlanBateman
The core-libs label was successfully removed.

@thswlsqls
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 1, 2026

@thswlsqls This pull request has not yet been marked as ready for integration.

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.

When init or max is -1 (undefined), MemoryUsage.toString() outputs "-1(-1K)", which is confusing. While Javadoc states that -1 means undefined, the output does not clearly indicate this, making it difficult for users to distinguish undefined values from actual negative values.

Hi. When does this happen? When is a MemoryUsage created with init or max as -1 ? When is it then printed using toString() for a user to understand, and when would the user then have to distinguish between the -1 which suggests a problem, and "actual negative values"?

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

Labels

rfr Pull request is ready for review serviceability [email protected]

Development

Successfully merging this pull request may close these issues.

3 participants