-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
8296024: Usage of DirectBuffer::address should be guarded #11260
Changes from 10 commits
23a6fd1
9fafafa
9fcf2bb
c081b4a
eca7c38
17a72e9
a0de3bc
7097934
88ed3aa
0526e3d
06c764c
88ae68b
682b6f5
0546b23
30aff11
95c4058
eedf41a
619473e
cd95bc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -778,6 +778,7 @@ final void checkSession() { | |
// setup access to this package in SharedSecrets | ||
SharedSecrets.setJavaNioAccess( | ||
new JavaNioAccess() { | ||
|
||
@Override | ||
public BufferPool getDirectBufferPool() { | ||
return Bits.BUFFER_POOL; | ||
|
@@ -823,7 +824,7 @@ public MemorySegment bufferSegment(Buffer buffer) { | |
} | ||
|
||
@Override | ||
public Runnable acquireSession(Buffer buffer, boolean async) { | ||
public Runnable acquireSessionOrNull(Buffer buffer, boolean async) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If allocation/performance is an issue, a relatively straightforward way to adjust the code would be to let go of the TWR entirely. E.g. we have code that does this:
We could transform to this:
This leads to a simpler patch that is probably easier to validate. The remaining IOUtil code will be using a different idiom, and perhaps we can, at some point, go back and make that consistent too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The AutoCloseable experiment was interesting to try but I think you are right, acquire try { .. } finally release would be simpler and also remove the concerns about the performance critical code paths. |
||
var session = buffer.session(); | ||
if (session == null) { | ||
return null; | ||
|
@@ -835,6 +836,16 @@ public Runnable acquireSession(Buffer buffer, boolean async) { | |
return session::release0; | ||
} | ||
|
||
@Override | ||
public ScopeAcquisition acquireScope(Buffer buffer) { | ||
var scope = buffer.session(); | ||
if (scope == null) { | ||
return ScopeAcquisition.create(buffer); | ||
} | ||
scope.acquire0(); | ||
return ScopeAcquisition.create(buffer, scope); | ||
} | ||
|
||
@Override | ||
public void force(FileDescriptor fd, long address, boolean isSync, long offset, long size) { | ||
MappedMemoryUtils.force(fd, address, isSync, offset, size); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at the implementation some more, I'm not sure this need fixing? E.g. this method is just using the address to compute some overlap - and return a buffer sliced accordingly. There's no access to the buffer data (except for the last part which does a
put
). The access will fail if the session is closed from underneath. I don't think this can crash the VM (in fact this code did not have a reachability fence to begin with).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted. I will remove the guarding here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
@SuppressWarnings
annotation is no longer needed: