Skip to content

8358623: Avoid unnecessary data copying in ICC_Profile #25650

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

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

Conversation

mrserb
Copy link
Member

@mrserb mrserb commented Jun 4, 2025

This PR simplifies several aspects of the ICC_Profile class:

  • Change 1:
    The ICC_Profile.getInstance(byte[] data) method used to copy the profile header for validation. This copy appears redundant, as the original data array is used later anyway. This logic was originally introduced by JDK-8347377.

  • Change 2:
    In some places, the code retrieves the profile header using getData(icSigHead), which always creates a new array. It is now replaced with private getData(cmmProfile(), icSigHead) to avoid unnecessary copying. To clarify the purpose of the private method, I have added documentation.

  • Change 3:
    After Change 2, static analysis tools began reporting a potential NPE when using getData(cmmProfile(), icSigHead), since it may return null. To address this, the internal implementation of getData was updated to always return a non-null value or throw an exception. The public method now catches this exception and returns null, as required by the specification. Note: this potential NPE is not a regression introduced by any changes, it simply became easier for tools to detect due to the simplified code.

@prrace @honkar-jdk please take a look


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-8358623: Avoid unnecessary data copying in ICC_Profile (Bug - P4)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25650

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 4, 2025

👋 Welcome back serb! 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 Jun 4, 2025

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

@mrserb mrserb changed the title 8347377: Add validation checks for ICC_Profile header fields 8358623: Avoid unnecessary data copying in ICC_Profile Jun 4, 2025
@openjdk
Copy link

openjdk bot commented Jun 4, 2025

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

  • client

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.

&& getData(p, icSigRedTRCTag) != null
&& getData(p, icSigGreenTRCTag) != null
&& getData(p, icSigBlueTRCTag) != null) {
} else if (type == ColorSpace.TYPE_RGB) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The above checks are moved to the corresponding constructors.

throw new RuntimeException("Test failed for ColorSpace: " + cs);
}
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Also added a test for the changed methods, since they were not covered by any jtreg tests.

Copy link
Member Author

@mrserb mrserb Jun 5, 2025

Choose a reason for hiding this comment

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

Interestingly, ICC_Profile.getMinorVersion() does not return just the minor version as specified, but instead returns the raw byte, which includes both the minor and patch versions. Perhaps the specification should be updated to reflect this behavior?

@mrserb mrserb marked this pull request as ready for review June 6, 2025 05:44
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 6, 2025
@mlbridge
Copy link

mlbridge bot commented Jun 6, 2025

Webrevs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client [email protected] rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

1 participant