Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2021-10-26 15:52:12 +0000
committerThomas Watson2021-11-02 13:51:13 +0000
commit7890b102fbad337f4f2aea05abf17dd8d3124475 (patch)
tree6c844ce8b529ab7363cb9eac545cb0b8efeab29a
parent07fdd58113b5f45e20257d4601f5ce108a4c90ee (diff)
downloadrt.equinox.framework-7890b102fbad337f4f2aea05abf17dd8d3124475.tar.gz
rt.equinox.framework-7890b102fbad337f4f2aea05abf17dd8d3124475.tar.xz
rt.equinox.framework-7890b102fbad337f4f2aea05abf17dd8d3124475.zip
Bug 575932 - cache existence of parent directoriesI20211103-1800I20211103-0020I20211102-1800I20211102-1020
For dependent and registered buddy policy it is possible that a large number of dependent and/or registered bundles can be queried for classes for a single hosting class loader. This results in many bundle files getting searched. For DirBundleFile this can be expensive because it involves checking for the existence of each file. This solution caches if the parent path of the entry lookup exists. The idea is that in most cases where an entry lookup doesn't exists the parent directory also doesn't exists. We cache a smaller number of existence checks and can do a faster lookup if files in an non-existing parent exist or not. Change-Id: Ibc4b48800335288bb0d2a770786c612c5d5eb6dc Signed-off-by: Thomas Watson <tjwatson@us.ibm.com> Reviewed-on: https://git.eclipse.org/r/c/equinox/rt.equinox.framework/+/186979 Tested-by: Equinox Bot <equinox-bot@eclipse.org>
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/DirBundleFile.java22
1 files changed, 21 insertions, 1 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/DirBundleFile.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/DirBundleFile.java
index 366c82b47..42483984f 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/DirBundleFile.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/bundlefile/DirBundleFile.java
@@ -16,7 +16,11 @@ package org.eclipse.osgi.storage.bundlefile;
import java.io.File;
import java.io.IOException;
-import java.util.*;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.osgi.internal.messages.Msg;
import org.eclipse.osgi.util.NLS;
@@ -30,6 +34,7 @@ public class DirBundleFile extends BundleFile {
private static final String POINTER_UPPER_DIRECTORY = "..";//$NON-NLS-1$
private final boolean enableStrictBundleEntryPath;
+ private final Map<File, Boolean> doesNotExistCache = new ConcurrentHashMap<>();
/**
* Constructs a DirBundleFile
@@ -52,7 +57,12 @@ public class DirBundleFile extends BundleFile {
public File getFile(String path, boolean nativeCode) {
final boolean checkInBundle = path != null && path.indexOf(POINTER_UPPER_DIRECTORY) >= 0;
File file = new File(this.basefile, path);
+ File parentFile = file.getParentFile();
+ if (!parentExists(parentFile)) {
+ return null;
+ }
if (!BundleFile.secureAction.exists(file)) {
+ cacheIfParentExists(parentFile);
return null;
}
@@ -106,6 +116,16 @@ public class DirBundleFile extends BundleFile {
return file;
}
+
+ private void cacheIfParentExists(File parentFile) {
+ doesNotExistCache.computeIfAbsent(parentFile, secureAction::isDirectory);
+ }
+
+ private boolean parentExists(File parentFile) {
+ Boolean exists = doesNotExistCache.get(parentFile);
+ return exists == null || exists.booleanValue();
+ }
+
@Override
public BundleEntry getEntry(String path) {
File filePath = getFile(path, false);

Back to the top