com.oracle.truffle.nfi.NFIClosureGen Maven / Gradle / Ivy
// CheckStyle: start generated
package com.oracle.truffle.nfi;
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.dsl.InlineSupport.ReferenceField;
import com.oracle.truffle.api.dsl.InlineSupport.UnsafeAccessedField;
import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.library.DynamicDispatchLibrary;
import com.oracle.truffle.api.library.LibraryExport;
import com.oracle.truffle.api.library.LibraryFactory;
import com.oracle.truffle.api.nodes.DenyReplace;
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.profiles.BranchProfile;
import com.oracle.truffle.nfi.ConvertTypeNode.ConvertFromNativeNode;
import com.oracle.truffle.nfi.ConvertTypeNode.ConvertToNativeNode;
import com.oracle.truffle.nfi.ConvertTypeNodeFactory.ConvertFromNativeNodeGen;
import com.oracle.truffle.nfi.ConvertTypeNodeFactory.ConvertToNativeNodeGen;
import com.oracle.truffle.nfi.NFIClosure.Execute;
import com.oracle.truffle.nfi.NFISignature.SignatureCachedState;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.Objects;
@GeneratedBy(NFIClosure.class)
@SuppressWarnings("javadoc")
final class NFIClosureGen {
private static final LibraryFactory DYNAMIC_DISPATCH_LIBRARY_ = LibraryFactory.resolve(DynamicDispatchLibrary.class);
private static final LibraryFactory INTEROP_LIBRARY_ = LibraryFactory.resolve(InteropLibrary.class);
static {
LibraryExport.register(NFIClosure.class, new InteropLibraryExports());
}
private NFIClosureGen() {
}
@GeneratedBy(NFIClosure.class)
private static final class InteropLibraryExports extends LibraryExport {
private InteropLibraryExports() {
super(InteropLibrary.class, NFIClosure.class, false, false, 0);
}
@Override
protected InteropLibrary createUncached(Object receiver) {
assert receiver instanceof NFIClosure;
InteropLibrary uncached = new Uncached();
return uncached;
}
@Override
protected InteropLibrary createCached(Object receiver) {
assert receiver instanceof NFIClosure;
return new Cached(receiver);
}
@GeneratedBy(NFIClosure.class)
private static final class Cached extends InteropLibrary {
static final ReferenceField EXECUTE_OPTIMIZED_DIRECT_CACHE_UPDATER = ReferenceField.create(MethodHandles.lookup(), "execute_optimizedDirect_cache", ExecuteOptimizedDirectData.class);
@Child private InteropLibrary receiverExecutableInteropLibrary_;
/**
* State Info:
* 0: SpecializationActive {@link Execute#doOptimizedDirect}
* 1: SpecializationActive {@link Execute#doOptimizedIndirect}
* 2: SpecializationActive {@link Execute#doSlowPath}
*
*/
@CompilationFinal private int state_0_;
@UnsafeAccessedField @Child private ExecuteOptimizedDirectData execute_optimizedDirect_cache;
/**
* Source Info:
* Specialization: {@link Execute#doOptimizedIndirect}
* Parameter: {@link IndirectCallNode} call
*/
@Child private IndirectCallNode execute_optimizedIndirect_call_;
@Child private ExecuteSlowPathData execute_slowPath_cache;
protected Cached(Object receiver) {
NFIClosure castReceiver = ((NFIClosure) receiver) ;
this.receiverExecutableInteropLibrary_ = super.insert(INTEROP_LIBRARY_.create((castReceiver.executable)));
}
@Override
public boolean accepts(Object receiver) {
assert !(receiver instanceof NFIClosure) || DYNAMIC_DISPATCH_LIBRARY_.getUncached().dispatch(receiver) == null : "Invalid library export. Exported receiver with dynamic dispatch found but not expected.";
if (!(receiver instanceof NFIClosure)) {
return false;
} else if (!this.receiverExecutableInteropLibrary_.accepts((((NFIClosure) receiver).executable))) {
return false;
} else {
return true;
}
}
/**
* Debug Info:
* Specialization {@link Execute#doOptimizedDirect}
* Activation probability: 0.24167
* With/without class size: 10/8 bytes
* Specialization {@link Execute#doOptimizedIndirect}
* Activation probability: 0.16667
* With/without class size: 7/4 bytes
* Specialization {@link Execute#doSlowPath}
* Activation probability: 0.09167
* With/without class size: 6/12 bytes
*
*/
@ExplodeLoop
@Override
public Object execute(Object arg0Value_, Object... arg1Value) throws UnsupportedTypeException, ArityException, UnsupportedMessageException {
assert arg0Value_ instanceof NFIClosure : "Invalid library usage. Library does not accept given receiver.";
assert assertAdopted();
NFIClosure arg0Value = ((NFIClosure) arg0Value_);
int state_0 = this.state_0_;
if (state_0 != 0 /* is SpecializationActive[NFIClosure.Execute.doOptimizedDirect(NFIClosure, Object[], SignatureCachedState, CallSignatureNode)] || SpecializationActive[NFIClosure.Execute.doOptimizedIndirect(NFIClosure, Object[], IndirectCallNode)] || SpecializationActive[NFIClosure.Execute.doSlowPath(NFIClosure, Object[], BranchProfile, ConvertFromNativeNode, ConvertToNativeNode, InteropLibrary)] */) {
if ((state_0 & 0b1) != 0 /* is SpecializationActive[NFIClosure.Execute.doOptimizedDirect(NFIClosure, Object[], SignatureCachedState, CallSignatureNode)] */ && (arg0Value.signature.cachedState != null)) {
ExecuteOptimizedDirectData s0_ = this.execute_optimizedDirect_cache;
while (s0_ != null) {
if ((arg0Value.signature.cachedState == s0_.cachedState_)) {
return Execute.doOptimizedDirect(arg0Value, arg1Value, s0_.cachedState_, s0_.call_);
}
s0_ = s0_.next_;
}
}
if ((state_0 & 0b10) != 0 /* is SpecializationActive[NFIClosure.Execute.doOptimizedIndirect(NFIClosure, Object[], IndirectCallNode)] */) {
{
IndirectCallNode call__ = this.execute_optimizedIndirect_call_;
if (call__ != null) {
if ((arg0Value.signature.cachedState != null)) {
return Execute.doOptimizedIndirect(arg0Value, arg1Value, call__);
}
}
}
}
if ((state_0 & 0b100) != 0 /* is SpecializationActive[NFIClosure.Execute.doSlowPath(NFIClosure, Object[], BranchProfile, ConvertFromNativeNode, ConvertToNativeNode, InteropLibrary)] */) {
ExecuteSlowPathData s2_ = this.execute_slowPath_cache;
if (s2_ != null) {
if ((arg0Value.signature.cachedState == null)) {
InteropLibrary interop__ = this.receiverExecutableInteropLibrary_;
return Execute.doSlowPath(arg0Value, arg1Value, s2_.exception_, s2_.convertArg_, s2_.convertRet_, interop__);
}
}
}
}
CompilerDirectives.transferToInterpreterAndInvalidate();
return executeAndSpecialize(arg0Value, arg1Value);
}
private Object executeAndSpecialize(NFIClosure arg0Value, Object[] arg1Value) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
int state_0 = this.state_0_;
if (((state_0 & 0b10)) == 0 /* is-not SpecializationActive[NFIClosure.Execute.doOptimizedIndirect(NFIClosure, Object[], IndirectCallNode)] */ && (arg0Value.signature.cachedState != null)) {
while (true) {
int count0_ = 0;
ExecuteOptimizedDirectData s0_ = EXECUTE_OPTIMIZED_DIRECT_CACHE_UPDATER.getVolatile(this);
ExecuteOptimizedDirectData s0_original = s0_;
while (s0_ != null) {
if ((arg0Value.signature.cachedState == s0_.cachedState_)) {
break;
}
count0_++;
s0_ = s0_.next_;
}
if (s0_ == null) {
// assert (arg0Value.signature.cachedState == s0_.cachedState_);
if (count0_ < (3)) {
s0_ = this.insert(new ExecuteOptimizedDirectData(s0_original));
s0_.cachedState_ = (arg0Value.signature.cachedState);
s0_.call_ = s0_.insert((s0_.cachedState_.createOptimizedClosureCall()));
if (!EXECUTE_OPTIMIZED_DIRECT_CACHE_UPDATER.compareAndSet(this, s0_original, s0_)) {
continue;
}
state_0 = state_0 | 0b1 /* add SpecializationActive[NFIClosure.Execute.doOptimizedDirect(NFIClosure, Object[], SignatureCachedState, CallSignatureNode)] */;
this.state_0_ = state_0;
}
}
if (s0_ != null) {
return Execute.doOptimizedDirect(arg0Value, arg1Value, s0_.cachedState_, s0_.call_);
}
break;
}
}
if ((arg0Value.signature.cachedState != null)) {
VarHandle.storeStoreFence();
this.execute_optimizedIndirect_call_ = this.insert((IndirectCallNode.create()));
this.execute_optimizedDirect_cache = null;
state_0 = state_0 & 0xfffffffe /* remove SpecializationActive[NFIClosure.Execute.doOptimizedDirect(NFIClosure, Object[], SignatureCachedState, CallSignatureNode)] */;
state_0 = state_0 | 0b10 /* add SpecializationActive[NFIClosure.Execute.doOptimizedIndirect(NFIClosure, Object[], IndirectCallNode)] */;
this.state_0_ = state_0;
return Execute.doOptimizedIndirect(arg0Value, arg1Value, this.execute_optimizedIndirect_call_);
}
{
InteropLibrary interop__ = null;
if ((arg0Value.signature.cachedState == null)) {
ExecuteSlowPathData s2_ = this.insert(new ExecuteSlowPathData());
BranchProfile exception__ = (BranchProfile.create());
Objects.requireNonNull(exception__, "Specialization 'doSlowPath(NFIClosure, Object[], BranchProfile, ConvertFromNativeNode, ConvertToNativeNode, InteropLibrary)' cache 'exception' returned a 'null' default value. The cache initializer must never return a default value for this cache. Use @Cached(neverDefault=false) to allow default values for this cached value or make sure the cache initializer never returns 'null'.");
s2_.exception_ = exception__;
ConvertFromNativeNode convertArg__ = s2_.insert((ConvertFromNativeNodeGen.create()));
Objects.requireNonNull(convertArg__, "Specialization 'doSlowPath(NFIClosure, Object[], BranchProfile, ConvertFromNativeNode, ConvertToNativeNode, InteropLibrary)' cache 'convertArg' returned a 'null' default value. The cache initializer must never return a default value for this cache. Use @Cached(neverDefault=false) to allow default values for this cached value or make sure the cache initializer never returns 'null'.");
s2_.convertArg_ = convertArg__;
ConvertToNativeNode convertRet__ = s2_.insert((ConvertToNativeNodeGen.create()));
Objects.requireNonNull(convertRet__, "Specialization 'doSlowPath(NFIClosure, Object[], BranchProfile, ConvertFromNativeNode, ConvertToNativeNode, InteropLibrary)' cache 'convertRet' returned a 'null' default value. The cache initializer must never return a default value for this cache. Use @Cached(neverDefault=false) to allow default values for this cached value or make sure the cache initializer never returns 'null'.");
s2_.convertRet_ = convertRet__;
interop__ = this.receiverExecutableInteropLibrary_;
VarHandle.storeStoreFence();
this.execute_slowPath_cache = s2_;
state_0 = state_0 | 0b100 /* add SpecializationActive[NFIClosure.Execute.doSlowPath(NFIClosure, Object[], BranchProfile, ConvertFromNativeNode, ConvertToNativeNode, InteropLibrary)] */;
this.state_0_ = state_0;
return Execute.doSlowPath(arg0Value, arg1Value, exception__, convertArg__, convertRet__, interop__);
}
}
throw new UnsupportedSpecializationException(this, new Node[] {null, null}, arg0Value, arg1Value);
}
@Override
public NodeCost getCost() {
int state_0 = this.state_0_;
if (state_0 == 0) {
return NodeCost.UNINITIALIZED;
} else {
if ((state_0 & (state_0 - 1)) == 0 /* is-single */) {
ExecuteOptimizedDirectData s0_ = this.execute_optimizedDirect_cache;
if ((s0_ == null || s0_.next_ == null)) {
return NodeCost.MONOMORPHIC;
}
}
}
return NodeCost.POLYMORPHIC;
}
/**
* Debug Info:
* Specialization {@link NFIClosure#isExecutable(NFIClosure, InteropLibrary)}
* Activation probability: 0.50000
* With/without class size: 10/0 bytes
*
*/
@Override
public boolean isExecutable(Object arg0Value_) {
assert arg0Value_ instanceof NFIClosure : "Invalid library usage. Library does not accept given receiver.";
assert assertAdopted();
NFIClosure arg0Value = ((NFIClosure) arg0Value_);
{
InteropLibrary interop__ = this.receiverExecutableInteropLibrary_;
return arg0Value.isExecutable(interop__);
}
}
@GeneratedBy(NFIClosure.class)
@DenyReplace
private static final class ExecuteOptimizedDirectData extends Node {
@Child ExecuteOptimizedDirectData next_;
/**
* Source Info:
* Specialization: {@link Execute#doOptimizedDirect}
* Parameter: {@link SignatureCachedState} cachedState
*/
@CompilationFinal SignatureCachedState cachedState_;
/**
* Source Info:
* Specialization: {@link Execute#doOptimizedDirect}
* Parameter: {@link CallSignatureNode} call
*/
@Child CallSignatureNode call_;
ExecuteOptimizedDirectData(ExecuteOptimizedDirectData next_) {
this.next_ = next_;
}
@Override
public NodeCost getCost() {
return NodeCost.NONE;
}
}
@GeneratedBy(NFIClosure.class)
@DenyReplace
private static final class ExecuteSlowPathData extends Node {
/**
* Source Info:
* Specialization: {@link Execute#doSlowPath}
* Parameter: {@link BranchProfile} exception
*/
@CompilationFinal BranchProfile exception_;
/**
* Source Info:
* Specialization: {@link Execute#doSlowPath}
* Parameter: {@link ConvertFromNativeNode} convertArg
*/
@Child ConvertFromNativeNode convertArg_;
/**
* Source Info:
* Specialization: {@link Execute#doSlowPath}
* Parameter: {@link ConvertToNativeNode} convertRet
*/
@Child ConvertToNativeNode convertRet_;
ExecuteSlowPathData() {
}
@Override
public NodeCost getCost() {
return NodeCost.NONE;
}
}
}
@GeneratedBy(NFIClosure.class)
@DenyReplace
private static final class Uncached extends InteropLibrary {
protected Uncached() {
}
@Override
@TruffleBoundary
public boolean accepts(Object receiver) {
assert !(receiver instanceof NFIClosure) || DYNAMIC_DISPATCH_LIBRARY_.getUncached().dispatch(receiver) == null : "Invalid library export. Exported receiver with dynamic dispatch found but not expected.";
return receiver instanceof NFIClosure;
}
@Override
public boolean isAdoptable() {
return false;
}
@Override
public NodeCost getCost() {
return NodeCost.MEGAMORPHIC;
}
@TruffleBoundary
@Override
public Object execute(Object arg0Value_, Object... arg1Value) throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
// declared: true
assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
NFIClosure arg0Value = ((NFIClosure) arg0Value_);
if ((arg0Value.signature.cachedState != null)) {
return Execute.doOptimizedIndirect(arg0Value, arg1Value, (IndirectCallNode.getUncached()));
}
if ((arg0Value.signature.cachedState == null)) {
return Execute.doSlowPath(arg0Value, arg1Value, (BranchProfile.getUncached()), (ConvertFromNativeNodeGen.getUncached()), (ConvertToNativeNodeGen.getUncached()), INTEROP_LIBRARY_.getUncached((arg0Value.executable)));
}
throw new UnsupportedSpecializationException(this, new Node[] {null, null}, arg0Value, arg1Value);
}
@TruffleBoundary
@Override
public boolean isExecutable(Object arg0Value_) {
// declared: true
assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
NFIClosure arg0Value = ((NFIClosure) arg0Value_);
return arg0Value.isExecutable(INTEROP_LIBRARY_.getUncached((arg0Value.executable)));
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy