Package sun.misc

Examples of sun.misc.Unsafe.objectFieldOffset()


      fc = Foo.class.getDeclaredField("c");
    } catch (NoSuchFieldException e) {
      System.out.println(e);
      return;
    }
    long offset = unsafe.objectFieldOffset(fc);
    System.out.println(unsafe.getObject(f,offset));
    unsafe.putObject(f,offset, "hello Unsafe");
    System.out.println(unsafe.getObject(f,offset));
    System.out.println(((Foo)f).c);
    String newC = "hello again Unsafe";
View Full Code Here


    f.setAccessible(true);
    Unsafe unsafe = (Unsafe)f.get(c);

    f = Reference.class.getDeclaredField("referent");
    f.setAccessible(true);
    long referent_offset = unsafe.objectFieldOffset(f);

    Test7190310_unsafe t = new Test7190310_unsafe();
    TestObject o = new TestObject();
    t.obj = o;
View Full Code Here

    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

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.