Package com.onpositive.instrumentation.tasks

Source Code of com.onpositive.instrumentation.tasks.CallTracerParticipant

/**
*
*/
package com.onpositive.instrumentation.tasks;

import java.util.HashSet;

import org.objectweb.asm.ClassReader;
import org.objectweb.asm.commons.GeneratorAdapter;

import com.onpositive.instrumentation.processors.ClassProcessingParticipant;
import com.onpositive.instrumentation.processors.InstrumentationContributor;

final class CallTracerParticipant extends ClassProcessingParticipant {
  /**
   *
   */
  private final Instrumentor instrumentor;
  private HashSet<String>packagesToSkip;

  /**
   * @param instrumentor
   */
  CallTracerParticipant(Instrumentor instrumentor,HashSet<String>packagesToSkip) {
    this.instrumentor = instrumentor;
    this.packagesToSkip=packagesToSkip;
  }

 
  public boolean isInterestedIn(ClassReader reader) {
    if (reader.getClassName().endsWith("Trap")) {
      return false;
    }
    return true;
  }
 

 
  public InstrumentationContributor getInstrumentationContributor(int access,
      String name, String desc, String signature, String[] exceptions,
      final GeneratorAdapter adapter) {
    if (name.startsWith("jdo")){
      return new InstrumentationContributor(adapter);
    }
    if (name.startsWith("__jdo")){
      return new InstrumentationContributor(adapter);
    }
    if (name.startsWith("___jdo")){
      return new InstrumentationContributor(adapter);
    }       
    if (name.equals("<clinit>")){
      return new InstrumentationContributor(adapter);
    }
    return new InstrumentationContributor(adapter) {

     
      public void visitMethodInsn(int opcode, String owner, String name,
          String desc) {
        if (owner.endsWith("Trap")) {
          return;
        }
        for (String s:packagesToSkip){
          if (owner.startsWith(s)){
            return;
          }
        }
        if (!instrumentor.isBinary(owner)) {
          return;
        }
       
        int methodId = getMethodId(owner, name, desc);
        adapter.push(methodId);
        adapter.invokeStatic(Instrumentor.methodTrap,
            Instrumentor.enterMethod);
       
      }

     
      public void afterVisitMethodInsn(int opcode, String owner,
          String name, String desc) {
        if (owner.endsWith("Trap")) {
          return;
        }
        for (String s:packagesToSkip){
          if (owner.startsWith(s)){
            return;
          }
        }
        if (!instrumentor.isBinary(owner)) {
          return;
        }
       
        int methodId = getMethodId(owner, name, desc);
        adapter.push(methodId);
        adapter.invokeStatic(Instrumentor.methodTrap,
            Instrumentor.exitMethod);
       
      }

      private int getMethodId(String owner, String name, String desc) {
        return CallTracerParticipant.this.instrumentor.dict.getCallId(
            owner, name, desc);
      }
    };
  }
}
TOP

Related Classes of com.onpositive.instrumentation.tasks.CallTracerParticipant

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.