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

com.oracle.truffle.api.interop.java.IsApplicableByArityNodeGen Maven / Gradle / Ivy

Go to download

Truffle is a multi-language framework for executing dynamic languages that achieves high performance when combined with Graal.

There is a newer version: 1.0.0-rc7
Show newest version
// CheckStyle: start generated
package com.oracle.truffle.api.interop.java;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
import java.util.concurrent.locks.Lock;

@GeneratedBy(IsApplicableByArityNode.class)
final class IsApplicableByArityNodeGen extends IsApplicableByArityNode {

    @CompilationFinal private int state_;
    @CompilationFinal private int exclude_;
    @CompilationFinal private CachedData cached_cache;

    private IsApplicableByArityNodeGen() {
    }

    @ExplodeLoop(kind = LoopExplosionKind.FULL_EXPLODE_UNTIL_RETURN)
    @Override
    public boolean execute(JavaMethodDesc arg0Value, int arg1Value) {
        int state = state_;
        if (state != 0 /* is-active doCached(JavaMethodDesc, int, int, boolean) || doUncached(JavaMethodDesc, int) */) {
            if ((state & 0b1) != 0 /* is-active doCached(JavaMethodDesc, int, int, boolean) */) {
                CachedData s1_ = this.cached_cache;
                while (s1_ != null) {
                    if ((arg1Value == s1_.cachedArgsLength_)) {
                        return IsApplicableByArityNode.doCached(arg0Value, arg1Value, s1_.cachedArgsLength_, s1_.applicableByArity_);
                    }
                    s1_ = s1_.next_;
                }
            }
            if ((state & 0b10) != 0 /* is-active doUncached(JavaMethodDesc, int) */) {
                return IsApplicableByArityNode.doUncached(arg0Value, arg1Value);
            }
        }
        CompilerDirectives.transferToInterpreterAndInvalidate();
        return executeAndSpecialize(arg0Value, arg1Value);
    }

    private boolean executeAndSpecialize(JavaMethodDesc arg0Value, int arg1Value) {
        Lock lock = getLock();
        boolean hasLock = true;
        lock.lock();
        int state = state_;
        int exclude = exclude_;
        try {
            if ((exclude) == 0 /* is-not-excluded doCached(JavaMethodDesc, int, int, boolean) */) {
                int count1_ = 0;
                CachedData s1_ = this.cached_cache;
                if ((state & 0b1) != 0 /* is-active doCached(JavaMethodDesc, int, int, boolean) */) {
                    while (s1_ != null) {
                        if ((arg1Value == s1_.cachedArgsLength_)) {
                            break;
                        }
                        s1_ = s1_.next_;
                        count1_++;
                    }
                }
                if (s1_ == null) {
                    // assert (arg1Value == s1_.cachedArgsLength_);
                    if (count1_ < (IsApplicableByArityNode.LIMIT)) {
                        s1_ = new CachedData(cached_cache);
                        s1_.cachedArgsLength_ = (arg1Value);
                        s1_.applicableByArity_ = (IsApplicableByArityNode.doUncached(arg0Value, arg1Value));
                        this.cached_cache = s1_;
                        this.state_ = state = state | 0b1 /* add-active doCached(JavaMethodDesc, int, int, boolean) */;
                    }
                }
                if (s1_ != null) {
                    lock.unlock();
                    hasLock = false;
                    return IsApplicableByArityNode.doCached(arg0Value, arg1Value, s1_.cachedArgsLength_, s1_.applicableByArity_);
                }
            }
            this.exclude_ = exclude = exclude | 0b1 /* add-excluded doCached(JavaMethodDesc, int, int, boolean) */;
            this.cached_cache = null;
            state = state & 0xfffffffe /* remove-active doCached(JavaMethodDesc, int, int, boolean) */;
            this.state_ = state = state | 0b10 /* add-active doUncached(JavaMethodDesc, int) */;
            lock.unlock();
            hasLock = false;
            return IsApplicableByArityNode.doUncached(arg0Value, arg1Value);
        } 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  */) {
            CachedData s1_ = this.cached_cache;
            if ((s1_ == null || s1_.next_ == null)) {
                return NodeCost.MONOMORPHIC;
            }
        }
        return NodeCost.POLYMORPHIC;
    }

    public static IsApplicableByArityNode create() {
        return new IsApplicableByArityNodeGen();
    }

    @GeneratedBy(IsApplicableByArityNode.class)
    private static final class CachedData {

        @CompilationFinal CachedData next_;
        @CompilationFinal int cachedArgsLength_;
        @CompilationFinal boolean applicableByArity_;

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

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy