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

com.oracle.truffle.nfi.backend.libffi.SignatureBuilderGen Maven / Gradle / Ivy

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

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.dsl.UnsupportedSpecializationException;
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.memory.MemoryFence;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.ArgsState;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.CachedSignatureInfo;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.SignatureBuilder;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.SignatureBuilder.AddArgument;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.SignatureBuilder.Build;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.SignatureBuilder.SetReturnType;
import com.oracle.truffle.nfi.backend.libffi.LibFFIType.CachedTypeInfo;
import com.oracle.truffle.nfi.backend.spi.NFIBackendSignatureBuilderLibrary;
import java.util.concurrent.locks.Lock;

@GeneratedBy(SignatureBuilder.class)
final class SignatureBuilderGen {

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

    static  {
        LibraryExport.register(SignatureBuilder.class, new NFIBackendSignatureBuilderLibraryExports());
    }

    private SignatureBuilderGen() {
    }

    @GeneratedBy(SignatureBuilder.class)
    private static final class NFIBackendSignatureBuilderLibraryExports extends LibraryExport {

        private NFIBackendSignatureBuilderLibraryExports() {
            super(NFIBackendSignatureBuilderLibrary.class, SignatureBuilder.class, false, false, 0);
        }

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

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

        @GeneratedBy(SignatureBuilder.class)
        private static final class Cached extends NFIBackendSignatureBuilderLibrary {

            @CompilationFinal private volatile int state_0_;
            @CompilationFinal private volatile int exclude_;
            @CompilationFinal private AddArgumentCachedData addArgument_cached_cache;
            @Child private BuildCachedData build_cached_cache;

            protected Cached() {
            }

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

            @Override
            public void setReturnType(Object arg0Value_, Object arg1Value) {
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                assert getRootNode() != null : "Invalid libray usage. Cached library must be adopted by a RootNode before it is executed.";
                SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
                int state_0 = this.state_0_;
                if ((state_0 & 0b1) != 0 /* is-state_0 doSet(SignatureBuilder, LibFFIType) */ && arg1Value instanceof LibFFIType) {
                    LibFFIType arg1Value_ = (LibFFIType) arg1Value;
                    SetReturnType.doSet(arg0Value, arg1Value_);
                    return;
                }
                CompilerDirectives.transferToInterpreterAndInvalidate();
                setReturnTypeAndSpecialize(arg0Value, arg1Value);
                return;
            }

            private void setReturnTypeAndSpecialize(SignatureBuilder arg0Value, Object arg1Value) {
                Lock lock = getLock();
                boolean hasLock = true;
                lock.lock();
                try {
                    int state_0 = this.state_0_;
                    if (arg1Value instanceof LibFFIType) {
                        LibFFIType arg1Value_ = (LibFFIType) arg1Value;
                        this.state_0_ = state_0 = state_0 | 0b1 /* add-state_0 doSet(SignatureBuilder, LibFFIType) */;
                        lock.unlock();
                        hasLock = false;
                        SetReturnType.doSet(arg0Value, arg1Value_);
                        return;
                    }
                    throw new UnsupportedSpecializationException(this, new Node[] {null, null}, arg0Value, arg1Value);
                } finally {
                    if (hasLock) {
                        lock.unlock();
                    }
                }
            }

            @Override
            public NodeCost getCost() {
                int state_0 = this.state_0_;
                if ((state_0 & 0b1) == 0) {
                    return NodeCost.UNINITIALIZED;
                } else {
                    return NodeCost.MONOMORPHIC;
                }
            }

            @ExplodeLoop
            @Override
            public void addArgument(Object arg0Value_, Object arg1Value) {
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                assert getRootNode() != null : "Invalid libray usage. Cached library must be adopted by a RootNode before it is executed.";
                SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
                int state_0 = this.state_0_;
                if ((state_0 & 0b110) != 0 /* is-state_0 doCached(SignatureBuilder, LibFFIType, ArgsState, CachedTypeInfo, ArgsState) || doGeneric(SignatureBuilder, LibFFIType) */ && arg1Value instanceof LibFFIType) {
                    LibFFIType arg1Value_ = (LibFFIType) arg1Value;
                    if ((state_0 & 0b10) != 0 /* is-state_0 doCached(SignatureBuilder, LibFFIType, ArgsState, CachedTypeInfo, ArgsState) */) {
                        AddArgumentCachedData s0_ = this.addArgument_cached_cache;
                        while (s0_ != null) {
                            if ((arg0Value.state == s0_.oldState_) && (arg1Value_.typeInfo == s0_.cachedTypeInfo_)) {
                                AddArgument.doCached(arg0Value, arg1Value_, s0_.oldState_, s0_.cachedTypeInfo_, s0_.newState_);
                                return;
                            }
                            s0_ = s0_.next_;
                        }
                    }
                    if ((state_0 & 0b100) != 0 /* is-state_0 doGeneric(SignatureBuilder, LibFFIType) */) {
                        AddArgument.doGeneric(arg0Value, arg1Value_);
                        return;
                    }
                }
                CompilerDirectives.transferToInterpreterAndInvalidate();
                addArgumentAndSpecialize(arg0Value, arg1Value);
                return;
            }

