Ejemplo n.º 1
0
  @Override
  @ForceInline
  public void write(long offsetInRDO, @NotNull ByteBuffer bytes, int offset, int length) {
    if (bytes.isDirect()) {
      memory.copyMemory(((DirectBuffer) bytes).address(), address + translate(offsetInRDO), length);

    } else {
      memory.copyMemory(bytes.array(), offset, address + translate(offsetInRDO), length);
    }
  }
 public int byteCheckSum() throws IORuntimeException {
   if (readLimit() >= Integer.MAX_VALUE || start() != 0) throw new AssertionError();
   byte b = 0;
   NativeBytesStore bytesStore = (NativeBytesStore) bytesStore();
   Memory memory = bytesStore.memory;
   assert memory != null;
   for (int i = (int) readPosition(), lim = (int) readLimit(); i < lim; i++) {
     b += memory.readByte(bytesStore.address + i);
   }
   return b & 0xFF;
 }
Ejemplo n.º 3
0
 @NotNull
 private static NativeBytesStore<Void> of(long capacity, boolean zeroOut, boolean elastic)
     throws IllegalArgumentException {
   Memory memory = OS.memory();
   long address = memory.allocate(capacity);
   if (zeroOut || capacity < MEMORY_MAPPED_SIZE) {
     memory.setMemory(address, capacity, (byte) 0);
     memory.storeFence();
   }
   Deallocator deallocator = new Deallocator(address, capacity);
   return new NativeBytesStore<>(address, capacity, deallocator, elastic);
 }
Ejemplo n.º 4
0
 @NotNull
 @Override
 @ForceInline
 public NativeBytesStore<Underlying> writeFloat(long offset, float f) {
   memory.writeFloat(address + translate(offset), f);
   return this;
 }
Ejemplo n.º 5
0
  @Override
  @ForceInline
  public byte readByte(long offset) {
    if (Jvm.isDebug()) checkReleased();

    return memory.readByte(address + translate(offset));
  }
Ejemplo n.º 6
0
 @NotNull
 @Override
 @ForceInline
 public NativeBytesStore<Underlying> writeDouble(long offset, double d) {
   memory.writeDouble(address + translate(offset), d);
   return this;
 }
Ejemplo n.º 7
0
 @NotNull
 @Override
 @ForceInline
 public NativeBytesStore<Underlying> writeVolatileShort(long offset, short i16) {
   memory.writeVolatileShort(address + translate(offset), i16);
   return this;
 }
Ejemplo n.º 8
0
 @NotNull
 @Override
 @ForceInline
 public NativeBytesStore<Underlying> writeVolatileLong(long offset, long i64) {
   memory.writeVolatileLong(address + translate(offset), i64);
   return this;
 }
Ejemplo n.º 9
0
  public long appendUTF(long pos, char[] chars, int offset, int length) {
    long address = this.address + translate(0);
    Memory memory = this.memory;
    int i;
    ascii:
    {
      for (i = 0; i < length; i++) {
        char c = chars[offset + i];
        if (c > 0x007F) break ascii;
        memory.writeByte(address + pos++, (byte) c);
      }

      return pos;
    }
    return appendUTF0(pos, chars, offset, length, i);
  }
Ejemplo n.º 10
0
 @NotNull
 @Override
 @ForceInline
 public NativeBytesStore<Underlying> writeOrderedInt(long offset, int i) {
   memory.writeOrderedInt(address + translate(offset), i);
   return this;
 }
Ejemplo n.º 11
0
 @NotNull
 @Override
 @ForceInline
 public NativeBytesStore<Underlying> write(
     long offsetInRDO, byte[] bytes, int offset, int length) {
   memory.copyMemory(bytes, offset, address + translate(offsetInRDO), length);
   return this;
 }
Ejemplo n.º 12
0
 public long readIncompleteLong(long offset) {
   int remaining = (int) Math.min(8, readRemaining() - offset);
   long l = 0;
   for (int i = 0; i < remaining; i++) {
     byte b = memory.readByte(address + offset + i);
     l |= (long) (b & 0xFF) << (i * 8);
   }
   return l;
 }
  @NotNull
  public Bytes<Underlying> append8bit(@NotNull CharSequence cs)
      throws BufferOverflowException, BufferUnderflowException, IORuntimeException {
    if (cs instanceof BytesStore) {
      return write((BytesStore) cs);
    }
    int length = cs.length();
    long offset = writeOffsetPositionMoved(length);
    long address = bytesStore.address(offset);
    Memory memory = bytesStore.memory;
    assert memory != null;
    for (int i = 0; i < length; i++) {
      char c = cs.charAt(i);
      if (c > 255) c = '?';
      memory.writeByte(address + i, (byte) c);
    }

    return this;
  }
