All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.oracle.truffle.nfi.NFIRootNodeFactory Maven / Gradle / Ivy

// CheckStyle: start generated
package com.oracle.truffle.nfi;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.library.LibraryFactory;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.EncapsulatingNodeReference;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.utilities.TruffleWeakReference;
import com.oracle.truffle.nfi.NFIRootNode.LoadLibraryNode;
import com.oracle.truffle.nfi.NFIRootNode.LookupAndBindNode;
import com.oracle.truffle.nfi.SignatureRootNode.BuildSignatureNode;
import com.oracle.truffle.nfi.api.SignatureLibrary;
import com.oracle.truffle.nfi.backend.spi.NFIBackend;
import com.oracle.truffle.nfi.backend.spi.types.NativeLibraryDescriptor;
import java.lang.invoke.VarHandle;
import java.util.concurrent.locks.Lock;

@GeneratedBy(NFIRootNode.class)
@SuppressWarnings("unused")
final class NFIRootNodeFactory {

    private static final LibraryFactory INTEROP_LIBRARY_ = LibraryFactory.resolve(InteropLibrary.class);
    private static final LibraryFactory SIGNATURE_LIBRARY_ = LibraryFactory.resolve(SignatureLibrary.class);

    @GeneratedBy(LookupAndBindNode.class)
    static final class LookupAndBindNodeGen extends LookupAndBindNode {

        @CompilationFinal private volatile int state_0_;
        @CompilationFinal private volatile int exclude_;
        @Child private InteropLibrary lookupAndBind0_libInterop_;
        @Child private SignatureLibrary lookupAndBind0_signatures_;
        @Child private SignatureLibrary lookupAndBind1_signatures_;

        private LookupAndBindNodeGen(String name, BuildSignatureNode signature) {
            super(name, signature);
        }

        @Override
        Object execute(API arg0Value, Object arg1Value) {
            int state_0 = this.state_0_;
            if (state_0 != 0 /* is-state_0 doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) || doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */) {
                if ((state_0 & 0b1) != 0 /* is-state_0 doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */) {
                    if ((this.lookupAndBind0_libInterop_.accepts(arg1Value))) {
                        return doLookupAndBind(arg0Value, arg1Value, this.lookupAndBind0_libInterop_, this.lookupAndBind0_signatures_);
                    }
                }
                if ((state_0 & 0b10) != 0 /* is-state_0 doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */) {
                    return this.lookupAndBind1Boundary(state_0, arg0Value, arg1Value);
                }
            }
            CompilerDirectives.transferToInterpreterAndInvalidate();
            return executeAndSpecialize(arg0Value, arg1Value);
        }

        @SuppressWarnings("static-method")
        @TruffleBoundary
        private Object lookupAndBind1Boundary(int state_0, API arg0Value, Object arg1Value) {
            EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
            Node prev_ = encapsulating_.set(this);
            try {
                {
                    InteropLibrary lookupAndBind1_libInterop__ = (INTEROP_LIBRARY_.getUncached(arg1Value));
                    return doLookupAndBind(arg0Value, arg1Value, lookupAndBind1_libInterop__, this.lookupAndBind1_signatures_);
                }
            } finally {
                encapsulating_.set(prev_);
            }
        }

