Fix JVM crashes and a number of test failures
Still more test failures left, but getting close now.
This commit is contained in:
parent
c73dd07384
commit
1fe8abecfa
@ -97,6 +97,7 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Buffer readerOffset(int offset) {
|
public Buffer readerOffset(int offset) {
|
||||||
|
checkRead(offset, 0);
|
||||||
roff = offset;
|
roff = offset;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -108,6 +109,7 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Buffer writerOffset(int offset) {
|
public Buffer writerOffset(int offset) {
|
||||||
|
checkWrite(offset, 0);
|
||||||
woff = offset;
|
woff = offset;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -115,6 +117,9 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
@Override
|
@Override
|
||||||
public Buffer fill(byte value) {
|
public Buffer fill(byte value) {
|
||||||
checkSet(0, capacity());
|
checkSet(0, capacity());
|
||||||
|
if (rsize == CLOSED_SIZE) {
|
||||||
|
throw bufferIsClosed();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
PlatformDependent.setMemory(base, address, rsize, value);
|
PlatformDependent.setMemory(base, address, rsize, value);
|
||||||
} finally {
|
} finally {
|
||||||
@ -142,12 +147,7 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Buffer slice(int offset, int length) {
|
public Buffer slice(int offset, int length) {
|
||||||
if (length < 0) {
|
checkGet(offset, length);
|
||||||
throw new IllegalArgumentException("Length cannot be negative: " + length + '.');
|
|
||||||
}
|
|
||||||
if (!isAccessible()) {
|
|
||||||
throw new IllegalStateException("This buffer is closed: " + this + '.');
|
|
||||||
}
|
|
||||||
ArcDrop<UnsafeBuffer> drop = (ArcDrop<UnsafeBuffer>) unsafeGetDrop();
|
ArcDrop<UnsafeBuffer> drop = (ArcDrop<UnsafeBuffer>) unsafeGetDrop();
|
||||||
drop.increment();
|
drop.increment();
|
||||||
return new UnsafeBuffer(memory, baseOffset + offset, length, control, drop)
|
return new UnsafeBuffer(memory, baseOffset + offset, length, control, drop)
|
||||||
@ -215,10 +215,13 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
@Override
|
@Override
|
||||||
public void copyInto(int srcPos, Buffer dest, int destPos, int length) {
|
public void copyInto(int srcPos, Buffer dest, int destPos, int length) {
|
||||||
checkCopyIntoArgs(srcPos, length, destPos, dest.capacity());
|
checkCopyIntoArgs(srcPos, length, destPos, dest.capacity());
|
||||||
|
if (dest.readOnly()) {
|
||||||
|
throw bufferIsReadOnly();
|
||||||
|
}
|
||||||
long nativeAddress = dest.nativeAddress();
|
long nativeAddress = dest.nativeAddress();
|
||||||
try {
|
try {
|
||||||
if (nativeAddress != 0) {
|
if (nativeAddress != 0) {
|
||||||
PlatformDependent.copyMemory(base, address + srcPos, null, nativeAddress, length);
|
PlatformDependent.copyMemory(base, address + srcPos, null, nativeAddress + destPos, length);
|
||||||
} else if (dest instanceof UnsafeBuffer) {
|
} else if (dest instanceof UnsafeBuffer) {
|
||||||
UnsafeBuffer destUnsafe = (UnsafeBuffer) dest;
|
UnsafeBuffer destUnsafe = (UnsafeBuffer) dest;
|
||||||
PlatformDependent.copyMemory(
|
PlatformDependent.copyMemory(
|
||||||
@ -345,7 +348,7 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
index -= 7;
|
index -= 7;
|
||||||
try {
|
try {
|
||||||
long value = PlatformDependent.getLong(baseObj, baseAddress + index);
|
long value = PlatformDependent.getLong(baseObj, baseAddress + index);
|
||||||
longValue = BIG_ENDIAN_NATIVE_ORDER? value : Long.reverseBytes(value);
|
longValue = BIG_ENDIAN_NATIVE_ORDER? Long.reverseBytes(value) : value;
|
||||||
} finally {
|
} finally {
|
||||||
Reference.reachabilityFence(memory);
|
Reference.reachabilityFence(memory);
|
||||||
}
|
}
|
||||||
@ -828,13 +831,14 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
@Override
|
@Override
|
||||||
public int readMedium() {
|
public int readMedium() {
|
||||||
checkRead(roff, 3);
|
checkRead(roff, 3);
|
||||||
|
long offset = address + roff;
|
||||||
int value = order() == ByteOrder.BIG_ENDIAN ?
|
int value = order() == ByteOrder.BIG_ENDIAN ?
|
||||||
loadByte(roff) << 16 |
|
loadByte(offset) << 16 |
|
||||||
(loadByte(roff + 1) & 0xFF) << 8 |
|
(loadByte(offset + 1) & 0xFF) << 8 |
|
||||||
loadByte(roff + 2) & 0xFF :
|
loadByte(offset + 2) & 0xFF :
|
||||||
loadByte(roff) & 0xFF |
|
loadByte(offset) & 0xFF |
|
||||||
(loadByte(roff + 1) & 0xFF) << 8 |
|
(loadByte(offset + 1) & 0xFF) << 8 |
|
||||||
loadByte(roff + 2) << 16;
|
loadByte(offset + 2) << 16;
|
||||||
roff += 3;
|
roff += 3;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -842,25 +846,27 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
@Override
|
@Override
|
||||||
public int getMedium(int roff) {
|
public int getMedium(int roff) {
|
||||||
checkGet(roff, 3);
|
checkGet(roff, 3);
|
||||||
|
long offset = address + roff;
|
||||||
return order() == ByteOrder.BIG_ENDIAN?
|
return order() == ByteOrder.BIG_ENDIAN?
|
||||||
loadByte(roff) << 16 |
|
loadByte(offset) << 16 |
|
||||||
(loadByte(roff + 1) & 0xFF) << 8 |
|
(loadByte(offset + 1) & 0xFF) << 8 |
|
||||||
loadByte(roff + 2) & 0xFF :
|
loadByte(offset + 2) & 0xFF :
|
||||||
loadByte(roff) & 0xFF |
|
loadByte(offset) & 0xFF |
|
||||||
(loadByte(roff + 1) & 0xFF) << 8 |
|
(loadByte(offset + 1) & 0xFF) << 8 |
|
||||||
loadByte(roff + 2) << 16;
|
loadByte(offset + 2) << 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int readUnsignedMedium() {
|
public int readUnsignedMedium() {
|
||||||
checkRead(roff, 3);
|
checkRead(roff, 3);
|
||||||
|
long offset = address + roff;
|
||||||
int value = order() == ByteOrder.BIG_ENDIAN?
|
int value = order() == ByteOrder.BIG_ENDIAN?
|
||||||
(loadByte(roff) << 16 |
|
(loadByte(offset) << 16 |
|
||||||
(loadByte(roff + 1) & 0xFF) << 8 |
|
(loadByte(offset + 1) & 0xFF) << 8 |
|
||||||
loadByte(roff + 2) & 0xFF) & 0xFFFFFF :
|
loadByte(offset + 2) & 0xFF) & 0xFFFFFF :
|
||||||
(loadByte(roff) & 0xFF |
|
(loadByte(offset) & 0xFF |
|
||||||
(loadByte(roff + 1) & 0xFF) << 8 |
|
(loadByte(offset + 1) & 0xFF) << 8 |
|
||||||
loadByte(roff + 2) << 16) & 0xFFFFFF;
|
loadByte(offset + 2) << 16) & 0xFFFFFF;
|
||||||
roff += 3;
|
roff += 3;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -868,26 +874,28 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
@Override
|
@Override
|
||||||
public int getUnsignedMedium(int roff) {
|
public int getUnsignedMedium(int roff) {
|
||||||
checkGet(roff, 3);
|
checkGet(roff, 3);
|
||||||
|
long offset = address + roff;
|
||||||
return order() == ByteOrder.BIG_ENDIAN?
|
return order() == ByteOrder.BIG_ENDIAN?
|
||||||
(loadByte(roff) << 16 |
|
(loadByte(offset) << 16 |
|
||||||
(loadByte(roff + 1) & 0xFF) << 8 |
|
(loadByte(offset + 1) & 0xFF) << 8 |
|
||||||
loadByte(roff + 2) & 0xFF) & 0xFFFFFF :
|
loadByte(offset + 2) & 0xFF) & 0xFFFFFF :
|
||||||
(loadByte(roff) & 0xFF |
|
(loadByte(offset) & 0xFF |
|
||||||
(loadByte(roff + 1) & 0xFF) << 8 |
|
(loadByte(offset + 1) & 0xFF) << 8 |
|
||||||
loadByte(roff + 2) << 16) & 0xFFFFFF;
|
loadByte(offset + 2) << 16) & 0xFFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Buffer writeMedium(int value) {
|
public Buffer writeMedium(int value) {
|
||||||
checkWrite(woff, 3);
|
checkWrite(woff, 3);
|
||||||
|
long offset = address + woff;
|
||||||
if (order() == ByteOrder.BIG_ENDIAN) {
|
if (order() == ByteOrder.BIG_ENDIAN) {
|
||||||
storeByte(woff, (byte) (value >> 16));
|
storeByte(offset, (byte) (value >> 16));
|
||||||
storeByte(woff + 1, (byte) (value >> 8 & 0xFF));
|
storeByte(offset + 1, (byte) (value >> 8 & 0xFF));
|
||||||
storeByte(woff + 2, (byte) (value & 0xFF));
|
storeByte(offset + 2, (byte) (value & 0xFF));
|
||||||
} else {
|
} else {
|
||||||
storeByte(woff, (byte) (value & 0xFF));
|
storeByte(offset, (byte) (value & 0xFF));
|
||||||
storeByte(woff + 1, (byte) (value >> 8 & 0xFF));
|
storeByte(offset + 1, (byte) (value >> 8 & 0xFF));
|
||||||
storeByte(woff + 2, (byte) (value >> 16 & 0xFF));
|
storeByte(offset + 2, (byte) (value >> 16 & 0xFF));
|
||||||
}
|
}
|
||||||
woff += 3;
|
woff += 3;
|
||||||
return this;
|
return this;
|
||||||
@ -896,14 +904,15 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
@Override
|
@Override
|
||||||
public Buffer setMedium(int woff, int value) {
|
public Buffer setMedium(int woff, int value) {
|
||||||
checkSet(woff, 3);
|
checkSet(woff, 3);
|
||||||
|
long offset = address + woff;
|
||||||
if (order() == ByteOrder.BIG_ENDIAN) {
|
if (order() == ByteOrder.BIG_ENDIAN) {
|
||||||
storeByte(woff, (byte) (value >> 16));
|
storeByte(offset, (byte) (value >> 16));
|
||||||
storeByte(woff + 1, (byte) (value >> 8 & 0xFF));
|
storeByte(offset + 1, (byte) (value >> 8 & 0xFF));
|
||||||
storeByte(woff + 2, (byte) (value & 0xFF));
|
storeByte(offset + 2, (byte) (value & 0xFF));
|
||||||
} else {
|
} else {
|
||||||
storeByte(woff, (byte) (value & 0xFF));
|
storeByte(offset, (byte) (value & 0xFF));
|
||||||
storeByte(woff + 1, (byte) (value >> 8 & 0xFF));
|
storeByte(offset + 1, (byte) (value >> 8 & 0xFF));
|
||||||
storeByte(woff + 2, (byte) (value >> 16 & 0xFF));
|
storeByte(offset + 2, (byte) (value >> 16 & 0xFF));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -911,14 +920,15 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
@Override
|
@Override
|
||||||
public Buffer writeUnsignedMedium(int value) {
|
public Buffer writeUnsignedMedium(int value) {
|
||||||
checkWrite(woff, 3);
|
checkWrite(woff, 3);
|
||||||
|
long offset = address + woff;
|
||||||
if (order() == ByteOrder.BIG_ENDIAN) {
|
if (order() == ByteOrder.BIG_ENDIAN) {
|
||||||
storeByte(woff, (byte) (value >> 16));
|
storeByte(offset, (byte) (value >> 16));
|
||||||
storeByte(woff + 1, (byte) (value >> 8 & 0xFF));
|
storeByte(offset + 1, (byte) (value >> 8 & 0xFF));
|
||||||
storeByte(woff + 2, (byte) (value & 0xFF));
|
storeByte(offset + 2, (byte) (value & 0xFF));
|
||||||
} else {
|
} else {
|
||||||
storeByte(woff, (byte) (value & 0xFF));
|
storeByte(offset, (byte) (value & 0xFF));
|
||||||
storeByte(woff + 1, (byte) (value >> 8 & 0xFF));
|
storeByte(offset + 1, (byte) (value >> 8 & 0xFF));
|
||||||
storeByte(woff + 2, (byte) (value >> 16 & 0xFF));
|
storeByte(offset + 2, (byte) (value >> 16 & 0xFF));
|
||||||
}
|
}
|
||||||
woff += 3;
|
woff += 3;
|
||||||
return this;
|
return this;
|
||||||
@ -927,14 +937,15 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
@Override
|
@Override
|
||||||
public Buffer setUnsignedMedium(int woff, int value) {
|
public Buffer setUnsignedMedium(int woff, int value) {
|
||||||
checkSet(woff, 3);
|
checkSet(woff, 3);
|
||||||
|
long offset = address + woff;
|
||||||
if (order() == ByteOrder.BIG_ENDIAN) {
|
if (order() == ByteOrder.BIG_ENDIAN) {
|
||||||
storeByte(woff, (byte) (value >> 16));
|
storeByte(offset, (byte) (value >> 16));
|
||||||
storeByte(woff + 1, (byte) (value >> 8 & 0xFF));
|
storeByte(offset + 1, (byte) (value >> 8 & 0xFF));
|
||||||
storeByte(woff + 2, (byte) (value & 0xFF));
|
storeByte(offset + 2, (byte) (value & 0xFF));
|
||||||
} else {
|
} else {
|
||||||
storeByte(woff, (byte) (value & 0xFF));
|
storeByte(offset, (byte) (value & 0xFF));
|
||||||
storeByte(woff + 1, (byte) (value >> 8 & 0xFF));
|
storeByte(offset + 1, (byte) (value >> 8 & 0xFF));
|
||||||
storeByte(woff + 2, (byte) (value >> 16 & 0xFF));
|
storeByte(offset + 2, (byte) (value >> 16 & 0xFF));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -1231,6 +1242,7 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
|
|||||||
void makeInaccessible() {
|
void makeInaccessible() {
|
||||||
rsize = CLOSED_SIZE;
|
rsize = CLOSED_SIZE;
|
||||||
wsize = CLOSED_SIZE;
|
wsize = CLOSED_SIZE;
|
||||||
|
readOnly = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user