io.opentelemetry.javaagent.tooling.util.ClassLoaderMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opentelemetry-javaagent-tooling Show documentation
Show all versions of opentelemetry-javaagent-tooling Show documentation
Instrumentation of Java libraries using OpenTelemetry.
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.tooling.util;
import io.opentelemetry.instrumentation.api.internal.cache.Cache;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.description.modifier.Ownership;
import net.bytebuddy.description.modifier.Visibility;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
class ClassLoaderMap {
private static final Cache>> data = Cache.weak();
public static Object get(ClassLoader classLoader, Object key) {
return getClassLoaderData(classLoader, false).get(key);
}
public static void put(ClassLoader classLoader, Object key, Object value) {
getClassLoaderData(classLoader, true).put(key, value);
}
public static Object computeIfAbsent(
ClassLoader classLoader, Object key, Supplier extends Object> value) {
return getClassLoaderData(classLoader, true).computeIfAbsent(key, unused -> value.get());
}
private static Map