Examples of Unsafe


Examples of sun.misc.Unsafe

        long offset = mappingOffset();
        long length = mappingLength(offset);
        load0(mappingAddress(offset), length);

        // touch each page
        Unsafe unsafe = Unsafe.getUnsafe();
        int ps = Bits.pageSize();
        int count = Bits.pageCount(length);
        long a = mappingAddress(offset);
        for (int i=0; i<count; i++) {
            unsafe.getByte(a);
            a += ps;
        }

        return this;
    }
View Full Code Here

Examples of sun.misc.Unsafe

      } else if (output instanceof UnsafeMemoryOutput) {
        UnsafeMemoryOutput unsafeOutput = (UnsafeMemoryOutput)output;
        unsafeOutput.writeBytes(object, offset, len);
      } else {
        long off;
        Unsafe unsafe = unsafe();
        for (off = offset; off < offset + len - 8; off += 8) {
          output.writeLong(unsafe.getLong(object, off));
        }

        if (off < offset + len) {
          for (; off < offset + len; ++off) {
            output.write(unsafe.getByte(object, off));
          }
        }
      }
    }
View Full Code Here

Examples of sun.misc.Unsafe

     *
     * @param input
     * @param object */
    private void readSlow (Input input, Object object) {
      long off;
      Unsafe unsafe = unsafe();
      for (off = offset; off < offset + len - 8; off += 8) {
        unsafe.putLong(object, off, input.readLong());
      }

      if (off < offset + len) {
        for (; off < offset + len; ++off) {
          unsafe.putByte(object, off, input.readByte());
        }
      }
    }
View Full Code Here

Examples of sun.misc.Unsafe

   * allocates 1MB, write a bunch of bytes, reads them back, frees the memory
   * @throws Exception
   */
  @Test(groups = "fast")
  public void testSanity() throws Exception {
    Unsafe unsafe = UnsafeAccessor.get();

    int size = 1024 * 1024;
    long ptr = unsafe.allocateMemory(size);
    long writePtr = ptr;
   
    for (int i = 0; i < size; i++) {
      byte b = (byte)(i % 127);

      unsafe.putByte(writePtr, b);
      writePtr++;
    }
   
    long readPtr = ptr;
   
    for (int i = 0; i < size; i++) {
      byte b = (byte)(i % 127);

      byte readByte = unsafe.getByte(readPtr);
      readPtr++;
     
      Assert.assertEquals(b, readByte);
    }
   
    unsafe.freeMemory(ptr);
  }
View Full Code Here

Examples of sun.misc.Unsafe

  /**
   * Attempts to dump physical object's memory as a string.
   */
  public static String objectMemoryAsString(Object o) {
    final Unsafe unsafe = getUnsafe();
    final ByteOrder byteOrder = ByteOrder.nativeOrder();
   
    StringBuilder b = new StringBuilder();
    final int obSize = (int) RamUsageEstimator.shallowSizeOf(o);
    for (int i = 0; i < obSize; i += 2) {
      if ((i & 0xf) == 0) {
        if (i > 0) b.append("\n");
        b.append(String.format(Locale.ENGLISH, "%#06x", i));
      }
 
      // we go short by short because J9 fails on odd addresses (everything is aligned,
      // including byte fields.
      int shortValue = unsafe.getShort(o, (long) i);
 
      if (byteOrder == ByteOrder.BIG_ENDIAN) {
        b.append(String.format(Locale.ENGLISH, " %02x", (shortValue >>> 8) & 0xff));
        b.append(String.format(Locale.ENGLISH, " %02x", (shortValue & 0xff)));
      } else {
View Full Code Here

Examples of sun.misc.Unsafe

   * Attempts to dump a layout of a class's fields in memory
   * (offsets from base object pointer).
   */
  @SuppressWarnings({"unchecked"})
  public static String fieldsLayoutAsString(Class<?> clazz) {
    Unsafe unsafe = getUnsafe();
    TreeMap<Long, String> fields = new TreeMap<Long, String>();
    for (Class<?> c = clazz; c != null; c = c.getSuperclass()) {
      for (Field f : c.getDeclaredFields()) {
        fields.put(
            unsafe.objectFieldOffset(f),
            f.getDeclaringClass().getSimpleName() + "." + f.getName());
      }
    }
    fields.put(
        RamUsageEstimator.shallowSizeOfInstance(clazz), "#shallowSizeOfInstance(" + clazz.getName() + ")");
View Full Code Here

Examples of sun.misc.Unsafe

            entity.ridingEntity = null;
          }

          if (!entity.isDead) {
            if (entity instanceof EntityPlayerMP) {
              Unsafe $ = UnsafeAccess.$;
              Object lock = ((EntityPlayerMP) entity).playerNetServerHandler;
              if ($.tryMonitorEnter(lock)) {
                try {
                  world.updateEntity(entity);
                } finally {
                  $.monitorExit(lock);
                }
              }
            } else {
              world.updateEntity(entity);
            }
View Full Code Here

Examples of sun.misc.Unsafe

    private Class<?> performLoadClassChecked(final String className, final boolean exportsOnly, final boolean resolve) throws ClassNotFoundException {
        if (SAFE_JDK) {
            return performLoadClassUnchecked(className, exportsOnly, resolve);
        } else if (Thread.holdsLock(this)) {
            if (LOCKLESS) {
                final Unsafe unsafe = UnsafeHolder.UNSAFE;
                unsafe.monitorExit(this);
                try {
                    return performLoadClassChecked(className, exportsOnly, resolve);
                } finally {
                    unsafe.monitorEnter(this);
                }
            }
            if (Thread.currentThread() != LoaderThreadHolder.LOADER_THREAD) {
                // Only the classloader thread may take this lock; use a condition to relinquish it
                final LoadRequest req = new LoadRequest(className, resolve, exportsOnly, this, AccessController.getContext());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.