-
Notifications
You must be signed in to change notification settings - Fork 292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix inner classes matching for line probes #4604
Conversation
When class are already loaded, we need to retransform them for passing through the DebuggerTransformer. But to detect which class need to be retransformed, we rely on the naming. However inner classes or Top-Level classes are in independent class files and the only way to associate them is the sourcefile attribute in each class file. So we need to track all dependent classes by their source file in order to avoid scanning all loaded classes to parse their sourcefile and try to match with actual probe definitions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome stuff. few refactor suggestions
sourceFile = sourceFile.substring(idx + 1); | ||
} | ||
List<String> additionalClasses = | ||
SourceFileTrackingTransformer.INSTANCE.getClassNameBySourceFile(sourceFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that use static INSTANCE and creating hidden dependencies that complicate how we do unit testing.
Lets clean this up to make more single responsibility classes
My take on this would be:
- Extract all getLoadedClasses logic from this class. maybe
ClassesToRetansformFinder
that gets list of changes, loaded classes and classFileMapping provider to do all this logic.
a. that would make the configurationComparer simpler
b. remote the dependency of SourceFileTrackingTransformer - ClassesToRetansformFinder can have a function "registerClassWithCustomSourceName(classname, sourceilfe)
a. then SourceFileTrackingTransformer can be created debuggerAgent an pass the instance of ClassesToRetansformFinder to it to register classes
b. configuration updater can use ClassesToRetansformFinder.getAllChangedClasses(changes)
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds nice!
done
} | ||
} | ||
|
||
private String removeExtension(String fileName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move all those helper functions to ClassFileHelper utility classes - to have a single place when we load file name, normalize it, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
private static boolean lookupClass(Trie changedClasses, Class<?> clazz) { | ||
String reversedTypeName = reverseStr(clazz.getName()); | ||
// try first with FQN (java.lang.String) | ||
if (changedClasses.contains(reversedTypeName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not doing containsPrefix? as it the same we do at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (sourceFile == null) { | ||
return null; | ||
} | ||
String simpleClassName = className.substring(className.lastIndexOf('/') + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look like the normalize or removeExtention functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
ab594c2
to
f85142e
Compare
handle the resolution of classes that need to be retransformed based on SourceFile and probe definitions
f85142e
to
01ee5e0
Compare
What Does This Do
Allows the DebuggerTransformer to find inner classes when using file+line probe definitions.
Reporting of line not found was removed because it can be found latter by loading inner/top-level class.
Background
When class are already loaded, we need to retransform them for passing through the
DebuggerTransformer
.But to detect which class need to be retransformed, we rely on the naming. However inner classes or Top-Level classes are independent class files and the only way to associate them is the sourcefile attribute in each class file.
Solution
Track all dependent classes by their source file, so it easier to find all related class given a filename.
This avoids scanning all loaded classes to parse their sourcefile and try to match with actual probe definitions.
Motivation
Support line probe in inner/top-level classes or Kotlin lambdas
Additional Notes