Skip to content

Commit

Permalink
store only weaved class names in the generatedClasses map
Browse files Browse the repository at this point in the history
The generatedClasses map contained both keys of woven classes that had
generated classes associated with them, and the keys of the generated
classes themselves. It seems like this map is never consulted for the
generated class key - the generated class is generated from within the
context of woven class loading / retransformation, and thus no transform
event is generated for it by the JVM. Because of that we don't need to
guard against re-weaving it. Other uses of generatedClasses map are for
full/empty tests, where the woven class key is sufficient. This change
simplifies deletion of a class because we don't have to look for its
associated generated classes.
  • Loading branch information
urisimchoni committed Feb 5, 2024
1 parent 203ffcc commit 5328e54
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1008,21 +1008,8 @@ public void flushGeneratedClasses() {
* @param className a slashed classname (e.g. com/foo/Bar)
*/
public void flushGeneratedClassesFor(String className) {
try {
String dottedClassName = className.replace('/', '.');
String dottedClassNameDollar = dottedClassName+"$"; // to pickup inner classes
Iterator<Map.Entry<String, IUnwovenClassFile>> iter = generatedClasses.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, IUnwovenClassFile> next = iter.next();
String existingGeneratedName = next.getKey();
if (existingGeneratedName.equals(dottedClassName) ||
existingGeneratedName.startsWith(dottedClassNameDollar)) {
iter.remove();
}
}
} catch (Throwable t) {
new RuntimeException("Unexpected problem tidying up generated classes for "+className,t).printStackTrace();
}
String dottedClassName = className.replace('/', '.');
generatedClasses.remove(dottedClassName);
}

private static final Object lock = new Object();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,6 @@ public void acceptResult(IUnwovenClassFile result) {
lacache.addGeneratedClassesNames(wovenClass.getClassName(), wovenClass.getBytes(), result.getClassName());
}

generatedClasses.put(className, result);
generatedClasses.put(wovenClass.getClassName(), wovenClass);
generatedClassHandler.acceptClass(className, null, resultBytes);
}
Expand Down

0 comments on commit 5328e54

Please sign in to comment.