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

8277863: Deprecate sun.misc.Unsafe methods that return offsets #6700

Closed
wants to merge 3 commits into from

Conversation

AlanBateman
Copy link
Contributor

@AlanBateman AlanBateman commented Dec 3, 2021

Deprecate the sun.misc.Unsafe methods that return field offsets. These method are an impediment to possible future changes. Layout may not be fixed in the future, the VM should be allowed to re-layout dynamically based on patterns of usage. We also have the issue of libraries using these methods to get offsets (sometimes of classes with the same layout as JDK classes) so they can directly access the fields of privileged classes. It's untenable for libraries to rely on this going forward.

The java.lang.invoke.VarHandle API (added in Java 9) provides a strongly typed reference to a variable that is a safe and a much better alternative to many cases that use these methods. Deprecating these method provides a gentle nudge in that directory. Once the Panama memory APIs are permanent then we can look at terminally deprecating and removing these methods, along with the accessors.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed
  • Change requires a CSR request to be approved

Issues

  • JDK-8277863: Deprecate sun.misc.Unsafe methods that return offsets
  • JDK-8278223: Deprecate sun.misc.Unsafe methods that return offsets (CSR)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6700/head:pull/6700
$ git checkout pull/6700

Update a local copy of the PR:
$ git checkout pull/6700
$ git pull https://git.openjdk.java.net/jdk pull/6700/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 6700

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6700.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 3, 2021

👋 Welcome back alanb! 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 csr Pull request needs approved CSR before integration label Dec 3, 2021
@openjdk
Copy link

openjdk bot commented Dec 3, 2021

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

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Dec 3, 2021
@AlanBateman AlanBateman marked this pull request as ready for review December 6, 2021 16:25
@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 6, 2021
@mlbridge
Copy link

mlbridge bot commented Dec 6, 2021

Webrevs

Copy link
Member

@PaulSandoz PaulSandoz left a comment

Choose a reason for hiding this comment

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

Slowly chipping away... but we are getting really close to being able to deprecate all the unsafe accessor methods.

Did you also consider the method staticFieldBase and the field INVALID_FIELD_OFFSET? I think those could also be included since the aim is to discourage unsafe access to fields of objects.

@AlanBateman
Copy link
Contributor Author

Yes, we have to keep chipping away at this. Most of the on-heap usages that I found could have been replaced with VarHandles a long time ago but many of these projects are still building to old JDK releases and maybe MR JARs are still problematic in the build. The great progress on the memory API in Project Panama means it won't be long before those accessors are needed for off-heap. So yes, a few more releases and we should be able to make more progress.

I toyed with including staticFieldBase but I didn't find anything like the usage as the offset methods. Easy to include if you think it's worth doing.

@PaulSandoz
Copy link
Member

I toyed with including staticFieldBase but I didn't find anything like the usage as the offset methods. Easy to include if you think it's worth doing.

Yes, I think you should include it, it's part of this set of functionality (since base is used in conjunction with offsets)

@AlanBateman
Copy link
Contributor Author

Yes, I think you should include it, it's part of this set of functionality (since base is used in conjunction with offsets)

Okay, done.

Copy link
Member

@mlchung mlchung left a comment

Choose a reason for hiding this comment

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

It's okay to leave INVALID_FIELD_OFFSET as is as it's also for arrayBaseOffset.

@AlanBateman
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 7, 2021

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

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Dec 7, 2021
@openjdk
Copy link

openjdk bot commented Dec 7, 2021

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

8277863: Deprecate sun.misc.Unsafe methods that return offsets

Reviewed-by: psandoz, mchung

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

  • 24877ac: 8278270: ServerSocket is not thread safe
  • e535cb3: 8272395: Bad HTML in JVMTI man page
  • f22d157: 8277353: java/security/MessageDigest/ThreadSafetyTest.java test times out
  • 10db0e4: 8277932: Subject:callAs() not throwing NPE when action is null
  • f148e3e: 8278318: Create {@index} entries for key LangTools terms
  • 2ff1296: 8277957: Add test group for IPv6 exclusive testing
  • ea8d3c9: 8271566: DSA signature length value is not accurate in P11Signature
  • 239362d: 8247973: Javadoc incorrect for IdentityArrayList, IdentityLinkedList
  • 2c31a17: 8275082: Update XML Security for Java to 2.3.0

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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 Dec 7, 2021
@AlanBateman
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Dec 7, 2021

Going to push as commit 56ca66e.
Since your change was applied there have been 13 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Dec 7, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Dec 7, 2021
@openjdk
Copy link

openjdk bot commented Dec 7, 2021

@AlanBateman Pushed as commit 56ca66e.

💡 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
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants