From 0dfac454d2cfd78671f3c51ad96c70810e9b2e32 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Tue, 14 Aug 2018 11:13:08 -0500 Subject: Bug 537505 - Fix issues with priming multiple cp entries When a host bundle has many classpath entries it was possible to miss the priming of the entries CDSBundleFile Change-Id: I4816b57bf425e202cbc4fa02ce5f0b7bd015a8ff Signed-off-by: Thomas Watson --- .../eclipse/osgi/internal/cds/CDSBundleFile.java | 8 +++++ .../eclipse/osgi/internal/cds/CDSHookImpls.java | 36 +++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSBundleFile.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSBundleFile.java index 39588afd4..941a4118e 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSBundleFile.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSBundleFile.java @@ -128,4 +128,12 @@ public class CDSBundleFile extends BundleFileWrapper { return null; return urlHelper.findSharedClass(null, url, name); } + + /** + * Returns the primed flag for this bundle file. + * @return the primed flag + */ + public boolean getPrimed() { + return this.primed; + } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java index 3322768e9..bde9bde34 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookImpls.java @@ -35,6 +35,7 @@ import org.eclipse.osgi.internal.hookregistry.HookRegistry; import org.eclipse.osgi.internal.loader.ModuleClassLoader; import org.eclipse.osgi.internal.loader.classpath.ClasspathEntry; import org.eclipse.osgi.internal.loader.classpath.ClasspathManager; +import org.eclipse.osgi.internal.loader.classpath.FragmentClasspath; import org.eclipse.osgi.storage.BundleInfo.Generation; import org.eclipse.osgi.storage.bundlefile.BundleEntry; import org.eclipse.osgi.storage.bundlefile.BundleFile; @@ -143,18 +144,41 @@ public class CDSHookImpls extends ClassLoaderHook implements BundleFileWrapperFa if (factory == null) { return; } - CDSBundleFile hostFile = null; try { SharedClassURLHelper urlHelper = factory.getURLHelper(classLoader); + boolean minimizeUpdateChecks = urlHelper.setMinimizeUpdateChecks(); // set the url helper for the host base CDSBundleFile - hostFile = getCDSBundleFile(classLoader.getClasspathManager().getGeneration().getBundleFile()); + CDSBundleFile hostFile = getCDSBundleFile(classLoader.getClasspathManager().getGeneration().getBundleFile()); if (hostFile != null) { hostFile.setURLHelper(urlHelper); - if (urlHelper.setMinimizeUpdateChecks()) { - // no need to prime if we were able to setsetMinimizeUpdateChecks + if (minimizeUpdateChecks) { + // no need to prime if we were able to setMinimizeUpdateChecks hostFile.setPrimed(true); } } + // No need to prime if we were able to setMinimizeUpdateChecks. + // Mark all the BundleFiles on the classpath as primed. + ClasspathManager cpManager = classLoader.getClasspathManager(); + for (ClasspathEntry entry : cpManager.getHostClasspathEntries()) { + CDSBundleFile cdsBundleFile = getCDSBundleFile(entry.getBundleFile()); + if (cdsBundleFile != null) { + cdsBundleFile.setURLHelper(urlHelper); + if (minimizeUpdateChecks) { + cdsBundleFile.setPrimed(true); + } + } + } + for (FragmentClasspath fragCP : cpManager.getFragmentClasspaths()) { + for (ClasspathEntry entry : fragCP.getEntries()) { + CDSBundleFile cdsBundleFile = getCDSBundleFile(entry.getBundleFile()); + if (cdsBundleFile != null) { + cdsBundleFile.setURLHelper(urlHelper); + if (minimizeUpdateChecks) { + cdsBundleFile.setPrimed(true); + } + } + } + } } catch (HelperAlreadyDefinedException e) { // We should never get here. // If we do, we simply won't share for this ClassLoader @@ -165,9 +189,11 @@ public class CDSHookImpls extends ClassLoaderHook implements BundleFileWrapperFa CDSBundleFile hostFile = getCDSBundleFile(hostmanager.getGeneration().getBundleFile()); CDSBundleFile sourceFile = getCDSBundleFile(sourceGeneration.getBundleFile()); if ((hostFile != sourceFile) && (null != hostFile) && (null != sourceFile)) { - // set the helper that got set on the host base bundle file in initializedClassLoader + // Set the helper that got set on the host base bundle file in classLoaderCreated. + // This is to handle the case where fragments are dynamically attached SharedClassURLHelper urlHelper = hostFile.getURLHelper(); sourceFile.setURLHelper(urlHelper); + sourceFile.setPrimed(hostFile.getPrimed()); } return false; -- cgit v1.2.3