Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnjum Fatima2019-06-06 20:33:19 +0000
committerThomas Watson2019-06-10 12:19:27 +0000
commit7e858cf2d9b52934e943b584b0975eeda8e27fb3 (patch)
treeeccdd5394341577ea3e94f509c10a0a05b4947f1
parent6a09934020229233b209d32545fbcb0a0bdd1128 (diff)
downloadrt.equinox.framework-7e858cf2d9b52934e943b584b0975eeda8e27fb3.tar.gz
rt.equinox.framework-7e858cf2d9b52934e943b584b0975eeda8e27fb3.tar.xz
rt.equinox.framework-7e858cf2d9b52934e943b584b0975eeda8e27fb3.zip
Bug 548017 - Reduce contention in BundleLoaderSources.getPackageSource()
Change-Id: Idcfb5d02d66f1be20c627e362148439f43733408 Signed-off-by: Anjum Fatima <anjum.eclipse@gmail.com>
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoaderSources.java25
1 files changed, 12 insertions, 13 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoaderSources.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoaderSources.java
index 982a2cd2d..a4a7f7523 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoaderSources.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/loader/BundleLoaderSources.java
@@ -14,8 +14,9 @@
package org.eclipse.osgi.internal.loader;
import java.security.AccessController;
-import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import org.eclipse.osgi.container.ModuleCapability;
import org.eclipse.osgi.framework.util.SecureAction;
import org.eclipse.osgi.internal.loader.sources.FilteredSourcePackage;
@@ -25,23 +26,22 @@ import org.osgi.framework.namespace.PackageNamespace;
public class BundleLoaderSources {
static SecureAction secureAction = AccessController.doPrivileged(SecureAction.createSecureAction());
- private final Map<String, PackageSource> pkgSources;
+ private final ConcurrentMap<String, PackageSource> pkgSources;
private final BundleLoader loader;
public BundleLoaderSources(BundleLoader loader) {
- this.pkgSources = new HashMap<>();
+ this.pkgSources = new ConcurrentHashMap<>();
this.loader = loader;
}
PackageSource getPackageSource(String pkgName) {
- synchronized (pkgSources) {
- PackageSource pkgSource = pkgSources.get(pkgName);
- if (pkgSource == null) {
- pkgSource = new SingleSourcePackage(pkgName, loader);
- pkgSources.put(pkgSource.getId(), pkgSource);
- }
+ PackageSource pkgSource = pkgSources.get(pkgName);
+ if (pkgSource != null) {
return pkgSource;
}
+ PackageSource newSource = new SingleSourcePackage(pkgName, loader);
+ PackageSource existingSource = pkgSources.putIfAbsent(newSource.getId(), newSource);
+ return existingSource != null ? existingSource : newSource;
}
boolean forceSourceCreation(ModuleCapability packageCapability) {
@@ -68,10 +68,9 @@ public class BundleLoaderSources {
if (storeSource) {
if (pkgSource != null) {
- synchronized (pkgSources) {
- if (pkgSources.get(name) == null) {
- pkgSources.put(pkgSource.getId(), pkgSource);
- }
+ PackageSource existingSource = pkgSources.putIfAbsent(pkgSource.getId(), pkgSource);
+ if (existingSource != null) {
+ pkgSource = existingSource;
}
}
} else {

Back to the top