in lightning-core/src/main/java/org/apache/directmemory/lightning/internal/beans/SunUnsafePropertyAccessorFactory.java [177:339]
private PropertyAccessor buildForArrayField( final Field field, final Class<?> definedClass )
{
return new FieldArrayPropertyAccessor( field, definedClass )
{
private final long offset;
private final int arrayBaseOffset;
private final int arrayIndexScale;
{
offset = UNSAFE.objectFieldOffset( field );
arrayBaseOffset = UNSAFE.arrayBaseOffset( field.getType() );
arrayIndexScale = UNSAFE.arrayIndexScale( field.getType() );
}
@Override
public <T> void writeObject( Object instance, T value )
{
UNSAFE.putObject( instance, offset, value );
}
@Override
@SuppressWarnings( "unchecked" )
public <T> T readObject( Object instance )
{
return (T) UNSAFE.getObject( instance, offset );
}
@Override
public <T> void writeObject( Object instance, int index, T value )
{
long offset = calculateIndexOffset( index );
UNSAFE.putObject( instance, offset, value );
}
@Override
@SuppressWarnings( "unchecked" )
public <T> T readObject( Object instance, int index )
{
long localOffset = calculateIndexOffset( index );
return (T) UNSAFE.getObject( instance, localOffset );
}
@Override
public void writeBoolean( Object instance, int index, boolean value )
{
long offset = calculateIndexOffset( index );
UNSAFE.putBoolean( instance, offset, value );
}
@Override
public boolean readBoolean( Object instance, int index )
{
long offset = calculateIndexOffset( index );
return UNSAFE.getBoolean( instance, offset );
}
@Override
public void writeByte( Object instance, int index, byte value )
{
long offset = calculateIndexOffset( index );
UNSAFE.putByte( instance, offset, value );
}
@Override
public byte readByte( Object instance, int index )
{
long offset = calculateIndexOffset( index );
return UNSAFE.getByte( instance, offset );
}
@Override
public void writeShort( Object instance, int index, short value )
{
long offset = calculateIndexOffset( index );
UNSAFE.putShort( instance, offset, value );
}
@Override
public short readShort( Object instance, int index )
{
long offset = calculateIndexOffset( index );
return UNSAFE.getShort( instance, offset );
}
@Override
public void writeChar( Object instance, int index, char value )
{
long offset = calculateIndexOffset( index );
UNSAFE.putChar( instance, offset, value );
}
@Override
public char readChar( Object instance, int index )
{
long offset = calculateIndexOffset( index );
return UNSAFE.getChar( instance, offset );
}
@Override
public void writeInt( Object instance, int index, int value )
{
long offset = calculateIndexOffset( index );
UNSAFE.putInt( instance, offset, value );
}
@Override
public int readInt( Object instance, int index )
{
long offset = calculateIndexOffset( index );
return UNSAFE.getInt( instance, offset );
}
@Override
public void writeLong( Object instance, int index, long value )
{
long offset = calculateIndexOffset( index );
UNSAFE.putLong( instance, offset, value );
}
@Override
public long readLong( Object instance, int index )
{
long offset = calculateIndexOffset( index );
return UNSAFE.getLong( instance, offset );
}
@Override
public void writeFloat( Object instance, int index, float value )
{
long offset = calculateIndexOffset( index );
UNSAFE.putFloat( instance, offset, value );
}
@Override
public float readFloat( Object instance, int index )
{
long offset = calculateIndexOffset( index );
return UNSAFE.getFloat( instance, offset );
}
@Override
public void writeDouble( Object instance, int index, double value )
{
long offset = calculateIndexOffset( index );
UNSAFE.putDouble( instance, offset, value );
}
@Override
public double readDouble( Object instance, int index )
{
long offset = calculateIndexOffset( index );
return UNSAFE.getDouble( instance, offset );
}
private long calculateIndexOffset( int index )
{
return arrayBaseOffset + ( index * arrayIndexScale );
}
};
}