Package measurements.suites

Source Code of measurements.suites.JVMAIInfoMeasurement$FieldOwnerTestHook

// $Id: JVMAIInfoMeasurement.java,v 1.5 2008/11/18 10:41:01 anicoara Exp $
// =====================================================================

package measurements.suites;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import junit.framework.Assert;
import junit.framework.Test;
import ch.ethz.inf.util.junit.PerformanceTest;
import ch.ethz.inf.util.junit.PerformanceTestSuite;
import ch.ethz.jvmai.*;

/**
* Performance testcase for measuring the speed of the info-interface.
*
* @version  $Revision: 1.5 $
* @author  Andrei Popovici
* @author  Angela Nicoara
*/
public class JVMAIInfoMeasurement extends PerformanceTest {

  public int theMethodToCall(int i, long l, double d, Object o) { return i; }
  public void theMethodToCall(long i){}
  public void theMethodToCall(Object o){}
  public void theMethodToCall(int i){}
  public void theMethodToCall(double d){}
  public void theMethodToCall(){}

  public int theFieldToAccess = 0;

  public static class EmptyTestHook extends JoinPointHook {
    public void onFieldAccess      (FieldAccessJoinPoint       joinPoint) { }
    public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
    public void onMethodEntry      (MethodEntryJoinPoint       joinPoint) { }
    public void onMethodExit       (MethodExitJoinPoint        joinPoint) { }
    public void onExceptionThrow   (ExceptionJoinPoint         joinPoint) { }
    public void onExceptionCatch   (ExceptionCatchJoinPoint     joinPoint) { }       
    public void onClassLoad        (Class cls)                            { }
    public void onConstructor     (ConstructorJoinPoint       joinPoint) { }
  }

  final boolean useProse;

  /**
   * Construct test with given name.
   * @param name test name
   */
  public JVMAIInfoMeasurement(String name) {
    super(name);
    String proseParam = System.getProperty("useprose");
    if(proseParam==null)
      useProse = isDebuggerEnabled();
    else
      useProse = proseParam.toUpperCase().equals("TRUE");
    if (isDebuggerEnabled())
      RANGE = new int[]{ 10000};
    else
      RANGE = new int[]{ 1000000 };
  }

  JVMAspectInterface aspectInterface;

  Method method,methodI,methodL,methodD,methodO,methodV;
  Field field;
  Object param;

