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

com.oracle.truffle.sl.runtime.SLFunctionGen Maven / Gradle / Ivy

There is a newer version: 24.1.1
Show newest version
// CheckStyle: start generated
package com.oracle.truffle.sl.runtime;

import com.oracle.truffle.api.Assumption;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.RootCallTarget;
import com.oracle.truffle.api.TruffleLanguage;
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.ArityException;
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.DynamicDispatchLibrary;
import com.oracle.truffle.api.library.LibraryExport;
import com.oracle.truffle.api.library.LibraryFactory;
import com.oracle.truffle.api.nodes.DirectCallNode;
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.SourceSection;
import com.oracle.truffle.api.utilities.TriState;
import com.oracle.truffle.sl.runtime.SLFunction.Execute;
import com.oracle.truffle.sl.runtime.SLFunction.IsIdenticalOrUndefined;
import java.util.concurrent.locks.Lock;

@GeneratedBy(SLFunction.class)
@SuppressWarnings("unused")
final class SLFunctionGen {

    private static final LibraryFactory DYNAMIC_DISPATCH_LIBRARY_ = LibraryFactory.resolve(DynamicDispatchLibrary.class);

    static  {
        LibraryExport.register(SLFunction.class, new InteropLibraryExports());
    }

    private SLFunctionGen() {
    }

    @GeneratedBy(SLFunction.class)
    private static final class InteropLibraryExports extends LibraryExport {

        private InteropLibraryExports() {
            super(InteropLibrary.class, SLFunction.class, false);
        }

        @Override
        protected InteropLibrary createUncached(Object receiver) {
            assert receiver instanceof SLFunction;
            InteropLibrary uncached = new Uncached();
            return uncached;
        }

        @Override
        protected InteropLibrary createCached(Object receiver) {
            assert receiver instanceof SLFunction;
            return new Cached();
        }

        @GeneratedBy(SLFunction.class)
        private static final class Cached extends InteropLibrary {

            @CompilationFinal private volatile int state_;
            @CompilationFinal private volatile int exclude_;
            @Child private ExecuteDirectData execute_direct_cache;
            @Child private IndirectCallNode execute_indirect_callNode_;

            Cached() {
            }

            @Override
            public boolean accepts(Object receiver) {
                assert !(receiver instanceof SLFunction) || DYNAMIC_DISPATCH_LIBRARY_.getUncached().dispatch(receiver) == null : "Invalid library export. Exported receiver with dynamic dispatch found but not expected.";
                return receiver instanceof SLFunction;
            }

            @Override
            protected TriState isIdenticalOrUndefined(Object arg0Value_, Object arg1Value) {
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                SLFunction arg0Value = ((SLFunction) arg0Value_);
                int state = state_;
                if ((state & 0b11) != 0 /* is-active doSLFunction(SLFunction, SLFunction) || doOther(SLFunction, Object) */) {
                    if ((state & 0b1) != 0 /* is-active doSLFunction(SLFunction, SLFunction) */ && arg1Value instanceof SLFunction) {
                        SLFunction arg1Value_ = (SLFunction) arg1Value;
                        return IsIdenticalOrUndefined.doSLFunction(arg0Value, arg1Value_);
                    }
                    if ((state & 0b10) != 0 /* is-active doOther(SLFunction, Object) */) {
                        if (isIdenticalOrUndefinedFallbackGuard_(state, arg0Value, arg1Value)) {
                            return IsIdenticalOrUndefined.doOther(arg0Value, arg1Value);
                        }
                    }
                }
                CompilerDirectives.transferToInterpreterAndInvalidate();
                return isIdenticalOrUndefinedAndSpecialize(arg0Value, arg1Value);
            }

