Skip to content

Commit 6fd30d6

Browse files
committed
Lazily initialize TruffleString.FromLongNode.
1 parent 1a845b5 commit 6fd30d6

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ abstract static class JSObjectReadElementTypeCacheNode extends JavaScriptBaseNod
566566
@Child private IsArrayNode isArrayNode;
567567
@Child private ToArrayIndexNode toArrayIndexNode;
568568
@Child private JSObjectReadElementNonArrayTypeCacheNode nonArrayCaseNode;
569+
@Child private TruffleString.FromLongNode fromLongNode;
569570
private final JSClassProfile jsclassProfile = JSClassProfile.create();
570571

571572
JSObjectReadElementTypeCacheNode() {
@@ -636,15 +637,14 @@ private Object readNonArrayObjectIndex(JSDynamicObject targetObject, Object inde
636637
protected int doLongIndexAsInt(Object target, long index, Object receiver, Object defaultValue, ReadElementNode root, @SuppressWarnings("unused") boolean indexIsLong,
637638
@Cached @Shared ArrayReadElementCacheDispatchNode arrayDispatch,
638639
@Cached @Shared InlinedConditionProfile arrayIf,
639-
@Cached @Shared InlinedConditionProfile arrayIndexIf,
640-
@Cached TruffleString.FromLongNode fromLong) throws UnexpectedResultException {
640+
@Cached @Shared InlinedConditionProfile arrayIndexIf) throws UnexpectedResultException {
641641
JSDynamicObject targetObject = (JSDynamicObject) target;
642642
if (arrayIf.profile(this, isArray(targetObject))) {
643643
ScriptArray array = JSObject.getArray(targetObject);
644644
if (arrayIndexIf.profile(this, JSRuntime.isArrayIndex(index))) {
645645
return arrayDispatch.executeArrayGetInt(this, targetObject, array, index, receiver, defaultValue, root.context);
646646
} else {
647-
return JSTypesGen.expectInteger(getProperty(targetObject, Strings.fromLong(fromLong, index), receiver, defaultValue));
647+
return JSTypesGen.expectInteger(getProperty(targetObject, stringFromLong(index), receiver, defaultValue));
648648
}
649649
} else {
650650
return JSTypesGen.expectInteger(readNonArrayObjectIndex(targetObject, index, receiver, defaultValue, root));
@@ -655,15 +655,14 @@ protected int doLongIndexAsInt(Object target, long index, Object receiver, Objec
655655
protected double doLongIndexAsDouble(Object target, long index, Object receiver, Object defaultValue, ReadElementNode root, @SuppressWarnings("unused") boolean indexIsLong,
656656
@Cached @Shared ArrayReadElementCacheDispatchNode arrayDispatch,
657657
@Cached @Shared InlinedConditionProfile arrayIf,
658-
@Cached @Shared InlinedConditionProfile arrayIndexIf,
659-
@Cached TruffleString.FromLongNode fromLong) throws UnexpectedResultException {
658+
@Cached @Shared InlinedConditionProfile arrayIndexIf) throws UnexpectedResultException {
660659
JSDynamicObject targetObject = (JSDynamicObject) target;
661660
if (arrayIf.profile(this, isArray(targetObject))) {
662661
ScriptArray array = JSObject.getArray(targetObject);
663662
if (arrayIndexIf.profile(this, JSRuntime.isArrayIndex(index))) {
664663
return arrayDispatch.executeArrayGetDouble(this, targetObject, array, index, receiver, defaultValue, root.context);
665664
} else {
666-
return JSTypesGen.expectDouble(getProperty(targetObject, Strings.fromLong(fromLong, index), receiver, defaultValue));
665+
return JSTypesGen.expectDouble(getProperty(targetObject, stringFromLong(index), receiver, defaultValue));
667666
}
668667
} else {
669668
return JSTypesGen.expectDouble(readNonArrayObjectIndex(targetObject, index, receiver, defaultValue, root));
@@ -674,15 +673,14 @@ protected double doLongIndexAsDouble(Object target, long index, Object receiver,
674673
protected Object doLongIndex(Object target, long index, Object receiver, Object defaultValue, ReadElementNode root, @SuppressWarnings("unused") boolean indexIsLong,
675674
@Cached @Shared ArrayReadElementCacheDispatchNode arrayDispatch,
676675
@Cached @Shared InlinedConditionProfile arrayIf,
677-
@Cached @Shared InlinedConditionProfile arrayIndexIf,
678-
@Cached TruffleString.FromLongNode fromLong) {
676+
@Cached @Shared InlinedConditionProfile arrayIndexIf) {
679677
JSDynamicObject targetObject = (JSDynamicObject) target;
680678
if (arrayIf.profile(this, isArray(targetObject))) {
681679
ScriptArray array = JSObject.getArray(targetObject);
682680
if (arrayIndexIf.profile(this, JSRuntime.isArrayIndex(index))) {
683681
return arrayDispatch.executeArrayGet(this, targetObject, array, index, receiver, defaultValue, root.context);
684682
} else {
685-
return getProperty(targetObject, Strings.fromLong(fromLong, index), receiver, defaultValue);
683+
return getProperty(targetObject, stringFromLong(index), receiver, defaultValue);
686684
}
687685
} else {
688686
return readNonArrayObjectIndex(targetObject, index, receiver, defaultValue, root);
@@ -763,6 +761,20 @@ private JSObjectReadElementNonArrayTypeCacheNode getNonArrayNode() {
763761
}
764762
return nonArrayCaseNode;
765763
}
764+
765+
@InliningCutoff
766+
private TruffleString stringFromLong(long index) {
767+
var fromLong = fromLongNode;
768+
if (fromLong == null) {
769+
fromLong = initFromLongNode();
770+
}
771+
return Strings.fromLong(fromLong, index);
772+
}
773+
774+
private TruffleString.FromLongNode initFromLongNode() {
775+
CompilerDirectives.transferToInterpreterAndInvalidate();
776+
return fromLongNode = insert(TruffleString.FromLongNode.create());
777+
}
766778
}
767779

768780
private static class JSObjectReadElementNonArrayTypeCacheNode extends JavaScriptBaseNode {

0 commit comments

Comments
 (0)