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

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

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

import com.oracle.truffle.api.Assumption;
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.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.library.LibraryFactory;
import com.oracle.truffle.api.memory.MemoryFence;
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.source.Source;
import java.util.concurrent.locks.Lock;

@GeneratedBy(BindSignatureNode.class)
final class BindSignatureNodeGen extends BindSignatureNode {

    private static final Uncached UNCACHED = new Uncached();
    private static final LibraryFactory INTEROP_LIBRARY_ = LibraryFactory.resolve(InteropLibrary.class);

    @CompilationFinal private volatile int state_0_;
    @CompilationFinal private volatile int exclude_;
    @CompilationFinal private CachedSignatureData cachedSignature_cache;
    @Child private CachedSignatureStringData cachedSignatureString_cache;

    private BindSignatureNodeGen() {
    }

    @ExplodeLoop
    @Override
    Object execute(NFISymbol arg0Value, Object arg1Value) throws UnsupportedMessageException, UnsupportedTypeException {
        int state_0 = this.state_0_;
        if (state_0 != 0 /* is-state_0 doCachedSignature(NFISymbol, Object, String, Object, NFISignature) || doCachedSignatureString(NFISymbol, Object, InteropLibrary, String, Source, IndirectCallNode) || doGeneric(NFISymbol, Object) */) {
            if ((state_0 & 0b1) != 0 /* is-state_0 doCachedSignature(NFISymbol, Object, String, Object, NFISignature) */) {
                CachedSignatureData s0_ = this.cachedSignature_cache;
                while (s0_ != null) {
                    if (!Assumption.isValidAssumption(s0_.assumption0_)) {
                        CompilerDirectives.transferToInterpreterAndInvalidate();
                        removeCachedSignature_(s0_);
                        return executeAndSpecialize(arg0Value, arg1Value);
                    }
                    if ((arg0Value.backend == s0_.cachedBackend_) && (arg1Value == s0_.cachedSignature_)) {
                        return BindSignatureNode.doCachedSignature(arg0Value, arg1Value, s0_.cachedBackend_, s0_.cachedSignature_, s0_.parsedSignature_);
                    }
                    s0_ = s0_.next_;
                }
            }
            if ((state_0 & 0b10) != 0 /* is-state_0 doCachedSignatureString(NFISymbol, Object, InteropLibrary, String, Source, IndirectCallNode) */) {
                CachedSignatureStringData s1_ = this.cachedSignatureString_cache;
                while (s1_ != null) {
                    if ((s1_.interop_.accepts(arg1Value)) && (s1_.cachedSignature_.equals(BindSignatureNode.asString(s1_.interop_, arg1Value)))) {
                        return doCachedSignatureString(arg0Value, arg1Value, s1_.interop_, s1_.cachedSignature_, s1_.signatureSource_, s1_.call_);
                    }
                    s1_ = s1_.next_;
                }
            }
            if ((state_0 & 0b100) != 0 /* is-state_0 doGeneric(NFISymbol, Object) */) {
                return BindSignatureNode.doGeneric(arg0Value, arg1Value);
            }
        }
        CompilerDirectives.transferToInterpreterAndInvalidate();
        return executeAndSpecialize(arg0Value, arg1Value);
    }

