Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] RE: Re: Re: Array Constructor Pointcut ?

Hi Erik,

Thanks for the reply!  Some comments:

This was intended to be a language restriction.  The compiler bug is that
we're not signaling an error for the syntax "call(String[].new(..))".  Array
types don't have constructors, initializers, or static initializers in Java.

It seems to me then, that the pointcut syntax is misleading. Perhaps, for example, something like call(*.construct(..)) would be a clearer notation compared with call(*.new(..)). What do you think?

As for a use case, I have several. I am currently working on low overhead profiling with AspectJ. One thing of interest is to profile the memory usage of a program. To do this in AspectJ, the idea is to intercept all calls to "new" in the program and record how many bytes are being allocated by that call. This basically works fine, except of course, that I cannot account for arrays which is something of a hole in the idea.

Another use case, along a similar line, might be to try and monitor the lifetime of heap objects. The idea here is that we again intercept all calls to "new", but this time we associate a weak reference with the object so that we can be notified of when it is garbage collected. This gives a rough indication of how long the object lives for, which could be useful in tracking down functions which create large numbers of short-lived objects.

Anyway, comments please!!

Cheers,

Dave

I've to submitted a bug report so we catch that illegal syntax (and the
other illegal syntax David Pearce found *smile*).
As Matt correctly says, there is an anewarray/newarray bytecode representing
array construction, so capturing array construction as a join point is
technically feasible.  If someone has a good use case for "array constructor
join points" (which would be call-site-like things in the same way as field
references are) then he or she should submit it as a feature request to
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=AspectJ.

-erik

-----Original Message-----
From: aspectj-users-admin@xxxxxxxxxxx
[mailto:aspectj-users-admin@xxxxxxxxxxx] On Behalf Of Matthew Webster
Sent: Thursday, June 17, 2004 8:10am
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Re: Re: Array Constructor Pointcut ?





The fact that the following code compiles suggests that this is not a
language restriction:

public aspect Aspect {

      pointcut initArray () :
            call(String[].new(..));

      after () : initArray() {
            System.err.println("? " + thisJoinPoint
.getSignature().getName());
      }

      pointcut all () :
            within(Test);

      after () : all() {
            System.err.println("? " + thisJoinPoint);
      }
}

public class Test {
      public static void main(String[] args) {
            String s = new String("Hello");
            String[] sa = new String[1];
            int[] ia = new int[1];
      }
}

However the output indicated the array construction join point is not
recognized by AspectJ although there is a bytecode associated with it
(newarray/anewarray):

? staticinitialization(Test.<clinit>)
? call(java.lang.String(String))
? execution(void Test.main(String[]))


This is probably a complier bug.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/


--__--__--




Back to the top