Package measurements.suites

Source Code of measurements.suites.ProceedMeasurements2_rejitOverhead2$MethodRedefineAspect1

// $Id: ProceedMeasurements2_rejitOverhead2.java,v 1.1 2008/11/18 10:43:24 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.1 $
* @author  Angela Nicoara
*/
public class ProceedMeasurements2_rejitOverhead2 extends PerformanceTest {
//public class ProceedMeasurements2_rejitOverhead2 extends JikesRVMPerformanceTest {

  //public int x;
  public int field = 0;
  public boolean checkAssert = true;

  /*BEFORE:
  public void localMethod() {
    field = 1;
    //x = 1;    //set the "x" field
    //System.err.println("localMethod() - field = " + field);
  }
   */
  public int localMethod (int k) {
    field = k;
    //x = 1;    //set the "x" field
    //System.err.println("localMethod() - field = " + field);
    return field;
  }

  // METHOD REDEFINITION - no proceed()
  public class MethodRedefineAspect1 extends DefaultAspect {

    public Crosscut c1 = new MethodRedefineCut() {
      // the new method code
      public int METHOD_ARGS(ProceedMeasurements2_rejitOverhead2 target, int k) {
        //target.field = 10;
        return k;
      }

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

  // METHOD REDEFINITION - one proceed()
  public class MethodRedefineAspect2 extends DefaultAspect {

    public Crosscut c2 = new MethodRedefineCut() {
      // the new method code
      public int METHOD_ARGS(ProceedMeasurements2_rejitOverhead2 target, int k) {
        proceed();
        //target.field = 20;
        return k;
      }

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

  // METHOD REDEFINITION - two proceed()
  public class MethodRedefineAspect3 extends DefaultAspect {

    public Crosscut c3 = new MethodRedefineCut() {
      // the new method code
      public int METHOD_ARGS(ProceedMeasurements2_rejitOverhead2 target, int k) {
        proceed();
        proceed();
        //target.field = 30;
        return k;
      }

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

  // METHOD REDEFINITION - three proceed()
  public class MethodRedefineAspect4 extends DefaultAspect {

    public Crosscut c4 = new MethodRedefineCut() {
      // the new method code
      public int METHOD_ARGS(ProceedMeasurements2_rejitOverhead2 target, int k) {
        proceed();
        proceed();
        proceed();
        //target.field = 40;
        return k;
      }

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

  // METHOD REDEFINITION - four proceed()
  public class MethodRedefineAspect5 extends DefaultAspect {

    public Crosscut c5 = new MethodRedefineCut() {
      // the new method code
      public int METHOD_ARGS(ProceedMeasurements2_rejitOverhead2 target, int k) {
        proceed();
        proceed();
        proceed();
        proceed();
        //target.field = 50;
        return k;
      }

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

  // METHOD REDEFINITION - five proceed()
  public class MethodRedefineAspect6 extends DefaultAspect {

    public Crosscut c6 = new MethodRedefineCut() {
      // the new method code
      public int METHOD_ARGS(ProceedMeasurements2_rejitOverhead2 target, int k) {
        proceed();
        proceed();
        proceed();
        proceed();
        proceed();
        //target.field = 60;
        return k;
      }

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

  Aspect aspect1;  // METHOD REDEFINITION - no proceed()
  Aspect aspect2;  // METHOD REDEFINITION - one proceed()
  Aspect aspect3;  // METHOD REDEFINITION - two proceed()
  Aspect aspect4;  // METHOD REDEFINITION - three proceed()
  Aspect aspect5;  // METHOD REDEFINITION - four proceed()
  Aspect aspect6;  // METHOD REDEFINITION - five proceed()

  public boolean useProse = false;

  /**
   * Construct test with given name.
   * @param name test name
   */
  public ProceedMeasurements2_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 MethodRedefineAspect1();
    aspect2 = new MethodRedefineAspect2();
    aspect3 = new MethodRedefineAspect3();
    aspect4 = new MethodRedefineAspect4();
    aspect5 = new MethodRedefineAspect5();
    aspect6 = new MethodRedefineAspect6();

    field = 0;
  }

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

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


  //========= METHOD REDEFINITION - no proceed() =========
  /*
  // rejit overhead
  public void test_the_rejit_overhead_for_MethodRedefinition_noProceed() {
    int sum = 0;
    for (int i=0; i < 100000; i++) { localMethod(i); sum += field; }

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

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

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

    //if(checkAssert) assertEquals("Hook notifications", 10, field);
  }
   */

  //========= METHOD REDEFINITION - one proceed() =========

  // rejit overhead
  public void test_the_rejit_overhead_for_MethodRedefinition_oneProceed() {
    int sum = 0;
    for (int i=0; i < 100000; i++) { localMethod(i); sum += field; }
    //localMethod(1); sum += field;

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

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

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

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


  //========= METHOD REDEFINITION - two proceed() =========

  // rejit overhead
  public void test_the_rejit_overhead_for_MethodRedefinition_twoProceed() {
    int sum = 0;
    for (int i=0; i < 100000; i++) { localMethod(i); sum += field; }
    //localMethod(1); sum += field;

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

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

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

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


  //========= METHOD REDEFINITION - three proceed() =========

  // rejit overhead
  public void test_the_rejit_overhead_for_MethodRedefinition_threeProceed() {
    int sum = 0;
    for (int i=0; i < 100000; i++) { localMethod(i); sum += field; }
    //localMethod(1); sum += field;

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

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

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

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


  //========= METHOD REDEFINITION - four proceed() =========

  // rejit overhead
  public void test_the_rejit_overhead_for_MethodRedefinition_fourProceed() {
    int sum = 0;
    for (int i=0; i < 100000; i++) { localMethod(i); sum += field; }
    //localMethod(1); sum += field;

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

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

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

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


  //========= METHOD REDEFINITION - five proceed() =========

  // rejit overhead
  public void test_the_rejit_overhead_for_MethodRedefinition_fiveProceed() {
    int sum = 0;
    for (int i=0; i < 100000; i++) { localMethod(i); sum += field; }
    //localMethod(1); sum += field;

    if (useProse) ProseSystem.getAspectManager().insert(aspect6);

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

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

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

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

Related Classes of measurements.suites.ProceedMeasurements2_rejitOverhead2$MethodRedefineAspect1

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.