Search in sources :

Example 11 with Memory

use of net.openhft.chronicle.core.Memory in project Chronicle-Queue by OpenHFT.

the class InternalBenchmarkMain method writeMessage.

private static void writeMessage(Wire wire, int messageSize) {
    Bytes<?> bytes = wire.bytes();
    long wp = bytes.writePosition();
    long addr = bytes.addressForWrite(wp);
    Memory memory = OS.memory();
    for (int i = 0; i < messageSize; i += 16) {
        memory.writeLong(addr + i, 0L);
        memory.writeLong(addr + i + 8, 0L);
    }
    bytes.writeSkip(messageSize);
    bytes.writeLong(wp, System.nanoTime());
}
Also used : Memory(net.openhft.chronicle.core.Memory)

Example 12 with Memory

use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.

the class VanillaBytes method isEqual0.

private static boolean isEqual0(@NotNull char[] chars, @NotNull NativeBytesStore bs, long address) {
    @Nullable Memory memory = bs.memory;
    int i = 0;
    for (; i < chars.length - 3; i += 4) {
        int b = memory.readInt(address + i);
        int b0 = b & 0xFF;
        int b1 = (b >> 8) & 0xFF;
        int b2 = (b >> 16) & 0xFF;
        int b3 = (b >> 24) & 0xFF;
        if (b0 != chars[i] || b1 != chars[i + 1] || b2 != chars[i + 2] || b3 != chars[i + 3])
            return false;
    }
    for (; i < chars.length; i++) {
        int b = memory.readByte(address + i) & 0xFF;
        if (b != chars[i])
            return false;
    }
    return true;
}
Also used : Memory(net.openhft.chronicle.core.Memory) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with Memory

use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.

the class NativeBytesStore method write8bit.

void write8bit(long position, char[] chars, int offset, int length) {
    long addr = address + translate(position);
    @Nullable Memory memory = this.memory;
    for (int i = 0; i < length; i++) memory.writeByte(addr + i, (byte) chars[offset + i]);
}
Also used : UnsafeMemory(net.openhft.chronicle.core.UnsafeMemory) Memory(net.openhft.chronicle.core.Memory) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with Memory

use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.

the class NativeBytesStore method read8bit.

void read8bit(long position, char[] chars, int length) {
    long addr = address + translate(position);
    Memory memory = OS.memory();
    for (int i = 0; i < length; i++) chars[i] = (char) (memory.readByte(addr + i) & 0xFF);
}
Also used : UnsafeMemory(net.openhft.chronicle.core.UnsafeMemory) Memory(net.openhft.chronicle.core.Memory)

Example 15 with Memory

use of net.openhft.chronicle.core.Memory in project Chronicle-Bytes by OpenHFT.

the class NativeBytesStore method appendUtf8.

public long appendUtf8(long pos, char[] chars, int offset, int length) throws BufferOverflowException {
    if (pos + length > realCapacity())
        throw new BufferOverflowException();
    long address = this.address + translate(0);
    @Nullable Memory memory = this.memory;
    if (memory == null)
        throw new NullPointerException();
    Unsafe unsafe = UnsafeMemory.UNSAFE;
    int i;
    ascii: {
        for (i = 0; i < length - 3; i += 4) {
            final int i2 = offset + i;
            char c0 = chars[i2];
            char c1 = chars[i2 + 1];
            char c2 = chars[i2 + 2];
            char c3 = chars[i2 + 3];
            if ((c0 | c1 | c2 | c3) > 0x007F)
                break ascii;
            final int value = (c0) | (c1 << 8) | (c2 << 16) | (c3 << 24);
            unsafe.putInt(address + pos, value);
            pos += 4;
        }
        for (; i < length; i++) {
            char c = chars[offset + i];
            if (c > 0x007F)
                break ascii;
            unsafe.putByte(address + pos++, (byte) c);
        }
        return pos;
    }
    return appendUtf8a(pos, chars, offset, length, i);
}
Also used : UnsafeMemory(net.openhft.chronicle.core.UnsafeMemory) Memory(net.openhft.chronicle.core.Memory) Unsafe(sun.misc.Unsafe) BufferOverflowException(java.nio.BufferOverflowException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Memory (net.openhft.chronicle.core.Memory)17 Nullable (org.jetbrains.annotations.Nullable)11 UnsafeMemory (net.openhft.chronicle.core.UnsafeMemory)9 NotNull (org.jetbrains.annotations.NotNull)6 BufferOverflowException (java.nio.BufferOverflowException)1 Java9 (net.openhft.chronicle.core.annotation.Java9)1 Unsafe (sun.misc.Unsafe)1