use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.
the class MappedBytes method append8bit0.
@NotNull
private MappedBytes append8bit0(@NotNull String s, int start, int length) throws BufferOverflowException {
assert singleThreadedAccess();
if (Jvm.isJava9Plus()) {
byte[] bytes = extractBytes(s);
long address = addressForWrite(writePosition());
Memory memory = bytesStore().memory;
int i = 0;
for (; i < length - 3; i += 4) {
int c0 = bytes[i + start] & 0xff;
int c1 = bytes[i + start + 1] & 0xff;
int c2 = bytes[i + start + 2] & 0xff;
int c3 = bytes[i + start + 3] & 0xff;
memory.writeInt(address, (c3 << 24) | (c2 << 16) | (c1 << 8) | c0);
address += 4;
}
for (; i < length; i++) {
byte c = bytes[i + start];
memory.writeByte(address++, c);
}
writeSkip(length);
} else {
char[] chars = extractChars(s);
long address = addressForWrite(writePosition());
Memory memory = bytesStore().memory;
int i = 0;
for (; i < length - 3; i += 4) {
int c0 = chars[i + start] & 0xff;
int c1 = chars[i + start + 1] & 0xff;
int c2 = chars[i + start + 2] & 0xff;
int c3 = chars[i + start + 3] & 0xff;
memory.writeInt(address, (c3 << 24) | (c2 << 16) | (c1 << 8) | c0);
address += 4;
}
for (; i < length; i++) {
char c = chars[i + start];
memory.writeByte(address++, (byte) c);
}
writeSkip(length);
}
return this;
}
use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.
the class MappedBytes method peekVolatileInt.
@Override
public int peekVolatileInt() {
if (!bytesStore.inside(readPosition)) {
acquireNextByteStore(readPosition, true);
}
@Nullable MappedBytesStore bytesStore = (MappedBytesStore) (BytesStore) this.bytesStore;
long address = bytesStore.address + bytesStore.translate(readPosition);
@Nullable Memory memory = bytesStore.memory;
// are we inside a cache line?
if ((address & 63) <= 60) {
// if (memory == null) throw new NullPointerException();
// faster check for null.
memory.getClass();
return UnsafeMemory.UNSAFE.getIntVolatile(null, address);
} else {
return memory.readVolatileInt(address);
}
}
Aggregations