Search in sources :

Example 1 with CGlobalDataImpl

use of com.oracle.svm.core.c.CGlobalDataImpl 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 CGlobalDataImpl

use of com.oracle.svm.core.c.CGlobalDataImpl 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)

Aggregations

CGlobalDataImpl (com.oracle.svm.core.c.CGlobalDataImpl)2 CGlobalDataInfo (com.oracle.svm.core.graal.code.CGlobalDataInfo)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