Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] A pointcut to match all static methods in a class with some restrictions

Hi,

Printing the messages won't be the cause of the OutOfMemory but it may be an indicator that the pointcuts are not quite as well targetting as they could be.  If you are using primitives like cflow() you may get a LOT of matching and weaving unless you are careful - because we may not be able to determine something statically and put the test off until runtime by weaving the code anyway.  I would turn on -showWeaveInfo to see how much weaving is happening.  Are you getting far far more than you thought?  I think you might be, and so we should look to rework the pointcuts to more accurately describe exactly what you want to say.

> expect that more detailed the pointcut description is, the more runtime checks they need?!

No, the runtime checks come from writing pointcut components that cannot be statically determined - I could write a reallllly long pointcut that may need to no runtime checks, or I could write something tiny that would destroy the weaver (eg. cflow(execution(* *(..))

When writing optimal pointcuts it is a question of ensuring as much as possible can be statically determined.

For example, I worry about this component of your pointcut:

!cflow(initMethod())

there may be an awful lot of places that match that...

But as I say, turn on showWeaveInfo - do you see things you don't think should be there?  Can the statically determinable parts of the pointcut be tidied up to reduce the unnecessary matching and weaving?

Andy.

2009/3/14 Jochen Wuttke <jochen.wuttke@xxxxxx>
Thanks Andy,

I think I get the point here. One thing I forgot to mention is that when I do this with LTW the warnings keep coming for a minute or so and then comes the dreaded OutOfMemory: Java Heap Space exception. So in some sense it's not really working how I want ;-) Should printing error messages really consume this much memory?
This might be a problem for me because I'm working on an automatic code generator that generates these aspects, and the more detail I have to put in the generator, the more of a pain it will be to keep correct, and I expect that more detailed the pointcut description is, the more runtime checks they need?!

Jochen




On Mar 13, 2009, at 9:06 PM, Andy Clement wrote:

So everything is working as you want, you just want to know about the warnings.

> [AppClassLoader@517590db] warning at javax/servlet/jsp/aspects/Users/joe/Documents/uni/research/LuMi/workspace/tomcat6.0.9
> _aspects/src/javax/servlet/jsp/aspects/JspFactory_Initialized.aj:31::0 does not match because declaring type is java.lang.Object,
> if match desired use target(javax.servlet.jsp.JspFactory) [Xlint:unmatchedSuperTypeInCall]
> see also: org/apache/catalina/connector/Connector.java:1013::0

Suppose the toString() method is called on a JspFactory, or hashCode() - those are methods inherited from Object, perhaps not implemented
by your JspFactory.  Should call(* JspFactory.*(..)) match calls to them? well JspFactory doesn't define them, so no.  And just in case you
really wanted to include them but accidentally used the declaring type inappropriately in call(), there is a warning from the compiler.

The warning is telling you the declaring type of the method involved is Object and if you want a match, you will need to use target, if you
don't want a match then it doesn't matter and you can ignore it (turn off the warning if you like, it is an xlint).

Here is a trivial case:
-- A.java --
public class A {
 public void foo() {
   int i = hashCode();
 }
}

aspect X {
 before(): call(* A.*(..)) {}
}
---
C:\aspectj164-dev>ajc A.java
C:\aspectj164-dev\A.java:8 [warning] does not match because declaring type is java.lang.Object, if match desired use target(A) [Xlint:unmatchedSuperTypeInCall]
before(): call(* A.*(..)) {}
         ^^^^^^^^^^^^
       [Xlint:unmatchedSuperTypeInCall]
       see also: C:\aspectj164-dev\A.java:3::0

1 warning

Doesn't matter for static methods.  And target can be used to match non-static methods:
--- A.java ---
public class A {
 void foo() {
 }

 static void goo() {
 }

}

aspect X {
 before(): execution(* *(..)) && !target(Object) {}
}
---
C:\aspectj164-dev>ajc A.java -showWeaveInfo
Join point 'method-execution(void A.goo())' in Type 'A' (A.java:5) advised by before advice from 'X' (A.java:11)

if target is not a derivative of Object then it must be a static method.  But qualifying it in your pointcut is a more optimal way to express it.


Andy



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top