    private Object executeAndSpecialize(NFISymbol arg0Value, Object arg1Value) throws UnsupportedTypeException {
        Lock lock = getLock();
        boolean hasLock = true;
        lock.lock();
        try {
            int state_0 = this.state_0_;
            int exclude = this.exclude_;
            if (((exclude & 0b1)) == 0 /* is-not-exclude doCachedSignature(NFISymbol, Object, String, Object, NFISignature) */) {
                int count0_ = 0;
                CachedSignatureData s0_ = this.cachedSignature_cache;
                if ((state_0 & 0b1) != 0 /* is-state_0 doCachedSignature(NFISymbol, Object, String, Object, NFISignature) */) {
                    while (s0_ != null) {
                        if ((arg0Value.backend == s0_.cachedBackend_) && (arg1Value == s0_.cachedSignature_) && (s0_.assumption0_ == null || Assumption.isValidAssumption(s0_.assumption0_))) {
                            break;
                        }
                        s0_ = s0_.next_;
                        count0_++;
                    }
                }
                if (s0_ == null) {
                    // assert (arg0Value.backend == s0_.cachedBackend_);
                    // assert (arg1Value == s0_.cachedSignature_);
                    {
                        Assumption assumption0 = (NFILanguage.getSingleContextAssumption());
                        if (Assumption.isValidAssumption(assumption0)) {
                            if (count0_ < (5)) {
                                s0_ = new CachedSignatureData(cachedSignature_cache);
                                s0_.cachedBackend_ = (arg0Value.backend);
                                s0_.cachedSignature_ = (arg1Value);
                                s0_.parsedSignature_ = (BindSignatureNode.parseSignature(s0_.cachedBackend_, s0_.cachedSignature_));
                                s0_.assumption0_ = assumption0;
                                MemoryFence.storeStore();
                                this.cachedSignature_cache = s0_;
                                this.state_0_ = state_0 = state_0 | 0b1 /* add-state_0 doCachedSignature(NFISymbol, Object, String, Object, NFISignature) */;
                            }
                        }
                    }
                }
                if (s0_ != null) {
                    lock.unlock();
                    hasLock = false;
                    return BindSignatureNode.doCachedSignature(arg0Value, arg1Value, s0_.cachedBackend_, s0_.cachedSignature_, s0_.parsedSignature_);
                }
            }
            if (((exclude & 0b10)) == 0 /* is-not-exclude doCachedSignatureString(NFISymbol, Object, InteropLibrary, String, Source, IndirectCallNode) */) {
                int count1_ = 0;
                CachedSignatureStringData s1_ = this.cachedSignatureString_cache;
                if ((state_0 & 0b10) != 0 /* is-state_0 doCachedSignatureString(NFISymbol, Object, InteropLibrary, String, Source, IndirectCallNode) */) {
                    while (s1_ != null) {
                        if ((s1_.interop_.accepts(arg1Value)) && (s1_.cachedSignature_.equals(BindSignatureNode.asString(s1_.interop_, arg1Value)))) {
                            break;
                        }
                        s1_ = s1_.next_;
                        count1_++;
                    }
                }
                if (s1_ == null) {
                    {
                        InteropLibrary interop__ = super.insert((INTEROP_LIBRARY_.create(arg1Value)));
                        String cachedSignature__ = (BindSignatureNode.asString(interop__, arg1Value));
                        // assert (s1_.interop_.accepts(arg1Value));
                        if ((cachedSignature__.equals(BindSignatureNode.asString(interop__, arg1Value))) && count1_ < (5)) {
                            s1_ = super.insert(new CachedSignatureStringData(cachedSignatureString_cache));
                            s1_.interop_ = s1_.insertAccessor(interop__);
                            s1_.cachedSignature_ = cachedSignature__;
                            s1_.signatureSource_ = (BindSignatureNode.createSignatureSource(arg0Value.backend, cachedSignature__));
                            s1_.call_ = s1_.insertAccessor((IndirectCallNode.create()));
                            MemoryFence.storeStore();
                            this.cachedSignatureString_cache = s1_;
                            this.exclude_ = exclude = exclude | 0b1 /* add-exclude doCachedSignature(NFISymbol, Object, String, Object, NFISignature) */;
                            this.cachedSignature_cache = null;
                            state_0 = state_0 & 0xfffffffe /* remove-state_0 doCachedSignature(NFISymbol, Object, String, Object, NFISignature) */;
                            this.state_0_ = state_0 = state_0 | 0b10 /* add-state_0 doCachedSignatureString(NFISymbol, Object, InteropLibrary, String, Source, IndirectCallNode) */;
                        }
                    }
                }
                if (s1_ != null) {
                    lock.unlock();
                    hasLock = false;
                    return doCachedSignatureString(arg0Value, arg1Value, s1_.interop_, s1_.cachedSignature_, s1_.signatureSource_, s1_.call_);
                }
            }
            this.exclude_ = exclude = exclude | 0b11 /* add-exclude doCachedSignature(NFISymbol, Object, String, Object, NFISignature), doCachedSignatureString(NFISymbol, Object, InteropLibrary, String, Source, IndirectCallNode) */;
            this.cachedSignature_cache = null;
            this.cachedSignatureString_cache = null;
            state_0 = state_0 & 0xfffffffc /* remove-state_0 doCachedSignature(NFISymbol, Object, String, Object, NFISignature), doCachedSignatureString(NFISymbol, Object, InteropLibrary, String, Source, IndirectCallNode) */;
            this.state_0_ = state_0 = state_0 | 0b100 /* add-state_0 doGeneric(NFISymbol, Object) */;
            lock.unlock();
            hasLock = false;
            return BindSignatureNode.doGeneric(arg0Value, arg1Value);
        } 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  */) {
                CachedSignatureData s0_ = this.cachedSignature_cache;
                CachedSignatureStringData s1_ = this.cachedSignatureString_cache;
                if ((s0_ == null || s0_.next_ == null) && (s1_ == null || s1_.next_ == null)) {
                    return NodeCost.MONOMORPHIC;
                }
            }
        }
        return NodeCost.POLYMORPHIC;
    }

    void removeCachedSignature_(Object s0_) {
        Lock lock = getLock();
        lock.lock();
        try {
            CachedSignatureData prev = null;
            CachedSignatureData cur = this.cachedSignature_cache;
            while (cur != null) {
                if (cur == s0_) {
                    if (prev == null) {
                        this.cachedSignature_cache = cur.next_;
                    } else {
                        prev.next_ = cur.next_;
                    }
                    break;
                }
                prev = cur;
                cur = cur.next_;
            }
            if (this.cachedSignature_cache == null) {
                this.state_0_ = this.state_0_ & 0xfffffffe /* remove-state_0 doCachedSignature(NFISymbol, Object, String, Object, NFISignature) */;
            }
        } finally {
            lock.unlock();
        }
    }

    public static BindSignatureNode create() {
        return new BindSignatureNodeGen();
    }

    public static BindSignatureNode getUncached() {
        return BindSignatureNodeGen.UNCACHED;
    }

    @GeneratedBy(BindSignatureNode.class)
    private static final class CachedSignatureData {

        @CompilationFinal CachedSignatureData next_;
        @CompilationFinal String cachedBackend_;
        @CompilationFinal Object cachedSignature_;
        @CompilationFinal NFISignature parsedSignature_;
        @CompilationFinal Assumption assumption0_;

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

    }
    @GeneratedBy(BindSignatureNode.class)
    private static final class CachedSignatureStringData extends Node {

        @Child CachedSignatureStringData next_;
        @Child InteropLibrary interop_;
        @CompilationFinal String cachedSignature_;
        @CompilationFinal Source signatureSource_;
        @Child IndirectCallNode call_;

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

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

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

    }
    @GeneratedBy(BindSignatureNode.class)
    private static final class Uncached extends BindSignatureNode {

        @TruffleBoundary
        @Override
        Object execute(NFISymbol arg0Value, Object arg1Value) throws UnsupportedMessageException, UnsupportedTypeException {
            return BindSignatureNode.doGeneric(arg0Value, arg1Value);
        }

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

        @Override
        public boolean isAdoptable() {
            return false;
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy