diff options
author | Thomas Watson | 2018-08-14 14:43:40 +0000 |
---|---|---|
committer | Thomas Watson | 2018-08-14 14:43:40 +0000 |
commit | c26eaf1d2d4e9ddf1f1ec39bb03c4b07e68c4030 (patch) | |
tree | ebfd597bbc7d76bd4770715c1742e81581a878dd | |
parent | 9d7d4ab89cfd67c9bea95d1cc1b463ee5566bace (diff) | |
download | rt.equinox.framework-c26eaf1d2d4e9ddf1f1ec39bb03c4b07e68c4030.tar.gz rt.equinox.framework-c26eaf1d2d4e9ddf1f1ec39bb03c4b07e68c4030.tar.xz rt.equinox.framework-c26eaf1d2d4e9ddf1f1ec39bb03c4b07e68c4030.zip |
Bug 537505 - Additional changes after review
- Use Boolean.valueOf
- Use FrameworkLog for reporting errors when j9 is not used
- Change config property to j9.cds.reporterrors
- Define final constant for .class string
- Use ! operator instead of false ==
- Remove unecessary reflection on setMinimizeUpdateChecks since Java 6
is no longer supported
Change-Id: I4404841bd10c3a2c129f2581d97dcaee6181638b
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
4 files changed, 13 insertions, 61 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 f540a9eb5..39588afd4 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 @@ -34,6 +34,7 @@ import org.eclipse.osgi.storage.bundlefile.BundleFileWrapper; * shared classes cache. */ public class CDSBundleFile extends BundleFileWrapper { + private final static String classFileExt = ".class"; //$NON-NLS-1$ private URL url; // the URL to the content of the real bundle file private SharedClassURLHelper urlHelper; // the url helper set by the classloader private boolean primed = false; @@ -67,12 +68,11 @@ public class CDSBundleFile extends BundleFileWrapper { * shared classes cache. If found, the bytes representing the magic cookie are stored in CDSBundleEntry object. */ public BundleEntry getEntry(String path) { - String classFileExt = ".class"; //$NON-NLS-1$ BundleEntry wrappedEntry = super.getEntry(path); if (wrappedEntry == null) { return null; } - if ((false == primed) || (false == path.endsWith(classFileExt))) { + if (!primed || !path.endsWith(classFileExt)) { return wrappedEntry; } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookConfigurator.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookConfigurator.java index 42a71fc72..9891f4cb5 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookConfigurator.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/cds/CDSHookConfigurator.java @@ -22,18 +22,21 @@ package org.eclipse.osgi.internal.cds; +import org.eclipse.osgi.framework.log.FrameworkLogEntry; +import org.eclipse.osgi.internal.framework.EquinoxContainer; import org.eclipse.osgi.internal.hookregistry.HookConfigurator; import org.eclipse.osgi.internal.hookregistry.HookRegistry; +import org.eclipse.osgi.internal.log.EquinoxLogServices; public class CDSHookConfigurator implements HookConfigurator { - private static final String SUPPRESS_ERRORS = "j9.cds.suppresserrors"; //$NON-NLS-1$ + private static final String REPORT_ERRORS = "j9.cds.reporterrors"; //$NON-NLS-1$ private static final String DISABLE_CDS = "j9.cds.disable"; //$NON-NLS-1$ private static final String OLD_CDS_CONFIGURATOR = "com.ibm.cds.CDSHookConfigurator"; //$NON-NLS-1$ private static final String J9_SHARED_CLASS_HELPER_CLASS = "com.ibm.oti.shared.SharedClassHelperFactory"; //$NON-NLS-1$ public void addHooks(HookRegistry hookRegistry) { - boolean disableCDS = "true".equals(hookRegistry.getConfiguration().getProperty(DISABLE_CDS)); //$NON-NLS-1$ + boolean disableCDS = Boolean.valueOf(hookRegistry.getConfiguration().getProperty(DISABLE_CDS)); if (disableCDS) { return; } @@ -48,11 +51,12 @@ public class CDSHookConfigurator implements HookConfigurator { try { Class.forName(J9_SHARED_CLASS_HELPER_CLASS); } catch (ClassNotFoundException e) { - boolean reportErrors = "false".equals(hookRegistry.getConfiguration().getProperty(SUPPRESS_ERRORS)); //$NON-NLS-1$ + boolean reportErrors = Boolean.valueOf(hookRegistry.getConfiguration().getProperty(REPORT_ERRORS)); // not running on J9 if (reportErrors) { - System.err.println("The J9 Class Sharing Adaptor will not work in this configuration."); //$NON-NLS-1$ - System.err.println("You are not running on a J9 Java VM."); //$NON-NLS-1$ + EquinoxContainer container = hookRegistry.getContainer(); + EquinoxLogServices logServices = container.getLogServices(); + logServices.log(EquinoxContainer.NAME, FrameworkLogEntry.WARNING, "The J9 Class Sharing Adaptor will not work in this configuration. You are not running on a J9 Java VM.", null); //$NON-NLS-1$ } return; } 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 2166d275a..3322768e9 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 @@ -43,8 +43,6 @@ import org.eclipse.osgi.storage.bundlefile.BundleFileWrapperChain; public class CDSHookImpls extends ClassLoaderHook implements BundleFileWrapperFactoryHook { private static SharedClassHelperFactory factory = Shared.getSharedClassHelperFactory(); - private static java.lang.reflect.Method minimizeMethod = null; - private static boolean hasMinimizeMethod = true; /* Assume true to begin with */ // With Equinox bug 226038 (v3.4), the framework will now pass an instance // of BundleFileWrapperChain rather than the wrapped BundleFile. This is @@ -133,55 +131,6 @@ public class CDSHookImpls extends ClassLoaderHook implements BundleFileWrapperFa } } - /* Calling setMinimizeUpdateChecks() on the urlHelper tells it to only check the plugin jar for updates - * once on startup. This removes the need to "prime" plugins by always cacheing the first class from the jar. - * - * Java5 does not have a runMinimizeUpdateChecks method, but Java6 does. The text below explains why. - * - * Java6 has an improved jar update detection mechanism which is event-driven and listens for - * real jar open and close events. It will check jar timestamps on every class-load for closed jars (when - * loading cached classes from those jars) and not check them if it knows the jars are open. - * - * Java5 didn't know about jar open/close events so simply assumed that the first class to be stored by - * a plugin implied that its jar was opened indefinitely. This is why it helps to "prime" a plugin when - * running under Java5 - by storing a class, the jar is opened and the JVM stops checking its timestamp - * which results in faster startup. - * - * While the Java6 behaviour is more correct (it will pick up changes if a jar is closed after having been opened), - * if the jars are not opened or "primed", then it will perform constant checks on their timestamps which hurts startup times. - * This is why setMinimizeUpdateChecks was introduced - it's a means of saying to the urlHelper - regardless of - * whether my container(s) is open or closed, I only want you to check it once for updates. - * - * The consequence of this is that less file handles are open on startup in Java6. - * - * This has been written in such a way that this adaptor will continue to work exactly the same with Java5, but - * will adapt its behaviour when used with Java6 to do the right thing. - */ - private boolean runMinimizeMethod(SharedClassURLHelper urlHelper) { - if (hasMinimizeMethod && (urlHelper != null)) { - if (minimizeMethod == null) { - hasMinimizeMethod = false; /* Assume failure - prove success below */ - try { - Class<?> c = urlHelper.getClass(); - minimizeMethod = c.getMethod("setMinimizeUpdateChecks"); //$NON-NLS-1$ - minimizeMethod.setAccessible(true); - hasMinimizeMethod = true; - } catch (Exception e) { - /* hasMinimizeMethod will be false and we won't try this again */ - } - } - if (minimizeMethod != null) { - try { - minimizeMethod.invoke(urlHelper); - return true; - } catch (Exception e) { - hasMinimizeMethod = false; - } - } - } - return false; - } - private boolean hasMagicClassNumber(byte[] classbytes) { if (classbytes == null || classbytes.length < 4) return false; @@ -197,13 +146,12 @@ public class CDSHookImpls extends ClassLoaderHook implements BundleFileWrapperFa CDSBundleFile hostFile = null; try { SharedClassURLHelper urlHelper = factory.getURLHelper(classLoader); - boolean minimizeSucceeded = runMinimizeMethod(urlHelper); // set the url helper for the host base CDSBundleFile hostFile = getCDSBundleFile(classLoader.getClasspathManager().getGeneration().getBundleFile()); if (hostFile != null) { hostFile.setURLHelper(urlHelper); - if (minimizeSucceeded) { - /* In Java6, there is no longer a requirement to "prime" plugins */ + if (urlHelper.setMinimizeUpdateChecks()) { + // no need to prime if we were able to setsetMinimizeUpdateChecks hostFile.setPrimed(true); } } diff --git a/bundles/org.eclipse.osgi/osgi/j9stubs.jar b/bundles/org.eclipse.osgi/osgi/j9stubs.jar Binary files differindex 597a2d4b6..4053e6cdc 100644 --- a/bundles/org.eclipse.osgi/osgi/j9stubs.jar +++ b/bundles/org.eclipse.osgi/osgi/j9stubs.jar |