            private TriState isIdenticalOrUndefinedAndSpecialize(SLFunction arg0Value, Object arg1Value) {
                Lock lock = getLock();
                boolean hasLock = true;
                lock.lock();
                int state = state_;
                try {
                    if (arg1Value instanceof SLFunction) {
                        SLFunction arg1Value_ = (SLFunction) arg1Value;
                        this.state_ = state = state | 0b1 /* add-active doSLFunction(SLFunction, SLFunction) */;
                        lock.unlock();
                        hasLock = false;
                        return IsIdenticalOrUndefined.doSLFunction(arg0Value, arg1Value_);
                    }
                    this.state_ = state = state | 0b10 /* add-active doOther(SLFunction, Object) */;
                    lock.unlock();
                    hasLock = false;
                    return IsIdenticalOrUndefined.doOther(arg0Value, arg1Value);
                } finally {
                    if (hasLock) {
                        lock.unlock();
                    }
                }
            }

            @Override
            public NodeCost getCost() {
                int state = state_;
                if ((state & 0b11) == 0b0) {
                    return NodeCost.UNINITIALIZED;
                } else if (((state & 0b11) & ((state & 0b11) - 1)) == 0 /* is-single-active  */) {
                    return NodeCost.MONOMORPHIC;
                }
                return NodeCost.POLYMORPHIC;
            }

            @ExplodeLoop
            @Override
            public Object execute(Object arg0Value_, Object... arg1Value) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                SLFunction arg0Value = ((SLFunction) arg0Value_);
                int state = state_;
                if ((state & 0b1100) != 0 /* is-active doDirect(SLFunction, Object[], Assumption, RootCallTarget, DirectCallNode) || doIndirect(SLFunction, Object[], IndirectCallNode) */) {
                    if ((state & 0b100) != 0 /* is-active doDirect(SLFunction, Object[], Assumption, RootCallTarget, DirectCallNode) */) {
                        ExecuteDirectData s1_ = this.execute_direct_cache;
                        while (s1_ != null) {
                            if (!Assumption.isValidAssumption(s1_.assumption0_)) {
                                CompilerDirectives.transferToInterpreterAndInvalidate();
                                removeDirect_(s1_);
                                return executeAndSpecialize(arg0Value, arg1Value);
                            }
                            if ((arg0Value.getCallTarget() == s1_.cachedTarget_)) {
                                return Execute.doDirect(arg0Value, arg1Value, s1_.callTargetStable_, s1_.cachedTarget_, s1_.callNode_);
                            }
                            s1_ = s1_.next_;
                        }
                    }
                    if ((state & 0b1000) != 0 /* is-active doIndirect(SLFunction, Object[], IndirectCallNode) */) {
                        return Execute.doIndirect(arg0Value, arg1Value, this.execute_indirect_callNode_);
                    }
                }
                CompilerDirectives.transferToInterpreterAndInvalidate();
                return executeAndSpecialize(arg0Value, arg1Value);
            }

