com.oracle.truffle.sl.builtins.SLIsNullBuiltinFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truffle-sl Show documentation
Show all versions of truffle-sl Show documentation
Truffle SL is an example language implemented using the Truffle API.
// 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.dsl.GeneratedBy;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.frame.VirtualFrame;
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.nodes.SLExpressionNode;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.locks.Lock;
@GeneratedBy(SLIsNullBuiltin.class)
@SuppressWarnings("unused")
public final class SLIsNullBuiltinFactory implements NodeFactory {
private static final SLIsNullBuiltinFactory INSTANCE = new SLIsNullBuiltinFactory();
private static final LibraryFactory INTEROP_LIBRARY_ = LibraryFactory.resolve(InteropLibrary.class);
private SLIsNullBuiltinFactory() {
}
@Override
public Class getNodeClass() {
return SLIsNullBuiltin.class;
}
@Override
public List> getExecutionSignature() {
return Arrays.asList(SLExpressionNode.class);
}
@Override
public List>> getNodeSignatures() {
return Arrays.asList(Arrays.asList(SLExpressionNode[].class));
}
@Override
public SLIsNullBuiltin 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 SLIsNullBuiltin create(SLExpressionNode[] arguments) {
return new SLIsNullBuiltinNodeGen(arguments);
}
@GeneratedBy(SLIsNullBuiltin.class)
public static final class SLIsNullBuiltinNodeGen extends SLIsNullBuiltin {
@Child private SLExpressionNode arguments0_;
@CompilationFinal private volatile int state_;
@CompilationFinal private volatile int exclude_;
@Child private IsExecutable0Data isExecutable0_cache;
private SLIsNullBuiltinNodeGen(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 != 0 /* is-active isExecutable(Object, InteropLibrary) || isExecutable(Object, InteropLibrary) */) {
if ((state & 0b1) != 0 /* is-active isExecutable(Object, InteropLibrary) */) {
IsExecutable0Data s1_ = this.isExecutable0_cache;
while (s1_ != null) {
if ((s1_.values_.accepts(arguments0Value_))) {
return isExecutable(arguments0Value_, s1_.values_);
}
s1_ = s1_.next_;
}
}
if ((state & 0b10) != 0 /* is-active isExecutable(Object, InteropLibrary) */) {
return this.isExecutable1Boundary(state, arguments0Value_);
}
}
CompilerDirectives.transferToInterpreterAndInvalidate();
return executeAndSpecialize(arguments0Value_);
}
@SuppressWarnings("static-method")
@TruffleBoundary
private Object isExecutable1Boundary(int state, Object arguments0Value_) {
EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
Node prev_ = encapsulating_.set(this);
try {
{
InteropLibrary isExecutable1_values__ = (INTEROP_LIBRARY_.getUncached(arguments0Value_));
return isExecutable(arguments0Value_, isExecutable1_values__);
}
} finally {
encapsulating_.set(prev_);
}
}
private boolean executeAndSpecialize(Object arguments0Value) {
Lock lock = getLock();
boolean hasLock = true;
lock.lock();
int state = state_;
int exclude = exclude_;
try {
if ((exclude) == 0 /* is-not-excluded isExecutable(Object, InteropLibrary) */) {
int count1_ = 0;
IsExecutable0Data s1_ = this.isExecutable0_cache;
if ((state & 0b1) != 0 /* is-active isExecutable(Object, InteropLibrary) */) {
while (s1_ != null) {
if ((s1_.values_.accepts(arguments0Value))) {
break;
}
s1_ = s1_.next_;
count1_++;
}
}
if (s1_ == null) {
// assert (s1_.values_.accepts(arguments0Value));
if (count1_ < (3)) {
s1_ = super.insert(new IsExecutable0Data(isExecutable0_cache));
s1_.values_ = s1_.insertAccessor((INTEROP_LIBRARY_.create(arguments0Value)));
this.isExecutable0_cache = s1_;
this.state_ = state = state | 0b1 /* add-active isExecutable(Object, InteropLibrary) */;
}
}
if (s1_ != null) {
lock.unlock();
hasLock = false;
return isExecutable(arguments0Value, s1_.values_);
}
}
{
InteropLibrary isExecutable1_values__ = null;
{
EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
Node prev_ = encapsulating_.set(this);
try {
isExecutable1_values__ = (INTEROP_LIBRARY_.getUncached(arguments0Value));
this.exclude_ = exclude = exclude | 0b1 /* add-excluded isExecutable(Object, InteropLibrary) */;
this.isExecutable0_cache = null;
state = state & 0xfffffffe /* remove-active isExecutable(Object, InteropLibrary) */;
this.state_ = state = state | 0b10 /* add-active isExecutable(Object, InteropLibrary) */;
lock.unlock();
hasLock = false;
return isExecutable(arguments0Value, isExecutable1_values__);
} finally {
encapsulating_.set(prev_);
}
}
}
} 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 */) {
IsExecutable0Data s1_ = this.isExecutable0_cache;
if ((s1_ == null || s1_.next_ == null)) {
return NodeCost.MONOMORPHIC;
}
}
return NodeCost.POLYMORPHIC;
}
@GeneratedBy(SLIsNullBuiltin.class)
private static final class IsExecutable0Data extends Node {
@Child IsExecutable0Data next_;
@Child InteropLibrary values_;
IsExecutable0Data(IsExecutable0Data next_) {
this.next_ = next_;
}
@Override
public NodeCost getCost() {
return NodeCost.NONE;
}
T insertAccessor(T node) {
return super.insert(node);
}
}
}
}