Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 44598 invoked from network); 19 Nov 2006 22:34:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Nov 2006 22:34:26 -0000 Received: (qmail 69029 invoked by uid 500); 19 Nov 2006 22:34:35 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 68392 invoked by uid 500); 19 Nov 2006 22:34:34 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 68383 invoked by uid 500); 19 Nov 2006 22:34:34 -0000 Delivered-To: apmail-incubator-harmony-dev@incubator.apache.org Received: (qmail 68379 invoked by uid 99); 19 Nov 2006 22:34:34 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Nov 2006 14:34:34 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of maxim.kurzenev@gmail.com designates 64.233.182.185 as permitted sender) Received: from [64.233.182.185] (HELO nf-out-0910.google.com) (64.233.182.185) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Nov 2006 14:34:21 -0800 Received: by nf-out-0910.google.com with SMTP id p46so2263483nfa for ; Sun, 19 Nov 2006 14:33:59 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=V3iaW6s5vVpGwGftA2d4dqxvuBieD++8SLNot426R09qu+cRknt8hdUamoEJZTTKqNhFSuzYJpdruny7Y/5BuTG7jFdJaL/F+8AWIn0gFAVjjJhpI2EVKm1DIdmy7RLa5VE3KgWoa53n3pZT0UAWK86hARmFszYJsj6M8CMjd0M= Received: by 10.82.126.5 with SMTP id y5mr481264buc.1163975638962; Sun, 19 Nov 2006 14:33:58 -0800 (PST) Received: by 10.82.112.13 with HTTP; Sun, 19 Nov 2006 14:33:58 -0800 (PST) Message-ID: <800cfc630611191433u647df676ld57307a26a27384d@mail.gmail.com> Date: Mon, 20 Nov 2006 01:33:58 +0300 From: "Maxim Kurzenev" To: harmony-dev@incubator.apache.org Subject: Re: [classlib] Using Aspects for Tracing In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_31098_16942830.1163975638509" References: <2c9597b90611140431n39d95d37l7ff116bc6b70ae0b@mail.gmail.com> <2c9597b90611150432s6471d019pc95956857e2f57c9@mail.gmail.com> <455B2183.4020300@gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_31098_16942830.1163975638509 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hello, just a few comments: > Please also note that it's not possible to use this kind of tracing > for any classes that are depended on by the AspectJ runtime or there > will be errors initializing the classes because of circular > dependencies. However I think most modules apart from luni should be > safe. While we're not able to trace execution of some restricted methods within luni, we may use aspects for some specific tasks like tracing calls to luni methods from anything outside of luni. This may be done using the "call" pointcut instead of "execution". In such a case the called code is not affected by aspect instrumentation, only the calling code is affected. As long as the calling code resides outside of luni, this technique will work. > Also it's important to not trace methods that are called > (directly or indirectly) by your tracing methods otherwise you will > end up in an endless loop. The above technique, if applicable to the specific task, also gives a free solution to this problem. You just restrict the occurrence of your pointcut to be !within(YourAspect) Thanks, Max -- Maxim Kurzenev, Intel ESSD On 11/15/06, Anton Luht wrote: > > Forwarded Conversation > Subject: [classlib] Using Aspects for Tracing > ------------------------ > > From: Sian January > Reply-To: harmony-dev@incubator.apache.org > To: harmony-dev@incubator.apache.org > Date: Tue, Nov 14, 2006 at 2:57 PM > Attachments: buildxmlpatch.txt > > Hello, > > Following a recent discussion on this list I have been looking into > how aspects could be used for tracing in the Harmony class library > code. I have been using AspectJ and have written a really simple > tracing aspect for the math module, adapted the build.xml script and > written some instructions on how to apply it. At the moment the > aspect just does entry and exit tracing and prints to System.out, but > this is because it's a first draft - it is possible to do more > targeted tracing and to use frameworks such as java.util.logging with > aspects. > > Steps to follow: > > > 1. Download AspectJ from http://www.eclipse.org/aspectj/downloads.php > > 2. Copy aspectjrt.jar to /depends/jars/aspectj/ > > 3. Copy aspectjtools.jar and aspectjrt.jar to ANT_HOME/lib and if > using Eclipse add both of these to your ant runtime configuration > (Window > Preferences > Ant > Runtime > Add...) > > 4. Edit build file to use iajc* instead of javac and include aspect > class files (or apply the buildxmlpatch.txt to build.xml in the math > module) > > 5. Write a tracing aspect (or copy the one attached to > modules\math\src\main\java\org\apache\harmony\tracing) > > 6. Re-build the module > > 7. Make sure to add aspectjrt.jar to the runtime classpath of whatever > program you are running. > > > * - iajc isn't incremental like javac in ant, it will always do a > total rebuild. Also if you switch from using iajc back to javac you > will need to do a clean before you do a rebuild. > Please also note that it's not possible to use this kind of tracing > for any classes that are depended on by the AspectJ runtime or there > will be errors initializing the classes because of circular > dependencies. However I think most modules apart from luni should be > safe. Also it's important to not trace methods that are called > (directly or indirectly) by your tracing methods otherwise you will > end up in an endless loop. > > If anyone thinks this information might be useful to have available > somewhere I would be happy to expand it a bit for a web page or a Wiki > page. > > Regards, > > Sian > > -- > Sian January > > IBM Java Technology Centre, UK > -------- > From: Alexei Zakharov > Reply-To: harmony-dev@incubator.apache.org > To: harmony-dev@incubator.apache.org > Date: Tue, Nov 14, 2006 at 3:31 PM > > Sian, > > Cool! Thanks for this. Can AspectJ be used for something more > sophisticated than just tracing? For application-level logging for > example? > > Thanks, > > 2006/11/14, Sian January : > [Quoted text hidden]Alexei Zakharov, > Intel Enterprise Solutions Software Division > > -------- > From: Sian January > Reply-To: harmony-dev@incubator.apache.org > To: harmony-dev@incubator.apache.org > Date: Tue, Nov 14, 2006 at 6:50 PM > > Hi Alexei, > > I'm not entirely sure what you mean by application-level logging. It is > possible to get more fine-grained information using aspects if that's what > you mean, such as tracing individual methods, logging field reads and > writes, logging when Exceptions are caught and logging when certain > methods > are called and where from. You can't use aspects to add logging into the > middle of a method, unless it's at a well defined point. If there was > some > specific information you wanted to add at a specific place there's no > problem using a combination of aspects and hand-coded logging. Does that > answer your question at all? > > Thanks, > > Sian > [Quoted text hidden] > [Quoted text hidden] > -------- > From: Anton Luht > To: harmony-dev@incubator.apache.org > Date: Wed, Nov 15, 2006 at 10:00 AM > > Hello Sian, > > [skip] > > > 5. Write a tracing aspect (or copy the one attached to > > modules\math\src\main\java\org\apache\harmony\tracing) > > There was only patch to build.xml attached - could you please send the > aspect or better create a JIRA issue and attach all stuff to it? > > -- > Regards, > Anton Luht, > Intel Java & XML Engineering > > -------- > From: Sian January > Reply-To: harmony-dev@incubator.apache.org > To: harmony-dev@incubator.apache.org > Date: Wed, Nov 15, 2006 at 2:09 PM > > Hi Anton, > > I have created HARMONY-2195 for this information. > > Thanks, > > Sian > [Quoted text hidden] > [Quoted text hidden] > -------- > From: Alexei Zakharov > Reply-To: harmony-dev@incubator.apache.org > To: harmony-dev@incubator.apache.org > Date: Wed, Nov 15, 2006 at 3:32 PM > > > I'm not entirely sure what you mean by application-level logging. > > Well, I mean the situation when log calls are scattered around the > code. Something like this: > > --- > void dataExchange() throws Exception { > boolean handshakePerformed = false; > > log("in performConnection"); // log point 1 > ... > for (int i = 0; i < 5; i++) { > int k = performHandshake(); > > if (k == NEED_MORE_DATA) { > log("server responded: needs more data"); // log point 2 > addSomeDataForServer(); > } else if (k == NEED_MORE_SECURITY) { > log("server responded: needs more security"); // log point 3 > addMoreSecurity(); > } else if (k == OK) { > handshakePerformed = true; > log("handshake OK"); // log point 4 > break; > } > } > > if (!handshakePerformed) { > log("give up: unable to handshake"); // log point 5 > throw new Exception("unable to handshake"); > } > > log("ready to send data"); // log point 6 > .... > log("leaving performConnection"); // log point 7 > } > --- > > From your explanation I've understood that aspects can be used for > points one and seven. Is it possible to cover other log points with > aspects? What should be done for this (if so)? > [Quoted text hidden]-- > [Quoted text hidden] > -------- > From: Sian January > Reply-To: harmony-dev@incubator.apache.org > To: harmony-dev@incubator.apache.org > Date: Wed, Nov 15, 2006 at 4:26 PM > > Hi Alexei, > > Yes - it is possible to match those points with aspects > > e.g if the class is called MyClass > > log point 2 would be matched by "call(* MyClass.addSomeDataForServer()) && > withincode(MyClass.dataExchange())" > > log point 3 could be matched by "call(* MyClass.addMoreSecurity()) && > withincode(MyClass.dataExchange())" > > log point 4 could be matched by "set(MyClass.handshakePerformed) && > args(true) && withincode(MyClass.dataExchange())" > > log point 5 could be matched by "call(Exception.new(..)) && withincode( > MyClass.dataExchange())" (or by after() throwing advice on the > dataExchange > method. > > an alternative would be do something like this, which combines 2, 3 and 4: > > after() returning(int k): execution(int MyClass.performHandshake()) && > withincode(MyClass.dataExchange()) { > if (k == NEED_MORE_DATA) { > log("server responded: needs more data"); // log point 2 > } else if (k == NEED_MORE_SECURITY) { > log("server responded: needs more security"); // log point 3 > } else if (k == OK) { > log("handshake OK"); // log point 4 > } > } > > I wouldn't necessarily recommend doing a lot of this kind of logging with > aspects as it can make quite a messy aspect and the pointcuts can be quite > fragile (i.e. minor changes in the code can easily cause a pointcut to > stop > matching). But it is possible. My second suggestion is a little more > robust and you may find that that advice could be applied more > generally anyway (e.g. 2, 3 and 4 could be logged after all calls to > performHandshake instead of just calls from MyClass.dataExchange). > > Hope this helps. I'm happy to answer any further questions or take a look > at any aspects you decide to write. > > Regards, > > Sian > [Quoted text hidden] > [Quoted text hidden] > -------- > From: Tim Ellison > Reply-To: harmony-dev@incubator.apache.org > To: harmony-dev@incubator.apache.org > Date: Wed, Nov 15, 2006 at 5:17 PM > > Sian January wrote: > > I wouldn't necessarily recommend doing a lot of this kind of logging > with > > aspects as it can make quite a messy aspect and the pointcuts can be > quite > > fragile (i.e. minor changes in the code can easily cause a pointcut to > stop > > matching). But it is possible. My second suggestion is a little more > > robust and you may find that that advice could be applied more > > generally anyway (e.g. 2, 3 and 4 could be logged after all calls to > > performHandshake instead of just calls from MyClass.dataExchange). > > I agree, but would also point out that: > > - putting the explicit logging calls in the implementation clutter the > 'business end' of the code; keeping logging separate like this makes it > clearer what each part of the code is doing. > > - we can reduce logging code duplication by defining pointcuts that > apply to numerous places. > > - logging becomes trivially turn-off-and-on-able. > > - if you have decent IDE support, like AspectJ, you can see where the > logging calls are being applied and develop them quite 'naturally'. > > > and the usual caveat, that I'd suggest we only use aspects sparingly > like this, and don't start going crazy. If a vi user only misses out > seeing a few logging calls (without looking through the aspects list) > that is acceptable IMHO, but if there is any functional change missed > then that is unacceptable. > > Regards, > Tim > > -- > > Tim Ellison (t.p.ellison@gmail.com) > IBM Java technology centre, UK. > > -------- > > > ------=_Part_31098_16942830.1163975638509--