Skip to content

Commit

Permalink
Fixup overflow of int arithmetic and check for null data segments
Browse files Browse the repository at this point in the history
  • Loading branch information
kdnilsen committed Sep 11, 2022
1 parent 7fb976d commit 1df83ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
class Arraylet<BaseType> extends ExtrememObject {
// We use max_arraylet_length for the typical segment size and the typical index size. We only truncate the
// last array segment and the last indexing segment at each indexing level.

private final int max_arraylet_length;
private final int length; // Number of elements in Arraylet
private final int num_segments; // Total number of array segments representing the elements of this Arraylet
Expand All @@ -40,7 +39,7 @@ class Arraylet<BaseType> extends ExtrememObject {
// At second indexing tier, each index element represents max_arraylet_length * max_arraylet_length
// At level N (with bottom equal to zero), each index element represents max_arraylet_length * max_arraylet_length ^ N
int index_levels = 1;
int potential_span = max_arraylet_length * max_arraylet_length;
long potential_span = max_arraylet_length * (long) max_arraylet_length;
while (potential_span < length) {
index_levels++;
potential_span *= max_arraylet_length;
Expand Down Expand Up @@ -235,7 +234,9 @@ private void helpTallyMemory(MemoryLog log, LifeSpan ls, Polarity p, Object[] in
log.accumulate(ls, MemoryFlavor.ArrayObject, p, index_segment.length);;
for (int i = 0; i < index_segment.length; i++) {
BaseType[] data_segment = (BaseType[]) index_segment[i];
log.accumulate(ls, MemoryFlavor.ArrayReference, p, data_segment.length);
if (data_segment != null) {
log.accumulate(ls, MemoryFlavor.ArrayReference, p, data_segment.length);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
class ArrayletOflong extends ExtrememObject {
// We use max_arraylet_length for the typical segment size and the typical index size. We only truncate the
// last array segment and the last indexing segment at each indexing level.

private final int max_arraylet_length;
private final int length; // Number of elements in Arraylet
private final int num_segments; // Total number of array segments representing the elements of this Arraylet
Expand All @@ -40,7 +39,7 @@ class ArrayletOflong extends ExtrememObject {
// At second indexing tier, each index element represents max_arraylet_length * max_arraylet_length
// At level N (with bottom equal to zero), each index element represents max_arraylet_length * max_arraylet_length ^ N
int index_levels = 1;
int potential_span = max_arraylet_length * max_arraylet_length;
long potential_span = max_arraylet_length * (long) max_arraylet_length;
while (potential_span < length) {
index_levels++;
potential_span *= max_arraylet_length;
Expand Down Expand Up @@ -236,7 +235,9 @@ private void helpTallyMemory(MemoryLog log, LifeSpan ls, Polarity p, Object[] in
log.accumulate(ls, MemoryFlavor.ArrayObject, p, index_segment.length);;
for (int i = 0; i < index_segment.length; i++) {
long[] data_segment = (long[]) index_segment[i];
log.accumulate(ls, MemoryFlavor.ArrayRSB, p, data_segment.length * Util.SizeOfLong);
if (data_segment != null) {
log.accumulate(ls, MemoryFlavor.ArrayRSB, p, data_segment.length * Util.SizeOfLong);
}
}
}
}
Expand Down

0 comments on commit 1df83ca

Please sign in to comment.