            private Object executeAndSpecialize(SLFunction arg0Value, Object[] arg1Value) {
                Lock lock = getLock();
                boolean hasLock = true;
                lock.lock();
                int state = state_;
                int exclude = exclude_;
                int oldState = (state & 0b1100);
                int oldExclude = exclude;
                int oldCacheCount = state == 0 ? 0 : execute_countCaches();
                try {
                    if ((exclude) == 0 /* is-not-excluded doDirect(SLFunction, Object[], Assumption, RootCallTarget, DirectCallNode) */) {
                        int count1_ = 0;
                        ExecuteDirectData s1_ = this.execute_direct_cache;
                        if ((state & 0b100) != 0 /* is-active doDirect(SLFunction, Object[], Assumption, RootCallTarget, DirectCallNode) */) {
                            while (s1_ != null) {
                                if ((arg0Value.getCallTarget() == s1_.cachedTarget_) && (s1_.assumption0_ == null || Assumption.isValidAssumption(s1_.assumption0_))) {
                                    break;
                                }
                                s1_ = s1_.next_;
                                count1_++;
                            }
                        }
                        if (s1_ == null) {
                            {
                                RootCallTarget cachedTarget__ = (arg0Value.getCallTarget());
                                if ((arg0Value.getCallTarget() == cachedTarget__)) {
                                    Assumption callTargetStable__ = (arg0Value.getCallTargetStable());
                                    Assumption assumption0 = (callTargetStable__);
                                    if (Assumption.isValidAssumption(assumption0)) {
                                        if (count1_ < (SLFunction.INLINE_CACHE_SIZE)) {
                                            s1_ = super.insert(new ExecuteDirectData(execute_direct_cache));
                                            s1_.callTargetStable_ = callTargetStable__;
                                            s1_.cachedTarget_ = cachedTarget__;
                                            s1_.callNode_ = s1_.insertAccessor((DirectCallNode.create(cachedTarget__)));
                                            s1_.assumption0_ = assumption0;
                                            this.execute_direct_cache = s1_;
                                            this.state_ = state = state | 0b100 /* add-active doDirect(SLFunction, Object[], Assumption, RootCallTarget, DirectCallNode) */;
                                        }
                                    }
                                }
                            }
                        }
                        if (s1_ != null) {
                            lock.unlock();
                            hasLock = false;
                            return Execute.doDirect(arg0Value, arg1Value, s1_.callTargetStable_, s1_.cachedTarget_, s1_.callNode_);
                        }
                    }
                    this.execute_indirect_callNode_ = super.insert((IndirectCallNode.create()));
                    this.exclude_ = exclude = exclude | 0b1 /* add-excluded doDirect(SLFunction, Object[], Assumption, RootCallTarget, DirectCallNode) */;
                    this.execute_direct_cache = null;
                    state = state & 0xfffffffb /* remove-active doDirect(SLFunction, Object[], Assumption, RootCallTarget, DirectCallNode) */;
                    this.state_ = state = state | 0b1000 /* add-active doIndirect(SLFunction, Object[], IndirectCallNode) */;
                    lock.unlock();
                    hasLock = false;
                    return Execute.doIndirect(arg0Value, arg1Value, this.execute_indirect_callNode_);
                } finally {
                    if (oldState != 0 || oldExclude != 0) {
                        execute_checkForPolymorphicSpecialize(oldState, oldExclude, oldCacheCount);
                    }
                    if (hasLock) {
                        lock.unlock();
                    }
                }
            }

            private void execute_checkForPolymorphicSpecialize(int oldState, int oldExclude, int oldCacheCount) {
                int newState = (this.state_ & 0b1100);
                int newExclude = this.exclude_;
                if ((oldState ^ newState) != 0 || (oldExclude ^ newExclude) != 0 || oldCacheCount < execute_countCaches()) {
                    this.reportPolymorphicSpecialize();
                }
            }

            private int execute_countCaches() {
                int cacheCount = 0;
                ExecuteDirectData s1_ = this.execute_direct_cache;
                while (s1_ != null) {
                    cacheCount++;
                    s1_= s1_.next_;
                }
                return cacheCount;
            }

            void removeDirect_(Object s1_) {
                Lock lock = getLock();
                lock.lock();
                try {
                    ExecuteDirectData prev = null;
                    ExecuteDirectData cur = this.execute_direct_cache;
                    while (cur != null) {
                        if (cur == s1_) {
                            if (prev == null) {
                                this.execute_direct_cache = cur.next_;
                                this.adoptChildren();
                            } else {
                                prev.next_ = cur.next_;
                                prev.adoptChildren();
                            }
                            break;
                        }
                        prev = cur;
                        cur = cur.next_;
                    }
                    if (this.execute_direct_cache == null) {
                        this.state_ = this.state_ & 0xfffffffb /* remove-active doDirect(SLFunction, Object[], Assumption, RootCallTarget, DirectCallNode) */;
                    }
                } finally {
                    lock.unlock();
                }
            }

            @Override
            public boolean hasLanguage(Object receiver) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                return (((SLFunction) receiver)).hasLanguage();
            }

            @Override
            public Class> getLanguage(Object receiver) throws UnsupportedMessageException {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                return (((SLFunction) receiver)).getLanguage();
            }

            @Override
            public SourceSection getSourceLocation(Object receiver) throws UnsupportedMessageException {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                return (((SLFunction) receiver)).getSourceLocation();
            }