Ejemplo n.º 14
0
 public static void entries(long address, long entries) {
   if (entries >= (1L << 32)) {
     throw new IllegalStateException(
         "tier entries overflow: up to "
             + UNSIGNED_INT_MASK
             + " supported, "
             + entries
             + " given");
   }
   memory.writeInt(address + ENTRIES_OFFSET, (int) entries);
 }
Ejemplo n.º 15
0
 public static void deleted(long address, long deleted) {
   if (deleted >= (1L << 32)) {
     throw new IllegalStateException(
         "tier deleted entries count overflow: up to "
             + UNSIGNED_INT_MASK
             + " supported, "
             + deleted
             + " given");
   }
   memory.writeInt(address + DELETED_OFFSET, (int) deleted);
 }
Ejemplo n.º 16
0
 @Override
 public boolean isEqual(String s) {
   if (s == null || s.length() != readRemaining()) return false;
   char[] chars = StringUtils.extractChars(s);
   if (bytesStore instanceof NativeBytesStore) {
     NativeBytesStore bs = (NativeBytesStore) this.bytesStore;
     long address = bs.address + bs.translate(readPosition);
     Memory memory = bs.memory;
     for (int i = 0; i < chars.length; i++) {
       int b = memory.readByte(address + i) & 0xFF;
       if (b != chars[i]) return false;
     }
   } else {
     try {
       for (int i = 0; i < chars.length; i++) {
         int b = bytesStore.readByte(readPosition + i) & 0xFF;
         if (b != chars[i]) return false;
       }
     } catch (IORuntimeException e) {
       throw new AssertionError(e);
     }
   }
   return true;
 }
Ejemplo n.º 17
0
  @NotNull
  @Override
  @ForceInline
  public NativeBytesStore<Underlying> zeroOut(long start, long end)
      throws IllegalArgumentException {
    if (start < writePosition() || end > writeLimit())
      throw new IllegalArgumentException(
          "position: "
              + writePosition()
              + ", start: "
              + start
              + ", end: "
              + end
              + ", limit: "
              + writeLimit());
    if (start >= end) return this;

    memory.setMemory(address + translate(start), end - start, (byte) 0);
    return this;
  }
Ejemplo n.º 18
0
 @Override
 @ForceInline
 public byte readVolatileByte(long offset) {
   return memory.readVolatileByte(address + translate(offset));
 }
Ejemplo n.º 19
0
 public static int tier(long address) {
   return memory.readInt(address + TIER_OFFSET);
 }
Ejemplo n.º 20
0
 public static void tier(long address, int tier) {
   memory.writeInt(address + TIER_OFFSET, tier);
 }
Ejemplo n.º 21
0
 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);
 }
Ejemplo n.º 22
0
 void write8bit(long position, char[] chars, int offset, int length) {
   long addr = address + translate(position);
   Memory memory = this.memory;
   for (int i = 0; i < length; i++) memory.writeByte(addr + i, (byte) chars[offset + i]);
 }
Ejemplo n.º 23
0
 public static long entries(long address) {
   return memory.readInt(address + ENTRIES_OFFSET) & UNSIGNED_INT_MASK;
 }
Ejemplo n.º 24
0
 public static long deleted(long address) {
   return memory.readInt(address + DELETED_OFFSET) & UNSIGNED_INT_MASK;
 }
Ejemplo n.º 25
0
 @Override
 @ForceInline
 public boolean compareAndSwapLong(long offset, long expected, long value) {
   return memory.compareAndSwapLong(address + translate(offset), expected, value);
 }
Ejemplo n.º 26
0
 @Override
 @ForceInline
 public float readFloat(long offset) {
   return memory.readFloat(address + translate(offset));
 }
Ejemplo n.º 27
0
 @Override
 @ForceInline
 public double readDouble(long offset) {
   return memory.readDouble(address + translate(offset));
 }
Ejemplo n.º 28
0
 @Override
 @ForceInline
 public long readVolatileLong(long offset) {
   return memory.readVolatileLong(address + translate(offset));
 }
Ejemplo n.º 29
0
 @Override
 @ForceInline
 public short readVolatileShort(long offset) {
   return memory.readVolatileShort(address + translate(offset));
 }
Ejemplo n.º 30
0
 public static void segmentIndex(long address, int segmentIndex) {
   memory.writeInt(address + SEGMENT_INDEX_OFFSET, segmentIndex);
 }