diff --git a/build-tools/scripts/src/main/groovy/geode-test.gradle b/build-tools/scripts/src/main/groovy/geode-test.gradle index 93488986e512..602f0b731651 100644 --- a/build-tools/scripts/src/main/groovy/geode-test.gradle +++ b/build-tools/scripts/src/main/groovy/geode-test.gradle @@ -182,7 +182,6 @@ gradle.taskGraph.whenReady({ graph -> if (project.hasProperty('testJVMVer') && testJVMVer.toInteger() >= 9) { jvmArgs += [ "--add-opens=java.base/java.io=ALL-UNNAMED", - "--add-opens=java.base/java.lang=ALL-UNNAMED", "--add-opens=java.base/java.lang.annotation=ALL-UNNAMED", "--add-opens=java.base/java.lang.module=ALL-UNNAMED", "--add-opens=java.base/java.lang.ref=ALL-UNNAMED", diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/deadlock/UnsafeThreadLocal.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/deadlock/UnsafeThreadLocal.java index 17872c29cb65..afabb84722d2 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/deadlock/UnsafeThreadLocal.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/deadlock/UnsafeThreadLocal.java @@ -14,72 +14,68 @@ */ package org.apache.geode.distributed.internal.deadlock; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; +import java.util.Map; +import java.util.WeakHashMap; /** - * Most of this thread local is safe to use, except for the getValue(Thread) method. That is not - * guaranteed to be correct. But for our deadlock detection tool I think it's good enough, and this - * class provides a very low overhead way for us to record what thread holds a particular resource. + * A ThreadLocal implementation that allows reading values from arbitrary threads, useful for + * deadlock detection. This implementation uses a WeakHashMap to track values per thread without + * requiring reflection or JVM internal access. * + *
+ * Unlike standard ThreadLocal, this class maintains an additional mapping that allows querying the + * value for any thread, not just the current thread. This is useful for deadlock detection where + * we need to inspect what resources other threads are holding. + *
* + *+ * The implementation uses WeakHashMap with Thread keys to ensure threads can be garbage collected + * when they terminate, preventing memory leaks. + *
*/ public class UnsafeThreadLocal+ * Unlike get(), this method does not set the initial value if none is found. Returns null if the + * specified thread has no value set. + *
+ * + * @param thread the thread whose value to retrieve + * @return the value for the specified thread, or null if none exists + */ + public T get(Thread thread) { + return threadValues.get(thread); } } diff --git a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/MemberJvmOptions.java b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/MemberJvmOptions.java index d0fa681f47f2..4021db507d62 100644 --- a/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/MemberJvmOptions.java +++ b/geode-gfsh/src/main/java/org/apache/geode/management/internal/cli/commands/MemberJvmOptions.java @@ -26,7 +26,7 @@ import java.util.Collections; import java.util.List; -import org.apache.geode.distributed.internal.deadlock.UnsafeThreadLocal; +import org.apache.geode.internal.offheap.AddressableMemoryManager; import org.apache.geode.internal.stats50.VMStats50; import org.apache.geode.unsafe.internal.com.sun.jmx.remote.security.MBeanServerAccessController; @@ -38,9 +38,9 @@ public class MemberJvmOptions { private static final String COM_SUN_JMX_REMOTE_SECURITY_EXPORT = "--add-exports=java.management/com.sun.jmx.remote.security=ALL-UNNAMED"; /** - * open needed by {@link UnsafeThreadLocal} + * open needed by {@link AddressableMemoryManager} */ - private static final String JAVA_LANG_OPEN = "--add-opens=java.base/java.lang=ALL-UNNAMED"; + private static final String JAVA_NIO_OPEN = "--add-opens=java.base/java.nio=ALL-UNNAMED"; /** * open needed by {@link VMStats50} */ @@ -50,7 +50,7 @@ public class MemberJvmOptions { static final List