Class AdaptingIntegerArray
- java.lang.Object
-
- io.opentelemetry.sdk.metrics.internal.aggregator.AdaptingIntegerArray
-
final class AdaptingIntegerArray extends java.lang.Object
An integer array that automatically expands its memory consumption (via copy/allocation) when reaching limits. This assumes counts remain low, to lower memory overhead.This class is NOT thread-safe. It is expected to be behind a synchronized incrementer.
Instances start by attempting to store one-byte per-cell in the integer array. As values grow, this will automatically instantiate the next-size integer array (byte => short => int => long) and copy over values into the larger array. This class expects most usage to remain within the byte boundary (e.g. cell values < 128).
This class lives in the (very) hot path of metric recording. As such, we do "fun" things, like switch on markers and assume non-null based on presence of the markers, as such we suppress NullAway as it can't understand/express this level of guarantee.
Implementations MUST preserve the following:
- If cellSize == BYTE then byteBacking is not null
- If cellSize == SHORT then shortBacking is not null
- If cellSize == INT then intBacking is not null
- If cellSize == LONG then longBacking is not null
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AdaptingIntegerArray.ArrayCellSize
Possible sizes of backing arrays.
-
Field Summary
Fields Modifier and Type Field Description private byte[]
byteBacking
private AdaptingIntegerArray.ArrayCellSize
cellSize
The current byte size of integer cells in this array.private int[]
intBacking
private long[]
longBacking
private short[]
shortBacking
-
Constructor Summary
Constructors Modifier Constructor Description (package private)
AdaptingIntegerArray(int size)
Construct an adapting integer array of a given size.private
AdaptingIntegerArray(AdaptingIntegerArray toCopy)
Creates deep copy of another adapting integer array.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
clear()
Zeroes out all counts in this array.(package private) AdaptingIntegerArray
copy()
Returns a deep-copy of this array, preserving cell size.(package private) long
get(int index)
Grab the value stored atindex
.(package private) void
increment(int idx, long count)
Addcount
to the value stored atindex
.(package private) int
length()
Return the length of this integer array.private void
resizeToInt()
Convert from short => int backing array.private void
resizeToLong()
convert from int => long backing array.private void
resizeToShort()
Convert from byte => short backing array.
-
-
-
Field Detail
-
byteBacking
@Nullable private byte[] byteBacking
-
shortBacking
@Nullable private short[] shortBacking
-
intBacking
@Nullable private int[] intBacking
-
longBacking
@Nullable private long[] longBacking
-
cellSize
private AdaptingIntegerArray.ArrayCellSize cellSize
The current byte size of integer cells in this array.
-
-
Constructor Detail
-
AdaptingIntegerArray
AdaptingIntegerArray(int size)
Construct an adapting integer array of a given size.
-
AdaptingIntegerArray
private AdaptingIntegerArray(AdaptingIntegerArray toCopy)
Creates deep copy of another adapting integer array.
-
-
Method Detail
-
copy
AdaptingIntegerArray copy()
Returns a deep-copy of this array, preserving cell size.
-
increment
void increment(int idx, long count)
Addcount
to the value stored atindex
.
-
get
long get(int index)
Grab the value stored atindex
.
-
length
int length()
Return the length of this integer array.
-
clear
void clear()
Zeroes out all counts in this array.
-
resizeToShort
private void resizeToShort()
Convert from byte => short backing array.
-
resizeToInt
private void resizeToInt()
Convert from short => int backing array.
-
resizeToLong
private void resizeToLong()
convert from int => long backing array.
-
-