Skip to content

Commit f3399cf

Browse files
committed
Use final Location get and set.
1 parent bb3e0ed commit f3399cf

File tree

2 files changed

+32
-62
lines changed

2 files changed

+32
-62
lines changed

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

Lines changed: 27 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static long doCachedLong(DynamicObject receiver, Object key, Object defaultValue
441441
@Cached("key") Object cachedKey,
442442
@Cached("cachedShape.getLocation(key)") Location cachedLocation) throws UnexpectedResultException {
443443
if (cachedLocation != null) {
444-
return cachedLocation.getLong(receiver, guard);
444+
return cachedLocation.getLongInternal(receiver, cachedShape, guard);
445445
} else {
446446
return Location.expectLong(defaultValue);
447447
}
@@ -456,11 +456,7 @@ static int doCachedInt(DynamicObject receiver, Object key, Object defaultValue,
456456
@Cached("key") Object cachedKey,
457457
@Cached("cachedShape.getLocation(key)") Location cachedLocation) throws UnexpectedResultException {
458458
if (cachedLocation != null) {
459-
if (cachedLocation instanceof ExtLocations.IntLocation intArrayLocation) {
460-
return intArrayLocation.getInt(receiver, guard);
461-
} else {
462-
return cachedLocation.getInt(receiver, guard);
463-
}
459+
return cachedLocation.getIntInternal(receiver, cachedShape, guard);
464460
} else {
465461
return Location.expectInteger(defaultValue);
466462
}
@@ -475,7 +471,7 @@ static double doCachedDouble(DynamicObject receiver, Object key, Object defaultV
475471
@Cached("key") Object cachedKey,
476472
@Cached("cachedShape.getLocation(key)") Location cachedLocation) throws UnexpectedResultException {
477473
if (cachedLocation != null) {
478-
return cachedLocation.getDouble(receiver, guard);
474+
return cachedLocation.getDoubleInternal(receiver, cachedShape, guard);
479475
} else {
480476
return Location.expectDouble(defaultValue);
481477
}
@@ -490,43 +486,40 @@ static Object doCached(DynamicObject receiver, Object key, Object defaultValue,
490486
@Cached("key") Object cachedKey,
491487
@Cached("cachedShape.getLocation(key)") Location cachedLocation) {
492488
if (cachedLocation != null) {
493-
if (cachedLocation instanceof ExtLocations.ObjectLocation objectArrayLocation) {
494-
return objectArrayLocation.get(receiver, guard);
495-
} else if (cachedLocation instanceof ExtLocations.IntLocation intArrayLocation) {
496-
return intArrayLocation.get(receiver, guard);
497-
} else {
498-
return cachedLocation.get(receiver, guard);
499-
}
489+
return cachedLocation.getInternal(receiver, cachedShape, guard);
500490
} else {
501491
return defaultValue;
502492
}
503493
}
504494

505495
@Specialization(replaces = {"doCachedLong", "doCachedInt", "doCachedDouble", "doCached"}, rewriteOn = UnexpectedResultException.class)
506496
static long doGenericLong(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException {
507-
Location location = receiver.getShape().getLocation(key);
497+
Shape shape = receiver.getShape();
498+
Location location = shape.getLocation(key);
508499
if (location != null) {
509-
return location.getLong(receiver, false);
500+
return location.getLongInternal(receiver, shape, false);
510501
} else {
511502
return Location.expectLong(defaultValue);
512503
}
513504
}
514505

515506
@Specialization(replaces = {"doCachedLong", "doCachedInt", "doCachedDouble", "doCached"}, rewriteOn = UnexpectedResultException.class)
516507
static int doGenericInt(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException {
517-
Location location = receiver.getShape().getLocation(key);
508+
Shape shape = receiver.getShape();
509+
Location location = shape.getLocation(key);
518510
if (location != null) {
519-
return location.getInt(receiver, false);
511+
return location.getIntInternal(receiver, shape, false);
520512
} else {
521513
return Location.expectInteger(defaultValue);
522514
}
523515
}
524516

525517
@Specialization(replaces = {"doCachedLong", "doCachedInt", "doCachedDouble", "doCached"}, rewriteOn = UnexpectedResultException.class)
526518
static double doGenericDouble(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException {
527-
Location location = receiver.getShape().getLocation(key);
519+
Shape shape = receiver.getShape();
520+
Location location = shape.getLocation(key);
528521
if (location != null) {
529-
return location.getDouble(receiver, false);
522+
return location.getDoubleInternal(receiver, shape, false);
530523
} else {
531524
return Location.expectDouble(defaultValue);
532525
}
@@ -535,9 +528,10 @@ static double doGenericDouble(DynamicObject receiver, Object key, Object default
535528
@TruffleBoundary
536529
@Specialization(replaces = {"doCachedLong", "doCachedInt", "doCachedDouble", "doCached", "doGenericLong", "doGenericInt", "doGenericDouble"})
537530
static Object doGeneric(DynamicObject receiver, Object key, Object defaultValue) {
538-
Location location = receiver.getShape().getLocation(key);
531+
Shape shape = receiver.getShape();
532+
Location location = shape.getLocation(key);
539533
if (location != null) {
540-
return location.get(receiver, false);
534+
return location.getInternal(receiver, shape, false);
541535
} else {
542536
return defaultValue;
543537
}
@@ -683,7 +677,7 @@ public final boolean executeWithFlagsIfAbsent(DynamicObject receiver, Object key
683677
"key == cachedKey",
684678
"mode == cachedMode",
685679
"propertyFlags == cachedPropertyFlags",
686-
"newLocation == null || canStore(newLocation, value)",
680+
"newLocation == null || newLocation.canStoreValue(value)",
687681
}, assumptions = "newShapeValidAssumption", limit = "SHAPE_CACHE_LIMIT")
688682
static boolean doCached(DynamicObject receiver, Object key, Object value, int mode, int propertyFlags,
689683
@Bind("receiver.getShape()") Shape shape,
@@ -703,23 +697,14 @@ static boolean doCached(DynamicObject receiver, Object key, Object value, int mo
703697
}
704698
if ((mode & Flags.IF_PRESENT) != 0 && oldProperty == null) {
705699
return false;
706-
} else {
707-
boolean addingNewProperty = newShape != oldShape;
708-
if (addingNewProperty) {
709-
DynamicObjectSupport.grow(receiver, oldShape, newShape);
710-
}
700+
}
711701

712-
if (newLocation instanceof ExtLocations.ObjectLocation objectArrayLocation) {
713-
objectArrayLocation.set(receiver, value, guard, addingNewProperty);
714-
} else {
715-
newLocation.set(receiver, value, guard, addingNewProperty);
716-
}
702+
newLocation.setInternal(receiver, value, guard, oldShape, newShape);
717703

718-
if (addingNewProperty) {
719-
DynamicObjectSupport.setShapeWithStoreFence(receiver, newShape);
720-
}
721-
return true;
704+
if (newShape != oldShape) {
705+
DynamicObjectSupport.setShapeWithStoreFence(receiver, newShape);
722706
}
707+
return true;
723708
}
724709

725710
/*
@@ -876,7 +861,7 @@ public final boolean executeWithFlagsIfAbsent(DynamicObject receiver, Object key
876861
"key == cachedKey",
877862
"mode == cachedMode",
878863
"propertyFlags == cachedPropertyFlags",
879-
"newLocation == null || canStore(newLocation, value)",
864+
"newLocation == null || newLocation.canStoreConstant(value)",
880865
}, assumptions = "newShapeValidAssumption", limit = "SHAPE_CACHE_LIMIT")
881866
static boolean doCached(DynamicObject receiver, Object key, Object value, int mode, int propertyFlags,
882867
@Bind("receiver.getShape()") Shape shape,
@@ -896,23 +881,12 @@ static boolean doCached(DynamicObject receiver, Object key, Object value, int mo
896881
}
897882
if ((mode & Flags.IF_PRESENT) != 0 && oldProperty == null) {
898883
return false;
899-
} else {
900-
boolean addingNewProperty = newShape != oldShape;
901-
if (addingNewProperty) {
902-
DynamicObjectSupport.grow(receiver, oldShape, newShape);
903-
}
904-
905-
if (newLocation instanceof ExtLocations.ObjectLocation objectArrayLocation) {
906-
objectArrayLocation.set(receiver, value, guard, addingNewProperty);
907-
} else {
908-
newLocation.set(receiver, value, guard, addingNewProperty);
909-
}
884+
}
910885

911-
if (addingNewProperty) {
912-
DynamicObjectSupport.setShapeWithStoreFence(receiver, newShape);
913-
}
914-
return true;
886+
if (newShape != oldShape) {
887+
DynamicObjectSupport.setShapeWithStoreFence(receiver, newShape);
915888
}
889+
return true;
916890
}
917891

918892
/*
@@ -949,10 +923,6 @@ public static PutConstantNode getUncached() {
949923
}
950924
}
951925

952-
static boolean canStore(Location newLocation, Object value) {
953-
return newLocation instanceof ExtLocations.ObjectLocation || newLocation.canStore(value);
954-
}
955-
956926
static Shape getNewShape(Object cachedKey, Object value, int newPropertyFlags, int mode, Property existingProperty, Shape oldShape) {
957927
if (existingProperty == null) {
958928
if ((mode & Flags.IF_PRESENT) != 0) {

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)