        private Object executeAndSpecialize(API arg0Value, Object arg1Value) {
            Lock lock = getLock();
            boolean hasLock = true;
            lock.lock();
            try {
                int state_0 = this.state_0_;
                int exclude = this.exclude_;
                if ((exclude) == 0 /* is-not-exclude doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */) {
                    boolean LookupAndBind0_duplicateFound_ = false;
                    if ((state_0 & 0b1) != 0 /* is-state_0 doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */) {
                        if ((this.lookupAndBind0_libInterop_.accepts(arg1Value))) {
                            LookupAndBind0_duplicateFound_ = true;
                        }
                    }
                    if (!LookupAndBind0_duplicateFound_) {
                        // assert (this.lookupAndBind0_libInterop_.accepts(arg1Value));
                        if (((state_0 & 0b1)) == 0 /* is-not-state_0 doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */) {
                            this.lookupAndBind0_libInterop_ = super.insert((INTEROP_LIBRARY_.create(arg1Value)));
                            this.lookupAndBind0_signatures_ = super.insert((SIGNATURE_LIBRARY_.createDispatched(1)));
                            this.state_0_ = state_0 = state_0 | 0b1 /* add-state_0 doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */;
                            LookupAndBind0_duplicateFound_ = true;
                        }
                    }
                    if (LookupAndBind0_duplicateFound_) {
                        lock.unlock();
                        hasLock = false;
                        return doLookupAndBind(arg0Value, arg1Value, this.lookupAndBind0_libInterop_, this.lookupAndBind0_signatures_);
                    }
                }
                {
                    InteropLibrary lookupAndBind1_libInterop__ = null;
                    {
                        EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
                        Node prev_ = encapsulating_.set(this);
                        try {
                            lookupAndBind1_libInterop__ = (INTEROP_LIBRARY_.getUncached(arg1Value));
                            this.lookupAndBind1_signatures_ = super.insert((SIGNATURE_LIBRARY_.createDispatched(1)));
                            this.exclude_ = exclude = exclude | 0b1 /* add-exclude doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */;
                            state_0 = state_0 & 0xfffffffe /* remove-state_0 doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */;
                            this.state_0_ = state_0 = state_0 | 0b10 /* add-state_0 doLookupAndBind(API, Object, InteropLibrary, SignatureLibrary) */;
                            lock.unlock();
                            hasLock = false;
                            return doLookupAndBind(arg0Value, arg1Value, lookupAndBind1_libInterop__, this.lookupAndBind1_signatures_);
                        } finally {
                            encapsulating_.set(prev_);
                        }
                    }
                }
            } finally {
                if (hasLock) {
                    lock.unlock();
                }
            }
        }

        @Override
        public NodeCost getCost() {
            int state_0 = this.state_0_;
            if (state_0 == 0) {
                return NodeCost.UNINITIALIZED;
            } else {
                if ((state_0 & (state_0 - 1)) == 0 /* is-single-state_0  */) {
                    return NodeCost.MONOMORPHIC;
                }
            }
            return NodeCost.POLYMORPHIC;
        }

        public static LookupAndBindNode create(String name, BuildSignatureNode signature) {
            return new LookupAndBindNodeGen(name, signature);
        }

    }
    @GeneratedBy(LoadLibraryNode.class)
    static final class LoadLibraryNodeGen extends LoadLibraryNode {

        @CompilationFinal private volatile int state_0_;
        @CompilationFinal private volatile int exclude_;
        @Child private CachedData cached_cache;
        @Child private IndirectCallNode generic_callNode_;

        private LoadLibraryNodeGen(NativeLibraryDescriptor descriptor) {
            super(descriptor);
        }

        @ExplodeLoop
        @Override
        protected Object execute(NFIBackend arg0Value) {
            int state_0 = this.state_0_;
            if (state_0 != 0 /* is-state_0 doCached(NFIBackend, NFIBackend, DirectCallNode) || doGeneric(NFIBackend, IndirectCallNode) */) {
                if ((state_0 & 0b1) != 0 /* is-state_0 doCached(NFIBackend, NFIBackend, DirectCallNode) */) {
                    CachedData s0_ = this.cached_cache;
                    while (s0_ != null) {
                        {
                            NFIBackend cachedBackend__ = (s0_.weakCachedBackendGen__.get());
                            if ((cachedBackend__ != null) && (arg0Value == cachedBackend__)) {
                                return doCached(arg0Value, cachedBackend__, s0_.callNode_);
                            }
                        }
                        s0_ = s0_.next_;
                    }
                }
                if ((state_0 & 0b10) != 0 /* is-state_0 doGeneric(NFIBackend, IndirectCallNode) */) {
                    return doGeneric(arg0Value, this.generic_callNode_);
                }
            }
            CompilerDirectives.transferToInterpreterAndInvalidate();
            return executeAndSpecialize(arg0Value);
        }

