Search in sources :

Example 1 with CGlobalDataInfo

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;
        }
    });
}
Also used : CGlobalDataImpl(com.oracle.svm.core.c.CGlobalDataImpl) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) CGlobalDataInfo(com.oracle.svm.core.graal.code.CGlobalDataInfo) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with CGlobalDataInfo

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();
}
Also used : CGlobalDataImpl(com.oracle.svm.core.c.CGlobalDataImpl) CGlobalDataInfo(com.oracle.svm.core.graal.code.CGlobalDataInfo)

Example 3 with CGlobalDataInfo

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);
        }
    }
}
Also used : CGlobalDataInfo(com.oracle.svm.core.graal.code.CGlobalDataInfo)

Aggregations

CGlobalDataInfo (com.oracle.svm.core.graal.code.CGlobalDataInfo)3 CGlobalDataImpl (com.oracle.svm.core.c.CGlobalDataImpl)2 CGlobalDataLoadAddressNode (com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)1