I’m trying to find out whether Object
and String
are used in synchronization operations in rt.jar. The good news is that neither of them contains synchronized methods. Of course, both can still be used in monitorenter
/monitorexit
instructions.
That’s a bit harder to find out. I’ll have to scan through all of rt.jar and find out what’s on the top of the stack when these instructions are executed. Depending on how general I want to make this, I can either trust that javac will always encode a synchronized block in the same way (dup; astore\_?; monitorenter; ...; aload\_?; monitorexit
), or I have to simulate the stack and local variables.
Even then, I can’t really find out if the runtime type of an object is Object
or String
or a subclass. All I can find out is whether the upper bound happens to be one of those classes. While subclasses of String
are rare, I’m absolutely sure there are functions that accept an Object
and then perform a synchronization operation on them.
In those cases, I could add a runtime check and throw an exception, or I could try to perform some very expensive flow analysis. I have no idea how to do the latter, though. I’ll think about it, but maybe doing the class substitution (ProperObject
, etc.) is actually easier to do…