        private Object executeAndSpecialize(NFIBackend arg0Value) {
            Lock lock = getLock();
            boolean hasLock = true;
            lock.lock();
            try {
                int state_0 = this.state_0_;
                int exclude = this.exclude_;
                {
                    NFIBackend cachedBackend__ = null;
                    if ((exclude) == 0 /* is-not-exclude doCached(NFIBackend, NFIBackend, DirectCallNode) */) {
                        int count0_ = 0;
                        CachedData s0_ = this.cached_cache;
                        if ((state_0 & 0b1) != 0 /* is-state_0 doCached(NFIBackend, NFIBackend, DirectCallNode) */) {
                            while (s0_ != null) {
                                {
                                    cachedBackend__ = (s0_.weakCachedBackendGen__.get());
                                    if ((cachedBackend__ != null) && (arg0Value == cachedBackend__)) {
                                        break;
                                    }
                                }
                                s0_ = s0_.next_;
                                count0_++;
                            }
                        }
                        if (s0_ == null) {
                            {
                                TruffleWeakReference weakCachedBackendGen___ = (new TruffleWeakReference<>(arg0Value));
                                cachedBackend__ = (weakCachedBackendGen___.get());
                                if ((cachedBackend__ != null) && (arg0Value == cachedBackend__) && count0_ < (5)) {
                                    s0_ = super.insert(new CachedData(cached_cache));
                                    s0_.weakCachedBackendGen__ = weakCachedBackendGen___;
                                    s0_.callNode_ = s0_.insertAccessor((DirectCallNode.create(parseLibrary(cachedBackend__))));
                                    VarHandle.storeStoreFence();
                                    this.cached_cache = s0_;
                                    this.state_0_ = state_0 = state_0 | 0b1 /* add-state_0 doCached(NFIBackend, NFIBackend, DirectCallNode) */;
                                }
                            }
                        }
                        if (s0_ != null) {
                            lock.unlock();
                            hasLock = false;
                            return doCached(arg0Value, cachedBackend__, s0_.callNode_);
                        }
                    }
                }
                this.generic_callNode_ = super.insert((IndirectCallNode.create()));
                this.exclude_ = exclude = exclude | 0b1 /* add-exclude doCached(NFIBackend, NFIBackend, DirectCallNode) */;
                this.cached_cache = null;
                state_0 = state_0 & 0xfffffffe /* remove-state_0 doCached(NFIBackend, NFIBackend, DirectCallNode) */;
                this.state_0_ = state_0 = state_0 | 0b10 /* add-state_0 doGeneric(NFIBackend, IndirectCallNode) */;
                lock.unlock();
                hasLock = false;
                return doGeneric(arg0Value, this.generic_callNode_);
            } finally {
                if (hasLock) {
                    lock.unlock();
                }
            }
        }

        @Override
        public NodeCost getCost() {
            int state_0 = this.state_0_;
            if (state_0 == 0) {
                return NodeCost.UNINITIALIZED;
            } else {
                if ((state_0 & (state_0 - 1)) == 0 /* is-single-state_0  */) {
                    CachedData s0_ = this.cached_cache;
                    if ((s0_ == null || s0_.next_ == null)) {
                        return NodeCost.MONOMORPHIC;
                    }
                }
            }
            return NodeCost.POLYMORPHIC;
        }

        public static LoadLibraryNode create(NativeLibraryDescriptor descriptor) {
            return new LoadLibraryNodeGen(descriptor);
        }

        @GeneratedBy(LoadLibraryNode.class)
        private static final class CachedData extends Node {

            @Child CachedData next_;
            @CompilationFinal TruffleWeakReference weakCachedBackendGen__;
            @Child DirectCallNode callNode_;

            CachedData(CachedData next_) {
                this.next_ = next_;
            }

            @Override
            public NodeCost getCost() {
                return NodeCost.NONE;
            }

             T insertAccessor(T node) {
                return super.insert(node);
            }

        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy