Skip to content

Commit ff4b525

Browse files
committed
Change slot position to a short to keep object size below 32 bytes
1 parent f2dcd68 commit ff4b525

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

rhino/src/main/java/org/mozilla/javascript/OrderedSlotMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ private void insertNewSlot(Slot newSlot) {
228228
System.arraycopy(orderedSlots, 0, newOrderedSlots, 0, orderedCount);
229229
orderedSlots = newOrderedSlots;
230230
}
231-
newSlot.orderedPos = orderedCount;
231+
assert orderedCount < Short.MAX_VALUE;
232+
newSlot.orderedPos = (short)orderedCount;
232233
orderedSlots[orderedCount++] = newSlot;
233234
addKnownAbsentSlot(slots, newSlot);
234235
}

rhino/src/main/java/org/mozilla/javascript/Slot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class Slot implements Serializable {
1818
Object value;
1919
transient Slot next; // next in hash table bucket for EmbeddedSlotMap only
2020
transient Slot orderedNext; // next in linked list for EmbeddedSlotMap only
21-
transient int orderedPos; // Position in the array for OrderedSlotMap only
21+
transient short orderedPos; // Position in the array for OrderedSlotMap only
2222

2323
Slot(Object name, int index, int attributes) {
2424
this.name = name;

rhino/src/main/java/org/mozilla/javascript/SlotMapOwner.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
public abstract class SlotMapOwner {
1111
private static final long serialVersionUID = 1L;
1212

13+
/**
14+
* At this size, we switch from various cleverly optimized maps to an implementation based on
15+
* java.util.HashMap, which is collision-resistant. This must be less than Short.MAX_VALUE or
16+
* OrderedSlotMap will break.
17+
*/
1318
static final int LARGE_HASH_SIZE = 2000;
1419

1520
static final SlotMap EMPTY_SLOT_MAP = new EmptySlotMap();

0 commit comments

Comments
 (0)