in jvmti-access/src/main/java/co/elastic/otel/UniversalProfilingCorrelation.java [77:99]
public static ByteBuffer getCurrentThreadStorage(
boolean allocateIfRequired, int expectedCapacity) {
if (!virtualThreadSupportEnabled && isVirtual(Thread.currentThread())) {
return null;
}
ByteBuffer buffer = threadStorage.get();
if (buffer == null) {
if (!allocateIfRequired) {
return null;
}
buffer = ByteBuffer.allocateDirect(expectedCapacity);
buffer.order(ByteOrder.nativeOrder());
JvmtiAccess.setProfilingCorrelationCurrentThreadStorage(buffer);
threadStorage.set(buffer);
}
int actualCapacity = buffer.capacity();
if (actualCapacity != expectedCapacity) {
throw new IllegalArgumentException(
"Buffer has been allocated with a different capacity: " + actualCapacity);
}
return buffer;
}