Skip to content

Commit

Permalink
fix dynamic class method metadata collection
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Dec 10, 2024
1 parent 2b5ad05 commit ed47cae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public class ClazzDynamic extends Clazz {
private static Map<ClassLoader, String> clids = new IdentityHashMap<>();
private static String systemId;

private static Map<String, SoftReference<ClazzDynamic>> classes = new ConcurrentHashMap<>();
private static Map<Class, SoftReference<ClazzDynamic>> classes = new IdentityHashMap<>();
// private static Map<String, SoftReference<ClazzDynamic>> classes = new ConcurrentHashMap<>();

/*
* private static double generateClassLoderId = 0; private static double path = 0; private static
Expand All @@ -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<ClazzDynamic> sr = classes.get(key);
Reference<ClazzDynamic> 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();
Expand All @@ -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<ClazzDynamic>(cd));
classes.put(clazz, new SoftReference<ClazzDynamic>(cd));
// put += (SystemUtil.millis() - start);
// start = SystemUtil.millis();
}
Expand Down Expand Up @@ -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<String, FunctionMember> members = _getFunctionMembers(this.clid, clazz, null, log);
Map<String, FunctionMember> members = _getFunctionMembers(this.clid, clazz, log);

LinkedList<FunctionMember> tmpMethods = new LinkedList<>();
LinkedList<FunctionMember> tmpDeclaredMethods = new LinkedList<>();
Expand Down Expand Up @@ -365,18 +365,16 @@ public List<Constructor> getDeclaredConstructors(int argumentLength) throws IOEx
return list;
}

private static Map<String, FunctionMember> _getFunctionMembers(String clid, final Class clazz, Map<String, FunctionMember> membersInput, Log log) throws IOException {
private static Map<String, FunctionMember> _getFunctionMembers(String clid, final Class clazz, Log log) throws IOException {
String key = clid + ":" + clazz.getName();
if (membersInput == null) membersInput = new LinkedHashMap<>();
final Map<String, FunctionMember> members = membersInput;
final Map<String, FunctionMember> members = new LinkedHashMap<>();

Map<String, FunctionMember> existing = membersCollection.get(key);
if (existing != null) {
for (Entry<String, FunctionMember> e: existing.entrySet()) {
members.put(e.getKey(), e.getValue());
}
return members;

}

final String classPath = clazz.getName().replace('.', '/') + ".class";
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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<String, FunctionMember> members, Map<String, FunctionMember> add) {
for (Entry<String, FunctionMember> 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());
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.2.0.195-SNAPSHOT"/>
<property name="version" value="6.2.0.196-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.2.0.195-SNAPSHOT</version>
<version>6.2.0.196-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit ed47cae

Please sign in to comment.