GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Prepare for unsafe memory access deprecated for removal by chrisvest · Pull Request #14090 · netty/netty

Conversation

@chrisvest

@chrisvest chrisvest commented May 31, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Motivation:
Java 23 will introduce JEP 471 (https://openjdk.org/jeps/471) which deprecates all unsafe memory access methods for removal.

The JEP also starts the removal phase, by introducing a new --sun-misc-unsafe-memory-access={allow|warn|debug|deny} command line option. Initially, unsafe memory access will be allowed, but will in future Java versions produce warnings, and then eventually denying access by default. When access is denied, then calling the unsafe memory access methods will produce an UnsupportedOperationException.

Modification:
Include the value of --sun-misc-unsafe-memory-access in the consideration of explicit-no-unsafe computation. The command line value is available as the sun.misc.unsafe.memory.access system property. If the value is not either "allow" or unspecified, then unsafe is explicitly turned off.

Add many more tests to the unsafe availability, probing for all the unsafe memory access methods we use, and also testing some of them with direct calls.

Result:
We should hopefully not see any warnings, or "NoSuchMethodErrors", in the future.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@chrisvest
Prepare for unsafe memory access deprecated for removal
3c17007
Motivation:
Java 23 will introduce JEP 471 (https://openjdk.org/jeps/471) which deprecates all unsafe memory access methods for removal.

The JEP also starts the removal phase, by introducing a new `--sun-misc-unsafe-memory-access={allow|warn|debug|deny}` command line option.
Initially, unsafe memory access will be allowed, but will in future Java versions produce warnings, and then eventually denying access by default.
When access is denied, then calling the unsafe memory access methods will produce an `UnsupportedOperationException`.

Modification:
Include the value of `--sun-misc-unsafe-memory-access` in the consideration of explicit-no-unsafe computation.
The command line value is available as the `sun.misc.unsafe.memory.access` system property.
If the value is not either "allow" or unspecified, then unsafe is explicitly turned off.

Add many more tests to the unsafe availability, probing for all the unsafe memory access methods we use, and also testing some of them with direct calls.

Result:
We should hopefully not see any warnings, or "NoSuchMethodErrors", in the future.
@chrisvest
chrisvest requested a review from normanmaurer May 31, 2024 20:27
@chrisvest

chrisvest commented May 31, 2024

Copy link
Copy Markdown
Member Author

@pron @ChrisHegarty FYI.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bryce-anderson
bryce-anderson approved these changes May 31, 2024
View reviewed changes
Comment thread common/src/main/java/io/netty/util/internal/PlatformDependent0.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

bryce-anderson
bryce-anderson reviewed May 31, 2024
View reviewed changes
Comment thread common/src/main/java/io/netty/util/internal/PlatformDependent0.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

chrisvest added 2 commits May 31, 2024 14:02
@chrisvest
Small fixes
c8155df
@chrisvest
Add JDK 23 build profile
8525f8e
@chrisvest

chrisvest commented May 31, 2024

Copy link
Copy Markdown
Member Author

✅ I've done two builds locally, with a snapshot build of JDK 23, and things work as we'd expected with and without --sun-misc-unsafe-memory-access=deny.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest chrisvest modified the milestone: 4.1.111.Final May 31, 2024
chrisvest added 3 commits May 31, 2024 15:26
@chrisvest
Add a profile to deny unsafe on JDK 23+
830e45a
@chrisvest
Fix some issues discovered by denying unsafe access
6f97007
@chrisvest
Fix some codec issues discovered by denying unsafe access
87b7d53
@chrisvest

chrisvest commented May 31, 2024

Copy link
Copy Markdown
Member Author

@normanmaurer Once JDK 23 is GA, we should add another PR build with -Pjdk23DenyUnsafe because it finds issues we don't normally see.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pron

pron commented Jun 1, 2024

Copy link
Copy Markdown

Hi.

Now is indeed the time to prepare for sun.misc.Unsafe's removal, but it is not ideal to rely on the undocumented sun.misc.unsafe.memory.access system property. As we change the default in future JDK releases, the property may not be set by default, requiring further changes to the code.

A simpler and more future-proof approach is to remove the use of Unsafe altogether from versions of the library targeting new JDK versions. If you wish to choose the "one-size-fits-all" approach, where a library targets many JDK versions with the same binary artefact, you may want to consider a multi-release JAR (MR-JAR).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest
chrisvest marked this pull request as draft June 3, 2024 15:26
@chrisvest
chrisvest force-pushed the 41-jdk23-unsafe branch from 336a4d5 to 004e183 Compare June 3, 2024 18:29
@chrisvest
Fix some HTTP codec issues discovered by denying unsafe access
bafc6b5
This also removes the "seek ahead optimised" version of HTTP POST form field parsing, which was subtly broken, and - it turns out - was not any faster than the non-optimised version.
@chrisvest
chrisvest force-pushed the 41-jdk23-unsafe branch from 004e183 to bafc6b5 Compare June 3, 2024 18:29
@chrisvest

chrisvest commented Jun 3, 2024

Copy link
Copy Markdown
Member Author

I've proposed removing the use of Unsafe in Netty 5 with #14033.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest
chrisvest marked this pull request as ready for review June 3, 2024 18:54
normanmaurer
normanmaurer approved these changes Jun 4, 2024
View reviewed changes
@normanmaurer
normanmaurer merged commit 23c19b2 into netty:4.1 Jun 4, 2024
@normanmaurer

normanmaurer commented Jun 4, 2024

Copy link
Copy Markdown
Member

@chrisvest thanks! I will cherry-pick this to 4.2 as well. Not sure what todo about main, thoughts ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest

chrisvest commented Jun 4, 2024

Copy link
Copy Markdown
Member Author

@normanmaurer The pom.xml and PlatformDependent* changes should also be applicable to main. Whatever else is necessary has to be discovered by running builds on JDK 23 with -Pjdk23DenyUnsafe

normanmaurer reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chrisvest
chrisvest deleted the 41-jdk23-unsafe branch June 4, 2024 15:11
normanmaurer pushed a commit that referenced this pull request Jun 4, 2024
@chrisvest @normanmaurer
Prepare for unsafe memory access deprecated for removal (#14090)
21de89f
Motivation:
Java 23 will introduce JEP 471 (https://openjdk.org/jeps/471) which
deprecates all unsafe memory access methods for removal.

The JEP also starts the removal phase, by introducing a new
`--sun-misc-unsafe-memory-access={allow|warn|debug|deny}` command line
option. Initially, unsafe memory access will be allowed, but will in
future Java versions produce warnings, and then eventually denying
access by default. When access is denied, then calling the unsafe memory
access methods will produce an `UnsupportedOperationException`.

Modification:
Include the value of `--sun-misc-unsafe-memory-access` in the
consideration of explicit-no-unsafe computation. The command line value
is available as the `sun.misc.unsafe.memory.access` system property. If
the value is not either "allow" or unspecified, then unsafe is
explicitly turned off.

Add many more tests to the unsafe availability, probing for all the
unsafe memory access methods we use, and also testing some of them with
direct calls.

Result:
We should hopefully not see any warnings, or "NoSuchMethodErrors", in
the future.
mostroverkhov added a commit to mostroverkhov/netty that referenced this pull request Jun 11, 2024
@mostroverkhov
Avoid unnecessary reflective probes on netty initialization.
48352c4
Motivation:

netty#14090 added multiple reflective accesses on netty initialization to probe availability of Unsafe methods which may be removed after java 23 (jep 471).

This may have negative performance impact on application startup (particularly with lower end machines) since reflection is expensive
before jvm is warmed up. However, these reflective method probes may be potentially useful only after java 23 - when/if method removals actually materialize.

Modification:

Make reflective accesses on netty initialization to probe availability of Unsafe methods only if java version > 23.

Result:

Unnecessary reflective accesses on netty initialization are avoided for java version <= 23.
@mostroverkhov mostroverkhov mentioned this pull request Jun 11, 2024
Avoid unnecessary reflective probes on netty initialization #14107
Merged
chrisvest pushed a commit that referenced this pull request Jun 13, 2024
@mostroverkhov
Avoid unnecessary reflective probes on netty initialization (#14107)
db01c73
Motivation:

#14090 added multiple reflective
accesses on netty initialization to probe availability of Unsafe methods
which may be removed after java 23 (jep 471).

This may have negative performance impact on application startup
(particularly with lower end machines) since reflection is expensive
before jvm is warmed up. However, these reflective method probes may be
potentially useful only after java 23 - when/if method removals actually
materialize.

Modification:

Make reflective accesses on netty initialization to probe availability
of Unsafe methods only if java version > 23.

Result:

Unnecessary reflective accesses on netty initialization are avoided for
java version <= 23.
chrisvest pushed a commit that referenced this pull request Jun 13, 2024
@mostroverkhov @chrisvest
Avoid unnecessary reflective probes on netty initialization (#14107)
86b970d
Motivation:

#14090 added multiple reflective
accesses on netty initialization to probe availability of Unsafe methods
which may be removed after java 23 (jep 471).

This may have negative performance impact on application startup
(particularly with lower end machines) since reflection is expensive
before jvm is warmed up. However, these reflective method probes may be
potentially useful only after java 23 - when/if method removals actually
materialize.

Modification:

Make reflective accesses on netty initialization to probe availability
of Unsafe methods only if java version > 23.

Result:

Unnecessary reflective accesses on netty initialization are avoided for
java version <= 23.
@chrisvest chrisvest mentioned this pull request Jun 18, 2024
Fix the graal build #14133
Merged
This was referenced Sep 14, 2026
Http2: Reserve promised stream for PUSH_PROMISE after local RST_STREAM #17471
Closed
cache failure 1233e4a5 #17565
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@bryce-anderson bryce-anderson bryce-anderson approved these changes
@normanmaurer normanmaurer normanmaurer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.1.111.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@chrisvest @pron @normanmaurer @bryce-anderson
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.