FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Unify context propagation by zhengyu123 · Pull Request #231 · DataDog/java-profiler · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

Back | FazBrowse Home | New Git URL