Skip to content

Commit

Permalink
Cache layout in SqueakObjectNewNode
Browse files Browse the repository at this point in the history
and increase class cache from 3 to 6.
  • Loading branch information
fniephaus committed Feb 29, 2020
1 parent 73dc4c1 commit 2832582
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import de.hpi.swa.graal.squeak.nodes.accessing.SqueakObjectIdentityNode;
import de.hpi.swa.graal.squeak.nodes.accessing.UpdateSqueakObjectHashNode;
import de.hpi.swa.graal.squeak.util.ArrayUtils;
import de.hpi.swa.graal.squeak.util.UnsafeUtils;
import de.hpi.swa.graal.squeak.util.ObjectGraphUtils.ObjectTracer;
import de.hpi.swa.graal.squeak.util.UnsafeUtils;

public abstract class AbstractPointersObject extends AbstractSqueakObjectWithClassAndHash {
/*
Expand Down Expand Up @@ -56,9 +56,20 @@ protected AbstractPointersObject(final SqueakImageContext image) {
super(image);
}

protected AbstractPointersObject(final SqueakImageContext image, final ClassObject classObject, final ObjectLayout layout) {
super(image, classObject);
assert classObject.getLayout() == layout : "Layout mismatch";
CompilerAsserts.partialEvaluationConstant(layout);
this.layout = layout;
primitiveExtension = layout.getFreshPrimitiveExtension();
objectExtension = layout.getFreshObjectExtension();
}

protected AbstractPointersObject(final SqueakImageContext image, final ClassObject classObject) {
super(image, classObject);
initializeLayoutAndExtensionsUnsafe();
layout = classObject.getLayout();
primitiveExtension = layout.getFreshPrimitiveExtension();
objectExtension = layout.getFreshObjectExtension();
}

protected AbstractPointersObject(final SqueakImageContext image, final long hash, final ClassObject classObject) {
Expand Down Expand Up @@ -103,7 +114,7 @@ public final void copyLayoutValuesFrom(final AbstractPointersObject anotherObjec
}
}

protected final void initializeLayoutAndExtensionsUnsafe() {
protected final void fillInLayoutAndExtensions() {
layout = getSqueakClass().getLayout();
primitiveExtension = layout.getFreshPrimitiveExtension();
objectExtension = layout.getFreshObjectExtension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import de.hpi.swa.graal.squeak.image.SqueakImageChunk;
import de.hpi.swa.graal.squeak.image.SqueakImageContext;
import de.hpi.swa.graal.squeak.image.SqueakImageWriter;
import de.hpi.swa.graal.squeak.model.layout.ObjectLayout;
import de.hpi.swa.graal.squeak.model.layout.ObjectLayouts.ASSOCIATION;
import de.hpi.swa.graal.squeak.model.layout.ObjectLayouts.BINDING;
import de.hpi.swa.graal.squeak.model.layout.ObjectLayouts.FORM;
Expand All @@ -35,6 +36,10 @@ public PointersObject(final SqueakImageContext image, final long hash, final Cla
super(image, hash, klass);
}

public PointersObject(final SqueakImageContext image, final ClassObject classObject, final ObjectLayout layout) {
super(image, classObject, layout);
}

public PointersObject(final SqueakImageContext image, final ClassObject classObject) {
super(image, classObject);
}
Expand All @@ -55,7 +60,7 @@ public static PointersObject create(final AbstractPointersObjectWriteNode writeN
public void fillin(final SqueakImageChunk chunk) {
final AbstractPointersObjectWriteNode writeNode = AbstractPointersObjectWriteNode.getUncached();
final Object[] pointersObject = chunk.getPointers();
initializeLayoutAndExtensionsUnsafe();
fillInLayoutAndExtensions();
for (int i = 0; i < pointersObject.length; i++) {
writeNode.execute(this, i, pointersObject[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import de.hpi.swa.graal.squeak.image.SqueakImageChunk;
import de.hpi.swa.graal.squeak.image.SqueakImageContext;
import de.hpi.swa.graal.squeak.image.SqueakImageWriter;
import de.hpi.swa.graal.squeak.model.layout.ObjectLayout;
import de.hpi.swa.graal.squeak.nodes.accessing.AbstractPointersObjectNodes.AbstractPointersObjectWriteNode;
import de.hpi.swa.graal.squeak.nodes.accessing.SqueakObjectIdentityNode;
import de.hpi.swa.graal.squeak.nodes.accessing.UpdateSqueakObjectHashNode;
Expand All @@ -27,6 +28,11 @@ public VariablePointersObject(final SqueakImageContext image, final long hash, f
super(image, hash, classObject);
}

public VariablePointersObject(final SqueakImageContext image, final ClassObject classObject, final ObjectLayout layout, final int variableSize) {
super(image, classObject, layout);
variablePart = ArrayUtils.withAll(variableSize, NilObject.SINGLETON);
}

public VariablePointersObject(final SqueakImageContext image, final ClassObject classObject, final int variableSize) {
super(image, classObject);
variablePart = ArrayUtils.withAll(variableSize, NilObject.SINGLETON);
Expand All @@ -41,7 +47,7 @@ private VariablePointersObject(final VariablePointersObject original) {
public void fillin(final SqueakImageChunk chunk) {
final AbstractPointersObjectWriteNode writeNode = AbstractPointersObjectWriteNode.getUncached();
final Object[] pointersObject = chunk.getPointers();
initializeLayoutAndExtensionsUnsafe();
fillInLayoutAndExtensions();
final int instSize = getSqueakClass().getBasicInstanceSize();
for (int i = 0; i < instSize; i++) {
writeNode.execute(this, i, pointersObject[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import de.hpi.swa.graal.squeak.image.SqueakImageChunk;
import de.hpi.swa.graal.squeak.image.SqueakImageContext;
import de.hpi.swa.graal.squeak.image.SqueakImageWriter;
import de.hpi.swa.graal.squeak.model.layout.ObjectLayout;
import de.hpi.swa.graal.squeak.nodes.SqueakGuards;
import de.hpi.swa.graal.squeak.nodes.accessing.AbstractPointersObjectNodes.AbstractPointersObjectWriteNode;
import de.hpi.swa.graal.squeak.nodes.accessing.SqueakObjectIdentityNode;
Expand All @@ -31,6 +32,12 @@ public WeakVariablePointersObject(final SqueakImageContext image, final long has
super(image, hash, classObject);
}

public WeakVariablePointersObject(final SqueakImageContext image, final ClassObject classObject, final ObjectLayout layout, final int variableSize) {
super(image, classObject, layout);
variablePart = new WeakReference<?>[variableSize];
Arrays.fill(variablePart, NIL_REFERENCE);
}

public WeakVariablePointersObject(final SqueakImageContext image, final ClassObject classObject, final int variableSize) {
super(image, classObject);
variablePart = new WeakReference<?>[variableSize];
Expand All @@ -46,7 +53,7 @@ private WeakVariablePointersObject(final WeakVariablePointersObject original) {
public void fillin(final SqueakImageChunk chunk) {
final AbstractPointersObjectWriteNode writeNode = AbstractPointersObjectWriteNode.getUncached();
final Object[] pointersObject = chunk.getPointers();
initializeLayoutAndExtensionsUnsafe();
fillInLayoutAndExtensions();
final int instSize = getSqueakClass().getBasicInstanceSize();
for (int i = 0; i < instSize; i++) {
writeNode.execute(this, i, pointersObject[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
package de.hpi.swa.graal.squeak.nodes.accessing;

import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;

import de.hpi.swa.graal.squeak.exceptions.SqueakExceptions.SqueakException;
Expand All @@ -22,10 +25,13 @@
import de.hpi.swa.graal.squeak.model.PointersObject;
import de.hpi.swa.graal.squeak.model.VariablePointersObject;
import de.hpi.swa.graal.squeak.model.WeakVariablePointersObject;
import de.hpi.swa.graal.squeak.model.layout.ObjectLayout;
import de.hpi.swa.graal.squeak.model.layout.ObjectLayouts.CONTEXT;
import de.hpi.swa.graal.squeak.model.layout.ObjectLayouts.METACLASS;
import de.hpi.swa.graal.squeak.nodes.AbstractNodeWithImage;
import de.hpi.swa.graal.squeak.nodes.primitives.impl.StoragePrimitives.PrimNewNode;

@ImportStatic(PrimNewNode.class)
public abstract class SqueakObjectNewNode extends AbstractNodeWithImage {

protected SqueakObjectNewNode(final SqueakImageContext image) {
Expand Down Expand Up @@ -64,8 +70,17 @@ protected final ClassObject doClassOdd(final ClassObject classObject, final int
return new ClassObject(image, classObject, classObject.getBasicInstanceSize() + METACLASS.INST_SIZE);
}

@Specialization(guards = {"classObject.isNonIndexableWithInstVars()", "!classObject.isMetaClass()", "!classObject.instancesAreClasses()",
"classObject.getLayout() == cachedLayout"}, limit = "NEW_CACHE_SIZE")
protected final PointersObject doPointers(final ClassObject classObject, final int extraSize,
@Cached("classObject.getLayout()") final ObjectLayout cachedLayout) {
assert extraSize == 0;
return new PointersObject(image, classObject, cachedLayout);
}

@TruffleBoundary
@Specialization(guards = {"classObject.isNonIndexableWithInstVars()", "!classObject.isMetaClass()", "!classObject.instancesAreClasses()"})
protected final PointersObject doPointers(final ClassObject classObject, final int extraSize) {
protected final PointersObject doPointersFallback(final ClassObject classObject, final int extraSize) {
assert extraSize == 0;
return new PointersObject(image, classObject);
}
Expand All @@ -92,13 +107,28 @@ protected final BlockClosureObject doBlockClosure(final ClassObject classObject,
return BlockClosureObject.create(image, extraSize);
}

@Specialization(guards = {"classObject.isIndexableWithInstVars()", "!classObject.isMethodContextClass()", "!classObject.isBlockClosureClass()",
"classObject.getLayout() == cachedLayout"}, limit = "NEW_CACHE_SIZE")
protected final VariablePointersObject doVariablePointers(final ClassObject classObject, final int extraSize,
@Cached("classObject.getLayout()") final ObjectLayout cachedLayout) {
return new VariablePointersObject(image, classObject, cachedLayout, extraSize);
}

@TruffleBoundary
@Specialization(guards = {"classObject.isIndexableWithInstVars()", "!classObject.isMethodContextClass()", "!classObject.isBlockClosureClass()"})
protected final VariablePointersObject doVariablePointers(final ClassObject classObject, final int extraSize) {
protected final VariablePointersObject doVariablePointersFallback(final ClassObject classObject, final int extraSize) {
return new VariablePointersObject(image, classObject, extraSize);
}

@Specialization(guards = {"classObject.isWeak()", "classObject.getLayout() == cachedLayout"}, limit = "NEW_CACHE_SIZE")
protected final WeakVariablePointersObject doWeakPointers(final ClassObject classObject, final int extraSize,
@Cached("classObject.getLayout()") final ObjectLayout cachedLayout) {
return new WeakVariablePointersObject(image, classObject, cachedLayout, extraSize);
}

@TruffleBoundary
@Specialization(guards = "classObject.isWeak()")
protected final WeakVariablePointersObject doWeakPointers(final ClassObject classObject, final int extraSize) {
protected final WeakVariablePointersObject doWeakPointersFallback(final ClassObject classObject, final int extraSize) {
return new WeakVariablePointersObject(image, classObject, extraSize);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.oracle.truffle.api.dsl.CachedContext;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.NodeFactory;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.Frame;
Expand Down Expand Up @@ -186,8 +187,8 @@ protected static final Object setLiteral(final CompiledCodeObject code, final lo

@GenerateNodeFactory
@SqueakPrimitive(indices = 70)
protected abstract static class PrimNewNode extends AbstractPrimitiveNode implements UnaryPrimitive {
protected static final int NEW_CACHE_SIZE = 3;
public abstract static class PrimNewNode extends AbstractPrimitiveNode implements UnaryPrimitive {
public static final int NEW_CACHE_SIZE = 6;
@Child private SqueakObjectNewNode newNode;

protected PrimNewNode(final CompiledMethodObject method) {
Expand Down Expand Up @@ -222,8 +223,8 @@ protected final AbstractSqueakObjectWithHash newIndirect(final ClassObject recei

@GenerateNodeFactory
@SqueakPrimitive(indices = 71)
@ImportStatic(PrimNewNode.class)
protected abstract static class PrimNewWithArgNode extends AbstractPrimitiveNode implements BinaryPrimitiveWithoutFallback {
protected static final int NEW_CACHE_SIZE = 3;
@Child private SqueakObjectNewNode newNode;

protected PrimNewWithArgNode(final CompiledMethodObject method) {
Expand Down

0 comments on commit 2832582

Please sign in to comment.