35
35
*/
36
36
public final class JavaProfiler {
37
37
static final Unsafe UNSAFE ;
38
- static final boolean isJDK8 ;
39
38
static {
40
39
Unsafe unsafe = null ;
41
40
String version = System .getProperty ("java.version" );
42
- isJDK8 = version .startsWith ("1.8" );
43
41
try {
44
42
Field f = Unsafe .class .getDeclaredField ("theUnsafe" );
45
43
f .setAccessible (true );
@@ -129,7 +127,7 @@ private void initializeContextStorage() {
129
127
if (this .contextStorage == null ) {
130
128
int maxPages = getMaxContextPages0 ();
131
129
if (maxPages > 0 ) {
132
- if (isJDK8 ) {
130
+ if (UNSAFE != null ) {
133
131
contextBaseOffsets = new long [maxPages ];
134
132
// be sure to choose an illegal address as a sentinel value
135
133
Arrays .fill (contextBaseOffsets , Long .MIN_VALUE );
@@ -238,14 +236,14 @@ public void removeThread() {
238
236
*/
239
237
public void setContext (long spanId , long rootSpanId ) {
240
238
int tid = TID .get ();
241
- if (isJDK8 ) {
242
- setContextJDK8 (tid , spanId , rootSpanId );
239
+ if (UNSAFE != null ) {
240
+ setContextUnsafe (tid , spanId , rootSpanId );
243
241
} else {
244
242
setContextByteBuffer (tid , spanId , rootSpanId );
245
243
}
246
244
}
247
245
248
- private void setContextJDK8 (int tid , long spanId , long rootSpanId ) {
246
+ private void setContextUnsafe (int tid , long spanId , long rootSpanId ) {
249
247
if (contextBaseOffsets == null ) {
250
248
return ;
251
249
}
@@ -313,14 +311,14 @@ public void clearContext() {
313
311
*/
314
312
public void setContextValue (int offset , int value ) {
315
313
int tid = TID .get ();
316
- if (isJDK8 ) {
317
- setContextJDK8 (tid , offset , value );
314
+ if (UNSAFE != null ) {
315
+ setContextUnsafe (tid , offset , value );
318
316
} else {
319
317
setContextByteBuffer (tid , offset , value );
320
318
}
321
319
}
322
320
323
- private void setContextJDK8 (int tid , int offset , int value ) {
321
+ private void setContextUnsafe (int tid , int offset , int value ) {
324
322
if (contextBaseOffsets == null ) {
325
323
return ;
326
324
}
@@ -344,14 +342,14 @@ public void setContextByteBuffer(int tid, int offset, int value) {
344
342
345
343
void copyTags (int [] snapshot ) {
346
344
int tid = TID .get ();
347
- if (isJDK8 ) {
348
- copyTagsJDK8 (tid , snapshot );
345
+ if (UNSAFE != null ) {
346
+ copyTagsUnsafe (tid , snapshot );
349
347
} else {
350
348
copyTagsByteBuffer (tid , snapshot );
351
349
}
352
350
}
353
351
354
- void copyTagsJDK8 (int tid , int [] snapshot ) {
352
+ void copyTagsUnsafe (int tid , int [] snapshot ) {
355
353
if (contextBaseOffsets == null ) {
356
354
return ;
357
355
}
0 commit comments