changeset 22412:e7c2d89ddf20

SL write property node: simplify further
author Benoit Daloze <benoit.daloze@jku.at>
date Mon, 23 Nov 2015 19:29:26 +0100
parents 047a3382617c
children bc1e026ef5b1
files truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLWritePropertyCacheNode.java
diffstat 1 files changed, 16 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLWritePropertyCacheNode.java	Mon Nov 23 19:12:11 2015 +0100
+++ b/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/access/SLWritePropertyCacheNode.java	Mon Nov 23 19:29:26 2015 +0100
@@ -40,10 +40,8 @@
  */
 package com.oracle.truffle.sl.nodes.access;
 
-import com.oracle.truffle.api.Assumption;
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
-import com.oracle.truffle.api.Truffle;
 import com.oracle.truffle.api.dsl.Cached;
 import com.oracle.truffle.api.dsl.Specialization;
 import com.oracle.truffle.api.nodes.Node;
@@ -65,7 +63,7 @@
 
     public abstract void executeObject(DynamicObject receiver, Object value);
 
-    @Specialization(guards = {"location != null", "shape.check(receiver)", "canSet(location, receiver, value)"}, assumptions = {"shape.getValidAssumption()"}, limit = "CACHE_LIMIT")
+    @Specialization(guards = {"location != null", "shape.check(receiver)", "canSet(location, receiver, value)"}, assumptions = "shape.getValidAssumption()", limit = "CACHE_LIMIT")
     public void writeExistingPropertyCached(DynamicObject receiver, Object value, //
                     @Cached("lookupLocation(receiver, value)") Location location, //
                     @Cached("receiver.getShape()") Shape shape) {
@@ -76,36 +74,33 @@
         }
     }
 
-    @Specialization(guards = {"existing == null", "shapeBefore.check(receiver)", "canSet(newLocation, receiver, value)"}, assumptions = {"shapeBefore.getValidAssumption()",
-                    "shapeAfter.getValidAssumption()"}, limit = "CACHE_LIMIT")
+    @Specialization(guards = {"existingLocation == null", "oldShape.check(receiver)", "canSet(newLocation, receiver, value)"}, assumptions = {"oldShape.getValidAssumption()",
+                    "newShape.getValidAssumption()"}, limit = "CACHE_LIMIT")
     public void writeNewPropertyCached(DynamicObject receiver, Object value, //
-                    @Cached("lookupLocation(receiver, value)") @SuppressWarnings("unused") Location existing, //
-                    @Cached("receiver.getShape()") Shape shapeBefore, //
-                    @Cached("defineProperty(receiver, value)") Shape shapeAfter, //
-                    @Cached("getLocation(shapeAfter)") Location newLocation) {
+                    @Cached("lookupLocation(receiver, value)") @SuppressWarnings("unused") Location existingLocation, //
+                    @Cached("receiver.getShape()") Shape oldShape, //
+                    @Cached("defineProperty(oldShape, value)") Shape newShape, //
+                    @Cached("getLocation(newShape)") Location newLocation) {
         try {
-            newLocation.set(receiver, value, shapeBefore, shapeAfter);
+            newLocation.set(receiver, value, oldShape, newShape);
         } catch (IncompatibleLocationException e) {
             throw new IllegalStateException(e);
         }
     }
 
-    @Specialization(guards = {"updateShape(object)"}, assumptions = {"assumption"})
-    public void updateShape(DynamicObject object, Object value, @Cached("createAssumption()") Assumption assumption) {
-        CompilerDirectives.transferToInterpreter();
-        assumption.invalidate();
-        executeObject(object, value);
+    @Specialization(guards = "updateShape(receiver)")
+    public void updateShape(DynamicObject receiver, Object value) {
+        executeObject(receiver, value);
     }
 
-    @Specialization(contains = {"writeExistingPropertyCached", "writeNewPropertyCached"})
     @TruffleBoundary
+    @Specialization(contains = {"writeExistingPropertyCached", "writeNewPropertyCached", "updateShape"})
     public void writeUncached(DynamicObject receiver, Object value) {
         receiver.define(propertyName, value);
     }
 
     protected final Location lookupLocation(DynamicObject object, Object value) {
-        final Shape oldShape = object.getShape();
-        final Property property = oldShape.getProperty(propertyName);
+        final Property property = object.getShape().getProperty(propertyName);
 
         if (property != null && property.getLocation().canSet(object, value)) {
             return property.getLocation();
@@ -114,10 +109,8 @@
         }
     }
 
-    protected final Shape defineProperty(DynamicObject receiver, Object value) {
-        Shape oldShape = receiver.getShape();
-        Shape newShape = oldShape.defineProperty(propertyName, value, 0);
-        return newShape;
+    protected final Shape defineProperty(Shape oldShape, Object value) {
+        return oldShape.defineProperty(propertyName, value, 0);
     }
 
     protected final Location getLocation(Shape newShape) {
@@ -128,12 +121,9 @@
         return location.canSet(receiver, value);
     }
 
-    protected static Assumption createAssumption() {
-        return Truffle.getRuntime().createAssumption("temporary cache node");
-    }
-
     protected static boolean updateShape(DynamicObject object) {
         CompilerDirectives.transferToInterpreter();
         return object.updateShape();
     }
+
 }