Search in sources :

Example 1 with Patches

use of org.graalvm.compiler.code.DataSection.Patches in project graal by oracle.

the class HotSpotDataBuilder method createDataItem.

@Override
public Data createDataItem(Constant constant) {
    if (JavaConstant.isNull(constant)) {
        boolean compressed = COMPRESSED_NULL.equals(constant);
        int size = compressed ? 4 : target.wordSize;
        return ZeroData.create(size, size);
    } else if (constant instanceof VMConstant) {
        VMConstant vmConstant = (VMConstant) constant;
        if (!(constant instanceof HotSpotConstant)) {
            throw new GraalError(String.valueOf(constant));
        }
        HotSpotConstant c = (HotSpotConstant) vmConstant;
        int size = c.isCompressed() ? 4 : target.wordSize;
        return new Data(size, size) {

            @Override
            protected void emit(ByteBuffer buffer, Patches patches) {
                int position = buffer.position();
                if (getSize() == Integer.BYTES) {
                    buffer.putInt(0xDEADDEAD);
                } else {
                    buffer.putLong(0xDEADDEADDEADDEADL);
                }
                patches.registerPatch(position, vmConstant);
            }
        };
    } else if (constant instanceof SerializableConstant) {
        SerializableConstant s = (SerializableConstant) constant;
        return new SerializableData(s);
    } else {
        throw new GraalError(String.valueOf(constant));
    }
}
Also used : HotSpotConstant(jdk.vm.ci.hotspot.HotSpotConstant) GraalError(org.graalvm.compiler.debug.GraalError) VMConstant(jdk.vm.ci.meta.VMConstant) SerializableData(org.graalvm.compiler.code.DataSection.SerializableData) ZeroData(org.graalvm.compiler.code.DataSection.ZeroData) Data(org.graalvm.compiler.code.DataSection.Data) ByteBuffer(java.nio.ByteBuffer) SerializableData(org.graalvm.compiler.code.DataSection.SerializableData) Patches(org.graalvm.compiler.code.DataSection.Patches) SerializableConstant(jdk.vm.ci.meta.SerializableConstant)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 HotSpotConstant (jdk.vm.ci.hotspot.HotSpotConstant)1 SerializableConstant (jdk.vm.ci.meta.SerializableConstant)1 VMConstant (jdk.vm.ci.meta.VMConstant)1 Data (org.graalvm.compiler.code.DataSection.Data)1 Patches (org.graalvm.compiler.code.DataSection.Patches)1 SerializableData (org.graalvm.compiler.code.DataSection.SerializableData)1 ZeroData (org.graalvm.compiler.code.DataSection.ZeroData)1 GraalError (org.graalvm.compiler.debug.GraalError)1