            @Override
            public boolean hasSourceLocation(Object receiver) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                return (((SLFunction) receiver)).hasSourceLocation();
            }

            @Override
            public boolean isExecutable(Object receiver) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                return (((SLFunction) receiver)).isExecutable();
            }

            @Override
            public boolean hasMetaObject(Object receiver) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                return (((SLFunction) receiver)).hasMetaObject();
            }

            @Override
            public Object getMetaObject(Object receiver) throws UnsupportedMessageException {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                return (((SLFunction) receiver)).getMetaObject();
            }

            @Override
            public int identityHashCode(Object receiver) throws UnsupportedMessageException {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                return SLFunction.identityHashCode((((SLFunction) receiver)));
            }

            @Override
            public Object toDisplayString(Object receiver, boolean allowSideEffects) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert assertAdopted();
                return (((SLFunction) receiver)).toDisplayString(allowSideEffects);
            }

            private static boolean isIdenticalOrUndefinedFallbackGuard_(int state, SLFunction arg0Value, Object arg1Value) {
                if (((state & 0b1)) == 0 /* is-not-active doSLFunction(SLFunction, SLFunction) */ && arg1Value instanceof SLFunction) {
                    return false;
                }
                return true;
            }

            @GeneratedBy(SLFunction.class)
            private static final class ExecuteDirectData extends Node {

                @Child ExecuteDirectData next_;
                @CompilationFinal Assumption callTargetStable_;
                @CompilationFinal RootCallTarget cachedTarget_;
                @Child DirectCallNode callNode_;
                @CompilationFinal Assumption assumption0_;

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

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

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

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

            Uncached() {
            }

            @TruffleBoundary
            @Override
            public boolean accepts(Object receiver) {
                assert !(receiver instanceof SLFunction) || DYNAMIC_DISPATCH_LIBRARY_.getUncached().dispatch(receiver) == null : "Invalid library export. Exported receiver with dynamic dispatch found but not expected.";
                return receiver instanceof SLFunction;
            }

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

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

            @TruffleBoundary
            @Override
            public TriState isIdenticalOrUndefined(Object arg0Value_, Object arg1Value) {
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                SLFunction arg0Value = ((SLFunction) arg0Value_);
                if (arg1Value instanceof SLFunction) {
                    SLFunction arg1Value_ = (SLFunction) arg1Value;
                    return IsIdenticalOrUndefined.doSLFunction(arg0Value, arg1Value_);
                }
                return IsIdenticalOrUndefined.doOther(arg0Value, arg1Value);
            }

            @TruffleBoundary
            @Override
            public Object execute(Object arg0Value_, Object... arg1Value) {
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                SLFunction arg0Value = ((SLFunction) arg0Value_);
                return Execute.doIndirect(arg0Value, arg1Value, (IndirectCallNode.getUncached()));
            }

            @TruffleBoundary
            @Override
            public boolean hasLanguage(Object receiver) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                return ((SLFunction) receiver) .hasLanguage();
            }

            @TruffleBoundary
            @Override
            public Class> getLanguage(Object receiver) throws UnsupportedMessageException {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                return ((SLFunction) receiver) .getLanguage();
            }

            @TruffleBoundary
            @Override
            public SourceSection getSourceLocation(Object receiver) throws UnsupportedMessageException {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                return ((SLFunction) receiver) .getSourceLocation();
            }

            @TruffleBoundary
            @Override
            public boolean hasSourceLocation(Object receiver) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                return ((SLFunction) receiver) .hasSourceLocation();
            }

            @TruffleBoundary
            @Override
            public boolean isExecutable(Object receiver) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                return ((SLFunction) receiver) .isExecutable();
            }

            @TruffleBoundary
            @Override
            public boolean hasMetaObject(Object receiver) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                return ((SLFunction) receiver) .hasMetaObject();
            }

            @TruffleBoundary
            @Override
            public Object getMetaObject(Object receiver) throws UnsupportedMessageException {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                return ((SLFunction) receiver) .getMetaObject();
            }

            @TruffleBoundary
            @Override
            public int identityHashCode(Object receiver) throws UnsupportedMessageException {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                return SLFunction.identityHashCode(((SLFunction) receiver) );
            }

            @TruffleBoundary
            @Override
            public Object toDisplayString(Object receiver, boolean allowSideEffects) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                return ((SLFunction) receiver) .toDisplayString(allowSideEffects);
            }

        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy