use of org.graalvm.compiler.core.common.util.UnsafeArrayTypeWriter in project graal by oracle.
the class EncodedLineNumberTable method encode.
@Platforms(Platform.HOSTED_ONLY.class)
public static byte[] encode(LineNumberTable table) {
if (table == null) {
return null;
}
int[] lineNumbers = table.getLineNumbers();
int[] bcis = table.getBcis();
assert lineNumbers.length == bcis.length;
UnsafeArrayTypeWriter encodingBuffer = UnsafeArrayTypeWriter.create(ByteArrayReader.supportsUnalignedMemoryAccess());
int lastLineNumber = 0;
int lastBci = 0;
encodingBuffer.putUV(lineNumbers.length);
for (int i = 0; i < lineNumbers.length; i++) {
encodingBuffer.putSV(lineNumbers[i] - lastLineNumber);
encodingBuffer.putSV(bcis[i] - lastBci);
lastLineNumber = lineNumbers[i];
lastBci = bcis[i];
}
byte[] encodedTable = encodingBuffer.toArray(new byte[TypeConversion.asS4(encodingBuffer.getBytesWritten())]);
assert verifyTable(table, decode(encodedTable));
return encodedTable;
}
use of org.graalvm.compiler.core.common.util.UnsafeArrayTypeWriter in project graal by oracle.
the class CollectingObjectReferenceVisitor method encodeIPData.
private void encodeIPData() {
IPData first = null;
IPData prev = null;
for (IPData cur : entries.values()) {
if (first == null) {
first = cur;
} else {
while (!TypeConversion.isU1(cur.ip - prev.ip)) {
final IPData filler = new IPData();
filler.ip = prev.ip + 0xFF;
prev.next = filler;
prev = filler;
}
prev.next = cur;
}
prev = cur;
}
long nextIndexIP = 0;
UnsafeArrayTypeWriter indexBuffer = UnsafeArrayTypeWriter.create(ByteArrayReader.supportsUnalignedMemoryAccess());
UnsafeArrayTypeWriter encodingBuffer = UnsafeArrayTypeWriter.create(ByteArrayReader.supportsUnalignedMemoryAccess());
for (IPData data = first; data != null; data = data.next) {
assert data.ip <= nextIndexIP;
if (data.ip == nextIndexIP) {
indexBuffer.putU4(encodingBuffer.getBytesWritten());
nextIndexIP += CodeInfoDecoder.indexGranularity();
}
int entryFlags = 0;
entryFlags = entryFlags | flagsForSizeEncoding(data) << CodeInfoDecoder.FS_SHIFT;
entryFlags = entryFlags | flagsForExceptionOffset(data) << CodeInfoDecoder.EX_SHIFT;
entryFlags = entryFlags | flagsForReferenceMapIndex(data) << CodeInfoDecoder.RM_SHIFT;
entryFlags = entryFlags | flagsForDeoptFrameInfo(data) << CodeInfoDecoder.FI_SHIFT;
encodingBuffer.putU1(entryFlags);
encodingBuffer.putU1(data.next == null ? CodeInfoDecoder.DELTA_END_OF_TABLE : (data.next.ip - data.ip));
writeSizeEncoding(encodingBuffer, data, entryFlags);
writeExceptionOffset(encodingBuffer, data, entryFlags);
writeReferenceMapIndex(encodingBuffer, data, entryFlags);
writeDeoptFrameInfo(encodingBuffer, data, entryFlags);
}
codeInfoIndex = indexBuffer.toArray(newByteArray(TypeConversion.asU4(indexBuffer.getBytesWritten())));
codeInfoEncodings = encodingBuffer.toArray(newByteArray(TypeConversion.asU4(encodingBuffer.getBytesWritten())));
}
use of org.graalvm.compiler.core.common.util.UnsafeArrayTypeWriter in project graal by oracle.
the class DeoptimizationSourcePositionEncoder method encode.
public void encode(List<NodeSourcePosition> deoptimzationSourcePositions) {
addObjectConstants(deoptimzationSourcePositions);
deoptimizationObjectConstants = objectConstants.encodeAll(newObjectArray(objectConstants.getLength()));
UnsafeArrayTypeWriter encodingBuffer = UnsafeArrayTypeWriter.create(ByteArrayReader.supportsUnalignedMemoryAccess());
EconomicMap<NodeSourcePosition, Long> sourcePositionStartOffsets = EconomicMap.create(Equivalence.IDENTITY_WITH_SYSTEM_HASHCODE);
deoptimizationStartOffsets = newIntArray(deoptimzationSourcePositions.size());
encodeSourcePositions(deoptimzationSourcePositions, sourcePositionStartOffsets, encodingBuffer);
deoptimizationEncodings = encodingBuffer.toArray(newByteArray(TypeConversion.asS4(encodingBuffer.getBytesWritten())));
verifyEncoding(deoptimzationSourcePositions);
}
use of org.graalvm.compiler.core.common.util.UnsafeArrayTypeWriter in project graal by oracle.
the class TypeWriterTest method test01.
private static void test01(boolean supportsUnalignedMemoryAccess) {
UnsafeArrayTypeWriter writer = UnsafeArrayTypeWriter.create(supportsUnalignedMemoryAccess);
putValues(writer);
byte[] array = new byte[TypeConversion.asU4(writer.getBytesWritten())];
writer.toArray(array);
UnsafeArrayTypeReader reader = UnsafeArrayTypeReader.create(array, 0, supportsUnalignedMemoryAccess);
checkValues(reader);
}
use of org.graalvm.compiler.core.common.util.UnsafeArrayTypeWriter in project graal by oracle.
the class FrameInfoVerifier method encodeFrameDatas.
private void encodeFrameDatas() {
UnsafeArrayTypeWriter encodingBuffer = UnsafeArrayTypeWriter.create(ByteArrayReader.supportsUnalignedMemoryAccess());
for (FrameData data : allDebugInfos) {
data.indexInEncodings = encodingBuffer.getBytesWritten();
encodeFrameData(data, encodingBuffer);
}
frameInfoEncodings = encodingBuffer.toArray(newByteArray(TypeConversion.asS4(encodingBuffer.getBytesWritten())));
}
Aggregations