Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise #new primitives #140

Open
fniephaus opened this issue Apr 12, 2021 · 1 comment
Open

Revise #new primitives #140

fniephaus opened this issue Apr 12, 2021 · 1 comment
Assignees

Comments

@fniephaus
Copy link
Member

Both, SqueakObjectNewNode and the PrimNewNodes cache the receiverClass in some cases:

@Specialization(guards = {"classObject.isNonIndexableWithInstVars()", "!classObject.isMetaClass()", "!classObject.instancesAreClasses()",
"classObject.getLayout() == cachedLayout"}, assumptions = "cachedLayout.getValidAssumption()", limit = "NEW_CACHE_SIZE")
protected static final PointersObject doPointers(final SqueakImageContext image, final ClassObject classObject, final int extraSize,
@Cached(value = "classObject.getLayout()", allowUncached = true) final ObjectLayout cachedLayout) {
assert extraSize == 0;
return new PointersObject(image, classObject, cachedLayout);
}
@TruffleBoundary
@Specialization(guards = {"classObject.isNonIndexableWithInstVars()", "!classObject.isMetaClass()", "!classObject.instancesAreClasses()"})
protected static final PointersObject doPointersFallback(final SqueakImageContext image, final ClassObject classObject, final int extraSize) {
assert extraSize == 0;
return new PointersObject(image, classObject);
}

@GenerateNodeFactory
@SqueakPrimitive(indices = 70)
public abstract static class PrimNewNode extends AbstractPrimitiveNode implements UnaryPrimitiveFallback {
public static final int NEW_CACHE_SIZE = 6;
@Specialization(limit = "NEW_CACHE_SIZE", guards = {"receiver == cachedReceiver"}, assumptions = {"cachedReceiver.getClassFormatStable()"})
protected static final AbstractSqueakObjectWithClassAndHash newDirect(@SuppressWarnings("unused") final ClassObject receiver,
@Cached("receiver") final ClassObject cachedReceiver,
@Cached final SqueakObjectNewNode newNode,
@CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
try {
return newNode.execute(image, cachedReceiver);
} catch (final OutOfMemoryError e) {
CompilerDirectives.transferToInterpreter();
throw PrimitiveFailed.INSUFFICIENT_OBJECT_MEMORY;
}
}
@Specialization(replaces = "newDirect")
protected static final AbstractSqueakObjectWithClassAndHash newIndirect(final ClassObject receiver,
@Cached final SqueakObjectNewNode newNode,
@CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
try {
return newNode.execute(image, receiver);
} catch (final OutOfMemoryError e) {
CompilerDirectives.transferToInterpreter();
throw PrimitiveFailed.INSUFFICIENT_OBJECT_MEMORY;
}
}
}
@GenerateNodeFactory
@SqueakPrimitive(indices = 71)
protected abstract static class PrimNewWithArgNode extends AbstractPrimitiveNode {
public static final int NEW_CACHE_SIZE = 6;
@Specialization(limit = "NEW_CACHE_SIZE", guards = {"receiver == cachedReceiver", "isInstantiable(cachedReceiver, size)"}, assumptions = {"cachedReceiver.getClassFormatStable()"})
protected static final AbstractSqueakObjectWithClassAndHash newWithArgDirect(@SuppressWarnings("unused") final ClassObject receiver, final long size,
@Cached("createIdentityProfile()") final IntValueProfile sizeProfile,
@Cached("receiver") final ClassObject cachedReceiver,
@Cached final SqueakObjectNewNode newNode,
@CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
try {
return newNode.execute(image, cachedReceiver, sizeProfile.profile((int) size));
} catch (final OutOfMemoryError e) {
CompilerDirectives.transferToInterpreter();
throw PrimitiveFailed.INSUFFICIENT_OBJECT_MEMORY;
}
}
@Specialization(replaces = "newWithArgDirect", guards = "isInstantiable(receiver, size)")
protected static final AbstractSqueakObjectWithClassAndHash newWithArg(final ClassObject receiver, final long size,
@Cached final SqueakObjectNewNode newNode,
@CachedContext(SqueakLanguage.class) final SqueakImageContext image) {
try {
return newNode.execute(image, receiver, (int) size);
} catch (final OutOfMemoryError e) {
CompilerDirectives.transferToInterpreter();
throw PrimitiveFailed.INSUFFICIENT_OBJECT_MEMORY;
}
}
protected static final boolean isInstantiable(final ClassObject receiver, final long size) {
return size == 0 || receiver.isVariable() && 0 <= size && size <= Integer.MAX_VALUE;
}
@SuppressWarnings("unused")
@Fallback
protected static final Object doBadArgument(final Object receiver, final Object value) {
throw PrimitiveFailed.BAD_ARGUMENT;
}
}

It may make sense to revise this to avoid cache duplication.

@fniephaus fniephaus self-assigned this Apr 12, 2021
@smarr
Copy link
Collaborator

smarr commented Apr 12, 2021

If you don't mind the hacky bits, this is how TruffleSOM integrates your #basicNew into a dispatch chain: SOM-st/TruffleSOM@d2f04f3

Specifically this for the standard dispatch, similar for super:

SOM-st/TruffleSOM@d2f04f3#diff-e6ba7b4ffc50689737a20f2121025ae11325e28b29cdf1c21f395c58d2522cc1R53-R69

@fniephaus fniephaus changed the title Revise new primitives Revise #new primitives May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants