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

com.oracle.truffle.js.nodes.cast.OrdinaryToPrimitiveNodeGen Maven / Gradle / Ivy

There is a newer version: 4.15.102
Show newest version
// CheckStyle: start generated
package com.oracle.truffle.js.nodes.cast;

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.Introspection;
import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
import com.oracle.truffle.api.dsl.Introspection.Provider;
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.api.object.DynamicObject;
import com.oracle.truffle.js.nodes.JSGuards;
import com.oracle.truffle.js.nodes.JSTypes;
import com.oracle.truffle.js.nodes.cast.JSToPrimitiveNode.Hint;
import com.oracle.truffle.js.runtime.JSContext;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.locks.Lock;

@GeneratedBy(OrdinaryToPrimitiveNode.class)
@SuppressWarnings("unused")
public final class OrdinaryToPrimitiveNodeGen extends OrdinaryToPrimitiveNode implements Provider {

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

    @CompilationFinal private volatile int state_;
    @CompilationFinal private volatile int exclude_;
    @Child private Foreign0Data foreign0_cache;

    private OrdinaryToPrimitiveNodeGen(JSContext context, Hint hint) {
        super(context, hint);
    }

    @ExplodeLoop
    @Override
    public Object execute(Object arg0Value) {
        int state = state_;
        if ((state & 0b1) != 0 /* is-active doObject(DynamicObject) */ && JSTypes.isDynamicObject(arg0Value)) {
            DynamicObject arg0Value_ = (DynamicObject) arg0Value;
            if ((JSGuards.isJSObject(arg0Value_))) {
                return doObject(arg0Value_);
            }
        }
        if ((state & 0b110) != 0 /* is-active doForeign(Object, InteropLibrary) || doForeign(Object, InteropLibrary) */) {
            if ((state & 0b10) != 0 /* is-active doForeign(Object, InteropLibrary) */) {
                Foreign0Data s2_ = this.foreign0_cache;
                while (s2_ != null) {
                    if ((s2_.interop_.accepts(arg0Value)) && (JSGuards.isForeignObject(arg0Value))) {
                        return doForeign(arg0Value, s2_.interop_);
                    }
                    s2_ = s2_.next_;
                }
            }
            if ((state & 0b100) != 0 /* is-active doForeign(Object, InteropLibrary) */) {
                if ((JSGuards.isForeignObject(arg0Value))) {
                    return this.foreign1Boundary(state, arg0Value);
                }
            }
        }
        CompilerDirectives.transferToInterpreterAndInvalidate();
        return executeAndSpecialize(arg0Value);
    }

    @SuppressWarnings("static-method")
    @TruffleBoundary
    private Object foreign1Boundary(int state, Object arg0Value) {
        EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
        Node prev_ = encapsulating_.set(this);
        try {
            {
                InteropLibrary foreign1_interop__ = (INTEROP_LIBRARY_.getUncached(arg0Value));
                return doForeign(arg0Value, foreign1_interop__);
            }
        } finally {
            encapsulating_.set(prev_);
        }
    }

    private Object executeAndSpecialize(Object arg0Value) {
        Lock lock = getLock();
        boolean hasLock = true;
        lock.lock();
        int state = state_;
        int exclude = exclude_;
        try {
            if (JSTypes.isDynamicObject(arg0Value)) {
                DynamicObject arg0Value_ = (DynamicObject) arg0Value;
                if ((JSGuards.isJSObject(arg0Value_))) {
                    this.state_ = state = state | 0b1 /* add-active doObject(DynamicObject) */;
                    lock.unlock();
                    hasLock = false;
                    return doObject(arg0Value_);
                }
            }
            if ((exclude) == 0 /* is-not-excluded doForeign(Object, InteropLibrary) */) {
                int count2_ = 0;
                Foreign0Data s2_ = this.foreign0_cache;
                if ((state & 0b10) != 0 /* is-active doForeign(Object, InteropLibrary) */) {
                    while (s2_ != null) {
                        if ((s2_.interop_.accepts(arg0Value)) && (JSGuards.isForeignObject(arg0Value))) {
                            break;
                        }
                        s2_ = s2_.next_;
                        count2_++;
                    }
                }
                if (s2_ == null) {
                    if ((JSGuards.isForeignObject(arg0Value)) && count2_ < (5)) {
                        // assert (s2_.interop_.accepts(arg0Value));
                        s2_ = super.insert(new Foreign0Data(foreign0_cache));
                        s2_.interop_ = s2_.insertAccessor((INTEROP_LIBRARY_.create(arg0Value)));
                        this.foreign0_cache = s2_;
                        this.state_ = state = state | 0b10 /* add-active doForeign(Object, InteropLibrary) */;
                    }
                }
                if (s2_ != null) {
                    lock.unlock();
                    hasLock = false;
                    return doForeign(arg0Value, s2_.interop_);
                }
            }
            {
                InteropLibrary foreign1_interop__ = null;
                {
                    EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
                    Node prev_ = encapsulating_.set(this);
                    try {
                        if ((JSGuards.isForeignObject(arg0Value))) {
                            foreign1_interop__ = (INTEROP_LIBRARY_.getUncached(arg0Value));
                            this.exclude_ = exclude = exclude | 0b1 /* add-excluded doForeign(Object, InteropLibrary) */;
                            this.foreign0_cache = null;
                            state = state & 0xfffffffd /* remove-active doForeign(Object, InteropLibrary) */;
                            this.state_ = state = state | 0b100 /* add-active doForeign(Object, InteropLibrary) */;
                            lock.unlock();
                            hasLock = false;
                            return doForeign(arg0Value, foreign1_interop__);
                        }
                    } finally {
                        encapsulating_.set(prev_);
                    }
                }
            }
            throw new UnsupportedSpecializationException(this, new Node[] {null}, arg0Value);
        } 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  */) {
            Foreign0Data s2_ = this.foreign0_cache;
            if ((s2_ == null || s2_.next_ == null)) {
                return NodeCost.MONOMORPHIC;
            }
        }
        return NodeCost.POLYMORPHIC;
    }

    @Override
    public Introspection getIntrospectionData() {
        Object[] data = new Object[4];
        Object[] s;
        data[0] = 0;
        int state = state_;
        int exclude = exclude_;
        s = new Object[3];
        s[0] = "doObject";
        if ((state & 0b1) != 0 /* is-active doObject(DynamicObject) */) {
            s[1] = (byte)0b01 /* active */;
        } else {
            s[1] = (byte)0b00 /* inactive */;
        }
        data[1] = s;
        s = new Object[3];
        s[0] = "doForeign";
        if ((state & 0b10) != 0 /* is-active doForeign(Object, InteropLibrary) */) {
            s[1] = (byte)0b01 /* active */;
            ArrayList cached = new ArrayList<>();
            Foreign0Data s2_ = this.foreign0_cache;
            while (s2_ != null) {
                cached.add(Arrays.asList(s2_.interop_));
                s2_ = s2_.next_;
            }
            s[2] = cached;
        } else if (exclude != 0 /* is-excluded doForeign(Object, InteropLibrary) */) {
            s[1] = (byte)0b10 /* excluded */;
        } else {
            s[1] = (byte)0b00 /* inactive */;
        }
        data[2] = s;
        s = new Object[3];
        s[0] = "doForeign";
        if ((state & 0b100) != 0 /* is-active doForeign(Object, InteropLibrary) */) {
            s[1] = (byte)0b01 /* active */;
            ArrayList cached = new ArrayList<>();
            cached.add(Arrays.asList());
            s[2] = cached;
        } else {
            s[1] = (byte)0b00 /* inactive */;
        }
        data[3] = s;
        return Provider.create(data);
    }

    public static OrdinaryToPrimitiveNode create(JSContext context, Hint hint) {
        return new OrdinaryToPrimitiveNodeGen(context, hint);
    }

    @GeneratedBy(OrdinaryToPrimitiveNode.class)
    private static final class Foreign0Data extends Node {

        @Child Foreign0Data next_;
        @Child InteropLibrary interop_;

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

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

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

    }
}