From ed47cae8deba782970ec490832c7f55a56d330b8 Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Tue, 10 Dec 2024 01:03:26 +0100 Subject: [PATCH] fix dynamic class method metadata collection --- .../dynamic/meta/dynamic/ClazzDynamic.java | 30 +++++++++++-------- loader/build.xml | 2 +- loader/pom.xml | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) 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 58a487bc99..bb663cabb8 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 @@ -57,7 +57,8 @@ public class ClazzDynamic extends Clazz { private static Map clids = new IdentityHashMap<>(); private static String systemId; - private static Map> classes = new ConcurrentHashMap<>(); + private static Map> classes = new IdentityHashMap<>(); + // private static Map> classes = new ConcurrentHashMap<>(); /* * private static double generateClassLoderId = 0; private static double path = 0; private static @@ -77,13 +78,12 @@ public static ClazzDynamic getInstance(Class clazz, Resource dir, Log log) throw */ ClazzDynamic cd = null; - String id = generateClassLoderId(clazz); - String key = id + ":" + clazz.getName(); - Reference sr = classes.get(key); + Reference sr = classes.get(clazz); if (sr == null || (cd = sr.get()) == null) { synchronized (clazz) { - sr = classes.get(key); + sr = classes.get(clazz); if (sr == null || (cd = sr.get()) == null) { + String id = generateClassLoderId(clazz); // generateClassLoderId += (SystemUtil.millis() - start); // start = SystemUtil.millis(); StringBuilder sbClassPath = new StringBuilder(); @@ -102,7 +102,7 @@ public static ClazzDynamic getInstance(Class clazz, Resource dir, Log log) throw // deserialize += (SystemUtil.millis() - start); // start = SystemUtil.millis(); if (log != null) log.info("dynamic", "loaded metadata for [" + clazz.getName() + "] from serialized file:" + ser); - classes.put(key, new SoftReference(cd)); + classes.put(clazz, new SoftReference(cd)); // put += (SystemUtil.millis() - start); // start = SystemUtil.millis(); } @@ -188,7 +188,7 @@ public static String generateClassLoderId(Class clazz) { private ClazzDynamic(Class clazz, String clid, Log log) throws IOException { this.clazz = clazz; this.clid = clid; - Map members = _getFunctionMembers(this.clid, clazz, null, log); + Map members = _getFunctionMembers(this.clid, clazz, log); LinkedList tmpMethods = new LinkedList<>(); LinkedList tmpDeclaredMethods = new LinkedList<>(); @@ -365,10 +365,9 @@ public List getDeclaredConstructors(int argumentLength) throws IOEx return list; } - private static Map _getFunctionMembers(String clid, final Class clazz, Map membersInput, Log log) throws IOException { + private static Map _getFunctionMembers(String clid, final Class clazz, Log log) throws IOException { String key = clid + ":" + clazz.getName(); - if (membersInput == null) membersInput = new LinkedHashMap<>(); - final Map members = membersInput; + final Map members = new LinkedHashMap<>(); Map existing = membersCollection.get(key); if (existing != null) { @@ -376,7 +375,6 @@ private static Map _getFunctionMembers(String clid, fina members.put(e.getKey(), e.getValue()); } return members; - } final String classPath = clazz.getName().replace('.', '/') + ".class"; @@ -405,7 +403,7 @@ public void visit(int version, int access, String name, String signature, String if (interfaces != null && interfaces.length > 0) { for (String interf: interfaces) { try { - _getFunctionMembers(clid, cl.loadClass(ASMUtil.getClassName(Type.getObjectType(interf))), members, log); + add(members, _getFunctionMembers(clid, cl.loadClass(ASMUtil.getClassName(Type.getObjectType(interf))), log)); } catch (Exception e) { if (log != null) log.error("dynamic", e); @@ -414,7 +412,7 @@ public void visit(int version, int access, String name, String signature, String } if (superName != null) { try { - _getFunctionMembers(clid, cl.loadClass(ASMUtil.getClassName(Type.getObjectType(superName))), members, log); + add(members, _getFunctionMembers(clid, cl.loadClass(ASMUtil.getClassName(Type.getObjectType(superName))), log)); } catch (IllegalArgumentException iae) { String v = ASMUtil.getJavaVersionFromException(iae, null); @@ -437,6 +435,12 @@ public void visit(int version, int access, String name, String signature, String super.visit(version, access, name, signature, superName, interfaces); } + private void add(Map members, Map add) { + for (Entry e: add.entrySet()) { + members.put(e.getKey(), e.getValue()); + } + } + @Override public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { FunctionMemberDynamic fmCurrent = FunctionMemberDynamic.createInstance(clazz, name, access, descriptor, exceptions, classAccess.toInt()); diff --git a/loader/build.xml b/loader/build.xml index 5cbe8a26c2..9369f73347 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 6b5ea9bd50..36f819c8f7 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.2.0.195-SNAPSHOT + 6.2.0.196-SNAPSHOT jar Lucee Loader Build