com.oracle.truffle.polyglot.ProxyInvokeNodeGen Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truffle-api Show documentation
Show all versions of truffle-api Show documentation
Truffle is a multi-language framework for executing dynamic languages
that achieves high performance when combined with Graal.
// CheckStyle: start generated
package com.oracle.truffle.polyglot;
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.UnsupportedSpecializationException;
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.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ConditionProfile;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.concurrent.locks.Lock;
@GeneratedBy(ProxyInvokeNode.class)
@SuppressWarnings("unused")
final class ProxyInvokeNodeGen extends ProxyInvokeNode {
private static final LibraryFactory INTEROP_LIBRARY_ = LibraryFactory.resolve(InteropLibrary.class);
@CompilationFinal private volatile int state_;
@CompilationFinal private volatile int exclude_;
@Child private CachedMethod0Data cachedMethod0_cache;
@Child private CachedMethod1Data cachedMethod1_cache;
private ProxyInvokeNodeGen() {
}
@ExplodeLoop
@Override
public Object execute(PolyglotLanguageContext arg0Value, Object arg1Value, Method arg2Value, Object[] arg3Value) {
int state = state_;
if (state != 0 /* is-active doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) || doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */) {
if ((state & 0b1) != 0 /* is-active doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */) {
CachedMethod0Data s1_ = this.cachedMethod0_cache;
while (s1_ != null) {
if ((s1_.receivers_.accepts(arg1Value)) && (s1_.cachedMethod_ == arg2Value)) {
return doCachedMethod(arg0Value, arg1Value, arg2Value, arg3Value, s1_.cachedMethod_, s1_.name_, s1_.returnClass_, s1_.returnType_, s1_.receivers_, s1_.members_, s1_.branchProfile_, s1_.toHost_, s1_.error_);
}
s1_ = s1_.next_;
}
}
if ((state & 0b10) != 0 /* is-active doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */) {
CachedMethod1Data s2_ = this.cachedMethod1_cache;
while (s2_ != null) {
if ((s2_.cachedMethod_ == arg2Value)) {
return this.cachedMethod1Boundary(state, s2_, arg0Value, arg1Value, arg2Value, arg3Value);
}
s2_ = s2_.next_;
}
}
}
CompilerDirectives.transferToInterpreterAndInvalidate();
return executeAndSpecialize(arg0Value, arg1Value, arg2Value, arg3Value);
}
@SuppressWarnings("static-method")
@TruffleBoundary
private Object cachedMethod1Boundary(int state, CachedMethod1Data s2_, PolyglotLanguageContext arg0Value, Object arg1Value, Method arg2Value, Object[] arg3Value) {
EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
Node prev_ = encapsulating_.set(this);
try {
{
InteropLibrary receivers__ = (INTEROP_LIBRARY_.getUncached(arg1Value));
return doCachedMethod(arg0Value, arg1Value, arg2Value, arg3Value, s2_.cachedMethod_, s2_.name_, s2_.returnClass_, s2_.returnType_, receivers__, s2_.members_, s2_.branchProfile_, s2_.toHost_, s2_.error_);
}
} finally {
encapsulating_.set(prev_);
}
}
private Object executeAndSpecialize(PolyglotLanguageContext arg0Value, Object arg1Value, Method arg2Value, Object[] arg3Value) {
Lock lock = getLock();
boolean hasLock = true;
lock.lock();
int state = state_;
int exclude = exclude_;
try {
if ((exclude) == 0 /* is-not-excluded doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */) {
int count1_ = 0;
CachedMethod0Data s1_ = this.cachedMethod0_cache;
if ((state & 0b1) != 0 /* is-active doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */) {
while (s1_ != null) {
if ((s1_.receivers_.accepts(arg1Value)) && (s1_.cachedMethod_ == arg2Value)) {
break;
}
s1_ = s1_.next_;
count1_++;
}
}
if (s1_ == null) {
// assert (s1_.receivers_.accepts(arg1Value));
// assert (s1_.cachedMethod_ == arg2Value);
if (count1_ < (ProxyInvokeNode.LIMIT)) {
s1_ = super.insert(new CachedMethod0Data(cachedMethod0_cache));
s1_.cachedMethod_ = (arg2Value);
s1_.name_ = (arg2Value.getName());
s1_.returnClass_ = (HostInteropReflect.getMethodReturnType(arg2Value));
s1_.returnType_ = (HostInteropReflect.getMethodGenericReturnType(arg2Value));
s1_.receivers_ = s1_.insertAccessor((INTEROP_LIBRARY_.create(arg1Value)));
s1_.members_ = s1_.insertAccessor((INTEROP_LIBRARY_.createDispatched(ProxyInvokeNode.LIMIT)));
s1_.branchProfile_ = (ConditionProfile.create());
s1_.toHost_ = s1_.insertAccessor((ToHostNodeGen.create()));
s1_.error_ = (BranchProfile.create());
this.cachedMethod0_cache = s1_;
this.state_ = state = state | 0b1 /* add-active doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */;
}
}
if (s1_ != null) {
lock.unlock();
hasLock = false;
return doCachedMethod(arg0Value, arg1Value, arg2Value, arg3Value, s1_.cachedMethod_, s1_.name_, s1_.returnClass_, s1_.returnType_, s1_.receivers_, s1_.members_, s1_.branchProfile_, s1_.toHost_, s1_.error_);
}
}
{
InteropLibrary receivers__ = null;
{
EncapsulatingNodeReference encapsulating_ = EncapsulatingNodeReference.getCurrent();
Node prev_ = encapsulating_.set(this);
try {
int count2_ = 0;
CachedMethod1Data s2_ = this.cachedMethod1_cache;
if ((state & 0b10) != 0 /* is-active doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */) {
while (s2_ != null) {
if ((s2_.cachedMethod_ == arg2Value)) {
receivers__ = (INTEROP_LIBRARY_.getUncached(arg1Value));
break;
}
s2_ = s2_.next_;
count2_++;
}
}
if (s2_ == null) {
// assert (s2_.cachedMethod_ == arg2Value);
if (count2_ < (ProxyInvokeNode.LIMIT)) {
s2_ = super.insert(new CachedMethod1Data(cachedMethod1_cache));
s2_.cachedMethod_ = (arg2Value);
s2_.name_ = (arg2Value.getName());
s2_.returnClass_ = (HostInteropReflect.getMethodReturnType(arg2Value));
s2_.returnType_ = (HostInteropReflect.getMethodGenericReturnType(arg2Value));
receivers__ = (INTEROP_LIBRARY_.getUncached(arg1Value));
s2_.members_ = s2_.insertAccessor((INTEROP_LIBRARY_.createDispatched(ProxyInvokeNode.LIMIT)));
s2_.branchProfile_ = (ConditionProfile.create());
s2_.toHost_ = s2_.insertAccessor((ToHostNodeGen.create()));
s2_.error_ = (BranchProfile.create());
this.cachedMethod1_cache = s2_;
this.exclude_ = exclude = exclude | 0b1 /* add-excluded doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */;
this.cachedMethod0_cache = null;
state = state & 0xfffffffe /* remove-active doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */;
this.state_ = state = state | 0b10 /* add-active doCachedMethod(PolyglotLanguageContext, Object, Method, Object[], Method, String, Class<>, Type, InteropLibrary, InteropLibrary, ConditionProfile, ToHostNode, BranchProfile) */;
}
}
if (s2_ != null) {
lock.unlock();
hasLock = false;
return doCachedMethod(arg0Value, arg1Value, arg2Value, arg3Value, s2_.cachedMethod_, s2_.name_, s2_.returnClass_, s2_.returnType_, receivers__, s2_.members_, s2_.branchProfile_, s2_.toHost_, s2_.error_);
}
} finally {
encapsulating_.set(prev_);
}
}
}
throw new UnsupportedSpecializationException(this, new Node[] {null, null, null, null}, arg0Value, arg1Value, arg2Value, arg3Value);
} 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 */) {
CachedMethod0Data s1_ = this.cachedMethod0_cache;
CachedMethod1Data s2_ = this.cachedMethod1_cache;
if ((s1_ == null || s1_.next_ == null) && (s2_ == null || s2_.next_ == null)) {
return NodeCost.MONOMORPHIC;
}
}
return NodeCost.POLYMORPHIC;
}
public static ProxyInvokeNode create() {
return new ProxyInvokeNodeGen();
}
@GeneratedBy(ProxyInvokeNode.class)
private static final class CachedMethod0Data extends Node {
@Child CachedMethod0Data next_;
@CompilationFinal Method cachedMethod_;
@CompilationFinal String name_;
@CompilationFinal Class> returnClass_;
@CompilationFinal Type returnType_;
@Child InteropLibrary receivers_;
@Child InteropLibrary members_;
@CompilationFinal ConditionProfile branchProfile_;
@Child ToHostNode toHost_;
@CompilationFinal BranchProfile error_;
CachedMethod0Data(CachedMethod0Data next_) {
this.next_ = next_;
}
@Override
public NodeCost getCost() {
return NodeCost.NONE;
}
T insertAccessor(T node) {
return super.insert(node);
}
}
@GeneratedBy(ProxyInvokeNode.class)
private static final class CachedMethod1Data extends Node {
@Child CachedMethod1Data next_;
@CompilationFinal Method cachedMethod_;
@CompilationFinal String name_;
@CompilationFinal Class> returnClass_;
@CompilationFinal Type returnType_;
@Child InteropLibrary members_;
@CompilationFinal ConditionProfile branchProfile_;
@Child ToHostNode toHost_;
@CompilationFinal BranchProfile error_;
CachedMethod1Data(CachedMethod1Data next_) {
this.next_ = next_;
}
@Override
public NodeCost getCost() {
return NodeCost.NONE;
}
T insertAccessor(T node) {
return super.insert(node);
}
}
}