Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove url ref in native scenario #14006

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
*/
package org.apache.dubbo.common.utils;

import org.apache.dubbo.common.aot.NativeDetector;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.resource.GlobalResourcesRepository;

import java.io.IOException;
import java.lang.ref.SoftReference;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -32,7 +30,6 @@
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;

Expand Down Expand Up @@ -81,15 +78,9 @@ public static Set<URL> loadResources(String fileName, ClassLoader currentClassLo
Enumeration<URL> urls;
try {
urls = currentClassLoader.getResources(fileName);
boolean isNative = NativeDetector.inNativeImage();
if (urls != null) {
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (isNative) {
// In native mode, the address of each URL is the same instead of different paths, so it is
// necessary to set the ref to make it different
setRef(url);
}
set.add(url);
}
}
Expand All @@ -113,15 +104,6 @@ public static void destroy() {
}
}

private static void setRef(URL url) {
try {
Field field = URL.class.getDeclaredField("ref");
field.setAccessible(true);
field.set(url, UUID.randomUUID().toString());
} catch (Throwable ignore) {
}
}

// for test
protected static SoftReference<Map<ClassLoader, Map<String, Set<URL>>>> getClassLoaderResourcesCache() {
return classLoaderResourcesCache;
Expand Down
Loading