diff --git a/ddprof-lib/src/main/java/com/datadoghq/profiler/JavaProfiler.java b/ddprof-lib/src/main/java/com/datadoghq/profiler/JavaProfiler.java index 851c4baa..cae2c53a 100644 --- a/ddprof-lib/src/main/java/com/datadoghq/profiler/JavaProfiler.java +++ b/ddprof-lib/src/main/java/com/datadoghq/profiler/JavaProfiler.java @@ -35,11 +35,9 @@ */ public final class JavaProfiler { static final Unsafe UNSAFE; - static final boolean isJDK8; static { Unsafe unsafe = null; String version = System.getProperty("java.version"); - isJDK8 = version.startsWith("1.8"); try { Field f = Unsafe.class.getDeclaredField("theUnsafe"); f.setAccessible(true); @@ -129,7 +127,7 @@ private void initializeContextStorage() { if (this.contextStorage == null) { int maxPages = getMaxContextPages0(); if (maxPages > 0) { - if (isJDK8) { + if (UNSAFE != null) { contextBaseOffsets = new long[maxPages]; // be sure to choose an illegal address as a sentinel value Arrays.fill(contextBaseOffsets, Long.MIN_VALUE); @@ -238,14 +236,14 @@ public void removeThread() { */ public void setContext(long spanId, long rootSpanId) { int tid = TID.get(); - if (isJDK8) { - setContextJDK8(tid, spanId, rootSpanId); + if (UNSAFE != null) { + setContextUnsafe(tid, spanId, rootSpanId); } else { setContextByteBuffer(tid, spanId, rootSpanId); } } - private void setContextJDK8(int tid, long spanId, long rootSpanId) { + private void setContextUnsafe(int tid, long spanId, long rootSpanId) { if (contextBaseOffsets == null) { return; } @@ -313,14 +311,14 @@ public void clearContext() { */ public void setContextValue(int offset, int value) { int tid = TID.get(); - if (isJDK8) { - setContextJDK8(tid, offset, value); + if (UNSAFE != null) { + setContextUnsafe(tid, offset, value); } else { setContextByteBuffer(tid, offset, value); } } - private void setContextJDK8(int tid, int offset, int value) { + private void setContextUnsafe(int tid, int offset, int value) { if (contextBaseOffsets == null) { return; } @@ -344,14 +342,14 @@ public void setContextByteBuffer(int tid, int offset, int value) { void copyTags(int[] snapshot) { int tid = TID.get(); - if (isJDK8) { - copyTagsJDK8(tid, snapshot); + if (UNSAFE != null) { + copyTagsUnsafe(tid, snapshot); } else { copyTagsByteBuffer(tid, snapshot); } } - void copyTagsJDK8(int tid, int[] snapshot) { + void copyTagsUnsafe(int tid, int[] snapshot) { if (contextBaseOffsets == null) { return; }