use of com.oracle.svm.core.graal.code.CGlobalDataInfo in project graal by oracle.
the class CGlobalDataFeature method registerInvocationPlugins.
@Override
public void registerInvocationPlugins(Providers providers, SnippetReflectionProvider snippetReflection, InvocationPlugins invocationPlugins, boolean hosted) {
Registration r = new Registration(invocationPlugins, CGlobalData.class);
r.register1("get", Receiver.class, new InvocationPlugin() {
@Override
public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
VMError.guarantee(receiver.get().isConstant(), "Accessed CGlobalData is not a compile-time constant: " + b.getMethod().asStackTraceElement(b.bci()));
CGlobalDataImpl<?> data = (CGlobalDataImpl<?>) SubstrateObjectConstant.asObject(receiver.get().asConstant());
CGlobalDataInfo info = CGlobalDataFeature.this.map.get(data);
b.addPush(targetMethod.getSignature().getReturnKind(), new CGlobalDataLoadAddressNode(info));
return true;
}
});
}
use of com.oracle.svm.core.graal.code.CGlobalDataInfo in project graal by oracle.
the class CGlobalDataFeature method layout.
private void layout() {
assert !isLayouted() : "Already layouted";
final int wordSize = ConfigurationValues.getTarget().wordSize;
int offset = 0;
for (Entry<CGlobalDataImpl<?>, CGlobalDataInfo> entry : map.entrySet()) {
CGlobalDataImpl<?> data = entry.getKey();
CGlobalDataInfo info = entry.getValue();
int size;
byte[] bytes = null;
if (data.bytesSupplier != null) {
bytes = data.bytesSupplier.get();
size = bytes.length;
} else {
if (data.sizeSupplier != null) {
size = data.sizeSupplier.getAsInt();
} else {
assert data.symbolName != null : "CGlobalData without bytes, size, or referenced symbol";
/*
* A symbol reference: we support only instruction-pointer-relative addressing
* with 32-bit immediates, which might not be sufficient for the target symbol's
* address. Therefore, reserve space for a word with the symbol's true address.
*/
size = wordSize;
}
}
info.assign(offset, bytes);
offset += size;
// align
offset = (offset + (wordSize - 1)) & ~(wordSize - 1);
}
totalSize = offset;
assert isLayouted();
}
use of com.oracle.svm.core.graal.code.CGlobalDataInfo in project graal by oracle.
the class CGlobalDataFeature method writeData.
public void writeData(RelocatableBuffer buffer, BiFunction<Integer, String, ?> createSymbol) {
assert isLayouted() : "Not layouted yet";
int start = buffer.getPosition();
assert IntStream.range(0, totalSize).allMatch(i -> buffer.getByte(i) == 0) : "Buffer must be zero-initialized";
for (CGlobalDataInfo info : map.values()) {
byte[] bytes = info.getBytes();
if (bytes != null) {
buffer.setPosition(start + info.getOffset());
buffer.putBytes(bytes, 0, bytes.length);
}
CGlobalDataImpl<?> data = info.getData();
if (data.symbolName != null && !info.isSymbolReference()) {
createSymbol.apply(info.getOffset(), data.symbolName);
}
}
}
Aggregations