
com.oracle.truffle.nfi.backend.libffi.SignatureBuilderGen Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of truffle-nfi-libffi Show documentation
Show all versions of truffle-nfi-libffi Show documentation
Implementation of the Truffle NFI using libffi.
The newest version!
// CheckStyle: start generated
package com.oracle.truffle.nfi.backend.libffi;
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.DSLSupport.SpecializationDataNode;
import com.oracle.truffle.api.dsl.InlineSupport.ReferenceField;
import com.oracle.truffle.api.dsl.InlineSupport.UnsafeAccessedField;
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.Node;
import com.oracle.truffle.api.nodes.UnadoptableNode;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.ArgsState;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.CachedSignatureInfo;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.SignatureBuilder;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.SignatureBuilder.AddArgument;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.SignatureBuilder.Build;
import com.oracle.truffle.nfi.backend.libffi.LibFFISignature.SignatureBuilder.SetReturnType;
import com.oracle.truffle.nfi.backend.libffi.LibFFIType.CachedTypeInfo;
import com.oracle.truffle.nfi.backend.spi.NFIBackendSignatureBuilderLibrary;
import java.lang.invoke.MethodHandles;
import java.util.Objects;
@GeneratedBy(SignatureBuilder.class)
@SuppressWarnings("javadoc")
final class SignatureBuilderGen {
private static final LibraryFactory DYNAMIC_DISPATCH_LIBRARY_ = LibraryFactory.resolve(DynamicDispatchLibrary.class);
static {
LibraryExport.register(SignatureBuilder.class, new NFIBackendSignatureBuilderLibraryExports());
}
private SignatureBuilderGen() {
}
@GeneratedBy(SignatureBuilder.class)
private static final class NFIBackendSignatureBuilderLibraryExports extends LibraryExport {
private NFIBackendSignatureBuilderLibraryExports() {
super(NFIBackendSignatureBuilderLibrary.class, SignatureBuilder.class, false, false, 0);
}
@Override
protected NFIBackendSignatureBuilderLibrary createUncached(Object receiver) {
assert receiver instanceof SignatureBuilder;
NFIBackendSignatureBuilderLibrary uncached = new Uncached();
return uncached;
}
@Override
protected NFIBackendSignatureBuilderLibrary createCached(Object receiver) {
assert receiver instanceof SignatureBuilder;
return new Cached();
}
@GeneratedBy(SignatureBuilder.class)
private static final class Cached extends NFIBackendSignatureBuilderLibrary {
static final ReferenceField ADD_ARGUMENT_CACHED_CACHE_UPDATER = ReferenceField.create(MethodHandles.lookup(), "addArgument_cached_cache", AddArgumentCachedData.class);
static final ReferenceField BUILD_CACHED_CACHE_UPDATER = ReferenceField.create(MethodHandles.lookup(), "build_cached_cache", BuildCachedData.class);
/**
* State Info:
* 0: SpecializationActive {@link SetReturnType#doSet}
* 1: SpecializationActive {@link AddArgument#doCached}
* 2: SpecializationActive {@link AddArgument#doGeneric}
* 3: SpecializationActive {@link Build#doCached}
* 4: SpecializationActive {@link Build#doGeneric}
*
*/
@CompilationFinal private int state_0_;
@UnsafeAccessedField @CompilationFinal private AddArgumentCachedData addArgument_cached_cache;
@UnsafeAccessedField @CompilationFinal private BuildCachedData build_cached_cache;
protected Cached() {
}
@Override
public boolean accepts(Object receiver) {
assert !(receiver instanceof SignatureBuilder) || DYNAMIC_DISPATCH_LIBRARY_.getUncached().dispatch(receiver) == null : "Invalid library export. Exported receiver with dynamic dispatch found but not expected.";
return receiver instanceof SignatureBuilder;
}
/**
* Debug Info:
* Specialization {@link SetReturnType#doSet}
* Activation probability: 0.33333
* With/without class size: 8/0 bytes
*
*/
@Override
public void setReturnType(Object arg0Value_, Object arg1Value) {
assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
assert assertAdopted(this);
SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
int state_0 = this.state_0_;
if ((state_0 & 0b1) != 0 /* is SpecializationActive[SignatureBuilder.SetReturnType.doSet(SignatureBuilder, LibFFIType)] */ && arg1Value instanceof LibFFIType) {
LibFFIType arg1Value_ = (LibFFIType) arg1Value;
SetReturnType.doSet(arg0Value, arg1Value_);
return;
}
CompilerDirectives.transferToInterpreterAndInvalidate();
setReturnTypeAndSpecialize(arg0Value, arg1Value);
return;
}
private void setReturnTypeAndSpecialize(SignatureBuilder arg0Value, Object arg1Value) {
int state_0 = this.state_0_;
if (arg1Value instanceof LibFFIType) {
LibFFIType arg1Value_ = (LibFFIType) arg1Value;
state_0 = state_0 | 0b1 /* add SpecializationActive[SignatureBuilder.SetReturnType.doSet(SignatureBuilder, LibFFIType)] */;
this.state_0_ = state_0;
SetReturnType.doSet(arg0Value, arg1Value_);
return;
}
throw new UnsupportedSpecializationException(this, null, arg0Value, arg1Value);
}
/**
* Debug Info:
* Specialization {@link AddArgument#doCached}
* Activation probability: 0.21667
* With/without class size: 9/12 bytes
* Specialization {@link AddArgument#doGeneric}
* Activation probability: 0.11667
* With/without class size: 5/0 bytes
*
*/
@Override
public void addArgument(Object arg0Value_, Object arg1Value) {
assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
assert assertAdopted(this);
SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
int state_0 = this.state_0_;
if ((state_0 & 0b110) != 0 /* is SpecializationActive[SignatureBuilder.AddArgument.doCached(SignatureBuilder, LibFFIType, NFIBackendSignatureBuilderLibrary, LibFFIType, ArgsState, CachedTypeInfo, ArgsState)] || SpecializationActive[SignatureBuilder.AddArgument.doGeneric(SignatureBuilder, LibFFIType, NFIBackendSignatureBuilderLibrary)] */ && arg1Value instanceof LibFFIType) {
LibFFIType arg1Value_ = (LibFFIType) arg1Value;
if ((state_0 & 0b10) != 0 /* is SpecializationActive[SignatureBuilder.AddArgument.doCached(SignatureBuilder, LibFFIType, NFIBackendSignatureBuilderLibrary, LibFFIType, ArgsState, CachedTypeInfo, ArgsState)] */) {
AddArgumentCachedData s0_ = this.addArgument_cached_cache;
if (s0_ != null) {
if ((arg0Value.state == s0_.oldState_)) {
NFIBackendSignatureBuilderLibrary self__ = (this);
LibFFIType promotedType__ = (arg0Value.maybePromote(self__, arg1Value_));
if ((AddArgument.isSame(promotedType__.typeInfo, s0_.cachedTypeInfo_))) {
AddArgument.doCached(arg0Value, arg1Value_, self__, promotedType__, s0_.oldState_, s0_.cachedTypeInfo_, s0_.newState_);
return;
}
}
}
}
if ((state_0 & 0b100) != 0 /* is SpecializationActive[SignatureBuilder.AddArgument.doGeneric(SignatureBuilder, LibFFIType, NFIBackendSignatureBuilderLibrary)] */) {
{
NFIBackendSignatureBuilderLibrary self__1 = (this);
AddArgument.doGeneric(arg0Value, arg1Value_, self__1);
return;
}
}
}
CompilerDirectives.transferToInterpreterAndInvalidate();
addArgumentAndSpecialize(arg0Value, arg1Value);
return;
}
@SuppressWarnings("unused")
private void addArgumentAndSpecialize(SignatureBuilder arg0Value, Object arg1Value) {
int state_0 = this.state_0_;
if (arg1Value instanceof LibFFIType) {
LibFFIType arg1Value_ = (LibFFIType) arg1Value;
{
LibFFIType promotedType__ = null;
NFIBackendSignatureBuilderLibrary self__ = null;
if (((state_0 & 0b100)) == 0 /* is-not SpecializationActive[SignatureBuilder.AddArgument.doGeneric(SignatureBuilder, LibFFIType, NFIBackendSignatureBuilderLibrary)] */) {
while (true) {
int count0_ = 0;
AddArgumentCachedData s0_ = ADD_ARGUMENT_CACHED_CACHE_UPDATER.getVolatile(this);
AddArgumentCachedData s0_original = s0_;
while (s0_ != null) {
if ((arg0Value.state == s0_.oldState_)) {
self__ = (this);
promotedType__ = (arg0Value.maybePromote(self__, arg1Value_));
if ((AddArgument.isSame(promotedType__.typeInfo, s0_.cachedTypeInfo_))) {
break;
}
}
count0_++;
s0_ = null;
break;
}
if (s0_ == null && count0_ < 1) {
{
self__ = (this);
promotedType__ = (arg0Value.maybePromote(self__, arg1Value_));
CachedTypeInfo cachedTypeInfo__ = (promotedType__.typeInfo);
// assert (arg0Value.state == s0_.oldState_);
if ((AddArgument.isSame(promotedType__.typeInfo, cachedTypeInfo__))) {
s0_ = new AddArgumentCachedData();
ArgsState oldState__ = (arg0Value.state);
Objects.requireNonNull(oldState__, "A specialization cache returned a 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 the default value.");
s0_.oldState_ = oldState__;
Objects.requireNonNull(cachedTypeInfo__, "A specialization cache returned a 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 the default value.");
s0_.cachedTypeInfo_ = cachedTypeInfo__;
ArgsState newState__ = (oldState__.addArg(cachedTypeInfo__));
Objects.requireNonNull(newState__, "A specialization cache returned a 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 the default value.");
s0_.newState_ = newState__;
if (!ADD_ARGUMENT_CACHED_CACHE_UPDATER.compareAndSet(this, s0_original, s0_)) {
continue;
}
state_0 = state_0 | 0b10 /* add SpecializationActive[SignatureBuilder.AddArgument.doCached(SignatureBuilder, LibFFIType, NFIBackendSignatureBuilderLibrary, LibFFIType, ArgsState, CachedTypeInfo, ArgsState)] */;
this.state_0_ = state_0;
}
}
}
if (s0_ != null) {
AddArgument.doCached(arg0Value, arg1Value_, self__, promotedType__, s0_.oldState_, s0_.cachedTypeInfo_, s0_.newState_);
return;
}
break;
}
}
}
{
NFIBackendSignatureBuilderLibrary self__1 = null;
self__1 = (this);
this.addArgument_cached_cache = null;
state_0 = state_0 & 0xfffffffd /* remove SpecializationActive[SignatureBuilder.AddArgument.doCached(SignatureBuilder, LibFFIType, NFIBackendSignatureBuilderLibrary, LibFFIType, ArgsState, CachedTypeInfo, ArgsState)] */;
state_0 = state_0 | 0b100 /* add SpecializationActive[SignatureBuilder.AddArgument.doGeneric(SignatureBuilder, LibFFIType, NFIBackendSignatureBuilderLibrary)] */;
this.state_0_ = state_0;
AddArgument.doGeneric(arg0Value, arg1Value_, self__1);
return;
}
}
throw new UnsupportedSpecializationException(this, null, arg0Value, arg1Value);
}
/**
* Debug Info:
* Specialization {@link Build#doCached}
* Activation probability: 0.21667
* With/without class size: 9/12 bytes
* Specialization {@link Build#doGeneric}
* Activation probability: 0.11667
* With/without class size: 5/0 bytes
*
*/
@Override
public Object build(Object arg0Value_) {
assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
assert assertAdopted(this);
SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
int state_0 = this.state_0_;
if ((state_0 & 0b11000) != 0 /* is SpecializationActive[SignatureBuilder.Build.doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo)] || SpecializationActive[SignatureBuilder.Build.doGeneric(SignatureBuilder, NFIBackendSignatureBuilderLibrary)] */) {
if ((state_0 & 0b1000) != 0 /* is SpecializationActive[SignatureBuilder.Build.doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo)] */) {
BuildCachedData s0_ = this.build_cached_cache;
if (s0_ != null) {
if ((arg0Value.state == s0_.cachedState_) && (arg0Value.retTypeInfo == s0_.cachedRetType_)) {
NFIBackendSignatureBuilderLibrary self__ = (this);
return Build.doCached(arg0Value, s0_.cachedState_, s0_.cachedRetType_, self__, s0_.cachedSigInfo_);
}
}
}
if ((state_0 & 0b10000) != 0 /* is SpecializationActive[SignatureBuilder.Build.doGeneric(SignatureBuilder, NFIBackendSignatureBuilderLibrary)] */) {
{
NFIBackendSignatureBuilderLibrary self__1 = (this);
return Build.doGeneric(arg0Value, self__1);
}
}
}
CompilerDirectives.transferToInterpreterAndInvalidate();
return buildAndSpecialize(arg0Value);
}
@SuppressWarnings("unused")
private Object buildAndSpecialize(SignatureBuilder arg0Value) {
int state_0 = this.state_0_;
{
NFIBackendSignatureBuilderLibrary self__ = null;
if (((state_0 & 0b10000)) == 0 /* is-not SpecializationActive[SignatureBuilder.Build.doGeneric(SignatureBuilder, NFIBackendSignatureBuilderLibrary)] */) {
while (true) {
int count0_ = 0;
BuildCachedData s0_ = BUILD_CACHED_CACHE_UPDATER.getVolatile(this);
BuildCachedData s0_original = s0_;
while (s0_ != null) {
if ((arg0Value.state == s0_.cachedState_) && (arg0Value.retTypeInfo == s0_.cachedRetType_)) {
self__ = (this);
break;
}
count0_++;
s0_ = null;
break;
}
if (s0_ == null && count0_ < 1) {
{
CachedTypeInfo cachedRetType__ = (arg0Value.retType.typeInfo);
// assert (arg0Value.state == s0_.cachedState_);
if ((arg0Value.retTypeInfo == cachedRetType__)) {
s0_ = new BuildCachedData();
ArgsState cachedState__ = (arg0Value.state);
Objects.requireNonNull(cachedState__, "A specialization cache returned a 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 the default value.");
s0_.cachedState_ = cachedState__;
Objects.requireNonNull(cachedRetType__, "A specialization cache returned a 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 the default value.");
s0_.cachedRetType_ = cachedRetType__;
self__ = (this);
CachedSignatureInfo cachedSigInfo__ = (LibFFISignature.prepareSignatureInfo(cachedRetType__, cachedState__));
Objects.requireNonNull(cachedSigInfo__, "A specialization cache returned a 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 the default value.");
s0_.cachedSigInfo_ = cachedSigInfo__;
if (!BUILD_CACHED_CACHE_UPDATER.compareAndSet(this, s0_original, s0_)) {
continue;
}
state_0 = state_0 | 0b1000 /* add SpecializationActive[SignatureBuilder.Build.doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo)] */;
this.state_0_ = state_0;
}
}
}
if (s0_ != null) {
return Build.doCached(arg0Value, s0_.cachedState_, s0_.cachedRetType_, self__, s0_.cachedSigInfo_);
}
break;
}
}
}
{
NFIBackendSignatureBuilderLibrary self__1 = null;
self__1 = (this);
this.build_cached_cache = null;
state_0 = state_0 & 0xfffffff7 /* remove SpecializationActive[SignatureBuilder.Build.doCached(SignatureBuilder, ArgsState, CachedTypeInfo, NFIBackendSignatureBuilderLibrary, CachedSignatureInfo)] */;
state_0 = state_0 | 0b10000 /* add SpecializationActive[SignatureBuilder.Build.doGeneric(SignatureBuilder, NFIBackendSignatureBuilderLibrary)] */;
this.state_0_ = state_0;
return Build.doGeneric(arg0Value, self__1);
}
}
@Override
public void makeVarargs(Object receiver) {
assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
assert assertAdopted(this);
(((SignatureBuilder) receiver)).makeVarargs();
return;
}
@GeneratedBy(SignatureBuilder.class)
@DenyReplace
private static final class AddArgumentCachedData implements SpecializationDataNode {
/**
* Source Info:
* Specialization: {@link AddArgument#doCached}
* Parameter: {@link ArgsState} oldState
*/
@CompilationFinal ArgsState oldState_;
/**
* Source Info:
* Specialization: {@link AddArgument#doCached}
* Parameter: {@link CachedTypeInfo} cachedTypeInfo
*/
@CompilationFinal CachedTypeInfo cachedTypeInfo_;
/**
* Source Info:
* Specialization: {@link AddArgument#doCached}
* Parameter: {@link ArgsState} newState
*/
@CompilationFinal ArgsState newState_;
AddArgumentCachedData() {
}
}
@GeneratedBy(SignatureBuilder.class)
@DenyReplace
private static final class BuildCachedData implements SpecializationDataNode {
/**
* Source Info:
* Specialization: {@link Build#doCached}
* Parameter: {@link ArgsState} cachedState
*/
@CompilationFinal ArgsState cachedState_;
/**
* Source Info:
* Specialization: {@link Build#doCached}
* Parameter: {@link CachedTypeInfo} cachedRetType
*/
@CompilationFinal CachedTypeInfo cachedRetType_;
/**
* Source Info:
* Specialization: {@link Build#doCached}
* Parameter: {@link CachedSignatureInfo} cachedSigInfo
*/
@CompilationFinal CachedSignatureInfo cachedSigInfo_;
BuildCachedData() {
}
}
}
@GeneratedBy(SignatureBuilder.class)
@DenyReplace
private static final class Uncached extends NFIBackendSignatureBuilderLibrary implements UnadoptableNode {
protected Uncached() {
}
@Override
@TruffleBoundary
public boolean accepts(Object receiver) {
assert !(receiver instanceof SignatureBuilder) || DYNAMIC_DISPATCH_LIBRARY_.getUncached().dispatch(receiver) == null : "Invalid library export. Exported receiver with dynamic dispatch found but not expected.";
return receiver instanceof SignatureBuilder;
}
@TruffleBoundary
@Override
public void setReturnType(Object arg0Value_, Object arg1Value) {
// declared: true
assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
if (arg1Value instanceof LibFFIType) {
LibFFIType arg1Value_ = (LibFFIType) arg1Value;
SetReturnType.doSet(arg0Value, arg1Value_);
return;
}
throw newUnsupportedSpecializationException2(this, arg0Value, arg1Value);
}
@TruffleBoundary
@Override
public void addArgument(Object arg0Value_, Object arg1Value) {
// declared: true
assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
if (arg1Value instanceof LibFFIType) {
LibFFIType arg1Value_ = (LibFFIType) arg1Value;
AddArgument.doGeneric(arg0Value, arg1Value_, (this));
return;
}
throw newUnsupportedSpecializationException2(this, arg0Value, arg1Value);
}
@TruffleBoundary
@Override
public Object build(Object arg0Value_) {
// declared: true
assert this.accepts(arg0Value_) : "Invalid library usage. Library does not accept given receiver.";
SignatureBuilder arg0Value = ((SignatureBuilder) arg0Value_);
return Build.doGeneric(arg0Value, (this));
}
@TruffleBoundary
@Override
public void makeVarargs(Object receiver) {
// declared: true
assert this.accepts(receiver) : "Invalid library usage. Library does not accept given receiver.";
((SignatureBuilder) receiver) .makeVarargs();
return;
}
@TruffleBoundary
private static UnsupportedSpecializationException newUnsupportedSpecializationException2(Node thisNode_, Object arg0Value, Object arg1Value) {
return new UnsupportedSpecializationException(thisNode_, null, arg0Value, arg1Value);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy