Skip to content

Commit 49ce1bd

Browse files
committed
Use non-virtual Location get and set.
1 parent a26c369 commit 49ce1bd

File tree

3 files changed

+41
-71
lines changed

3 files changed

+41
-71
lines changed

truffle/src/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/DynamicObject.java

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@
6969
import com.oracle.truffle.api.nodes.ExplodeLoop;
7070
import com.oracle.truffle.api.nodes.Node;
7171
import com.oracle.truffle.api.nodes.UnexpectedResultException;
72-
import com.oracle.truffle.api.object.DynamicObjectLibraryImpl.RemovePlan;
7372
import com.oracle.truffle.api.object.DynamicObjectFactory.GetNodeGen;
7473
import com.oracle.truffle.api.object.DynamicObjectFactory.PutConstantNodeGen;
7574
import com.oracle.truffle.api.object.DynamicObjectFactory.PutNodeGen;
75+
import com.oracle.truffle.api.object.DynamicObjectLibraryImpl.RemovePlan;
7676

7777
import sun.misc.Unsafe;
7878

@@ -477,7 +477,7 @@ static long doCachedLong(DynamicObject receiver, Object key, Object defaultValue
477477
@Cached("key") Object cachedKey,
478478
@Cached("cachedShape.getLocation(key)") Location cachedLocation) throws UnexpectedResultException {
479479
if (cachedLocation != null) {
480-
return cachedLocation.getLong(receiver, guard);
480+
return cachedLocation.getLongInternal(receiver, cachedShape, guard);
481481
} else {
482482
return Location.expectLong(defaultValue);
483483
}
@@ -492,11 +492,7 @@ static int doCachedInt(DynamicObject receiver, Object key, Object defaultValue,
492492
@Cached("key") Object cachedKey,
493493
@Cached("cachedShape.getLocation(key)") Location cachedLocation) throws UnexpectedResultException {
494494
if (cachedLocation != null) {
495-
if (cachedLocation instanceof ExtLocations.IntArrayLocation intArrayLocation) {
496-
return intArrayLocation.getInt(receiver, guard);
497-
} else {
498-
return cachedLocation.getInt(receiver, guard);
499-
}
495+
return cachedLocation.getIntInternal(receiver, cachedShape, guard);
500496
} else {
501497
return Location.expectInteger(defaultValue);
502498
}
@@ -511,7 +507,7 @@ static double doCachedDouble(DynamicObject receiver, Object key, Object defaultV
511507
@Cached("key") Object cachedKey,
512508
@Cached("cachedShape.getLocation(key)") Location cachedLocation) throws UnexpectedResultException {
513509
if (cachedLocation != null) {
514-
return cachedLocation.getDouble(receiver, guard);
510+
return cachedLocation.getDoubleInternal(receiver, cachedShape, guard);
515511
} else {
516512
return Location.expectDouble(defaultValue);
517513
}
@@ -526,43 +522,40 @@ static Object doCached(DynamicObject receiver, Object key, Object defaultValue,
526522
@Cached("key") Object cachedKey,
527523
@Cached("cachedShape.getLocation(key)") Location cachedLocation) {
528524
if (cachedLocation != null) {
529-
if (cachedLocation instanceof ExtLocations.ObjectArrayLocation objectArrayLocation) {
530-
return objectArrayLocation.get(receiver, guard);
531-
} else if (cachedLocation instanceof ExtLocations.IntArrayLocation intArrayLocation) {
532-
return intArrayLocation.get(receiver, guard);
533-
} else {
534-
return cachedLocation.get(receiver, guard);
535-
}
525+
return cachedLocation.getInternal(receiver, cachedShape, guard);
536526
} else {
537527
return defaultValue;
538528
}
539529
}
540530

541531
@Specialization(replaces = {"doCachedLong", "doCachedInt", "doCachedDouble", "doCached"}, rewriteOn = UnexpectedResultException.class)
542532
static long doGenericLong(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException {
543-
Location location = receiver.getShape().getLocation(key);
533+
Shape shape = receiver.getShape();
534+
Location location = shape.getLocation(key);
544535
if (location != null) {
545-
return location.getLong(receiver, false);
536+
return location.getLongInternal(receiver, shape, false);
546537
} else {
547538
return Location.expectLong(defaultValue);
548539
}
549540
}
550541

551542
@Specialization(replaces = {"doCachedLong", "doCachedInt", "doCachedDouble", "doCached"}, rewriteOn = UnexpectedResultException.class)
552543
static int doGenericInt(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException {
553-
Location location = receiver.getShape().getLocation(key);
544+
Shape shape = receiver.getShape();
545+
Location location = shape.getLocation(key);
554546
if (location != null) {
555-
return location.getInt(receiver, false);
547+
return location.getIntInternal(receiver, shape, false);
556548
} else {
557549
return Location.expectInteger(defaultValue);
558550
}
559551
}
560552

561553
@Specialization(replaces = {"doCachedLong", "doCachedInt", "doCachedDouble", "doCached"}, rewriteOn = UnexpectedResultException.class)
562554
static double doGenericDouble(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException {
563-
Location location = receiver.getShape().getLocation(key);
555+
Shape shape = receiver.getShape();
556+
Location location = shape.getLocation(key);
564557
if (location != null) {
565-
return location.getDouble(receiver, false);
558+
return location.getDoubleInternal(receiver, shape, false);
566559
} else {
567560
return Location.expectDouble(defaultValue);
568561
}
@@ -571,9 +564,10 @@ static double doGenericDouble(DynamicObject receiver, Object key, Object default
571564
@TruffleBoundary
572565
@Specialization(replaces = {"doCachedLong", "doCachedInt", "doCachedDouble", "doCached", "doGenericLong", "doGenericInt", "doGenericDouble"})
573566
static Object doGeneric(DynamicObject receiver, Object key, Object defaultValue) {
574-
Location location = receiver.getShape().getLocation(key);
567+
Shape shape = receiver.getShape();
568+
Location location = shape.getLocation(key);
575569
if (location != null) {
576-
return location.get(receiver, false);
570+
return location.getInternal(receiver, shape, false);
577571
} else {
578572
return defaultValue;
579573
}
@@ -712,7 +706,7 @@ public final boolean putWithFlagsIfAbsent(DynamicObject receiver, Object key, Ob
712706
"key == cachedKey",
713707
"mode == cachedMode",
714708
"propertyFlags == cachedPropertyFlags",
715-
"newLocation == null || canStore(newLocation, value)",
709+
"newLocation == null || newLocation.canStoreValue(value)",
716710
}, assumptions = "newShapeValidAssumption", limit = "SHAPE_CACHE_LIMIT")
717711
static boolean doCached(DynamicObject receiver, Object key, Object value, int mode, int propertyFlags,
718712
@Bind("receiver.getShape()") Shape shape,
@@ -734,18 +728,9 @@ static boolean doCached(DynamicObject receiver, Object key, Object value, int mo
734728
if ((mode & Flags.IF_ABSENT) != 0) {
735729
return true;
736730
} else {
737-
boolean addingNewProperty = newShape != oldShape;
738-
if (addingNewProperty) {
739-
DynamicObjectSupport.grow(receiver, oldShape, newShape);
740-
}
731+
newLocation.setInternal(receiver, value, guard, oldShape, newShape);
741732

742-
if (newLocation instanceof ExtLocations.ObjectArrayLocation objectArrayLocation) {
743-
objectArrayLocation.set(receiver, value, guard, addingNewProperty);
744-
} else {
745-
newLocation.set(receiver, value, guard, addingNewProperty);
746-
}
747-
748-
if (addingNewProperty) {
733+
if (newShape != oldShape) {
749734
DynamicObjectSupport.setShapeWithStoreFence(receiver, newShape);
750735
}
751736
return true;
@@ -903,7 +888,7 @@ public final boolean putConstantWithFlagsIfAbsent(DynamicObject receiver, Object
903888
"key == cachedKey",
904889
"mode == cachedMode",
905890
"propertyFlags == cachedPropertyFlags",
906-
"newLocation == null || canStore(newLocation, value)",
891+
"newLocation == null || newLocation.canStoreConstant(value)",
907892
}, assumptions = "newShapeValidAssumption", limit = "SHAPE_CACHE_LIMIT")
908893
static boolean doCached(DynamicObject receiver, Object key, Object value, int mode, int propertyFlags,
909894
@Bind("receiver.getShape()") Shape shape,
@@ -925,18 +910,7 @@ static boolean doCached(DynamicObject receiver, Object key, Object value, int mo
925910
if ((mode & Flags.IF_ABSENT) != 0) {
926911
return true;
927912
} else {
928-
boolean addingNewProperty = newShape != oldShape;
929-
if (addingNewProperty) {
930-
DynamicObjectSupport.grow(receiver, oldShape, newShape);
931-
}
932-
933-
if (newLocation instanceof ExtLocations.ObjectArrayLocation objectArrayLocation) {
934-
objectArrayLocation.set(receiver, value, guard, addingNewProperty);
935-
} else {
936-
newLocation.set(receiver, value, guard, addingNewProperty);
937-
}
938-
939-
if (addingNewProperty) {
913+
if (newShape != oldShape) {
940914
DynamicObjectSupport.setShapeWithStoreFence(receiver, newShape);
941915
}
942916
return true;
@@ -962,10 +936,6 @@ static boolean doGeneric(DynamicObject receiver, Object key, Object value, int m
962936

963937
}
964938

965-
static boolean canStore(Location newLocation, Object value) {
966-
return newLocation instanceof ExtLocations.AbstractObjectLocation || newLocation.canStore(value);
967-
}
968-
969939
static Shape getNewShape(Object cachedKey, Object value, int newPropertyFlags, int putFlags, Property existingProperty, Shape oldShape) {
970940
if (existingProperty == null) {
971941
if ((putFlags & Flags.IF_PRESENT) != 0) {

truffle/src/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/DynamicObjectLibraryImpl.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,15 @@ private static final class Move implements Comparable<Move> {
431431
this.toOrd = toOrd;
432432
}
433433

434-
void perform(DynamicObject obj) {
434+
void perform(DynamicObject obj, Shape shapeBefore) {
435435
if (fromLoc == toLoc) {
436436
return;
437437
}
438-
performSet(obj, performGet(obj));
438+
performSet(obj, performGet(obj, shapeBefore));
439439
}
440440

441-
Object performGet(DynamicObject obj) {
442-
return fromLoc.get(obj, false);
441+
Object performGet(DynamicObject obj, Shape shapeBefore) {
442+
return fromLoc.getInternal(obj, shapeBefore, false);
443443
}
444444

445445
void performSet(DynamicObject obj, Object value) {
@@ -495,7 +495,7 @@ void perform(DynamicObject object) {
495495
if (canMoveInPlace) {
496496
// perform the moves in inverse order
497497
for (int i = moves.length - 1; i >= 0; i--) {
498-
moves[i].perform(object);
498+
moves[i].perform(object, shapeBefore);
499499
}
500500

501501
if (moves.length > 0) {
@@ -508,7 +508,7 @@ void perform(DynamicObject object) {
508508
// we cannot perform the moves in place, so stash away the values
509509
Object[] tempValues = new Object[moves.length];
510510
for (int i = moves.length - 1; i >= 0; i--) {
511-
tempValues[i] = moves[i].performGet(object);
511+
tempValues[i] = moves[i].performGet(object, shapeBefore);
512512
moves[i].clear(object);
513513
}
514514
DynamicObjectSupport.resize(object, shapeBefore, shapeAfter);
@@ -607,7 +607,7 @@ public boolean isAdoptable() {
607607
public Object getOrDefault(DynamicObject object, Shape cachedShape, Object key, Object defaultValue) {
608608
Property existing = object.getShape().getProperty(key);
609609
if (existing != null) {
610-
return existing.getLocation().get(object, false);
610+
return existing.getLocation().getInternal(object, cachedShape, false);
611611
} else {
612612
return defaultValue;
613613
}
@@ -618,7 +618,7 @@ public Object getOrDefault(DynamicObject object, Shape cachedShape, Object key,
618618
public int getIntOrDefault(DynamicObject object, Shape cachedShape, Object key, Object defaultValue) throws UnexpectedResultException {
619619
Property existing = object.getShape().getProperty(key);
620620
if (existing != null) {
621-
return existing.getLocation().getInt(object, false);
621+
return existing.getLocation().getIntInternal(object, cachedShape, false);
622622
} else {
623623
return expectInteger(defaultValue);
624624
}
@@ -629,7 +629,7 @@ public int getIntOrDefault(DynamicObject object, Shape cachedShape, Object key,
629629
public long getLongOrDefault(DynamicObject object, Shape cachedShape, Object key, Object defaultValue) throws UnexpectedResultException {
630630
Property existing = object.getShape().getProperty(key);
631631
if (existing != null) {
632-
return existing.getLocation().getLong(object, false);
632+
return existing.getLocation().getLongInternal(object, cachedShape, false);
633633
} else {
634634
return expectLong(defaultValue);
635635
}
@@ -640,7 +640,7 @@ public long getLongOrDefault(DynamicObject object, Shape cachedShape, Object key
640640
public double getDoubleOrDefault(DynamicObject object, Shape cachedShape, Object key, Object defaultValue) throws UnexpectedResultException {
641641
Property existing = object.getShape().getProperty(key);
642642
if (existing != null) {
643-
return existing.getLocation().getDouble(object, false);
643+
return existing.getLocation().getDoubleInternal(object, cachedShape, false);
644644
} else {
645645
return expectDouble(defaultValue);
646646
}
@@ -1023,28 +1023,28 @@ private static boolean guard(DynamicObject object, Shape cachedShape) {
10231023
public Object getOrDefault(DynamicObject object, Shape cachedShape, Object key, Object defaultValue) {
10241024
CompilerAsserts.partialEvaluationConstant(cachedShape);
10251025
assert assertCachedKeyAndShapeForRead(object, cachedShape, key);
1026-
return cachedProperty.getLocation().get(object, guard(object, cachedShape));
1026+
return cachedProperty.getLocation().getInternal(object, cachedShape, guard(object, cachedShape));
10271027
}
10281028

10291029
@Override
10301030
public int getIntOrDefault(DynamicObject object, Shape cachedShape, Object key, Object defaultValue) throws UnexpectedResultException {
10311031
CompilerAsserts.partialEvaluationConstant(cachedShape);
10321032
assert assertCachedKeyAndShapeForRead(object, cachedShape, key);
1033-
return cachedProperty.getLocation().getInt(object, guard(object, cachedShape));
1033+
return cachedProperty.getLocation().getIntInternal(object, cachedShape, guard(object, cachedShape));
10341034
}
10351035

10361036
@Override
10371037
public long getLongOrDefault(DynamicObject object, Shape cachedShape, Object key, Object defaultValue) throws UnexpectedResultException {
10381038
CompilerAsserts.partialEvaluationConstant(cachedShape);
10391039
assert assertCachedKeyAndShapeForRead(object, cachedShape, key);
1040-
return cachedProperty.getLocation().getLong(object, guard(object, cachedShape));
1040+
return cachedProperty.getLocation().getLongInternal(object, cachedShape, guard(object, cachedShape));
10411041
}
10421042

10431043
@Override
10441044
public double getDoubleOrDefault(DynamicObject object, Shape cachedShape, Object key, Object defaultValue) throws UnexpectedResultException {
10451045
CompilerAsserts.partialEvaluationConstant(cachedShape);
10461046
assert assertCachedKeyAndShapeForRead(object, cachedShape, key);
1047-
return cachedProperty.getLocation().getDouble(object, guard(object, cachedShape));
1047+
return cachedProperty.getLocation().getDoubleInternal(object, cachedShape, guard(object, cachedShape));
10481048
}
10491049

10501050
@Override

truffle/src/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/PropertyGetter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -93,7 +93,7 @@ public boolean accepts(DynamicObject receiver) {
9393
public Object get(DynamicObject receiver) {
9494
boolean guard = accepts(receiver);
9595
if (guard) {
96-
return location.get(receiver, guard);
96+
return location.getInternal(receiver, expectedShape, guard);
9797
} else {
9898
throw illegalArgumentException();
9999
}
@@ -115,7 +115,7 @@ public Object get(DynamicObject receiver) {
115115
public int getInt(DynamicObject receiver) throws UnexpectedResultException {
116116
boolean guard = accepts(receiver);
117117
if (guard) {
118-
return location.getInt(receiver, guard);
118+
return location.getIntInternal(receiver, expectedShape, guard);
119119
} else {
120120
throw illegalArgumentException();
121121
}
@@ -137,7 +137,7 @@ public int getInt(DynamicObject receiver) throws UnexpectedResultException {
137137
public long getLong(DynamicObject receiver) throws UnexpectedResultException {
138138
boolean guard = accepts(receiver);
139139
if (guard) {
140-
return location.getLong(receiver, guard);
140+
return location.getLongInternal(receiver, expectedShape, guard);
141141
} else {
142142
throw illegalArgumentException();
143143
}
@@ -159,7 +159,7 @@ public long getLong(DynamicObject receiver) throws UnexpectedResultException {
159159
public double getDouble(DynamicObject receiver) throws UnexpectedResultException {
160160
boolean guard = accepts(receiver);
161161
if (guard) {
162-
return location.getDouble(receiver, guard);
162+
return location.getDoubleInternal(receiver, expectedShape, guard);
163163
} else {
164164
throw illegalArgumentException();
165165
}

0 commit comments

Comments
 (0)