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

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

There is a newer version: 24.1.1
Show newest version
// 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.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
import com.oracle.truffle.api.TruffleLanguage.LanguageReference;
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.EncapsulatingNodeReference;
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.sl.SLLanguage;
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)
@SuppressWarnings("unused")
public final class SLNewObjectBuiltinFactory implements NodeFactory {

    private static final SLNewObjectBuiltinFactory INSTANCE = new SLNewObjectBuiltinFactory();
    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() {
        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 volatile int state_;
        @CompilationFinal private volatile int exclude_;
        @CompilationFinal private LanguageReference sLLanguageReference_;
        @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
        @Override
        protected Object execute(VirtualFrame frameValue) {
            int state = state_;
            Object arguments0Value_ = this.arguments0_.executeGeneric(frameValue);
            if ((state & 0b1) != 0 /* is-active newObject(SLNull, SLLanguage, ContextReference, AllocationReporter) */ && SLTypes.isSLNull(arguments0Value_)) {
                SLNull arguments0Value__ = SLTypes.asSLNull(arguments0Value_);
                {
                    LanguageReference sLLanguageReference__ = this.sLLanguageReference_;
                    SLLanguage newObject0_language__ = sLLanguageReference__.get();
                    ContextReference sLLanguageContextReference__ = this.sLLanguageContextReference_;
                    ContextReference newObject0_contextRef__ = sLLanguageContextReference__;
                    return newObject(arguments0Value__, newObject0_language__, newObject0_contextRef__, 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) */) {
                    EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
                    Node prev_ = encapsulating_.set(this);
                    try {
                        {
                            InteropLibrary newObject2_values__ = (INTEROP_LIBRARY_.getUncached());
                            if ((!(newObject2_values__.isNull(arguments0Value_)))) {
                                return this.newObject2Boundary(state, arguments0Value_);
                            }
                        }
                    } finally {
                        encapsulating_.set(prev_);
                    }
                }
            }
            CompilerDirectives.transferToInterpreterAndInvalidate();
            return executeAndSpecialize(arguments0Value_);
        }

        @SuppressWarnings("static-method")
        @TruffleBoundary
        private Object newObject2Boundary(int state, Object arguments0Value_) {
            {
                InteropLibrary newObject2_values__ = (INTEROP_LIBRARY_.getUncached());
                return newObject(arguments0Value_, newObject2_values__);
            }
        }

        private Object executeAndSpecialize(Object arguments0Value) {
            Lock lock = getLock();
            boolean hasLock = true;
            lock.lock();
            int state = state_;
            int exclude = exclude_;
            try {
                {
                    ContextReference newObject0_contextRef__ = null;
                    SLLanguage newObject0_language__ = null;
                    if (SLTypes.isSLNull(arguments0Value)) {
                        SLNull arguments0Value_ = SLTypes.asSLNull(arguments0Value);
                        LanguageReference sLLanguageReference__1 = this.sLLanguageReference_;
                        if (sLLanguageReference__1 == null) {
                            this.sLLanguageReference_ = sLLanguageReference__1 = super.lookupLanguageReference(SLLanguage.class);
                        }
                        newObject0_language__ = sLLanguageReference__1.get();
                        ContextReference sLLanguageContextReference__1 = this.sLLanguageContextReference_;
                        if (sLLanguageContextReference__1 == null) {
                            this.sLLanguageContextReference_ = sLLanguageContextReference__1 = super.lookupContextReference(SLLanguage.class);
                        }
                        newObject0_contextRef__ = sLLanguageContextReference__1;
                        this.newObject0_reporter_ = (newObject0_contextRef__.get().getAllocationReporter());
                        this.state_ = state = state | 0b1 /* add-active newObject(SLNull, SLLanguage, ContextReference, AllocationReporter) */;
                        lock.unlock();
                        hasLock = false;
                        return newObject(arguments0Value_, newObject0_language__, newObject0_contextRef__, 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_);
                    }
                }
                {
                    InteropLibrary newObject2_values__ = null;
                    {
                        EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
                        Node prev_ = encapsulating_.set(this);
                        try {
                            {
                                newObject2_values__ = (INTEROP_LIBRARY_.getUncached());
                                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 {
                            encapsulating_.set(prev_);
                        }
                    }
                }
                throw new UnsupportedSpecializationException(this, new Node[] {this.arguments0_}, arguments0Value);
            } finally {
                if (hasLock) {
                    lock.unlock();
                }
            }
        }

        @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 - 2024 Weber Informatics LLC | Privacy Policy