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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值