From cd11c995216358a26e83c35dfdd29bd38850c6e8 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Fri, 6 Dec 2024 09:18:08 +0100 Subject: [PATCH] clean up --- .../lucee/runtime/osgi/EnvClassLoader.java | 74 ++++++++++--------- .../transformer/dynamic/DynamicInvoker.java | 73 ++++++++---------- .../lucee/transformer/dynamic/meta/Clazz.java | 74 ++++++++----------- .../dynamic/meta/dynamic/ClazzDynamic.java | 68 ++++++++--------- loader/build.xml | 2 +- loader/pom.xml | 2 +- 6 files changed, 132 insertions(+), 161 deletions(-) diff --git a/core/src/main/java/lucee/runtime/osgi/EnvClassLoader.java b/core/src/main/java/lucee/runtime/osgi/EnvClassLoader.java index f1624693fd..fed9ed1ae4 100644 --- a/core/src/main/java/lucee/runtime/osgi/EnvClassLoader.java +++ b/core/src/main/java/lucee/runtime/osgi/EnvClassLoader.java @@ -85,13 +85,14 @@ public URL getResource(String name) { if (trace == null) { return (java.net.URL) load(name, URL, true, null, true); } - double start = SystemUtil.millis(); - try { - return (java.net.URL) load(name, URL, true, null, true); - } - finally { - trace.trace("EnvClassLoader", "EnvClassLoader.getResource(" + name + "):" + (SystemUtil.millis() - start)); - } + // double start = SystemUtil.millis(); + // try { + return (java.net.URL) load(name, URL, true, null, true); + // } + // finally { + // trace.trace("EnvClassLoader", "EnvClassLoader.getResource(" + name + "):" + (SystemUtil.millis() + // - start)); + // } } @@ -100,13 +101,14 @@ public InputStream getResourceAsStream(String name) { if (trace == null) { return (InputStream) load(name, STREAM, true, null, true); } - double start = SystemUtil.millis(); - try { - return (InputStream) load(name, STREAM, true, null, true); - } - finally { - trace.trace("EnvClassLoader", "EnvClassLoader.getResourceAsStream(" + name + "):" + (SystemUtil.millis() - start)); - } + // double start = SystemUtil.millis(); + // try { + return (InputStream) load(name, STREAM, true, null, true); + // } + // finally { + // trace.trace("EnvClassLoader", "EnvClassLoader.getResourceAsStream(" + name + "):" + + // (SystemUtil.millis() - start)); + // } } @Override @@ -118,16 +120,17 @@ public Enumeration getResources(String name) throws IOException { if (url != null) list.add(url); return new E(list.iterator()); } - double start = SystemUtil.millis(); - try { - List list = new ArrayList(); - URL url = (URL) load(name, URL, false, null, true); - if (url != null) list.add(url); - return new E(list.iterator()); - } - finally { - trace.trace("EnvClassLoader", "EnvClassLoader.getResources(" + name + "):" + (SystemUtil.millis() - start)); - } + // double start = SystemUtil.millis(); + // try { + List list = new ArrayList(); + URL url = (URL) load(name, URL, false, null, true); + if (url != null) list.add(url); + return new E(list.iterator()); + // } + // finally { + // trace.trace("EnvClassLoader", "EnvClassLoader.getResources(" + name + "):" + (SystemUtil.millis() + // - start)); + // } } @Override @@ -139,17 +142,18 @@ protected synchronized Class loadClass(String name, boolean resolve) throws C if (resolve) resolveClass(c); return c; } - double start = SystemUtil.millis(); - try { - Class c = findLoadedClass(name); - if (c == null) c = (Class) load(name, CLASS, true, null, true); - if (c == null) c = findClass(name); - if (resolve) resolveClass(c); - return c; - } - finally { - trace.trace("EnvClassLoader", "EnvClassLoader.loadClass(" + name + "):" + (SystemUtil.millis() - start)); - } + // double start = SystemUtil.millis(); + // try { + Class c = findLoadedClass(name); + if (c == null) c = (Class) load(name, CLASS, true, null, true); + if (c == null) c = findClass(name); + if (resolve) resolveClass(c); + return c; + // } + // finally { + // trace.trace("EnvClassLoader", "EnvClassLoader.loadClass(" + name + "):" + (SystemUtil.millis() - + // start)); + // } } diff --git a/core/src/main/java/lucee/transformer/dynamic/DynamicInvoker.java b/core/src/main/java/lucee/transformer/dynamic/DynamicInvoker.java index 407af783be..70e8a72ceb 100644 --- a/core/src/main/java/lucee/transformer/dynamic/DynamicInvoker.java +++ b/core/src/main/java/lucee/transformer/dynamic/DynamicInvoker.java @@ -30,7 +30,6 @@ import org.objectweb.asm.Type; import lucee.aprint; -import lucee.print; import lucee.commons.digest.HashUtil; import lucee.commons.io.SystemUtil; import lucee.commons.io.log.Log; @@ -142,38 +141,28 @@ public Clazz getClazz(Class clazz, boolean useReflection) { return Clazz.getClazz(clazz, root, log, useReflection); } - private static double getClass = 0; - private static double match = 0; - private static double types = 0; - private static double getDeclaringClass = 0; - private static double lclassPath = 0; - private static double pathName = 0; - private static double clsLoader = 0; - private static double loadInstance = 0; - private static int count = 0; - + /* + * private static double getClass = 0; private static double match = 0; private static double types + * = 0; private static double getDeclaringClass = 0; private static double lclassPath = 0; private + * static double pathName = 0; private static double clsLoader = 0; private static double + * loadInstance = 0; private static int count = 0; + */ public Pair createInstance(Class clazz, Key methodName, Object[] arguments, boolean convertComparsion) throws NoSuchMethodException, IOException, UnmodifiableClassException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, SecurityException, PageException { - count++; - if ((count % 500) == 0) { - print.e("-------------------"); - print.e("getClass:" + getClass); - print.e("match:" + match); - print.e("types:" + types); - print.e("getDeclaringClass:" + getDeclaringClass); - print.e("lclassPath:" + lclassPath); - print.e("pathName:" + pathName); - print.e("clsLoader:" + clsLoader); - print.e("loadInstance:" + loadInstance); - } + /* + * count++; if ((count % 500) == 0) { print.e("-------------------"); print.e("getClass:" + + * getClass); print.e("match:" + match); print.e("types:" + types); print.e("getDeclaringClass:" + + * getDeclaringClass); print.e("lclassPath:" + lclassPath); print.e("pathName:" + pathName); + * print.e("clsLoader:" + clsLoader); print.e("loadInstance:" + loadInstance); } + */ - double start = SystemUtil.millis(); + // double start = SystemUtil.millis(); boolean isConstr = methodName == null; Clazz clazzz = getClazz(clazz); - getClass += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // getClass += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); lucee.transformer.dynamic.meta.FunctionMember fm = null; lucee.transformer.dynamic.meta.Method method = null; @@ -185,15 +174,15 @@ public Pair createInstance(Class clazz, Key methodNam // Clazz clazz, final Collection.Key methodName, final Object[] args, boolean convertArgument fm = method = Clazz.getMethodMatch(clazzz, methodName, arguments, true, convertComparsion); } - match += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // match += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); - types += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // types += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); clazz = fm.getDeclaringClass(); // we wanna go as low as possible, to be as open as possible also this avoid not allow to access - getDeclaringClass += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // getDeclaringClass += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); StringBuilder sbClassPath = new StringBuilder(); sbClassPath.append(clazz.getName().replace('.', '/')).append('/').append(isConstr ? "____init____" : fm.getName()); @@ -204,17 +193,17 @@ public Pair createInstance(Class clazz, Key methodNam } sbClassPath.append('_').append(HashUtil.create64BitHashAsString(sbArgs, Character.MAX_RADIX)); } - lclassPath += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // lclassPath += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); String classPath = Clazz.getPackagePrefix() + sbClassPath.toString();// StringUtil.replace(sbClassPath.toString(), "javae/lang/", "java_lang/", false); String className = classPath.replace('/', '.'); - pathName += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // pathName += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); DynamicClassLoader loader = getCL(clazz); - clsLoader += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // clsLoader += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); if (loader.hasClass(className)) { try { return new Pair(fm, loader.loadInstance(className)); @@ -223,11 +212,11 @@ public Pair createInstance(Class clazz, Key methodNam catch (Exception e) { // simply ignore when fail } - finally { - loadInstance += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // finally { + // loadInstance += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); - } + // } } synchronized (SystemUtil.createToken("dyninvocer", className)) { Class[] parameterClasses = fm.getArgumentClasses(); diff --git a/core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java b/core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java index 1b13dc3cdd..644551895d 100644 --- a/core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java +++ b/core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java @@ -10,7 +10,6 @@ import org.objectweb.asm.Type; -import lucee.print; import lucee.commons.io.SystemUtil; import lucee.commons.io.log.Log; import lucee.commons.io.res.Resource; @@ -90,43 +89,32 @@ public static Clazz getClazz(Class clazz, Resource root, Log log) { private static Map>> cachedMethods = new ConcurrentHashMap<>(); private static RefInteger nirvana = new RefIntegerImpl(); - private static double cleanArgs = 0; - private static double checkAccessibility = 0; - private static double lmethods = 0; - private static double cache = 0; - private static double exact = 0; - private static double like = 0; - private static double convert = 0; - private static double lclasses = 0; - private static double lclasses2 = 0; - private static int count = 0; + /* + * private static double cleanArgs = 0; private static double checkAccessibility = 0; private static + * double lmethods = 0; private static double cache = 0; private static double exact = 0; private + * static double like = 0; private static double convert = 0; private static double lclasses = 0; + * private static double lclasses2 = 0; private static int count = 0; + */ public static Method getMethodMatch(Clazz clazz, final Collection.Key methodName, Object[] args, boolean convertArgument, boolean convertComparsion) throws NoSuchMethodException, IOException, PageException { - count++; - if ((count % 500) == 0) { - print.e("-------------------"); - print.e("cleanArgs:" + cleanArgs); - print.e("checkAccessibility:" + checkAccessibility); - print.e("lmethods:" + lmethods); - print.e("cache:" + cache); - print.e("exact:" + exact); - print.e("like:" + like); - print.e("convert:" + convert); - print.e("lclasses:" + lclasses); - print.e("lclasses2:" + lclasses2); - } - double start = SystemUtil.millis(); + /* + * count++; if ((count % 500) == 0) { print.e("-------------------"); print.e("cleanArgs:" + + * cleanArgs); print.e("checkAccessibility:" + checkAccessibility); print.e("lmethods:" + lmethods); + * print.e("cache:" + cache); print.e("exact:" + exact); print.e("like:" + like); print.e("convert:" + * + convert); print.e("lclasses:" + lclasses); print.e("lclasses2:" + lclasses2); } double start = + * SystemUtil.millis(); + */ args = Reflector.cleanArgs(args); - cleanArgs += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // cleanArgs += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); List methods = clazz.getMethods(methodName.getString(), false, args.length); - lmethods += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // lmethods += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); if (methods != null && methods.size() > 0) { Class[] clazzArgs = Reflector.getClasses(args); @@ -156,13 +144,13 @@ public static Method getMethodMatch(Clazz clazz, final Collection.Key methodName return p.getName(); } } - cache += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // cache += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); Reflector.checkAccessibility(clazz.getDeclaringClass(), methodName); - checkAccessibility += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // checkAccessibility += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); // exact comparsion outer: for (Method m: methods) { @@ -176,8 +164,8 @@ public static Method getMethodMatch(Clazz clazz, final Collection.Key methodName return m; } } - exact += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // exact += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); // like comparsion outer: for (Method m: methods) { @@ -191,8 +179,8 @@ public static Method getMethodMatch(Clazz clazz, final Collection.Key methodName return m; } } - like += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // like += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); // convert comparsion Pair result = null; @@ -219,8 +207,8 @@ public static Method getMethodMatch(Clazz clazz, final Collection.Key methodName } } } - convert += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // convert += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); if (result != null) { if (convertArgument) { Object[] newArgs = result.getValue(); @@ -255,8 +243,8 @@ public static Method getMethodMatch(Clazz clazz, final Collection.Key methodName } } - lclasses += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // lclasses += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); /* * the argument list contains objects created by createObject, that are no instantiated * (first,third,10th) and because this object have no constructor taking no arguments, Lucee cannot @@ -315,8 +303,8 @@ else if (trgClassLoader != null) { else { msg.append("there are no methods with this name."); } - lclasses2 += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // lclasses2 += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); throw new NoSuchMethodException(msg.toString()); } diff --git a/core/src/main/java/lucee/transformer/dynamic/meta/dynamic/ClazzDynamic.java b/core/src/main/java/lucee/transformer/dynamic/meta/dynamic/ClazzDynamic.java index bd3b2caab8..76ce3f1e97 100644 --- a/core/src/main/java/lucee/transformer/dynamic/meta/dynamic/ClazzDynamic.java +++ b/core/src/main/java/lucee/transformer/dynamic/meta/dynamic/ClazzDynamic.java @@ -25,7 +25,6 @@ import org.objectweb.asm.Type; import org.osgi.framework.Bundle; -import lucee.print; import lucee.commons.digest.HashUtil; import lucee.commons.io.IOUtil; import lucee.commons.io.SystemUtil; @@ -60,31 +59,22 @@ public class ClazzDynamic extends Clazz { private static Map> classes = new IdentityHashMap<>(); - private static double generateClassLoderId = 0; - private static double path = 0; - private static double isFile = 0; - private static double deserialize = 0; - private static double put = 0; - private static double neww = 0; - private static double serialize = 0; - private static double done = 0; - private static int count = 0; + /* + * private static double generateClassLoderId = 0; private static double path = 0; private static + * double isFile = 0; private static double deserialize = 0; private static double put = 0; private + * static double neww = 0; private static double serialize = 0; private static double done = 0; + * private static int count = 0; + */ public static ClazzDynamic getInstance(Class clazz, Resource dir, Log log) throws IOException { - count++; - if ((count % 500) == 0) { - print.e("-------------------"); - print.e("generateClassLoderId:" + generateClassLoderId); - print.e("path:" + path); - print.e("isFile:" + isFile); - print.e("deserialize:" + deserialize); - print.e("put:" + put); - print.e("neww:" + neww); - print.e("serialize:" + serialize); - print.e("done:" + done); - } - double start = SystemUtil.millis(); + /* + * count++; if ((count % 500) == 0) { print.e("-------------------"); + * print.e("generateClassLoderId:" + generateClassLoderId); print.e("path:" + path); + * print.e("isFile:" + isFile); print.e("deserialize:" + deserialize); print.e("put:" + put); + * print.e("neww:" + neww); print.e("serialize:" + serialize); print.e("done:" + done); } double + * start = SystemUtil.millis(); + */ ClazzDynamic cd = null; Reference sr = classes.get(clazz); @@ -93,27 +83,27 @@ public static ClazzDynamic getInstance(Class clazz, Resource dir, Log log) throw sr = classes.get(clazz); if (sr == null || (cd = sr.get()) == null) { String id = generateClassLoderId(clazz); - generateClassLoderId += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // generateClassLoderId += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); StringBuilder sbClassPath = new StringBuilder(); sbClassPath.append(clazz.getName().replace('.', '/')).append('-').append(id).append(".ser"); Resource ser = dir.getRealResource(getPackagePrefix() + sbClassPath.toString()); - path += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // path += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); if (id != null && ser.isFile()) { - isFile += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // isFile += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); if (log != null) log.info("dynamic", "found metadata for [" + clazz.getName() + "]in from serialized file:" + ser); try { cd = (ClazzDynamic) deserialize(getClassLoader(clazz), ser.getInputStream()); cd.clazz = clazz; - deserialize += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // deserialize += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); if (log != null) log.info("dynamic", "loaded metadata for [" + clazz.getName() + "] from serialized file:" + ser); classes.put(clazz, new SoftReference(cd)); - put += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // put += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); } catch (Exception e) { if (log != null) log.error("dynamic", e); @@ -123,8 +113,8 @@ public static ClazzDynamic getInstance(Class clazz, Resource dir, Log log) throw try { if (log != null) log.info("dynamic", "extract metadata from [" + clazz.getName() + "]"); cd = new ClazzDynamic(clazz, id, log); - neww += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // neww += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); if (id != null) { final ClazzDynamic _cd = cd; ThreadUtil.getThread(() -> { @@ -143,8 +133,8 @@ public static ClazzDynamic getInstance(Class clazz, Resource dir, Log log) throw } }, true).start(); - serialize += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // serialize += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); } } catch (IOException ioe) { @@ -155,8 +145,8 @@ public static ClazzDynamic getInstance(Class clazz, Resource dir, Log log) throw } } } - done += (SystemUtil.millis() - start); - start = SystemUtil.millis(); + // done += (SystemUtil.millis() - start); + // start = SystemUtil.millis(); return cd; } diff --git a/loader/build.xml b/loader/build.xml index 9e578a1430..d266aa70ec 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 8bace01a6d..82b83b949a 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.2.0.176-SNAPSHOT + 6.2.0.177-SNAPSHOT jar Lucee Loader Build