Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Logging JNI calls with AspectJ

You can't add execution advice to a native method since there is no Java 
method for the AspectJ compiler to work with. See the implementation notes 
at http://www.eclipse.org/aspectj/doc/progguide/implementation.html.

However, you can probably get the effect you want by using the following 
variation on your aspect:

public aspect LogNativeAspect {

  private static boolean isNative(JoinPoint.StaticPart jpsp) {
    return Modifier.isNative(jpsp.getSignature().getModifiers());
  }

  pointcut nativeMethodCall() : call( * *(..)) && 
if(isNative(thisJoinPointStaticPart));

  before() : nativeMethodCall() && !within(LogNativeAspect) {
     Logger.debug("Calling " + 
thisJoinPointStaticPart.getSignature().toLongString());
  }

}

If you know the target namespace of the native methods you want to log 
(like they're all in org.xyz..* packages) then you should tighten up the 
nativeMethodCall() pointcut, 

e.g.  pointcut nativeMethodCall() ; call(* org.xyz..*.*(..)) && 
if(isNative(thisJoinPointStaticPart));

*disclaimer - I haven't compiled this code...

-- Adrian
Adrian_Colyer@xxxxxxxxxx



"Shah, Manish" <Manish.Shah@xxxxxxxx> 
Sent by: aspectj-users-bounces@xxxxxxxxxxx
26/04/2005 09:18
Please respond to
aspectj-users@xxxxxxxxxxx


To
"'aspectj-users@xxxxxxxxxxx'" <aspectj-users@xxxxxxxxxxx>
cc

Subject
[aspectj-users] Logging JNI calls with AspectJ






Hi,

Is is possible to create a pointcut that intercepts native methods that
invoke non-java code through JNI?

I'd like to be able to put a logging aspect into an existing piece of code
that does lots of native invocations. Here's my aspect:

public aspect LogNativeAspect {

    private Logger LOGGER = Logger.getLogger("LogNativeAspect");

    pointcut traceMethods()
        : execution(*  *.*(..)) && !within(LogNativeAspect);

    before() : traceMethods() {

        Signature signature = thisJoinPointStaticPart.getSignature();

        if (Modifier.isNative(signature.getModifiers())) {
                       LOGGER.debug("Calling: " + 
signature.toLongString());
        }
    }
}

If I remove the conditional check on Modifier.isNative, then all other
method calls get logged. However, native methods don't get intercepted. Is
this supported?

Cheers,
Manish


--------------------------------------------------------------------------------
The information contained herein is confidential and is intended solely 
for the
addressee. Access by any other party is unauthorised without the express
written permission of the sender. If you are not the intended recipient, 
please
contact the sender either via the company switchboard on +44 (0)20 7623 
8000, or
via e-mail return. If you have received this e-mail in error or wish to 
read our
e-mail disclaimer statement and monitoring policy, please refer to 
http://www.drkw.com/disc/email/ or contact the sender. 3167
--------------------------------------------------------------------------------

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




Back to the top