Skip to content

Commit f3ffeaf

Browse files
committed
Skip unnecessary shape assumption checks for null prototype (immutable).
1 parent bbe2716 commit f3ffeaf

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/PropertyCacheNode.java

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
package com.oracle.truffle.js.nodes.access;
4242

4343
import java.io.PrintStream;
44+
import java.util.Arrays;
4445
import java.util.Locale;
4546
import java.util.concurrent.locks.Lock;
4647

@@ -338,9 +339,13 @@ static AbstractShapeCheckNode create(Shape shape, JSDynamicObject thisObj, Objec
338339
ass[pos++] = shape.getValidAssumption();
339340
JSDynamicObject finalProto = JSObject.getPrototype(thisObj);
340341
Shape protoShape = finalProto.getShape();
341-
ass[pos++] = protoShape.getValidAssumption();
342-
ass[pos++] = JSShape.getPropertyAssumption(protoShape, key, true);
343-
assert pos == ass.length;
342+
if (finalProto != Null.instance) {
343+
ass[pos++] = protoShape.getValidAssumption();
344+
ass[pos++] = JSShape.getPropertyAssumption(protoShape, key, true);
345+
}
346+
if (pos != ass.length) {
347+
ass = Arrays.copyOfRange(ass, 0, pos);
348+
}
344349
return new PrototypeShapeCheckNode(shape, ass, finalProto, context);
345350
}
346351

@@ -368,15 +373,19 @@ static AbstractShapeCheckNode create(Shape shape, JSDynamicObject thisObj, Objec
368373
JSDynamicObject depthProto = thisObj;
369374
for (int i = 0; i < depth; i++) {
370375
Assumption stablePrototypeAssumption = i == 0 ? null : JSShape.getPrototypeAssumption(depthShape);
371-
depthProto = JSObject.getPrototype(depthProto);
372-
depthShape = depthProto.getShape();
373-
ass[pos++] = depthShape.getValidAssumption();
374-
ass[pos++] = JSShape.getPropertyAssumption(depthShape, key, true);
375376
if (stablePrototypeAssumption != null) {
376377
ass[pos++] = stablePrototypeAssumption;
377378
}
379+
depthProto = JSObject.getPrototype(depthProto);
380+
depthShape = depthProto.getShape();
381+
if (depthProto != Null.instance) {
382+
ass[pos++] = depthShape.getValidAssumption();
383+
ass[pos++] = JSShape.getPropertyAssumption(depthShape, key, true);
384+
}
385+
}
386+
if (pos != ass.length) {
387+
ass = Arrays.copyOfRange(ass, 0, pos);
378388
}
379-
assert pos == ass.length;
380389
return new PrototypeChainShapeCheckNode(shape, ass, depthProto, context);
381390
}
382391

@@ -457,13 +466,17 @@ static AbstractShapeCheckNode create(Shape shape, JSDynamicObject thisObj, Objec
457466
JSDynamicObject depthProto = thisObj;
458467
for (int i = 0; i < depth; i++) {
459468
Assumption stablePrototypeAssumption = JSShape.getPrototypeAssumption(depthShape);
469+
ass[pos++] = stablePrototypeAssumption;
460470
depthProto = JSObject.getPrototype(depthProto);
461471
depthShape = depthProto.getShape();
462-
ass[pos++] = depthShape.getValidAssumption();
463-
ass[pos++] = JSShape.getPropertyAssumption(depthShape, key, true);
464-
ass[pos++] = stablePrototypeAssumption;
472+
if (depthProto != Null.instance) {
473+
ass[pos++] = depthShape.getValidAssumption();
474+
ass[pos++] = JSShape.getPropertyAssumption(depthShape, key, true);
475+
}
476+
}
477+
if (pos != ass.length) {
478+
ass = Arrays.copyOfRange(ass, 0, pos);
465479
}
466-
assert pos == ass.length;
467480
return new ConstantObjectPrototypeChainShapeCheckNode(shape, ass, depthProto, context);
468481
}
469482

@@ -653,15 +666,19 @@ static AbstractShapeCheckNode create(Class<?> valueClass, Shape shape, JSDynamic
653666
JSDynamicObject depthProto = thisObj;
654667
for (int i = 0; i < depth; i++) {
655668
Assumption stablePrototypeAssumption = i == 0 ? null : JSShape.getPrototypeAssumption(depthShape);
656-
depthProto = JSObject.getPrototype(depthProto);
657-
depthShape = depthProto.getShape();
658-
ass[pos++] = depthShape.getValidAssumption();
659-
ass[pos++] = JSShape.getPropertyAssumption(depthShape, key, true);
660669
if (stablePrototypeAssumption != null) {
661670
ass[pos++] = stablePrototypeAssumption;
662671
}
672+
depthProto = JSObject.getPrototype(depthProto);
673+
depthShape = depthProto.getShape();
674+
if (depthProto != Null.instance) {
675+
ass[pos++] = depthShape.getValidAssumption();
676+
ass[pos++] = JSShape.getPropertyAssumption(depthShape, key, true);
677+
}
678+
}
679+
if (pos != ass.length) {
680+
ass = Arrays.copyOfRange(ass, 0, pos);
663681
}
664-
assert pos == ass.length;
665682
return new ValuePrototypeChainCheckNode(valueClass, shape, ass, depthProto, context);
666683
}
667684

0 commit comments

Comments
 (0)