Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Dec 6, 2024
1 parent bf057cc commit cd11c99
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 161 deletions.
74 changes: 39 additions & 35 deletions core/src/main/java/lucee/runtime/osgi/EnvClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
// }

}

Expand All @@ -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
Expand All @@ -118,16 +120,17 @@ public Enumeration<URL> getResources(String name) throws IOException {
if (url != null) list.add(url);
return new E<URL>(list.iterator());
}
double start = SystemUtil.millis();
try {
List<URL> list = new ArrayList<URL>();
URL url = (URL) load(name, URL, false, null, true);
if (url != null) list.add(url);
return new E<URL>(list.iterator());
}
finally {
trace.trace("EnvClassLoader", "EnvClassLoader.getResources(" + name + "):" + (SystemUtil.millis() - start));
}
// double start = SystemUtil.millis();
// try {
List<URL> list = new ArrayList<URL>();
URL url = (URL) load(name, URL, false, null, true);
if (url != null) list.add(url);
return new E<URL>(list.iterator());
// }
// finally {
// trace.trace("EnvClassLoader", "EnvClassLoader.getResources(" + name + "):" + (SystemUtil.millis()
// - start));
// }
}

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

}

Expand Down
73 changes: 31 additions & 42 deletions core/src/main/java/lucee/transformer/dynamic/DynamicInvoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<FunctionMember, Object> 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;
Expand All @@ -185,15 +174,15 @@ public Pair<FunctionMember, Object> 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());
Expand All @@ -204,17 +193,17 @@ public Pair<FunctionMember, Object> 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<FunctionMember, Object>(fm, loader.loadInstance(className));
Expand All @@ -223,11 +212,11 @@ public Pair<FunctionMember, Object> 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();
Expand Down
74 changes: 31 additions & 43 deletions core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -90,43 +89,32 @@ public static Clazz getClazz(Class clazz, Resource root, Log log) {
private static Map<String, SoftReference<Pair<Method, Boolean>>> 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<Method> 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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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<Method, Object[]> result = null;
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
}

Expand Down
Loading

0 comments on commit cd11c99

Please sign in to comment.