private static sun.misc.Unsafe initUnsafe()
    {
        try
        {
            java.lang.reflect.Field f = sun.misc.Unsafe.class
                    .getDeclaredField("theUnsafe");

            f.setAccessible(true);

            return (sun.misc.Unsafe) f.get(null);
        }
        catch (Exception e)
        {
            // ignore

            /*
             * android 3.x try { java.lang.reflect.Field f = sun.misc.Unsafe.class.getDeclaredField("THE_ONE");
             * 
             * f.setAccessible(true);
             * 
             * return (sun.misc.Unsafe)f.get(null); } catch(Exception e1) { // ignore }
             */
        }

        return sun.misc.Unsafe.getUnsafe();
    }
Field factory via sun.misc.Unsafe.

@author David Yu
@created Jul 7, 2011
protostuff-runtime/src/main/java/io/protostuff/runtime/RuntimeUnsafeFieldFactory.java