Package sun.misc

Examples of sun.misc.Unsafe


    // static final Category log = Category.getInstance(Field.class);
    static final Unsafe unsafe = getUnsafe();

    private static Unsafe getUnsafe() {
        Unsafe unsafe = null;
        try {
            Class uc = Unsafe.class;
            java.lang.reflect.Field[] fields = uc.getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                if (fields[i].getName().equals("theUnsafe")) {
View Full Code Here


      } 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

     *
     * @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

            if (end - p > LONG_SIZE * 2) {
                int ep = ~LOWBITS & (p + LOWBITS);
                while (p < ep) {
                    if ((bytes[p++] & 0xc0 /*utf8 lead byte*/) != 0x80) len++;
                }
                Unsafe us = (Unsafe)UNSAFE;
                int eend = ~LOWBITS & end;
                while (p < eend) {
                    len += countUtf8LeadBytes(us.getLong(bytes, OFFSET + p));
                    p += LONG_SIZE;
                }
            }
        }
        while (p < end) {
View Full Code Here

            if (n > LONG_SIZE * 2) {
                int ep = ~LOWBITS & (p + LOWBITS);
                while (p < ep) {
                    if ((bytes[p++] & 0xc0 /*utf8 lead byte*/) != 0x80) n--;
                }
                Unsafe us = (Unsafe)UNSAFE;
                int eend = ~LOWBITS & end;
                do {
                    n -= countUtf8LeadBytes(us.getLong(bytes, OFFSET + p));
                    p += LONG_SIZE;
                } while (p < eend && n >= LONG_SIZE);
            }
        }
        while (p < end) {
View Full Code Here

    // static final Category log = Category.getInstance(Field.class);
    static final Unsafe unsafe = getUnsafe();

    private static Unsafe getUnsafe() {
        Unsafe unsafe = null;
        try {
            Class uc = Unsafe.class;
            java.lang.reflect.Field[] fields = uc.getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                if (fields[i].getName().equals("theUnsafe")) {
View Full Code Here

   */
  static long getOperatingSystemPageSize() {
    try {
      Field f = Unsafe.class.getDeclaredField("theUnsafe");
      f.setAccessible(true);
      Unsafe unsafe = (Unsafe)f.get(null);
      return unsafe.pageSize();
    } catch (Throwable e) {
      LOG.warn("Unable to get operating system page size.  Guessing 4096.", e);
      return 4096;
    }
  }
View Full Code Here

        load0(mappingAddress(offset), length);

        // Read a byte from each page to bring it into memory. A checksum
        // is computed as we go along to prevent the compiler from otherwise
        // considering the loop as dead code.
        Unsafe unsafe = Unsafe.getUnsafe();
        int ps = Bits.pageSize();
        int count = Bits.pageCount(length);
        long a = mappingAddress(offset);
        byte x = 0;
        for (int i=0; i<count; i++) {
            x ^= unsafe.getByte(a);
            a += ps;
        }
        if (unused != 0)
            unused = x;
View Full Code Here

            if (end - p > LONG_SIZE * 2) {
                int ep = ~LOWBITS & (p + LOWBITS);
                while (p < ep) {
                    if ((bytes[p++] & 0xc0 /*utf8 lead byte*/) != 0x80) len++;
                }
                Unsafe us = (Unsafe)UNSAFE;
                int eend = ~LOWBITS & end;
                while (p < eend) {
                    len += countUtf8LeadBytes(us.getLong(bytes, OFFSET + p));
                    p += LONG_SIZE;
                }
            }
        }
        while (p < end) {
View Full Code Here

            if (n > LONG_SIZE * 2) {
                int ep = ~LOWBITS & (p + LOWBITS);
                while (p < ep) {
                    if ((bytes[p++] & 0xc0 /*utf8 lead byte*/) != 0x80) n--;
                }
                Unsafe us = (Unsafe)UNSAFE;
                int eend = ~LOWBITS & end;
                do {
                    n -= countUtf8LeadBytes(us.getLong(bytes, OFFSET + p));
                    p += LONG_SIZE;
                } while (p < eend && n >= LONG_SIZE);
            }
        }
        while (p < end) {
View Full Code Here

TOP

Related Classes of sun.misc.Unsafe

Copyright © 2018 www.massapicom. 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.