Search in sources :

Example 1 with SerializableData

use of org.graalvm.compiler.code.DataSection.SerializableData 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)

Example 2 with SerializableData

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

the class SimpleAssemblerTest method doubleTest.

@Test
public void doubleTest() {
    CodeGenTest test = new CodeGenTest() {

        @Override
        public byte[] generateCode(CompilationResult compResult, TargetDescription target, RegisterConfig registerConfig, CallingConvention cc) {
            AMD64MacroAssembler asm = new AMD64MacroAssembler(target);
            Register ret = registerConfig.getReturnRegister(JavaKind.Double);
            Data data = new SerializableData(JavaConstant.forDouble(84.72), 8);
            DataSectionReference ref = compResult.getDataSection().insertData(data);
            compResult.recordDataPatch(asm.position(), ref);
            asm.movdbl(ret, asm.getPlaceholder(-1));
            asm.ret(0);
            return asm.close(true);
        }
    };
    assertReturn("doubleStub", test, 84.72);
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) RegisterConfig(jdk.vm.ci.code.RegisterConfig) Register(jdk.vm.ci.code.Register) DataSectionReference(jdk.vm.ci.code.site.DataSectionReference) TargetDescription(jdk.vm.ci.code.TargetDescription) AMD64MacroAssembler(org.graalvm.compiler.asm.amd64.AMD64MacroAssembler) SerializableData(org.graalvm.compiler.code.DataSection.SerializableData) Data(org.graalvm.compiler.code.DataSection.Data) RawData(org.graalvm.compiler.code.DataSection.RawData) CompilationResult(org.graalvm.compiler.code.CompilationResult) SerializableData(org.graalvm.compiler.code.DataSection.SerializableData) Test(org.junit.Test) AssemblerTest(org.graalvm.compiler.asm.test.AssemblerTest)

Aggregations

Data (org.graalvm.compiler.code.DataSection.Data)2 SerializableData (org.graalvm.compiler.code.DataSection.SerializableData)2 ByteBuffer (java.nio.ByteBuffer)1 CallingConvention (jdk.vm.ci.code.CallingConvention)1 Register (jdk.vm.ci.code.Register)1 RegisterConfig (jdk.vm.ci.code.RegisterConfig)1 TargetDescription (jdk.vm.ci.code.TargetDescription)1 DataSectionReference (jdk.vm.ci.code.site.DataSectionReference)1 HotSpotConstant (jdk.vm.ci.hotspot.HotSpotConstant)1 SerializableConstant (jdk.vm.ci.meta.SerializableConstant)1 VMConstant (jdk.vm.ci.meta.VMConstant)1 AMD64MacroAssembler (org.graalvm.compiler.asm.amd64.AMD64MacroAssembler)1 AssemblerTest (org.graalvm.compiler.asm.test.AssemblerTest)1 CompilationResult (org.graalvm.compiler.code.CompilationResult)1 Patches (org.graalvm.compiler.code.DataSection.Patches)1 RawData (org.graalvm.compiler.code.DataSection.RawData)1 ZeroData (org.graalvm.compiler.code.DataSection.ZeroData)1 GraalError (org.graalvm.compiler.debug.GraalError)1 Test (org.junit.Test)1