Package measurements.suites

Source Code of measurements.suites.JoinPointMeasurements2_rejitOverhead2$MethodEntryAspect

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

package measurements.suites;

import junit.framework.Assert;
import junit.framework.Test;
import ch.ethz.prose.DefaultAspect;
import ch.ethz.prose.Aspect;
import ch.ethz.prose.ProseSystem;
import ch.ethz.prose.crosscut.Crosscut;
import ch.ethz.prose.crosscut.MethodCut;
import ch.ethz.prose.crosscut.MethodRedefineCut;
import ch.ethz.prose.crosscut.GetCut;
import ch.ethz.prose.crosscut.SetCut;
import ch.ethz.prose.filter.Fields;
import ch.ethz.prose.filter.PointCutter;
import ch.ethz.prose.filter.Executions;
import ch.ethz.prose.filter.Within;
import ch.ethz.inf.util.junit.PerformanceTest;
import ch.ethz.inf.util.junit.PerformanceTestSuite;
//import ch.ethz.prose.jikesrvm.JikesRVMPerformanceTest;

/**
*  JoinPoint measurements
*
* Performance tests to calculate the relative rejit overhead
* after the aspect has been inserted.
*
* @version  $Revision: 1.2 $
* @author  Angela Nicoara
*/
public class JoinPointMeasurements2_rejitOverhead2 extends PerformanceTest {
//public class JoinPointMeasurements2_rejitOverhead2 extends JikesRVMPerformanceTest {

  public int x;
  public int y = 10;
  public int z;
  public int field = 0;
  public boolean checkAssert = true;

  public void localMethod() {
    x = 1//set the "x" field
    //System.err.println("LocalMethod");
  }

  public void otherMethod() {
    z = y;  // get the "y" field
    //System.err.println("OtherMethod");
  }

  // METHOD ENTRY
  public class MethodEntryAspect extends DefaultAspect {
    public Crosscut c1 = new MethodCut() {
      // execute the advice 'before' the method 'localMethod'
      public void METHOD_ARGS(JoinPointMeasurements2_rejitOverhead2 target) {
        //int q;
        //q = 20;
        target.field = 20;
      }

      // .. && calls(* localMethod())
      protected PointCutter pointCutter() {   
        return (  (Executions.before()) . AND
            (Within.method("localMethod")) . AND
            (Within.type("JoinPointMeasurements2_rejitOverhead2")) );
      }
    };
  }

  // METHOD EXIT
  public class MethodExitAspect extends DefaultAspect {
    public Crosscut c2 = new MethodCut() {
      // execute the advice 'after' the method 'localMethod'
      public void METHOD_ARGS(JoinPointMeasurements2_rejitOverhead2 target) {
        //int q;
        //q = 30;
        target.field = 30;
      }

      // .. && calls(* localMethod())
      protected PointCutter pointCutter() {
        return (  (Executions.after()) . AND
            (Within.method("localMethod")) . AND
            (Within.type("JoinPointMeasurements2_rejitOverhead2")) );
      }
    };
  }

  // METHOD REDEFINITION
  public class MethodRedefineAspect extends DefaultAspect {
    public Crosscut c3 = new MethodRedefineCut() {
      // the body of new method
      public void METHOD_ARGS(JoinPointMeasurements2_rejitOverhead2 target) {
        //int q;
        //q = 40;
        target.field = 40;
      }

      protected PointCutter pointCutter() {
        return ( (Within.method("localMethod")) .AND
            (Within.type("JoinPointMeasurements2_rejitOverhead2")) );
      }
    };
  }

  // FIELD ACCESS
  public class FieldAccessAspect extends DefaultAspect {
    public Crosscut c4 = new GetCut() {
      //public void GET_ARGS()   //EMPTY -> equivalent with GET_ARGS(ANY,ANY)
      public void GET_ARGS(JoinPointMeasurements2_rejitOverhead2 target, int x)   //CONCRETE__CONCRETE
      //public void GET_ARGS(ANY obj, double x) //WILDCARD__CONCRETE
      //public void GET_ARGS(ANY obj, ANY x)    //WILDCARD__WILDCARD -> equivalent with GET_ARGS()
      {
        //int q;
        //q = 50;
        target.field = 50;
      }

      protected PointCutter pointCutter() {
        return ( (Fields.named("y.*")) .AND (Fields.declaredInClass("JoinPointMeasurements2_rejitOverhead2")) );
      }
    };
  }

  // FIELD MODIFICATION
  public class FieldModificationAspect extends DefaultAspect {
    public Crosscut c5 = new SetCut() {
      //public void SET_ARGS()   //EMPTY -> equivalent with GET_ARGS(ANY,ANY)
      public void SET_ARGS(JoinPointMeasurements2_rejitOverhead2 target, int x)   //CONCRETE__CONCRETE
      //public void SET_ARGS(ANY obj, double x) //WILDCARD__CONCRETE
      //public void SET_ARGS(ANY obj, ANY x)    //WILDCARD__WILDCARD -> equivalent with GET_ARGS()
      {
        //int q;
        //q = 60;
        target.field = 60;
      }

      protected PointCutter pointCutter() {
        return ( Fields.named("x.*") .AND (Fields.declaredInClass("JoinPointMeasurements2_rejitOverhead2")) );
      }
    };
  }

