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));
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations