diff --git a/core/src/main/java/lucee/commons/lang/ClassUtil.java b/core/src/main/java/lucee/commons/lang/ClassUtil.java index 8e4354f6f4..b0ace3f38c 100644 --- a/core/src/main/java/lucee/commons/lang/ClassUtil.java +++ b/core/src/main/java/lucee/commons/lang/ClassUtil.java @@ -55,6 +55,7 @@ import lucee.runtime.osgi.OSGiUtil; import lucee.runtime.osgi.OSGiUtil.BundleDefinition; import lucee.runtime.reflection.Reflector; +import lucee.runtime.timer.Stopwatch; import lucee.runtime.type.Array; import lucee.runtime.type.util.ListUtil; import lucee.transformer.dynamic.DynamicInvoker; @@ -312,29 +313,47 @@ public static Class loadClass(ClassLoader cl, String className, Class defaultVal private static Class loadClass(ClassLoader cl, String className, Class defaultValue, Set exceptions) { + Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO); + stopwatch.start(); + if (cl != null) { Class clazz = _loadClass(new ClassLoaderBasedClassLoading(cl), className, defaultValue, exceptions); if (clazz != null) return clazz; } + lucee.aprint.o("ClassUtil.loadClass..ClassLoaderBasedClassLoading: " + stopwatch.time()); + stopwatch.start(); + // MUST javasettings? // OSGI env Class clazz = _loadClass(new OSGiBasedClassLoading(), className, null, exceptions); if (clazz != null) return clazz; + lucee.aprint.o("ClassUtil.loadClass..osgi: " + stopwatch.time()); + stopwatch.start(); + + // core classloader if (cl != SystemUtil.getCoreClassLoader()) { clazz = _loadClass(new ClassLoaderBasedClassLoading(SystemUtil.getCoreClassLoader()), className, null, exceptions); if (clazz != null) return clazz; } + lucee.aprint.o("ClassUtil.loadClass..core: " + stopwatch.time()); + stopwatch.start(); + + // loader classloader if (cl != SystemUtil.getLoaderClassLoader()) { clazz = _loadClass(new ClassLoaderBasedClassLoading(SystemUtil.getLoaderClassLoader()), className, null, exceptions); if (clazz != null) return clazz; } + lucee.aprint.o("ClassUtil.loadClass.loader: " + stopwatch.time()); + stopwatch.start(); + + return defaultValue; } diff --git a/core/src/main/java/lucee/commons/lang/PhysicalClassLoader.java b/core/src/main/java/lucee/commons/lang/PhysicalClassLoader.java index 57ba70d279..15b5cd6dbc 100644 --- a/core/src/main/java/lucee/commons/lang/PhysicalClassLoader.java +++ b/core/src/main/java/lucee/commons/lang/PhysicalClassLoader.java @@ -53,6 +53,7 @@ import lucee.runtime.listener.JavaSettings; import lucee.runtime.listener.JavaSettingsImpl; import lucee.runtime.listener.SerializationSettings; +import lucee.runtime.timer.Stopwatch; import lucee.runtime.type.Struct; import lucee.runtime.type.StructImpl; import lucee.runtime.type.util.KeyConstants; @@ -141,7 +142,10 @@ public static PhysicalClassLoader getRPCClassLoader(Config c, JavaSettings js, b } Resource dir = storeResourceMeta(c, key, js, resources); // (Config config, String key, JavaSettings js, Collection _resources) + Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO); + stopwatch.start(); classLoaders.put(key, rpccl = new PhysicalClassLoader(c, resources, dir, parent != null ? parent : SystemUtil.getCombinedClassLoader(), null, null, true)); + lucee.aprint.o("PhysicalClassLoader.getRPCClassLoader: " + stopwatch.time()); } } } @@ -158,7 +162,11 @@ public static PhysicalClassLoader getRPCClassLoader(Config c, BundleClassLoader Resource dir = c.getClassDirectory().getRealResource("RPC/" + key); if (!dir.exists()) ResourceUtil.createDirectoryEL(dir, true); // (Config config, String key, JavaSettings js, Collection _resources) + Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO); + stopwatch.start(); + classLoaders.put(key, rpccl = new PhysicalClassLoader(c, new ArrayList(), dir, SystemUtil.getCombinedClassLoader(), bcl, null, true)); + lucee.aprint.o("PhysicalClassLoader.getRPCClassLoader2: " + stopwatch.time()); } } } diff --git a/core/src/main/java/lucee/runtime/ComponentPageImpl.java b/core/src/main/java/lucee/runtime/ComponentPageImpl.java index dedc134fdf..90efc7a669 100755 --- a/core/src/main/java/lucee/runtime/ComponentPageImpl.java +++ b/core/src/main/java/lucee/runtime/ComponentPageImpl.java @@ -71,6 +71,7 @@ import lucee.runtime.rest.Result; import lucee.runtime.rest.Source; import lucee.runtime.rest.path.Path; +import lucee.runtime.timer.Stopwatch; import lucee.runtime.type.Array; import lucee.runtime.type.ArrayImpl; import lucee.runtime.type.Collection; @@ -1164,32 +1165,40 @@ public void setStaticScope(StaticScope staticScope) { } public JavaSettings getJavaSettings(PageContext pc, ComponentProperties properties) throws IOException { + Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO); + stopwatch.start(); + if (!initJS) { + lucee.aprint.o("ComponentPageImpl.getJavaSettings: getJson " + stopwatch.time()); + String json = properties.meta == null ? null : Caster.toString(properties.meta.get(KeyConstants._javasettings, null), null); + if (StringUtil.isEmpty(json, true)) { + initJS = true; + lucee.aprint.o("ComponentPageImpl.getJavaSettings: skip " + stopwatch.time()); + return js; + } synchronized (properties) { if (!initJS) { - // TODO cache - String json = properties.meta == null ? null : Caster.toString(properties.meta.get(KeyConstants._javasettings, null), null); - if (!StringUtil.isEmpty(json, true)) { - json = json.trim(); - try { - if (StringUtil.endsWithIgnoreCase(json, ".json")) { - pc = ThreadLocalPageContext.get(pc); - if (pc != null) json = IOUtil.toString(ResourceUtil.toResourceExisting(pc, json), CharsetUtil.UTF8); - else json = IOUtil.toString(ResourceUtil.toResourceExisting(ThreadLocalPageContext.getConfig(), json), CharsetUtil.UTF8); - } - - Struct sct = Caster.toStruct(new JSONExpressionInterpreter().interpret(null, json)); - js = JavaSettingsImpl.getInstance(ThreadLocalPageContext.getConfig(pc), sct, null); - } - catch (Exception e) { - // LogUtil.log("component", e); - throw ExceptionUtil.toIOException(e); + // TODO cache + json = json.trim(); + try { + if (StringUtil.endsWithIgnoreCase(json, ".json")) { + pc = ThreadLocalPageContext.get(pc); + if (pc != null) json = IOUtil.toString(ResourceUtil.toResourceExisting(pc, json), CharsetUtil.UTF8); + else json = IOUtil.toString(ResourceUtil.toResourceExisting(ThreadLocalPageContext.getConfig(), json), CharsetUtil.UTF8); } + + Struct sct = Caster.toStruct(new JSONExpressionInterpreter().interpret(null, json)); + js = JavaSettingsImpl.getInstance(ThreadLocalPageContext.getConfig(pc), sct, null); + } + catch (Exception e) { + // LogUtil.log("component", e); + throw ExceptionUtil.toIOException(e); } initJS = true; } } } + lucee.aprint.o("ComponentPageImpl.getJavaSettings: " + stopwatch.time()); return js; } diff --git a/core/src/main/java/lucee/runtime/functions/other/JavaProxy.java b/core/src/main/java/lucee/runtime/functions/other/JavaProxy.java index 5d4d99dcd2..c57a44474d 100644 --- a/core/src/main/java/lucee/runtime/functions/other/JavaProxy.java +++ b/core/src/main/java/lucee/runtime/functions/other/JavaProxy.java @@ -47,6 +47,7 @@ import lucee.runtime.op.Decision; import lucee.runtime.osgi.OSGiUtil.BundleDefinition; import lucee.runtime.security.SecurityManager; +import lucee.runtime.timer.Stopwatch; import lucee.runtime.type.Array; import lucee.runtime.type.Struct; import lucee.runtime.type.util.KeyConstants; @@ -172,14 +173,19 @@ private static Class loadClassByPath(PageContext pc, String className, String // load class try { JavaSettingsImpl js = null; + Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO); if (resources != null && !resources.isEmpty()) { js = (JavaSettingsImpl) JavaSettingsImpl.getInstance(pc.getConfig(), null, resources); } + stopwatch.start(); ClassLoader cl = pci.getRPCClassLoader(js); + lucee.aprint.o("JavaProxy.getRPCClassLoader: " + stopwatch.time()); Class clazz = null; try { + stopwatch.start(); clazz = ClassUtil.loadClass(cl, className); + lucee.aprint.o("JavaProxy.loadClass: " + stopwatch.time()); } catch (ClassException ce) { // try java.lang if no package definition diff --git a/core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java b/core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java index 70386ee966..af1f5a4f55 100644 --- a/core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java +++ b/core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java @@ -43,6 +43,7 @@ import lucee.runtime.op.Caster; import lucee.runtime.op.Decision; import lucee.runtime.osgi.BundleFile; +import lucee.runtime.timer.Stopwatch; import lucee.runtime.type.Array; import lucee.runtime.type.ArrayImpl; import lucee.runtime.type.Struct; @@ -352,6 +353,9 @@ public String[] watchedExtensions() { public static JavaSettings getInstance(Config config, Struct data, Object addionalResources) { + Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO); + stopwatch.start(); + List names = new ArrayList<>(); // maven @@ -449,6 +453,8 @@ public static JavaSettings getInstance(Config config, Struct data, Object addion } } } + lucee.aprint.o("JavaSettingsImpl.getInstance: add res " + stopwatch.time()); + stopwatch.start(); // addional resources if (addionalResources != null) { @@ -548,16 +554,20 @@ else if (addionalResources instanceof List) { Collections.sort(names); String id = HashUtil.create64BitHashAsString(names.toString()); + JavaSettings js = ((ConfigPro) config).getJavaSettings(id); if (js != null) { + lucee.aprint.o("JavaSettingsImpl.getInstance: withJs" + stopwatch.time()); return js; } + lucee.aprint.o("JavaSettingsImpl.getInstance: noJs " + stopwatch.time()); + stopwatch.start(); js = new JavaSettingsImpl(id, config, poms, osgis, paths == null ? RESOURCE_EMPTY : paths.toArray(new Resource[paths.size()]), bundles == null ? RESOURCE_EMPTY : bundles.toArray(new Resource[bundles.size()]), loadCFMLClassPath, reloadOnChange, watchInterval, extensions.toArray(new String[extensions.size()])); - + lucee.aprint.o("JavaSettingsImpl.getInstance new JavaSettingsImpl: " + stopwatch.time()); ((ConfigPro) config).setJavaSettings(id, js); return js; } diff --git a/core/src/main/java/lucee/runtime/listener/ModernApplicationContext.java b/core/src/main/java/lucee/runtime/listener/ModernApplicationContext.java index 4ad33ec67c..39b5e898cf 100644 --- a/core/src/main/java/lucee/runtime/listener/ModernApplicationContext.java +++ b/core/src/main/java/lucee/runtime/listener/ModernApplicationContext.java @@ -79,6 +79,7 @@ import lucee.runtime.rest.RestSettings; import lucee.runtime.tag.Query; import lucee.runtime.tag.listener.TagListener; +import lucee.runtime.timer.Stopwatch; import lucee.runtime.type.Array; import lucee.runtime.type.ArrayImpl; import lucee.runtime.type.Collection; @@ -1742,22 +1743,34 @@ public void setJavaSettings(JavaSettings javaSettings) { @Override public ClassLoader getRPCClassLoader() throws IOException { + Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO); + stopwatch.start(); + if (!initClassLoader) { // PATCH to avoid cycle if (initClassLoaderBefore) { return getDefaultClassLoader(config); } initClassLoaderBefore = true; + lucee.aprint.o("ModernApplicationContext.getRPCClassLoader getDefaultClassLoader: " + stopwatch.time()); + stopwatch.start(); cl = getDefaultClassLoader(config); Object o = javaSettings != null ? null : get(component, KeyConstants._javasettings, null); + lucee.aprint.o("ModernApplicationContext.getRPCClassLoader: b4js " + stopwatch.time()); + stopwatch.start(); if (javaSettings != null || (o != null && Decision.isStruct(o))) { if (javaSettings == null) javaSettings = JavaSettingsImpl.getInstance(config, Caster.toStruct(o, null), null); + lucee.aprint.o("ModernApplicationContext.config.getRPCClassLoader: js " + stopwatch.time()); + stopwatch.start(); cl = ((ConfigPro) config).getRPCClassLoader(false, javaSettings, cl); + lucee.aprint.o("ModernApplicationContext.config.getRPCClassLoader: post " + stopwatch.time()); + stopwatch.start(); } initClassLoader = true; initClassLoaderBefore = false; } + lucee.aprint.o("ModernApplicationContext.getRPCClassLoader: " + stopwatch.time()); return cl; } @@ -1773,13 +1786,17 @@ public JavaSettings getJavaSettings() { } public static ClassLoader getDefaultClassLoader(ConfigWeb config) throws IOException { + Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO); + stopwatch.start(); if (defaultClassLoader == null) { + synchronized (token) { if (defaultClassLoader == null) { defaultClassLoader = ((ConfigPro) config).getRPCClassLoader(false, ((ConfigPro) config).getJavaSettings(), null); } } } + lucee.aprint.o("ModernApplicationContext.getDefaultClassLoader: " + stopwatch.time()); return defaultClassLoader; }