  Aspect aspect1;  // METHOD ENTRY
  Aspect aspect2;  // METHOD EXIT
  Aspect aspect3;  // METHOD REDEFINITION
  Aspect aspect4;  // FIELD ACCESS
  Aspect aspect5;  // FIELD MODIFICATION

  public boolean useProse = false;

  /**
   * Construct test with given name.
   * @param name test name
   */
  public JoinPointMeasurements2_rejitOverhead2(String name) {
    super(name);
    //RANGE = new int[] { 1 };
    RANGE = new int[] { 100000 };

    String proseParam = System.getProperty("useprose");
    if (proseParam != null) useProse = true;   
  }

  /**
   * Set up fixture.
   */
  protected void setUp() {
    if (!useProse) return;

    try {
      ProseSystem.startup();
    } catch (Exception e) {
      Assert.fail("ProseSystem.startup() failed");
    }

    aspect1 = new MethodEntryAspect();
    aspect2 = new MethodExitAspect();
    aspect3 = new MethodRedefineAspect();
    aspect4 = new FieldAccessAspect();
    aspect5 = new FieldModificationAspect();

    field = 0;
  }

  protected void tearDown() {
    if (!useProse) return;

    try {
      ProseSystem.teardown();
    } catch (Exception e) {
      Assert.fail("ProseSystem.teardown() failed");
    }
  }

  //========= METHOD ENTRY =========

  // the rejit overhead is included
  public void test_the_rejit_overhead_for_MethodEntry_1() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect1);

    startChronometer();
    for (int i=0; i < RUNS; i++) localMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect1);

    if(checkAssert) assertEquals("Hook notifications", 20, field);
  }

  // the rejit overhead isn't included
  public void test_the_rejit_overhead_for_MethodEntry_2() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect1);

    startChronometer();
    for (int i=0; i < RUNS; i++) localMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect1);

    if(checkAssert) assertEquals("Hook notifications", 20, field);
  }


  //========= METHOD EXIT =========

  // the rejit overhead is included
  public void test_the_rejit_overhead_for_MethodExit_1() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect2);

    startChronometer();
    for (int i=0; i < RUNS; i++) localMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect2);

    if(checkAssert) assertEquals("Hook notifications", 30, field);
  }


  // the rejit overhead isn't included
  public void test_the_rejit_overhead_for_MethodExit_2() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect2);

    startChronometer();
    for (int i=0; i < RUNS; i++) localMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect2);

    if(checkAssert) assertEquals("Hook notifications", 30, field);
  }


  //========= METHOD REDEFINITION =========

  // the rejit overhead is included
  public void test_the_rejit_overhead_for_MethodRedefinition_1() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect3);

    startChronometer();
    for (int i=0; i < RUNS; i++) localMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect3);

    if(checkAssert) assertEquals("Hook notifications", 40, field);
  }


  // the rejit overhead isn't included
  public void test_the_rejit_overhead_for_MethodRedefinition_2() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect3);

    startChronometer();
    for (int i=0; i < RUNS; i++) localMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect3);

    if(checkAssert) assertEquals("Hook notifications", 40, field);
  }


  //========= FIELD ACCESS =========

  // the rejit overhead is included
  public void test_the_rejit_overhead_for_FieldAccess_1() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect4);

    startChronometer();
    for (int i=0; i < RUNS; i++) otherMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect4);

    if(checkAssert) assertEquals("Hook notifications", 50, field);
  }


  // the rejit overhead isn't included
  public void test_the_rejit_overhead_for_FieldAccess_2() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect4);

    startChronometer();
    for (int i=0; i < RUNS; i++) otherMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect4);

    if(checkAssert) assertEquals("Hook notifications", 50, field);
  }


  //========= FIELD MODIFICATION =========

  // the rejit overhead is included
  public void test_the_rejit_overhead_for_FieldModification_1() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect5);

    startChronometer();
    for (int i=0; i < RUNS; i++) localMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect5);

    if(checkAssert) assertEquals("Hook notifications", 60, field);
  }

  // the rejit overhead isn't included
  public void test_the_rejit_overhead_for_FieldModification_2() {
    if (useProse) ProseSystem.getAspectManager().insert(aspect5);

    startChronometer();
    for (int i=0; i < RUNS; i++) localMethod();
    stopChronometer();

    if (useProse) ProseSystem.getAspectManager().withdraw(aspect5);

    if(checkAssert) assertEquals("Hook notifications", 60, field);
  }

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

Related Classes of measurements.suites.JoinPointMeasurements2_rejitOverhead2$MethodEntryAspect

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.