            private void addArgumentAndSpecialize(SignatureBuilder arg0Value, Object arg1Value) {
                Lock lock = getLock();
                boolean hasLock = true;
                lock.lock();
                try {
                    int state_0 = this.state_0_;
                    int exclude = this.exclude_;
                    if (arg1Value instanceof LibFFIType) {
                        LibFFIType arg1Value_ = (LibFFIType) arg1Value;
                        if (((exclude & 0b1)) == 0 /* is-not-exclude doCached(SignatureBuilder, LibFFIType, ArgsState, CachedTypeInfo, ArgsState) */) {
                            int count0_ = 0;
                            AddArgumentCachedData s0_ = this.addArgument_cached_cache;
                            if ((state_0 & 0b10) != 0 /* is-state_0 doCached(SignatureBuilder, LibFFIType, ArgsState, CachedTypeInfo, ArgsState) */) {
                                while (s0_ != null) {
                                    if ((arg0Value.state == s0_.oldState_) && (arg1Value_.typeInfo == s0_.cachedTypeInfo_)) {
                                        break;
                                    }
                                    s0_ = s0_.next_;
                                    count0_++;
                                }
                            }
                            if (s0_ == null) {
                                // assert (arg0Value.state == s0_.oldState_);
                                // assert (arg1Value_.typeInfo == s0_.cachedTypeInfo_);
                                if (count0_ < (3)) {
                                    s0_ = new AddArgumentCachedData(addArgument_cached_cache);
                                    s0_.oldState_ = (arg0Value.state);
                                    s0_.cachedTypeInfo_ = (arg1Value_.typeInfo);
                                    s0_.newState_ = (s0_.oldState_.addArg(s0_.cachedTypeInfo_));
                                    MemoryFence.storeStore();
                                    this.addArgument_cached_cache = s0_;
                                    this.state_0_ = state_0 = state_0 | 0b10 /* add-state_0 doCached(SignatureBuilder, LibFFIType, ArgsState, CachedTypeInfo, ArgsState) */;
                                }
                            }
                            if (s0_ != null) {
                                lock.unlock();
                                hasLock = false;
                                AddArgument.doCached(arg0Value, arg1Value_, s0_.oldState_, s0_.cachedTypeInfo_, s0_.newState_);
                                return;
                            }
                        }
                        this.exclude_ = exclude = exclude | 0b1 /* add-exclude doCached(SignatureBuilder, LibFFIType, ArgsState, CachedTypeInfo, ArgsState) */;
                        this.addArgument_cached_cache = null;
                        state_0 = state_0 & 0xfffffffd /* remove-state_0 doCached(SignatureBuilder, LibFFIType, ArgsState, CachedTypeInfo, ArgsState) */;
                        this.state_0_ = state_0 = state_0 | 0b100 /* add-state_0 doGeneric(SignatureBuilder, LibFFIType) */;
                        lock.unlock();
                        hasLock = false;
                        AddArgument.doGeneric(arg0Value, arg1Value_);
                        return;
                    }
                    throw new UnsupportedSpecializationException(this, new Node[] {null, null}, arg0Value, arg1Value);
                } finally {
                    if (hasLock) {
                        lock.unlock();
                    }
                }
            }

            @ExplodeLoop
            @Override
            public Object build(Object arg0Value_) {
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                assert getRootNode() != null : "Invalid libray usage. Cached library must be adopted by a RootNode before it is executed.";
                SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
                int state_0 = this.state_0_;
                if ((state_0 & 0b11000) != 0 /* is-state_0 doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo) || doGeneric(SignatureBuilder, NFIBackendSignatureBuilderLibrary) */) {
                    if ((state_0 & 0b1000) != 0 /* is-state_0 doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo) */) {
                        BuildCachedData s0_ = this.build_cached_cache;
                        while (s0_ != null) {
                            if ((arg0Value.state == s0_.cachedState_) && (arg0Value.retTypeInfo == s0_.cachedRetType_)) {
                                NFIBackendSignatureBuilderLibrary self__ = (this);
                                return Build.doCached(arg0Value, s0_.cachedState_, s0_.cachedRetType_, self__, s0_.cachedSigInfo_);
                            }
                            s0_ = s0_.next_;
                        }
                    }
                    if ((state_0 & 0b10000) != 0 /* is-state_0 doGeneric(SignatureBuilder, NFIBackendSignatureBuilderLibrary) */) {
                        {
                            NFIBackendSignatureBuilderLibrary build_generic_self__ = (this);
                            return Build.doGeneric(arg0Value, build_generic_self__);
                        }
                    }
                }
                CompilerDirectives.transferToInterpreterAndInvalidate();
                return buildAndSpecialize(arg0Value);
            }

            private Object buildAndSpecialize(SignatureBuilder arg0Value) {
                Lock lock = getLock();
                boolean hasLock = true;
                lock.lock();
                try {
                    int state_0 = this.state_0_;
                    int exclude = this.exclude_;
                    {
                        NFIBackendSignatureBuilderLibrary self__ = null;
                        if (((exclude & 0b10)) == 0 /* is-not-exclude doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo) */) {
                            int count0_ = 0;
                            BuildCachedData s0_ = this.build_cached_cache;
                            if ((state_0 & 0b1000) != 0 /* is-state_0 doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo) */) {
                                while (s0_ != null) {
                                    if ((arg0Value.state == s0_.cachedState_) && (arg0Value.retTypeInfo == s0_.cachedRetType_)) {
                                        self__ = (this);
                                        break;
                                    }
                                    s0_ = s0_.next_;
                                    count0_++;
                                }
                            }
                            if (s0_ == null) {
                                {
                                    CachedTypeInfo cachedRetType__ = (arg0Value.retType.typeInfo);
                                    // assert (arg0Value.state == s0_.cachedState_);
                                    if ((arg0Value.retTypeInfo == cachedRetType__) && count0_ < (3)) {
                                        s0_ = super.insert(new BuildCachedData(build_cached_cache));
                                        s0_.cachedState_ = (arg0Value.state);
                                        s0_.cachedRetType_ = cachedRetType__;
                                        self__ = (this);
                                        s0_.cachedSigInfo_ = (LibFFISignature.prepareSignatureInfo(cachedRetType__, s0_.cachedState_));
                                        MemoryFence.storeStore();
                                        this.build_cached_cache = s0_;
                                        this.state_0_ = state_0 = state_0 | 0b1000 /* add-state_0 doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo) */;
                                    }
                                }
                            }
                            if (s0_ != null) {
                                lock.unlock();
                                hasLock = false;
                                return Build.doCached(arg0Value, s0_.cachedState_, s0_.cachedRetType_, self__, s0_.cachedSigInfo_);
                            }
                        }
                    }
                    {
                        NFIBackendSignatureBuilderLibrary build_generic_self__ = null;
                        build_generic_self__ = (this);
                        this.exclude_ = exclude = exclude | 0b10 /* add-exclude doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo) */;
                        this.build_cached_cache = null;
                        state_0 = state_0 & 0xfffffff7 /* remove-state_0 doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo) */;
                        this.state_0_ = state_0 = state_0 | 0b10000 /* add-state_0 doGeneric(SignatureBuilder, NFIBackendSignatureBuilderLibrary) */;
                        lock.unlock();
                        hasLock = false;
                        return Build.doGeneric(arg0Value, build_generic_self__);
                    }
                } finally {
                    if (hasLock) {
                        lock.unlock();
                    }
                }
            }

            @Override
            public void makeVarargs(Object receiver) {
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                assert getRootNode() != null : "Invalid libray usage. Cached library must be adopted by a RootNode before it is executed.";
                (((SignatureBuilder) receiver)).makeVarargs();
                return;
            }

            @GeneratedBy(SignatureBuilder.class)
            private static final class AddArgumentCachedData {

                @CompilationFinal AddArgumentCachedData next_;
                @CompilationFinal ArgsState oldState_;
                @CompilationFinal CachedTypeInfo cachedTypeInfo_;
                @CompilationFinal ArgsState newState_;

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

            }
            @GeneratedBy(SignatureBuilder.class)
            private static final class BuildCachedData extends Node {

                @Child BuildCachedData next_;
                @CompilationFinal ArgsState cachedState_;
                @CompilationFinal CachedTypeInfo cachedRetType_;
                @CompilationFinal CachedSignatureInfo cachedSigInfo_;

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

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

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

            protected Uncached() {
            }

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

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

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

            @TruffleBoundary
            @Override
            public void setReturnType(Object arg0Value_, Object arg1Value) {
                // declared: true
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
                if (arg1Value instanceof LibFFIType) {
                    LibFFIType arg1Value_ = (LibFFIType) arg1Value;
                    SetReturnType.doSet(arg0Value, arg1Value_);
                    return;
                }
                throw new UnsupportedSpecializationException(this, new Node[] {null, null}, arg0Value, arg1Value);
            }

            @TruffleBoundary
            @Override
            public void addArgument(Object arg0Value_, Object arg1Value) {
                // declared: true
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
                if (arg1Value instanceof LibFFIType) {
                    LibFFIType arg1Value_ = (LibFFIType) arg1Value;
                    AddArgument.doGeneric(arg0Value, arg1Value_);
                    return;
                }
                throw new UnsupportedSpecializationException(this, new Node[] {null, null}, arg0Value, arg1Value);
            }

            @TruffleBoundary
            @Override
            public Object build(Object arg0Value_) {
                // declared: true
                assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
                SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
                return Build.doGeneric(arg0Value, (this));
            }

            @TruffleBoundary
            @Override
            public void makeVarargs(Object receiver) {
                // declared: true
                assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
                ((SignatureBuilder) receiver) .makeVarargs();
                return;
            }

        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy