Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 021fa2759d78
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b7ed4d50a9a2
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Nov 26, 2015

  1. Copy the full SHA
    979881d View commit details
  2. Copy the full SHA
    b7ed4d5 View commit details
Showing with 20 additions and 45 deletions.
  1. +20 −45 truffle/src/main/java/org/jruby/truffle/nodes/objectstorage/WriteHeadObjectFieldNode.java
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@

public abstract class WriteHeadObjectFieldNode extends Node {

protected static final int CACHE_LIMIT = Options.FIELD_LOOKUP_CACHE;

private final Object name;

public WriteHeadObjectFieldNode(Object name) {
@@ -44,11 +46,11 @@ public Object getName() {
"location != null",
"object.getShape() == cachedShape"
},
assumptions = { "newArray(cachedShape.getValidAssumption(), validLocation)" },
limit = "getCacheLimit()")
assumptions = { "cachedShape.getValidAssumption()", "validLocation" },
limit = "CACHE_LIMIT")
public void writeExistingField(DynamicObject object, Object value,
@Cached("object.getShape()") Shape cachedShape,
@Cached("getLocation(object, value)") Location location,
@Cached("object.getShape()") Shape cachedShape,
@Cached("createAssumption()") Assumption validLocation) {
try {
location.set(object, value, cachedShape);
@@ -61,18 +63,18 @@ public void writeExistingField(DynamicObject object, Object value,

@Specialization(
guards = {
"!hasField",
"location == null",
"object.getShape() == oldShape" },
assumptions = { "newArray(oldShape.getValidAssumption(), newShape.getValidAssumption(), validLocation)" },
limit = "getCacheLimit()")
assumptions = { "oldShape.getValidAssumption()", "newShape.getValidAssumption()", "validLocation" },
limit = "CACHE_LIMIT")
public void writeNewField(DynamicObject object, Object value,
@Cached("hasField(object, value)") boolean hasField,
@Cached("getLocation(object, value)") Location location,
@Cached("object.getShape()") Shape oldShape,
@Cached("transitionWithNewField(object, value)") Shape newShape,
@Cached("getNewLocation(newShape)") Location location,
@Cached("defineProperty(oldShape, value)") Shape newShape,
@Cached("getNewLocation(newShape)") Location newLocation,
@Cached("createAssumption()") Assumption validLocation) {
try {
location.set(object, value, oldShape, newShape);
newLocation.set(object, value, oldShape, newShape);
} catch (IncompatibleLocationException e) {
// remove this entry
validLocation.invalidate();
@@ -85,27 +87,13 @@ public void updateShape(DynamicObject object, Object value) {
execute(object, value);
}

protected boolean updateShape(DynamicObject object) {
CompilerDirectives.transferToInterpreter();
return object.updateShape();
}

@TruffleBoundary
@Specialization(contains = { "writeExistingField", "writeNewField", "updateShape" })
public void writeUncached(DynamicObject object, Object value) {
object.updateShape();
final Shape shape = object.getShape();
final Property property = shape.getProperty(name);

if (property == null) {
object.define(name, value, 0);
} else {
property.setGeneric(object, value, shape);
}
object.define(name, value, 0);
}

protected Location getLocation(DynamicObject object, Object value) {
object.updateShape();
final Shape oldShape = object.getShape();
final Property property = oldShape.getProperty(name);

@@ -116,34 +104,21 @@ protected Location getLocation(DynamicObject object, Object value) {
}
}

protected boolean hasField(DynamicObject object, Object value) {
return getLocation(object, value) != null;
}

protected Shape transitionWithNewField(DynamicObject object, Object value) {
return object.getShape().defineProperty(name, value, 0);
protected Shape defineProperty(Shape oldShape, Object value) {
return oldShape.defineProperty(name, value, 0);
}

protected Location getNewLocation(Shape newShape) {
return newShape.getProperty(name).getLocation();
}

protected Assumption createAssumption() {
return Truffle.getRuntime().createAssumption();
}

protected int getCacheLimit() {
return Options.FIELD_LOOKUP_CACHE;
}

// workaround for DSL bug
protected Assumption[] newArray(Assumption a1, Assumption a2, Assumption a3) {
return new Assumption[] { a1, a2, a3 };
protected boolean updateShape(DynamicObject object) {
CompilerDirectives.transferToInterpreter();
return object.updateShape();
}

// workaround for DSL bug
protected Assumption[] newArray(Assumption a1, Assumption a2) {
return new Assumption[] { a1, a2 };
protected Assumption createAssumption() {
return Truffle.getRuntime().createAssumption("object location is valid");
}

}