public static void copyMemoryFieldByField(long srcAddress,Object dest){
  Class clazz=dest.getClass();
  while (clazz != Object.class) {
    for (    Field f : clazz.getDeclaredFields()) {
      if ((f.getModifiers() & Modifier.STATIC) == 0) {
        final Class type=f.getType();
        Preconditions.checkArgument(type.isPrimitive(),"Only primitives are supported");
        final long offset=unsafe.objectFieldOffset(f);
        final long src=srcAddress + offset;
        if (type == int.class) {
          unsafe.putInt(dest,offset,unsafe.getInt(src));
        }
 else         if (type == long.class) {
          unsafe.putLong(dest,offset,unsafe.getLong(src));
        }
 else {
          throw new IllegalArgumentException("Type not supported yet: " + type);
        }
      }
    }
    clazz=clazz.getSuperclass();
  }
}

public static void copyMemoryFieldByField ( long srcAddress , Object dest ) { Class clazz = dest . getClass ( ) ; while ( clazz != Object . class ) { for ( Field f : clazz . getDeclaredFields ( ) ) { if ( ( f . getModifiers ( ) & Modifier . STATIC ) == 0 ) { final Class type = f . getType ( ) ; Preconditions . checkArgument ( type . isPrimitive ( ) , "Only primitives are supported" ) ; final long offset = unsafe . objectFieldOffset ( f ) ; final long src = srcAddress + offset ; if ( type == int . class ) { unsafe . putInt ( dest , offset , unsafe . getInt ( src ) ) ; } else if ( type == long . class ) { unsafe . putLong ( dest , offset , unsafe . getLong ( src ) ) ; } else { throw new IllegalArgumentException ( "Type not supported yet: " + type ) ; } } } clazz = clazz . getSuperclass ( ) ; } }
copies from srcaddress to dest one field at a time .
