Search in sources :

Example 1 with Data

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

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

the class DataSection method buildDataSection.

/**
 * Builds the data section into a given buffer.
 *
 * This must only be called once this object has been {@linkplain #closed() closed}. When this
 * method returns, the buffers' position is just after the last data item.
 *
 * @param buffer the {@link ByteBuffer} where the data section should be built. The buffer must
 *            hold at least {@link #getSectionSize()} bytes.
 * @param patch a {@link Patches} instance to receive {@link VMConstant constants} for
 * @param onEmit a function that is called before emitting each data item with the
 *            {@link DataSectionReference} and the size of the data.
 */
public void buildDataSection(ByteBuffer buffer, Patches patch, BiConsumer<DataSectionReference, Integer> onEmit) {
    checkClosed();
    assert buffer.remaining() >= sectionSize;
    int start = buffer.position();
    for (Data d : dataItems) {
        buffer.position(start + d.ref.getOffset());
        onEmit.accept(d.ref, d.getSize());
        d.emit(buffer, patch);
    }
    buffer.position(start + sectionSize);
}
Also used : Data(org.graalvm.compiler.code.DataSection.Data)

Example 3 with Data

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

Example 4 with Data

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

the class SimpleAssemblerTest method rawDoubleTest.

@Test
public void rawDoubleTest() {
    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);
            byte[] rawBytes = new byte[8];
            ByteBuffer.wrap(rawBytes).order(ByteOrder.nativeOrder()).putDouble(84.72);
            Data data = new RawData(rawBytes, 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) RawData(org.graalvm.compiler.code.DataSection.RawData) 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) Test(org.junit.Test) AssemblerTest(org.graalvm.compiler.asm.test.AssemblerTest)

Example 5 with Data

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

the class CompilationResultBuilder method recordDataReferenceInCode.

public AbstractAddress recordDataReferenceInCode(Constant constant, int alignment) {
    assert constant != null;
    debug.log("Constant reference in code: pos = %d, data = %s", asm.position(), constant);
    Data data = createDataItem(constant);
    data.updateAlignment(alignment);
    return recordDataSectionReference(data);
}
Also used : RawData(org.graalvm.compiler.code.DataSection.RawData) Data(org.graalvm.compiler.code.DataSection.Data)

Aggregations

Data (org.graalvm.compiler.code.DataSection.Data)9 RawData (org.graalvm.compiler.code.DataSection.RawData)4 Register (jdk.vm.ci.code.Register)3 SerializableData (org.graalvm.compiler.code.DataSection.SerializableData)3 CallingConvention (jdk.vm.ci.code.CallingConvention)2 RegisterConfig (jdk.vm.ci.code.RegisterConfig)2 TargetDescription (jdk.vm.ci.code.TargetDescription)2 DataSectionReference (jdk.vm.ci.code.site.DataSectionReference)2 AMD64MacroAssembler (org.graalvm.compiler.asm.amd64.AMD64MacroAssembler)2 AssemblerTest (org.graalvm.compiler.asm.test.AssemblerTest)2 CompilationResult (org.graalvm.compiler.code.CompilationResult)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 ValueUtil.asRegister (jdk.vm.ci.code.ValueUtil.asRegister)1 ValueUtil.isRegister (jdk.vm.ci.code.ValueUtil.isRegister)1 HotSpotConstant (jdk.vm.ci.hotspot.HotSpotConstant)1 SerializableConstant (jdk.vm.ci.meta.SerializableConstant)1 VMConstant (jdk.vm.ci.meta.VMConstant)1 SPARCAddress (org.graalvm.compiler.asm.sparc.SPARCAddress)1 SPARCAssembler.isCPURegister (org.graalvm.compiler.asm.sparc.SPARCAssembler.isCPURegister)1