mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8316337: (bf) Concurrency issue in DirectByteBuffer.Deallocator
Reviewed-by: alanb, liach
This commit is contained in:
parent
4461eeb31d
commit
cf74b8c2a3
3 changed files with 31 additions and 45 deletions
|
@ -75,31 +75,15 @@ class Direct$Type$Buffer$RW$$BO$
|
|||
|
||||
#if[byte]
|
||||
|
||||
private static class Deallocator
|
||||
implements Runnable
|
||||
{
|
||||
|
||||
private long address;
|
||||
private long size;
|
||||
private int capacity;
|
||||
|
||||
private Deallocator(long address, long size, int capacity) {
|
||||
assert (address != 0);
|
||||
this.address = address;
|
||||
this.size = size;
|
||||
this.capacity = capacity;
|
||||
private record Deallocator(long address, long size, int capacity) implements Runnable {
|
||||
private Deallocator {
|
||||
assert address != 0;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (address == 0) {
|
||||
// Paranoia
|
||||
return;
|
||||
}
|
||||
UNSAFE.freeMemory(address);
|
||||
address = 0;
|
||||
Bits.unreserveMemory(size, capacity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final Cleaner cleaner;
|
||||
|
|
|
@ -116,28 +116,33 @@ public abstract sealed class MappedByteBuffer
|
|||
}
|
||||
|
||||
UnmapperProxy unmapper() {
|
||||
return fd != null ?
|
||||
new UnmapperProxy() {
|
||||
@Override
|
||||
public long address() {
|
||||
return address;
|
||||
}
|
||||
return fd == null
|
||||
? null
|
||||
: new UnmapperProxy() {
|
||||
|
||||
@Override
|
||||
public FileDescriptor fileDescriptor() {
|
||||
return fd;
|
||||
}
|
||||
// Ensure safe publication as MappedByteBuffer.this.address is not final
|
||||
private final long addr = address;
|
||||
|
||||
@Override
|
||||
public boolean isSync() {
|
||||
return isSync;
|
||||
}
|
||||
@Override
|
||||
public long address() {
|
||||
return addr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unmap() {
|
||||
Unsafe.getUnsafe().invokeCleaner(MappedByteBuffer.this);
|
||||
}
|
||||
} : null;
|
||||
@Override
|
||||
public FileDescriptor fileDescriptor() {
|
||||
return fd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSync() {
|
||||
return isSync;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unmap() {
|
||||
Unsafe.getUnsafe().invokeCleaner(MappedByteBuffer.this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue