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

com.oracle.truffle.sl.builtins.SLNewObjectBuiltinFactory Maven / Gradle / Ivy

// CheckStyle: start generated
package com.oracle.truffle.sl.builtins;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.AllocationReporter;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.library.LibraryFactory;
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.api.nodes.NodeUtil;
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
import com.oracle.truffle.sl.SLLanguage;
import com.oracle.truffle.sl.builtins.SLNewObjectBuiltin;
import com.oracle.truffle.sl.nodes.SLExpressionNode;
import com.oracle.truffle.sl.nodes.SLTypes;
import com.oracle.truffle.sl.runtime.SLContext;
import com.oracle.truffle.sl.runtime.SLNull;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.locks.Lock;

@GeneratedBy(SLNewObjectBuiltin.class)
public final class SLNewObjectBuiltinFactory implements NodeFactory {

    private static SLNewObjectBuiltinFactory instance;
    private static final LibraryFactory INTEROP_LIBRARY_ = LibraryFactory.resolve(InteropLibrary.class);

    private SLNewObjectBuiltinFactory() {
    }

    @Override
    public Class getNodeClass() {
        return SLNewObjectBuiltin.class;
    }

    @Override
    public List> getExecutionSignature() {
        return Arrays.asList(SLExpressionNode.class);
    }

    @Override
    public List>> getNodeSignatures() {
        return Arrays.asList(Arrays.asList(SLExpressionNode[].class));
    }

    @Override
    public SLNewObjectBuiltin createNode(Object... arguments) {
        if (arguments.length == 1 && (arguments[0] == null || arguments[0] instanceof SLExpressionNode[])) {
            return create((SLExpressionNode[]) arguments[0]);
        } else {
            throw new IllegalArgumentException("Invalid create signature.");
        }
    }

    public static NodeFactory getInstance() {
        if (instance == null) {
            instance = new SLNewObjectBuiltinFactory();
        }
        return instance;
    }

    public static SLNewObjectBuiltin create(SLExpressionNode[] arguments) {
        return new SLNewObjectBuiltinNodeGen(arguments);
    }

    @GeneratedBy(SLNewObjectBuiltin.class)
    public static final class SLNewObjectBuiltinNodeGen extends SLNewObjectBuiltin {

        @Child private SLExpressionNode arguments0_;
        @CompilationFinal private int state_;
        @CompilationFinal private int exclude_;
        @CompilationFinal private ContextReference sLLanguageContextReference_;
        @CompilationFinal private AllocationReporter newObject0_reporter_;
        @Child private NewObject1Data newObject1_cache;

        private SLNewObjectBuiltinNodeGen(SLExpressionNode[] arguments) {
            this.arguments0_ = arguments != null && 0 < arguments.length ? arguments[0] : null;
        }

        @ExplodeLoop(kind = LoopExplosionKind.FULL_EXPLODE_UNTIL_RETURN)
        @Override
        protected Object execute(VirtualFrame frameValue) {
            int state = state_;
            Object arguments0Value_ = this.arguments0_.executeGeneric(frameValue);
            if ((state & 0b1) != 0 /* is-active newObject(SLNull, SLContext, AllocationReporter) */ && SLTypes.isSLNull(arguments0Value_)) {
                SLNull arguments0Value__ = SLTypes.asSLNull(arguments0Value_);
                return newObject(arguments0Value__, this.sLLanguageContextReference_.get(), this.newObject0_reporter_);
            }
            if ((state & 0b110) != 0 /* is-active newObject(Object, InteropLibrary) || newObject(Object, InteropLibrary) */) {
                if ((state & 0b10) != 0 /* is-active newObject(Object, InteropLibrary) */) {
                    NewObject1Data s2_ = this.newObject1_cache;
                    while (s2_ != null) {
                        if ((s2_.values_.accepts(arguments0Value_)) && (!(s2_.values_.isNull(arguments0Value_)))) {
                            return newObject(arguments0Value_, s2_.values_);
                        }
                        s2_ = s2_.next_;
                    }
                }
                if ((state & 0b100) != 0 /* is-active newObject(Object, InteropLibrary) */) {
                    Node prev_ = NodeUtil.pushEncapsulatingNode(this);
                    try {
                        if ((!((INTEROP_LIBRARY_.getUncached(arguments0Value_)).isNull(arguments0Value_)))) {
                            return newObject(arguments0Value_, (INTEROP_LIBRARY_.getUncached(arguments0Value_)));
                        }
                    } finally {
                        NodeUtil.popEncapsulatingNode(prev_);
                    }
                }
            }
            CompilerDirectives.transferToInterpreterAndInvalidate();
            return executeAndSpecialize(arguments0Value_);
        }

        private Object executeAndSpecialize(Object arguments0Value) {
            Lock lock = getLock();
            boolean hasLock = true;
            lock.lock();
            int state = state_;
            int exclude = exclude_;
            int oldState = state;
            int oldExclude = exclude;
            int oldCacheCount = state == 0 ? 0 : countCaches();
            try {
                if (SLTypes.isSLNull(arguments0Value)) {
                    SLNull arguments0Value_ = SLTypes.asSLNull(arguments0Value);
                    ContextReference sLLanguageContextReference__ = this.sLLanguageContextReference_;
                    if (sLLanguageContextReference__ == null) {
                        this.sLLanguageContextReference_ = sLLanguageContextReference__ = super.lookupContextReference(SLLanguage.class);
                    }
                    this.newObject0_reporter_ = (sLLanguageContextReference__.get().getAllocationReporter());
                    this.state_ = state = state | 0b1 /* add-active newObject(SLNull, SLContext, AllocationReporter) */;
                    lock.unlock();
                    hasLock = false;
                    return newObject(arguments0Value_, sLLanguageContextReference__.get(), this.newObject0_reporter_);
                }
                if ((exclude) == 0 /* is-not-excluded newObject(Object, InteropLibrary) */) {
                    int count2_ = 0;
                    NewObject1Data s2_ = this.newObject1_cache;
                    if ((state & 0b10) != 0 /* is-active newObject(Object, InteropLibrary) */) {
                        while (s2_ != null) {
                            if ((s2_.values_.accepts(arguments0Value)) && (!(s2_.values_.isNull(arguments0Value)))) {
                                break;
                            }
                            s2_ = s2_.next_;
                            count2_++;
                        }
                    }
                    if (s2_ == null) {
                        {
                            InteropLibrary values__ = super.insert((INTEROP_LIBRARY_.create(arguments0Value)));
                            // assert (s2_.values_.accepts(arguments0Value));
                            if ((!(values__.isNull(arguments0Value))) && count2_ < (3)) {
                                s2_ = super.insert(new NewObject1Data(newObject1_cache));
                                s2_.values_ = s2_.insertAccessor(values__);
                                this.newObject1_cache = s2_;
                                this.state_ = state = state | 0b10 /* add-active newObject(Object, InteropLibrary) */;
                            }
                        }
                    }
                    if (s2_ != null) {
                        lock.unlock();
                        hasLock = false;
                        return newObject(arguments0Value, s2_.values_);
                    }
                }
                {
                    Node prev_ = NodeUtil.pushEncapsulatingNode(this);
                    try {
                        {
                            InteropLibrary newObject2_values__ = (INTEROP_LIBRARY_.getUncached(arguments0Value));
                            if ((!(newObject2_values__.isNull(arguments0Value)))) {
                                this.exclude_ = exclude = exclude | 0b1 /* add-excluded newObject(Object, InteropLibrary) */;
                                this.newObject1_cache = null;
                                state = state & 0xfffffffd /* remove-active newObject(Object, InteropLibrary) */;
                                this.state_ = state = state | 0b100 /* add-active newObject(Object, InteropLibrary) */;
                                lock.unlock();
                                hasLock = false;
                                return newObject(arguments0Value, newObject2_values__);
                            }
                        }
                    } finally {
                        NodeUtil.popEncapsulatingNode(prev_);
                    }
                }
                throw new UnsupportedSpecializationException(this, new Node[] {this.arguments0_}, arguments0Value);
            } finally {
                if (oldState != 0 || oldExclude != 0) {
                    checkForPolymorphicSpecialize(oldState, oldExclude, oldCacheCount);
                }
                if (hasLock) {
                    lock.unlock();
                }
            }
        }

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

        private int countCaches() {
            int cacheCount = 0;
            NewObject1Data s2_ = this.newObject1_cache;
            while (s2_ != null) {
                cacheCount++;
                s2_= s2_.next_;
            }
            return cacheCount;
        }

        @Override
        public NodeCost getCost() {
            int state = state_;
            if (state == 0b0) {
                return NodeCost.UNINITIALIZED;
            } else if ((state & (state - 1)) == 0 /* is-single-active  */) {
                NewObject1Data s2_ = this.newObject1_cache;
                if ((s2_ == null || s2_.next_ == null)) {
                    return NodeCost.MONOMORPHIC;
                }
            }
            return NodeCost.POLYMORPHIC;
        }

        @GeneratedBy(SLNewObjectBuiltin.class)
        private static final class NewObject1Data extends Node {

            @Child NewObject1Data next_;
            @Child InteropLibrary values_;

            NewObject1Data(NewObject1Data 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