-
Sub-task
-
Resolution: Done
-
Major
-
None
-
None
-
None
Long term, OpenJDK aims to remove sun.misc.Unsafe. In the transition from 8 to 11, a number of deprecated and seldom used methods have been removed from the class in JDK-8068975 and JDK-8054494
- getInt(Object,int)
- putInt(Object,int,int)
- getObject(Object,int)
- putObject(Object,int,Object)
- getBoolean(Object,int)
- putBoolean(Object,int,boolean)
- getByte(Object,int)
- putByte(Object,int,byte)
- getShort(Object,int)
- putShort(Object,int,byte)
- getChar(Object,int)
- putChar(Object,int,char)
- getLong(Object,int)
- putLong(Object,int,long)
- getFloat(Object,int)
- putFloat(Object,int,float)
- getDouble(Object,int)
- putDouble(Object,int,double)
- fieldOffset(Field)
- staticFieldBase(Class<?>)
- tryMoniterEnter(Object)
- moniterExit(Object)
When
a Java class uses any of the above methods
Perform
add a hint to replace them as follows:
- The get and put methods have equivalents that take long offsets, and OpenJDK 8's version of the removed methods just cast the int offsets and used the long versions anyway.
- staticFieldOffset(Field) and ObjectFieldOffset(Field) should replace fieldOffset(Field), which, again, the 8 version delegated to anyway.
- staticFieldBase(Class) should be replaced by asking for a specific field with staticFieldBase(Field). The removed method only returned the address of the first static field in the class and relied on the assumption that the JVM stored all statics together, which may not be true.
- tryMonitorEnter(Object) and monitorExit(Object) can be replaced with use of the Java synchronized primitives, as illustrated in the test changes for JDK-8054494
Long-term, the user should be advised to look into VarHandles