天天看點

playing with dacapo using aspectj [the series about program instrumentation is done]

I verified two hypothesis on dacapo.

The first is, there are many invocations to thread-safe library, such as synchronizedMap (Collections.synchronized()).

However, I find this hypothesis is wrong. 

I wrote the following aspect, aimed at pinpointing such invocations.

However, none are identified for avrora, batik....

    public pointcut executionOfMap(Object obj) :

          call(*  java.util.Map+.put(..)) && target(obj) ;

    // if you change it to execution, it does not work as aj cannot weave jdk classes.

    // use target(), instead of this(). this() is for the view inside of the invocation, like execution().

    before(Object obj): executionOfMap(obj)

    {

       Class clazz =obj.getClass();

       if(clazz.getName().contains("Synchronized"))

       {

           System.out.println(clazz);

       }

//       Method[] ms =clazz.getMethods();

//       for(Method m:ms)

//       {        

//           if((m.getModifiers()& Modifier.PUBLIC)!=0)

//           {

//               System.out.println(m);

//           }

//       }

    }

The second hypothesis is, there are lots of locking operations.

I wrote an aspect to capture the locking operations. 

For the convenience of future use, let me reitereate the deployment process.

1) ajc Locking.aj -outxml -outjar xx.jar

1.5) Update the Meta info in xx.jar

"Do not forget to include the option for support weaving synchronizations.

add <weaver options="-Xjoinpoints:synchronization"/> to the METAINFO/aop-ajc.xml"

2) java -javaagent:aspectweaver.jar -cp aspectrt.jar:dacapo.jar:xx.jar Harness avrora.

import java.util.HashMap;

import java.util.Iterator;

public aspect Locking {

    public static HashMap map = new HashMap();

    pointcut scope(): !within(Locking) && !cflow(within(Locking));

    after(Object l): lock() && args(l) && scope() {

//    System.out.println("lock:" + l.hashCode());

        Integer value = (Integer)map.get(l);

        if(value==null)

        {

            map.put(l, new Integer(1));

        }else {

            map.put(l, new Integer(value.intValue()+1));

        }

    }

    before():call(* System.exit(..))

    {

        Iterator keyit =map.keySet().iterator();

        while (keyit.hasNext()) {

            Object object = (Object) keyit.next();

            System.out.println(""+object.getClass() + object.hashCode());

            System.out.println(map.get(object));

        }

    }

//after(Object l): unlock() && args(l) && scope() {

//    System.out.println("unlock:" + l.hashCode());

//}

}

It will report the number of locking operations on each lock.

I found that few lock operations are carried out except for the case of eclipse and h2.

Also, I found an interesting scenario that, the code often use synchronized(hashmap) {} instead of invoking the synchronizedMap methods.

More trace files are in the folder ./asm/tami/tamiflexcpu2

繼續閱讀