  protected void setUp() {
    if (!useProse) Assert.fail("unable to test info-interface if prose is disabled");
    try {
      String providerName = System.getProperty("ch.ethz.prose.JVMAIProvider");
      Class providerClass = Class.forName(providerName);
      Provider provider = (Provider)providerClass.newInstance();

      aspectInterface = provider.getAspectInterface();

      aspectInterface.startup(new String[]{"ch.ethz.prose."},true);

      method = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",
          new Class[]{Integer.TYPE,Long.TYPE,Double.TYPE,Object.class});
      methodI = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class[]{Integer.TYPE});
      methodL = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class[]{Long.TYPE});
      methodD = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class[]{Double.TYPE});
      methodO = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class[]{Object.class});
      methodV = JVMAIInfoMeasurement.class.getDeclaredMethod("theMethodToCall",new Class[]{});
      field = JVMAIInfoMeasurement.class.getDeclaredField("theFieldToAccess");


      param = new String("hello world;");
      EmptyTestHook hook = new EmptyTestHook();
      // call every method at least once ...
      aspectInterface.setJoinPointHook(hook);
      aspectInterface.setMethodEntryWatch(method,new Object());
      aspectInterface.setMethodExitWatch(method,new Object());


      aspectInterface.setFieldAccessWatch(field,new Object());
      aspectInterface.setFieldModificationWatch(field,new Object());
      this.theMethodToCall(1,1,1.0,param);
      int  n = this.theFieldToAccess;
      this.theFieldToAccess = 1;
      aspectInterface.clearMethodEntryWatch(method);
      aspectInterface.clearMethodExitWatch(method);
      aspectInterface.clearFieldAccessWatch(field);
      aspectInterface.clearFieldModificationWatch(field);
      aspectInterface.setJoinPointHook(null);
      aspectInterface.suspendNotification(Thread.currentThread());
      aspectInterface.resumeNotification(Thread.currentThread());

    } catch (Exception e) {
      Assert.fail("loading provider or initializing aspect-interface failed");
    }
  }

  protected void tearDown() { }

  public void test_06_MethodEntry() {
    aspectInterface.setMethodEntryWatch(method,new Object());
    EmptyTestHook hook = new EmptyTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    for(int i =0; i<RUNS; i++)
      this.theMethodToCall(1,1,1.0,param);
    stopChronometer();
    aspectInterface.clearMethodEntryWatch(method);
    aspectInterface.setJoinPointHook(null);
  }

  public void test_13_MethodExit() {
    aspectInterface.setMethodExitWatch(method,new Object());
    EmptyTestHook hook = new EmptyTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    for(int i =0; i<RUNS; i++)
      this.theMethodToCall(1,1,1.0,param);
    stopChronometer();
    aspectInterface.clearMethodExitWatch(method);
    aspectInterface.setJoinPointHook(null);
  }

  public void test_15_FieldAccess() {
    aspectInterface.setFieldAccessWatch(field,new Object());
    EmptyTestHook hook = new EmptyTestHook();
    aspectInterface.setJoinPointHook(hook);
    int n = 0;
    startChronometer();
    for(int i =0; i<RUNS; i++)
      n = this.theFieldToAccess;
    stopChronometer();
    aspectInterface.clearFieldAccessWatch(field);
    aspectInterface.setJoinPointHook(null);
  }

  public void test_18_FieldModification() {
    aspectInterface.setFieldModificationWatch(field,new Object());
    EmptyTestHook hook = new EmptyTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    for(int i =0; i<RUNS; i++)
      this.theFieldToAccess = 1;
    stopChronometer();
    aspectInterface.clearFieldModificationWatch(field);
    aspectInterface.setJoinPointHook(null);
  }

  // ###############################################################################

  public static class LocalVariableTestHook extends JoinPointHook {
    public LocalVariableTestHook() {}
    public void onFieldAccess      (FieldAccessJoinPoint       joinPoint) { }
    public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
    public void onMethodEntry      (MethodEntryJoinPoint       joinPoint) {
      joinPoint.getArgs();
    }
    public void onMethodExit       (MethodExitJoinPoint        joinPoint) { }
    public void onExceptionThrow   (ExceptionJoinPoint         joinPoint) { }
    public void onExceptionCatch   (ExceptionCatchJoinPoint     joinPoint) { }        
    public void onClassLoad        (Class cls)                            { }
    public void onConstructor     (ConstructorJoinPoint     joinPoin) { }

  }

  public void test_08_GetLocalVariableValue_int() {
    aspectInterface.setMethodEntryWatch(methodI,new Object());
    LocalVariableTestHook hook = new LocalVariableTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    int param =1 ;
    for(int i =0; i<RUNS; i++)
      this.theMethodToCall(i);
    stopChronometer();
    aspectInterface.clearMethodEntryWatch(methodI);  aspectInterface.setJoinPointHook(null);
  }

  public void test_09_GetLocalVariableValue_long() {
    long longParam = 1;
    aspectInterface.setMethodEntryWatch(methodL,new Object());
    LocalVariableTestHook hook = new LocalVariableTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    for(int i =0; i<RUNS; i++)
      this.theMethodToCall(longParam);
    stopChronometer();
    aspectInterface.clearMethodEntryWatch(methodL);
    aspectInterface.setJoinPointHook(null);
  }

  public void test_10_GetLocalVariableValue_double() {
    double doubleParam = 12.0;
    aspectInterface.setMethodEntryWatch(methodD,new Object());
    LocalVariableTestHook hook = new LocalVariableTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    for(int i =0; i<RUNS; i++)
      this.theMethodToCall(doubleParam);
    stopChronometer();
    aspectInterface.clearMethodEntryWatch(methodD);
    aspectInterface.setJoinPointHook(null);
  }

  public void test_11_GetLocalVariableValue_Object() {
    Object objectParam = new Object();
    aspectInterface.setMethodEntryWatch(methodO,new Object());
    LocalVariableTestHook hook = new LocalVariableTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    for(int i =0; i<RUNS; i++)
      this.theMethodToCall(objectParam);
    stopChronometer();
    aspectInterface.clearMethodEntryWatch(methodO);
    aspectInterface.setJoinPointHook(null);
  }

  // ###############################################################################

  public static class ThisValueTestHook extends JoinPointHook {

    public ThisValueTestHook() { }
    public void onFieldAccess      (FieldAccessJoinPoint       joinPoint) { }
    public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
    public void onMethodEntry      (MethodEntryJoinPoint       joinPoint) {
      joinPoint.getThis();
    }
    public void onMethodExit       (MethodExitJoinPoint        joinPoint) { }
    public void onExceptionThrow   (ExceptionJoinPoint         joinPoint) { }
    public void onExceptionCatch   (ExceptionCatchJoinPoint     joinPoint) { }    
    public void onClassLoad        (Class cls)                            { }
    public void onConstructor     (ConstructorJoinPoint      joinPoint) { }
  }

  public void test_12_GetThisValue() {
    aspectInterface.setMethodEntryWatch(method,new Object());
    ThisValueTestHook hook = new ThisValueTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    for(int i =0; i<RUNS; i++)
      this.theMethodToCall(1,1,1.0,param);
    stopChronometer();
    aspectInterface.clearMethodEntryWatch(method);
    aspectInterface.setJoinPointHook(null);
  }

  // ###############################################################################

  public static class ReturnValueTestHook extends JoinPointHook {

    public ReturnValueTestHook() { }
    public void onFieldAccess      (FieldAccessJoinPoint       joinPoint) { }
    public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
    public void onMethodEntry      (MethodEntryJoinPoint       joinPoint) { }
    public void onMethodExit       (MethodExitJoinPoint        joinPoint) {
      joinPoint.getResult();
    }
    public void onExceptionThrow   (ExceptionJoinPoint         joinPoint) { }
    public void onExceptionCatch   (ExceptionCatchJoinPoint     joinPoint) { }    
    public void onClassLoad        (Class cls)                            { }
    public void onConstructor     (ConstructorJoinPoint joinPoint)       { }
  }

  public void test_14_GetReturnValue() {
    aspectInterface.setMethodExitWatch(method,new Object());
    ReturnValueTestHook hook = new ReturnValueTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    for(int i =0; i<RUNS; i++)
      this.theMethodToCall(1,1,1.0,param);
    stopChronometer();
    aspectInterface.clearMethodExitWatch(method);
    aspectInterface.setJoinPointHook(null);
  }

  // ###############################################################################

  public static class FieldOwnerTestHook extends JoinPointHook {

    public FieldOwnerTestHook() { }
    public void onFieldAccess      (FieldAccessJoinPoint       joinPoint) {
      joinPoint.getTarget();
    }
    public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
    public void onMethodEntry      (MethodEntryJoinPoint       joinPoint) { }
    public void onMethodExit       (MethodExitJoinPoint        joinPoint) { }
    public void onExceptionThrow   (ExceptionJoinPoint         joinPoint) { }
    public void onExceptionCatch   (ExceptionCatchJoinPoint     joinPoint) { }    
    public void onClassLoad        (Class cls)                            { }
    public void onConstructor     (ConstructorJoinPoint  joinPoint)      { }
  }

  public void test_16_GetFieldOwner() {
    aspectInterface.setFieldAccessWatch(field,new Object());
    FieldOwnerTestHook hook = new FieldOwnerTestHook();
    aspectInterface.setJoinPointHook(hook);
    int n = 0;
    startChronometer();
    for(int i =0; i<RUNS; i++)
      n = this.theFieldToAccess;
    stopChronometer();
    aspectInterface.clearFieldAccessWatch(field);
    aspectInterface.setJoinPointHook(null);
  }

  // ###############################################################################

  public static class FieldValueTestHook extends JoinPointHook {

    public FieldValueTestHook() {  }
    public void onFieldAccess      (FieldAccessJoinPoint       joinPoint) {
      joinPoint.getValue();
    }
    public void onFieldModification(FieldModificationJoinPoint joinPoint) {
      joinPoint.getNewValue();
    }
    public void onMethodEntry      (MethodEntryJoinPoint       joinPoint) { }
    public void onMethodExit       (MethodExitJoinPoint        joinPoint) { }
    public void onExceptionThrow   (ExceptionJoinPoint         joinPoint) { }
    public void onExceptionCatch   (ExceptionCatchJoinPoint     joinPoint) { }     
    public void onClassLoad        (Class cls)                            { }
    public void onConstructor     (ConstructorJoinPoint joinPoint)       { }
  }

  public void test_17_GetFieldValue() {
    aspectInterface.setFieldAccessWatch(field,new Object());
    FieldValueTestHook hook = new FieldValueTestHook();
    aspectInterface.setJoinPointHook(hook);
    int n = 0;
    startChronometer();
    for(int i =0; i<RUNS; i++)
      n = this.theFieldToAccess;
    stopChronometer();
    aspectInterface.clearFieldAccessWatch(field);
    aspectInterface.setJoinPointHook(null);
  }

  public void test_19_GetNewFieldValue() {
    aspectInterface.setFieldModificationWatch(field,new Object());
    FieldValueTestHook hook = new FieldValueTestHook();
    aspectInterface.setJoinPointHook(hook);
    startChronometer();
    for(int i =0; i<RUNS; i++)
      this.theFieldToAccess = 1;
    stopChronometer();
    aspectInterface.clearFieldModificationWatch(field);
    aspectInterface.setJoinPointHook(null);
  }

  /*
   missing measurements for :

   public void setLocalVariableValue(JoinPoint joinPoint, LocalVariableInfo info, Object value);
   public void setFieldValue(FieldJoinPoint joinPoint, Object value);
   public void setNewFieldValue(FieldModificationJoinPoint joinPoint, Object value);
   public void setReturnValue(MethodExitJoinPoint joinPoint, Object value);
   */

  //#####################################################################################################################

  /**
   * Test suite.
   * @return test instance
   */
  public static Test suite() {
    return new PerformanceTestSuite(JVMAIInfoMeasurement.class);
  }

}
TOP

Related Classes of measurements.suites.JVMAIInfoMeasurement$FieldOwnerTestHook

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.