Class AdaptingIntegerArray
java.lang.Object
io.opentelemetry.sdk.metrics.internal.aggregator.AdaptingIntegerArray
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 invalid input: '<' 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 ClassesModifier and TypeClassDescriptionprivate static enum
Possible sizes of backing arrays. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
The current byte size of integer cells in this array.private int[]
private long[]
private short[]
-
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
AdaptingIntegerArray
(int size) Construct an adapting integer array of a given size.private
Creates deep copy of another adapting integer array. -
Method Summary
Modifier and TypeMethodDescription(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
Convert from short => int backing array.private void
convert from int => long backing array.private void
Convert from byte => short backing array.
-
Field Details
-
byteBacking
-
shortBacking
-
intBacking
-
longBacking
-
cellSize
The current byte size of integer cells in this array.
-
-
Constructor Details
-
AdaptingIntegerArray
AdaptingIntegerArray(int size) Construct an adapting integer array of a given size. -
AdaptingIntegerArray
Creates deep copy of another adapting integer array.
-
-
Method Details
-
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.
-