1 18 package org.apache.geronimo.interop.rmi.iiop; 19 20 import java.lang.reflect.Field ; 21 22 29 30 public class FinalFieldSetterJdk14 extends FinalFieldSetter 31 { 32 private final long fieldOffset; 33 private static final sun.misc.Unsafe unsafe; 35 static 36 { 37 sun.misc.Unsafe val = null; 38 try 39 { 40 Class unsafeClass = Class.forName("sun.misc.Unsafe"); 41 Field unsafeField = unsafeClass.getDeclaredField("theUnsafe"); 42 unsafeField.setAccessible(true); 43 val = (sun.misc.Unsafe)unsafeField.get((java.lang.Object )null); 44 } 45 catch(Throwable e) 46 { 47 } 48 unsafe = val; 49 } 50 51 public FinalFieldSetterJdk14(Field field) 52 { 53 if(unsafe != null) 54 { 55 fieldOffset = unsafe.objectFieldOffset(field); 56 } 57 else 58 { 59 fieldOffset = -1; 60 } 61 } 62 63 public void setBoolean(Object that, boolean value) 64 { 65 unsafe.putBoolean(that, fieldOffset, value); 66 } 67 68 public void setByte(Object that, byte value) 69 { 70 unsafe.putByte(that, fieldOffset, value); 71 } 72 73 public void setChar(Object that, char value) 74 { 75 unsafe.putChar(that, fieldOffset, value); 76 } 77 78 public void setDouble(Object that, double value) 79 { 80 unsafe.putDouble(that, fieldOffset, value); 81 } 82 83 public void setFloat(Object that, float value) 84 { 85 unsafe.putFloat(that, fieldOffset, value); 86 } 87 88 public void setInt(Object that, int value) 89 { 90 unsafe.putInt(that, fieldOffset, value); 91 } 92 93 public void setLong(Object that, long value) 94 { 95 unsafe.putLong(that, fieldOffset, value); 96 } 97 98 public void setShort(Object that, short value) 99 { 100 unsafe.putShort(that, fieldOffset, value); 101 } 102 103 public void set(Object that, Object value) 104 { 105 unsafe.putObject(that, fieldOffset, value); 106 } 107 } 108 | Popular Tags |