// $Id: JVMAIMeasurement.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.iks.jvmai.jvmdi.FieldAccessJoinPointImpl;
import ch.ethz.inf.util.junit.PerformanceTest;
import ch.ethz.inf.util.junit.PerformanceTestSuite;
import ch.ethz.jvmai.*;
/**
* Performance testcase for measuring the dispatching speed of the debugger.
* <p>
* In this testcase,the column <code>RUNS</code> (the fifths)
* represents the time needed to breakpoint a method RUNS times.
* No additional functionality is called in the dispatch.
*
* @version $Revision: 1.5 $
* @author Andrei Popovici
*/
public class JVMAIMeasurement extends PerformanceTest {
// fixture
public void theMethodToCall() { }
public int theFieldToAccess = 0;
public static class TestHook 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 JVMAIMeasurement(String name) {
super(name);
String proseParam = System.getProperty("useprose");
if(proseParam==null)
useProse = isDebuggerEnabled();
else
useProse = proseParam.toUpperCase().equals("TRUE");
if(useProse) {
// we either do RVM or use the debugger
if (isDebuggerEnabled())
RANGE = new int[]{ 10000};
else
RANGE = new int[]{ 1000000};
}
else
RANGE = new int[]{ 10000000 };
}
JVMAspectInterface aspectInterface;
Method method;
Field field;
Method interfaceMethod;
TestHook hook;
protected void setUp() {
hook = new TestHook();
// call every method at least once ...
hook.onFieldAccess(null);
hook.onFieldModification(null);
hook.onMethodEntry(null);
hook.onMethodExit(null);
this.theMethodToCall();
int n = this.theFieldToAccess;
this.theFieldToAccess = 1;
if (!useProse) return;
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 = JVMAIMeasurement.class.getDeclaredMethod("theMethodToCall",new Class[]{});
interfaceMethod = TestClass1.class.getDeclaredMethod("interfaceMethodLong",
new Class[]{Object.class,
Object.class});
field = JVMAIMeasurement.class.getDeclaredField("theFieldToAccess");
// 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());
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 testHook() {
FieldAccessJoinPoint joinPoint = new FieldAccessJoinPointImpl(null,null);
JoinPointHook jpHook = hook;
// call every method at least once ...
jpHook.onFieldAccess(null);
jpHook.onFieldModification(null);
jpHook.onMethodEntry(null);
jpHook.onMethodExit(null);
startChronometer();
for(int i =0; i<RUNS; i++)
jpHook.onFieldAccess(joinPoint);
stopChronometer();
}
public void testEmptyFieldAccess() {
int n = 0;
startChronometer();
for(int i =0; i<RUNS; i++)
n = 0;
stopChronometer();
}
public void testDoubleField() {
startChronometer();
for(int i =0; i<RUNS; i++)
this.theFieldToAccess = this.theFieldToAccess;
stopChronometer();
}
//#####################################################################################################################
public void testMethod() {
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
}
public void testMethod_Hook() {
if(useProse) {
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.setJoinPointHook(null);
}
}
public void testMethod_Suspended() {
if(useProse) {
aspectInterface.suspendNotification(Thread.currentThread());
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.resumeNotification(Thread.currentThread());
}
}
public void testMethod_HookSuspended() {
if(useProse) {
aspectInterface.suspendNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.resumeNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(null);
}
}
//#####################################################################################################################
public void testMethodEntryWatch() {
if(useProse) {
aspectInterface.setMethodEntryWatch(method,new Object());
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.clearMethodEntryWatch(method);
}
}
public void testMethodEntryWatch_Hook() {
if(useProse) {
aspectInterface.setMethodEntryWatch(method,new Object());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.clearMethodEntryWatch(method);
aspectInterface.setJoinPointHook(null);
}
}
public void testMethodEntryWatch_Suspended() {
if(useProse) {
aspectInterface.setMethodEntryWatch(method,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.clearMethodEntryWatch(method);
aspectInterface.resumeNotification(Thread.currentThread());
}
}
public void testMethodEntryWatch_HookSuspended() {
if(useProse) {
aspectInterface.setMethodEntryWatch(method,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.clearMethodEntryWatch(method);
aspectInterface.resumeNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(null);
}
}
//#####################################################################################################################
//#####################################################################################################################
public void testInterfaceMethod() {
String x = "hello";
TestInterface obj = new TestClass1();
startChronometer();
for(int i =0; i<RUNS; i++)
obj.interfaceMethodLong(x,x);
stopChronometer();
}
public void testInterfaceEntryWatch() {
String x = "hello";
TestInterface obj = new TestClass1();
if(useProse) {
aspectInterface.setMethodEntryWatch(interfaceMethod,new Object());
}
startChronometer();
for(int i =0; i<RUNS; i++)
obj.interfaceMethodLong(x,x);
stopChronometer();
if(useProse) {
aspectInterface.clearMethodEntryWatch(interfaceMethod);
}
}
public void testInterfaceEntryWatch_Hook() {
String x = "hello";
TestInterface obj = new TestClass1();
if(useProse) {
aspectInterface.setMethodEntryWatch(interfaceMethod,new Object());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
obj.interfaceMethodLong(x,x);
stopChronometer();
if(useProse) {
aspectInterface.clearMethodEntryWatch(interfaceMethod);
aspectInterface.setJoinPointHook(null);
}
}
public void testInterfaceEntryWatch_Suspended() {
String x = "hello";
TestInterface obj = new TestClass1();
if(useProse) {
aspectInterface.setMethodEntryWatch(interfaceMethod,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
}
startChronometer();
for(int i =0; i<RUNS; i++)
obj.interfaceMethodLong(x,x);
stopChronometer();
if(useProse) {
aspectInterface.clearMethodEntryWatch(interfaceMethod);
aspectInterface.resumeNotification(Thread.currentThread());
}
}
public void testInterfaceEntryWatch_HookSuspended() {
String x = "hello";
TestInterface obj = new TestClass1();
if(useProse) {
aspectInterface.setMethodEntryWatch(interfaceMethod,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
obj.interfaceMethodLong(x,x);
stopChronometer();
if(useProse) {
aspectInterface.clearMethodEntryWatch(interfaceMethod);
aspectInterface.resumeNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(null);
}
}
public void testInterfaceExitWatch() {
String x = "hello";
TestInterface obj = new TestClass1();
if(useProse) {
aspectInterface.setMethodExitWatch(interfaceMethod,new Object());
}
startChronometer();
for(int i =0; i<RUNS; i++)
obj.interfaceMethodLong(x,x);
stopChronometer();
if(useProse) {
aspectInterface.clearMethodExitWatch(interfaceMethod);
}
}
public void testInterfaceExitWatch_Hook() {
String x = "hello";
TestInterface obj = new TestClass1();
if(useProse) {
aspectInterface.setMethodExitWatch(interfaceMethod,new Object());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
obj.interfaceMethodLong(x,x);
stopChronometer();
if(useProse) {
aspectInterface.clearMethodExitWatch(interfaceMethod);
aspectInterface.setJoinPointHook(null);
}
}
public void testInterfaceExitWatch_Suspended() {
String x = "hello";
TestInterface obj = new TestClass1();
if(useProse) {
aspectInterface.setMethodExitWatch(interfaceMethod,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
}
startChronometer();
for(int i =0; i<RUNS; i++)
obj.interfaceMethodLong(x,x);
stopChronometer();
if(useProse) {
aspectInterface.clearMethodExitWatch(interfaceMethod);
aspectInterface.resumeNotification(Thread.currentThread());
}
}
public void testInterfaceExitWatch_HookSuspended() {
String x = "hello";
TestInterface obj = new TestClass1();
if(useProse) {
aspectInterface.setMethodExitWatch(interfaceMethod,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
obj.interfaceMethodLong(x,x);
stopChronometer();
if(useProse) {
aspectInterface.clearMethodExitWatch(interfaceMethod);
aspectInterface.resumeNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(null);
}
}
//#####################################################################################################################
public void testMethodExitWatch() {
if(useProse) {
aspectInterface.setMethodExitWatch(method,new Object());
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.clearMethodExitWatch(method);
}
}
public void testMethodExitWatch_Hook() {
if(useProse) {
aspectInterface.setMethodExitWatch(method,new Object());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.clearMethodExitWatch(method);
aspectInterface.setJoinPointHook(null);
}
}
public void testMethodExitWatch_Suspended() {
if(useProse) {
aspectInterface.setMethodExitWatch(method,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.clearMethodExitWatch(method);
aspectInterface.resumeNotification(Thread.currentThread());
}
}
public void testMethodExitWatch_HookSuspended() {
if(useProse) {
aspectInterface.setMethodExitWatch(method,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theMethodToCall();
stopChronometer();
if(useProse) {
aspectInterface.clearMethodExitWatch(method);
aspectInterface.resumeNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(null);
}
}
//#####################################################################################################################
public void testFieldAccess() {
int n = 0;
startChronometer();
for(int i =0; i<RUNS; i++)
n = this.theFieldToAccess;
stopChronometer();
}
public void testFieldAccess_Hook() {
if(useProse) {
aspectInterface.setJoinPointHook(hook);
}
int n = 0;
startChronometer();
for(int i =0; i<RUNS; i++)
n = this.theFieldToAccess;
stopChronometer();
if(useProse) {
aspectInterface.setJoinPointHook(null);
}
}
public void testFieldAccess_Suspended() {
if(useProse) {
aspectInterface.suspendNotification(Thread.currentThread());
}
int n = 0;
startChronometer();
for(int i =0; i<RUNS; i++)
n = this.theFieldToAccess;
stopChronometer();
if(useProse) {
aspectInterface.resumeNotification(Thread.currentThread());
}
}
public void testFieldAccess_HookSuspended() {
if(useProse) {
aspectInterface.suspendNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(hook);
}
int n = 0;
startChronometer();
for(int i =0; i<RUNS; i++)
n = this.theFieldToAccess;
stopChronometer();
if(useProse) {
aspectInterface.resumeNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(null);
}
}
//#####################################################################################################################
public void testFieldModification() {
startChronometer();
for(int i =0; i<RUNS; i++)
this.theFieldToAccess = 1;
stopChronometer();
}
public void testFieldModification_Hook() {
if(useProse) {
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theFieldToAccess = 1;
stopChronometer();
if(useProse) {
aspectInterface.setJoinPointHook(null);
}
}
public void testFieldModification_Suspended() {
if(useProse) {
aspectInterface.suspendNotification(Thread.currentThread());
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theFieldToAccess = 1;
stopChronometer();
if(useProse) {
aspectInterface.resumeNotification(Thread.currentThread());
}
}
public void testFieldModification_HookSuspended() {
if(useProse) {
aspectInterface.suspendNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theFieldToAccess = 1;
stopChronometer();
if(useProse) {
aspectInterface.resumeNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(null);
}
}
//#####################################################################################################################
public void testFieldAccessWatch() {
if(useProse) {
aspectInterface.setFieldAccessWatch(field,new Object());
}
int n = 0;
startChronometer();
for(int i =0; i<RUNS; i++)
n = this.theFieldToAccess;
stopChronometer();
if(useProse) {
aspectInterface.clearFieldAccessWatch(field);
}
}
public void testFieldAccessWatch_Hook() {
if(useProse) {
aspectInterface.setFieldAccessWatch(field,new Object());
aspectInterface.setJoinPointHook(hook);
}
int n = 0;
startChronometer();
for(int i =0; i<RUNS; i++)
n = this.theFieldToAccess;
stopChronometer();
if(useProse) {
aspectInterface.clearFieldAccessWatch(field);
aspectInterface.setJoinPointHook(null);
}
}
public void testFieldAccessWatch_Suspended() {
if(useProse) {
aspectInterface.setFieldAccessWatch(field,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
}
int n = 0;
startChronometer();
for(int i =0; i<RUNS; i++)
n = this.theFieldToAccess;
stopChronometer();
if(useProse) {
aspectInterface.clearFieldAccessWatch(field);
aspectInterface.resumeNotification(Thread.currentThread());
}
}
public void testFieldAccessWatch_HookSuspended() {
if(useProse) {
aspectInterface.setFieldAccessWatch(field,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(hook);
}
int n = 0;
startChronometer();
for(int i =0; i<RUNS; i++)
n = this.theFieldToAccess;
stopChronometer();
if(useProse) {
aspectInterface.clearFieldAccessWatch(field);
aspectInterface.resumeNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(null);
}
}
//#####################################################################################################################
public void testFieldModificationWatch() {
if(useProse) {
aspectInterface.setFieldModificationWatch(field,new Object());
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theFieldToAccess = 1;
stopChronometer();
if(useProse) {
aspectInterface.clearFieldModificationWatch(field);
}
}
public void testFieldModificationWatch_Hook() {
if(useProse) {
aspectInterface.setFieldModificationWatch(field,new Object());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theFieldToAccess = 1;
stopChronometer();
if(useProse) {
aspectInterface.clearFieldModificationWatch(field);
aspectInterface.setJoinPointHook(null);
}
}
public void testFieldModificationWatch_Suspended() {
if(useProse) {
aspectInterface.setFieldModificationWatch(field,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theFieldToAccess = 1;
stopChronometer();
if(useProse) {
aspectInterface.clearFieldModificationWatch(field);
aspectInterface.resumeNotification(Thread.currentThread());
}
}
public void test1FieldModificationWatch_HookSuspended() {
if(useProse) {
aspectInterface.setFieldModificationWatch(field,new Object());
aspectInterface.suspendNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(hook);
}
startChronometer();
for(int i =0; i<RUNS; i++)
this.theFieldToAccess = 1;
stopChronometer();
if(useProse) {
aspectInterface.clearFieldModificationWatch(field);
aspectInterface.resumeNotification(Thread.currentThread());
aspectInterface.setJoinPointHook(null);
}
}
//#####################################################################################################################
/**
* Test suite.
* @return test instance
*/
public static Test suite() {
return new PerformanceTestSuite(JVMAIMeasurement.class);
}
}