|
[AOP]
Synchronized block join points (v2)
[
avasseur
]
Back in July Jonas suggested some semantics for a synchronized block join point. The discussion was interesting but I am wondering if we actually came up with the right question.
What if we simply think in terms of "is this type listening to locking events ?" instead of trying to come up with a pointcut expression that defines the semantics of a synchronized block - as done in Jonas discusion?
Lets draft some code:
Consider the program: class Bar { synchronized void foo() { .. } static synchronized void statfoo() { .. } void stuff() { .. synchronized(bar) { .. } } }
interface Lockable { void waiting(); void acquired(); void released(); } @Introduce("Bar")
class LockableNOOP implements Lockable {
void waiting() {}
void acquired() {}
void released() {}
}Replace all synchronized blocks like that: Given synchronized(stuff) {
..
}if (stuff instanceof Lockable) { Lockable lockable = (Lockable)stuff; lockable.waiting(); synchronized(stuff) { lockable.acquired(); ..// unchanged body } lockable.released(); } else { synchronized(stuff) { ..// unchanged body } } You can now access the enclosing static join point information if you need - which gives you if you really need it, the rich semantics Jonas was looking for: call(Lockable.waiting()) && withincode(....) && target(t) && cflow(...) .....
// t is the locked object
There are two interesting things to solve now:
I'll try to provide inputs from the point of view of a user who wants to use this feature. So, the join points are (a) just before getting the lock (i.e. entering the monitor) (b) just after getting the lock and (c) just after releasing the lock (i.e. exiting the monitor) I'd like to have a pointcut language that can express this in a simple way. And I need to be able to use them with existing pointcut expression such as cflows (and other such things) so that I can define pointcuts for synchronized blocks only for specific executions of code. (e.g., I'd like to know how much time was spent waiting for monitors within the Hibernate library). What happens at these pointcuts (calculating time) can be expressed as simple advices. For implementation choices, while it would be nice to leverage the existing features of the JVM such as JVMTI monitor entry/exit/wait events, whats the performance overhead of it? For e.g., I should be able to subscribe only to very specific monitor events (such as say those occurring from within certain methods) and not at all monitor events. If I subscribe to all monitor events in JVMTI and filter out the unnecessary events in my event handler, will be there a lot of overhead? If so, will a byte code instrumentation approach be faster for such use cases? Also, we need ways to do this for pre 1.5 versions of the JVM where JVMTI is not available (JVMPI had similar features, but it was never known to be fast). To answer some other specific questions, for the use case of APM for enterprise apps, use of instanceof is not a big cost. While its better to have as little change to the original program structure as possible, I can live with some of the implementation details mentioned here such as using introductions, transforming code with if conditions etc. Hope that helps! --Srinivas Narayanan, October 11, 2005 05:47 PM
Are fighting yesterday's battles? Sure, synchronized join points are interesting, but with the advent of java.util.concurrent, I sincerely hope that in 2 years serious multi-threaded Java program will NOT be using synchronized. And as I understand it, java.util.concurrent methods are natural to capture with existing join points. I'd be interested in opinions on that... --Ron Bodkin, October 26, 2005 08:24 AM
Post a comment
|