com.oracle.truffle.nfi.backend.libffi.FunctionExecuteNodeGen Maven / Gradle / Ivy
// CheckStyle: start generated
package com.oracle.truffle.nfi.backend.libffi;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.GenerateAOT;
import com.oracle.truffle.api.dsl.GeneratedBy;
import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.nodes.DenyReplace;
import com.oracle.truffle.api.nodes.DirectCallNode;
import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.nodes.IndirectCallNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.nodes.RootNode;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.CachedSignatureInfo;
import java.lang.invoke.VarHandle;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@GeneratedBy(FunctionExecuteNode.class)
final class FunctionExecuteNodeGen extends FunctionExecuteNode implements GenerateAOT.Provider {
private static final Uncached UNCACHED = new Uncached();
@CompilationFinal private volatile int state_0_;
@CompilationFinal private volatile int exclude_;
@Child private CachedSignatureData cachedSignature_cache;
@Child private IndirectCallNode genericExecute_execute_;
private FunctionExecuteNodeGen() {
}
@ExplodeLoop
@Override
public Object execute(long arg0Value, LibFFISignature arg1Value, Object[] arg2Value) throws ArityException, UnsupportedTypeException {
int state_0 = this.state_0_;
if (CompilerDirectives.inInterpreter() && (state_0 & 0b1) != 0 /* is-state_0 AOT-prepared */) {
return executeAndSpecialize(arg0Value, arg1Value, arg2Value);
}
if ((state_0 & 0b110) != 0 /* is-state_0 cachedSignature(long, LibFFISignature, Object[], CachedSignatureInfo, DirectCallNode) || genericExecute(long, LibFFISignature, Object[], IndirectCallNode) */) {
if ((state_0 & 0b10) != 0 /* is-state_0 cachedSignature(long, LibFFISignature, Object[], CachedSignatureInfo, DirectCallNode) */) {
CachedSignatureData s0_ = this.cachedSignature_cache;
while (s0_ != null) {
if ((arg1Value.signatureInfo == s0_.cachedInfo_)) {
return cachedSignature(arg0Value, arg1Value, arg2Value, s0_.cachedInfo_, s0_.execute_);
}
s0_ = s0_.next_;
}
}
if ((state_0 & 0b100) != 0 /* is-state_0 genericExecute(long, LibFFISignature, Object[], IndirectCallNode) */) {
return FunctionExecuteNode.genericExecute(arg0Value, arg1Value, arg2Value, this.genericExecute_execute_);
}
}
CompilerDirectives.transferToInterpreterAndInvalidate();
return executeAndSpecialize(arg0Value, arg1Value, arg2Value);
}
private Object executeAndSpecialize(long arg0Value, LibFFISignature arg1Value, Object[] arg2Value) {
Lock lock = getLock();
boolean hasLock = true;
lock.lock();
try {
if ((this.state_0_ & 0b1) != 0 /* is-state_0 AOT-prepared */) {
this.resetAOT_();
}
int state_0 = this.state_0_;
int exclude = this.exclude_;
if ((exclude) == 0 /* is-not-exclude cachedSignature(long, LibFFISignature, Object[], CachedSignatureInfo, DirectCallNode) */) {
int count0_ = 0;
CachedSignatureData s0_ = this.cachedSignature_cache;
if ((state_0 & 0b10) != 0 /* is-state_0 cachedSignature(long, LibFFISignature, Object[], CachedSignatureInfo, DirectCallNode) */) {
while (s0_ != null) {
if ((arg1Value.signatureInfo == s0_.cachedInfo_)) {
break;
}
s0_ = s0_.next_;
count0_++;
}
}
if (s0_ == null) {
// assert (arg1Value.signatureInfo == s0_.cachedInfo_);
if (count0_ < (3)) {
s0_ = super.insert(new CachedSignatureData(cachedSignature_cache));
s0_.cachedInfo_ = (arg1Value.signatureInfo);
s0_.execute_ = s0_.insertAccessor((FunctionExecuteNode.createCachedSignatureCall(s0_.cachedInfo_)));
VarHandle.storeStoreFence();
this.cachedSignature_cache = s0_;
this.state_0_ = state_0 = state_0 | 0b10 /* add-state_0 cachedSignature(long, LibFFISignature, Object[], CachedSignatureInfo, DirectCallNode) */;
}
}
if (s0_ != null) {
lock.unlock();
hasLock = false;
return cachedSignature(arg0Value, arg1Value, arg2Value, s0_.cachedInfo_, s0_.execute_);
}
}
this.genericExecute_execute_ = super.insert((IndirectCallNode.create()));
this.exclude_ = exclude = exclude | 0b1 /* add-exclude cachedSignature(long, LibFFISignature, Object[], CachedSignatureInfo, DirectCallNode) */;
this.cachedSignature_cache = null;
state_0 = state_0 & 0xfffffffd /* remove-state_0 cachedSignature(long, LibFFISignature, Object[], CachedSignatureInfo, DirectCallNode) */;
this.state_0_ = state_0 = state_0 | 0b100 /* add-state_0 genericExecute(long, LibFFISignature, Object[], IndirectCallNode) */;
lock.unlock();
hasLock = false;
return FunctionExecuteNode.genericExecute(arg0Value, arg1Value, arg2Value, this.genericExecute_execute_);
} finally {
if (hasLock) {
lock.unlock();
}
}
}
@Override
public NodeCost getCost() {
int state_0 = this.state_0_;
if ((state_0 & 0b110) == 0) {
return NodeCost.UNINITIALIZED;
} else {
if (((state_0 & 0b110) & ((state_0 & 0b110) - 1)) == 0 /* is-single-state_0 */) {
CachedSignatureData s0_ = this.cachedSignature_cache;
if ((s0_ == null || s0_.next_ == null)) {
return NodeCost.MONOMORPHIC;
}
}
}
return NodeCost.POLYMORPHIC;
}
@Override
public void prepareForAOT(TruffleLanguage> language, RootNode root) {
assert !isAdoptable() || ((ReentrantLock) getLock()).isHeldByCurrentThread() : "During prepare AST lock must be held.";
int state_0 = this.state_0_;
if ((state_0 & 0b1) != 0 /* is-state_0 AOT-prepared */) {
return;
}
this.genericExecute_execute_ = super.insert((IndirectCallNode.create()));
this.exclude_ = this.exclude_ | 0b1 /* add-exclude cachedSignature(long, LibFFISignature, Object[], CachedSignatureInfo, DirectCallNode) */;
this.cachedSignature_cache = null;
state_0 = state_0 & 0xfffffffd /* remove-state_0 cachedSignature(long, LibFFISignature, Object[], CachedSignatureInfo, DirectCallNode) */;
this.state_0_ = state_0 = state_0 | 0b101 /* add-state_0 AOT-prepared, genericExecute(long, LibFFISignature, Object[], IndirectCallNode) */;
}
private void resetAOT_() {
int state_0 = this.state_0_;
if (((state_0 & 0b1)) == 0 /* is-not-state_0 AOT-prepared */) {
return;
}
this.state_0_ = 0;
this.exclude_ = 0;
}
public static FunctionExecuteNode create() {
return new FunctionExecuteNodeGen();
}
public static FunctionExecuteNode getUncached() {
return FunctionExecuteNodeGen.UNCACHED;
}
@GeneratedBy(FunctionExecuteNode.class)
private static final class CachedSignatureData extends Node {
@Child CachedSignatureData next_;
@CompilationFinal CachedSignatureInfo cachedInfo_;
@Child DirectCallNode execute_;
CachedSignatureData(CachedSignatureData next_) {
this.next_ = next_;
}
@Override
public NodeCost getCost() {
return NodeCost.NONE;
}
T insertAccessor(T node) {
return super.insert(node);
}
}
@GeneratedBy(FunctionExecuteNode.class)
@DenyReplace
private static final class Uncached extends FunctionExecuteNode {
@TruffleBoundary
@Override
public Object execute(long arg0Value, LibFFISignature arg1Value, Object[] arg2Value) throws ArityException, UnsupportedTypeException {
return FunctionExecuteNode.genericExecute(arg0Value, arg1Value, arg2Value, (IndirectCallNode.getUncached()));
}
@Override
public NodeCost getCost() {
return NodeCost.MEGAMORPHIC;
}
@Override
public boolean isAdoptable() {
return false;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy