Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDEV-5023 debug timings for loading java objects (test only) #2459

Draft
wants to merge 2 commits into
base: 6.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions core/src/main/java/lucee/commons/lang/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Throwable> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Resource> _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());
}
}
}
Expand All @@ -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<Resource> _resources)
Stopwatch stopwatch = new Stopwatch(Stopwatch.UNIT_NANO);
stopwatch.start();

classLoaders.put(key, rpccl = new PhysicalClassLoader(c, new ArrayList<Resource>(), dir, SystemUtil.getCombinedClassLoader(), bcl, null, true));
lucee.aprint.o("PhysicalClassLoader.getRPCClassLoader2: " + stopwatch.time());
}
}
}
Expand Down
43 changes: 26 additions & 17 deletions core/src/main/java/lucee/runtime/ComponentPageImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion core/src/main/java/lucee/runtime/listener/JavaSettingsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> names = new ArrayList<>();

// maven
Expand Down Expand Up @@ -449,22 +453,41 @@ 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) {
lucee.aprint.o(addionalResources);
if (mapPath == null) mapPath = new HashMap<>();
Stopwatch stopwatch2 = new Stopwatch(Stopwatch.UNIT_NANO);

if (addionalResources instanceof Resource[]) {
for (Resource r: (Resource[]) addionalResources) {
stopwatch2.start();
r = ResourceUtil.getCanonicalResourceEL(r);
lucee.aprint.o("JavaSettingsImpl.getInstance: res.getCanonicalResourceEL " + stopwatch2.time());

stopwatch2.start();
mapPath.put("paths:" + r.getAbsolutePath(), r);
lucee.aprint.o("JavaSettingsImpl.getInstance: res.getAbsolutePath " + stopwatch2.time());

}
}
else if (addionalResources instanceof List) {
for (Resource r: (List<Resource>) addionalResources) {

stopwatch2.start();
r = ResourceUtil.getCanonicalResourceEL(r);
lucee.aprint.o("JavaSettingsImpl.getInstance: list.getCanonicalResourceEL " + stopwatch2.time());

stopwatch2.start();
mapPath.put("paths:" + r.getAbsolutePath(), r);
lucee.aprint.o("JavaSettingsImpl.getInstance: list.getAbsolutePath " + stopwatch2.time());

}
}
lucee.aprint.o(mapPath);
}
Collection<Resource> paths = null;
if (mapPath != null) {
Expand Down Expand Up @@ -548,16 +571,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
Loading