Browse Source

Performance benchmarks from Noel and Matthew. Run these tests standalone to generate a .csv file containing results.

tags/v_preCompileLoopAlteration
aclement 20 years ago
parent
commit
91cb850e1f

+ 301
- 0
org.aspectj.ajdt.core/testsrc/RunWeaveTests.java View File

@@ -0,0 +1,301 @@
/* *******************************************************************
* Copyright (c) 2004 IBM Corporation
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Common Public License v1.0
* which accompanies this distribution and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Noel Markham, Matthew Webster initial implementation
* ******************************************************************/

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.StringTokenizer;

/**
* @author Noel Markham
*/
public class RunWeaveTests {

private static boolean RUN_SMALL = true;
private static boolean RUN_MED = true;
private static boolean RUN_LARGE = true;
private static final String SMALL_PROGRAM_ARGS = "-c 5 -m 100 -l 10 "; // must end on a space in case any more arguments are added later in the script
private static final String MEDIUM_PROGRAM_ARGS = "-c 25 -m 100 -l 10 ";
private static final String LARGE_PROGRAM_ARGS = "-c 125 -m 100 -l 10 ";
private static final String WARMUP_ARGS = "-c 3 -m 100 -l 10 ";

private static final int ITERATIONS = 3;
private static String filename;
private static long[][] times = new long[7][3 * ITERATIONS];
public static void main(String[] args) throws IOException {
parseArgs(args);
// Purely as a warm-up...
System.out.println("Warming up...");
WeaveTests.main(split(WARMUP_ARGS + "-i " + ITERATIONS));

if (RUN_SMALL) {
WeaveTests.main(
split(SMALL_PROGRAM_ARGS + "-echo -i " + ITERATIONS));

for (int i = 0; i < ITERATIONS; i++)
times[0][i] = WeaveTests.compileTimes[i];

for (int i = 0; i < ITERATIONS; i++)
times[1][i] = WeaveTests.executionFastTimes[i];
for (int i = 0; i < ITERATIONS; i++)
times[2][i] = WeaveTests.executionMedTimes[i];
for (int i = 0; i < ITERATIONS; i++)
times[3][i] = WeaveTests.executionSlowTimes[i];

for (int i = 0; i < ITERATIONS; i++)
times[4][i] = WeaveTests.getFastTimes[i];
for (int i = 0; i < ITERATIONS; i++)
times[5][i] = WeaveTests.getMedTimes[i];
for (int i = 0; i < ITERATIONS; i++)
times[6][i] = WeaveTests.getSlowTimes[i];
}
if (RUN_MED) {
WeaveTests.main(
split(MEDIUM_PROGRAM_ARGS + "-echo -i " + ITERATIONS));

for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
times[0][i] = WeaveTests.compileTimes[i - ITERATIONS];

for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
times[1][i] = WeaveTests.executionFastTimes[i - ITERATIONS];
for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
times[2][i] = WeaveTests.executionMedTimes[i - ITERATIONS];
for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
times[3][i] = WeaveTests.executionSlowTimes[i - ITERATIONS];

for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
times[4][i] = WeaveTests.getFastTimes[i - ITERATIONS];
for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
times[5][i] = WeaveTests.getMedTimes[i - ITERATIONS];
for (int i = ITERATIONS; i < (2 * ITERATIONS); i++)
times[6][i] = WeaveTests.getSlowTimes[i - ITERATIONS];
}
if (RUN_LARGE) {
WeaveTests.main(
split(LARGE_PROGRAM_ARGS + "-echo -i " + ITERATIONS));

for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
times[0][i] = WeaveTests.compileTimes[i - (2 * ITERATIONS)];

for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
times[1][i] =
WeaveTests.executionFastTimes[i - (2 * ITERATIONS)];
for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
times[2][i] =
WeaveTests.executionMedTimes[i - (2 * ITERATIONS)];
for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
times[3][i] =
WeaveTests.executionSlowTimes[i - (2 * ITERATIONS)];

for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
times[4][i] = WeaveTests.getFastTimes[i - (2 * ITERATIONS)];
for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
times[5][i] = WeaveTests.getMedTimes[i - (2 * ITERATIONS)];
for (int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++)
times[6][i] = WeaveTests.getSlowTimes[i - (2 * ITERATIONS)];
}

createCSV();
}
/* Compatibility with JDK 1.3.1 */
private static String[] split (String s) {
List list = new ArrayList();
StringTokenizer st = new StringTokenizer(s," ");
while (st.hasMoreTokens()) {
list.add(st.nextToken());
}
String[] result = new String[list.size()];
list.toArray(result);
return result;
}
private static void parseArgs(String args[]) {
if(args == null || args.length <= 0) {
System.out.println("Running all program tests");
return;
}
if(args[0].equals("-small")) {
System.out.println("Running small-sized program test only");
RUN_SMALL = true;
RUN_MED = false;
RUN_LARGE = false;
}
else if(args[0].equals("-medium")) {
System.out.println("Running small- and medium -sized program tests");
RUN_SMALL = true;
RUN_MED = true;
RUN_LARGE = false;
}
else if(args[0].equals("-large")) {
System.out.println("Running all program tests");
RUN_SMALL = true;
RUN_MED = true;
RUN_LARGE = true;
}
else usage();
}
private static void usage() {
System.err.println("Usage:");
System.err.println("\tjava RunWeaveTests [-small|-medium|-large]");
System.exit(-1);
}
private static void createCSV() {
String NL = System.getProperty("line.separator", "\n");
StringBuffer csv = new StringBuffer(1000);
csv.append("Test Results");
if(RUN_SMALL) for(int i = 0; i < ITERATIONS; i++) csv.append("," + SMALL_PROGRAM_ARGS);
if(RUN_MED) for(int i = 0; i < ITERATIONS; i++) csv.append("," + MEDIUM_PROGRAM_ARGS);
if(RUN_LARGE) for(int i = 0; i < ITERATIONS; i++) csv.append("," + LARGE_PROGRAM_ARGS);
csv.append(NL);
csv.append("Compile");
if(RUN_SMALL) for(int i = 0; i < ITERATIONS; i++) csv.append("," + times[0][i]);
if(RUN_MED) for(int i = ITERATIONS; i < (2 * ITERATIONS); i++) csv.append("," + times[0][i]);
if(RUN_LARGE) for(int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++) csv.append("," + times[0][i]);

csv.append(NL);

csv.append(WeaveTests.EXECUTION_FAST);
if(RUN_SMALL) for(int i = 0; i < ITERATIONS; i++) csv.append("," + times[1][i]);
if(RUN_MED) for(int i = ITERATIONS; i < (2 * ITERATIONS); i++) csv.append("," + times[1][i]);
if(RUN_LARGE) for(int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++) csv.append("," + times[1][i]);
csv.append(NL);
csv.append(WeaveTests.EXECUTION_MED);
if(RUN_SMALL) for(int i = 0; i < ITERATIONS; i++) csv.append("," + times[2][i]);
if(RUN_MED) for(int i = ITERATIONS; i < (2 * ITERATIONS); i++) csv.append("," + times[2][i]);
if(RUN_LARGE) for(int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++) csv.append("," + times[2][i]);
csv.append(NL);

csv.append(WeaveTests.EXECUTION_SLOW);
if(RUN_SMALL) for(int i = 0; i < ITERATIONS; i++) csv.append("," + times[3][i]);
if(RUN_MED) for(int i = ITERATIONS; i < (2 * ITERATIONS); i++) csv.append("," + times[3][i]);
if(RUN_LARGE) for(int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++) csv.append("," + times[3][i]);
csv.append(NL);

csv.append(WeaveTests.GET_FAST);
if(RUN_SMALL) for(int i = 0; i < ITERATIONS; i++) csv.append("," + times[4][i]);
if(RUN_MED) for(int i = ITERATIONS; i < (2 * ITERATIONS); i++) csv.append("," + times[4][i]);
if(RUN_LARGE) for(int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++) csv.append("," + times[4][i]);
csv.append(NL);

csv.append(WeaveTests.GET_MED);
if(RUN_SMALL) for(int i = 0; i < ITERATIONS; i++) csv.append("," + times[5][i]);
if(RUN_MED) for(int i = ITERATIONS; i < (2 * ITERATIONS); i++) csv.append("," + times[5][i]);
if(RUN_LARGE) for(int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++) csv.append("," + times[5][i]);
csv.append(NL);

csv.append(WeaveTests.GET_SLOW);
if(RUN_SMALL) for(int i = 0; i < ITERATIONS; i++) csv.append("," + times[6][i]);
if(RUN_MED) for(int i = ITERATIONS; i < (2 * ITERATIONS); i++) csv.append("," + times[6][i]);
if(RUN_LARGE) for(int i = (2 * ITERATIONS); i < (3 * ITERATIONS); i++) csv.append("," + times[6][i]);
csv.append(NL);
filename = createFilename();
try {
FileOutputStream fos = new FileOutputStream(filename);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(new String(csv).getBytes());
bos.close();
fos.close();
} catch (IOException e) {
System.err.println("Could not print to file " + filename);
System.err.println(csv);
}
System.out.println("Written: " + filename);
}
private static String createFilename() {
return (getVMInfo() + "_" + getDateAndTime()).replace('.', '_') + ".csv";
}
private static StringBuffer getDateAndTime() {
Calendar c = Calendar.getInstance();
StringBuffer sb = new StringBuffer(15);
sb.append(c.get(Calendar.YEAR));
int month = (c.get(Calendar.MONTH)) + 1;
if(month < 10) sb.append(0);
sb.append(month);
int date = c.get(Calendar.DAY_OF_MONTH);
if(date < 10) sb.append(0);
sb.append(date);
sb.append("_");
int hour = c.get(Calendar.HOUR_OF_DAY);
if(hour < 10) sb.append(0);
sb.append(hour);
int minute = c.get(Calendar.MINUTE);
if(minute < 10) sb.append(0);
sb.append(minute);
int second = c.get(Calendar.SECOND);
if(second < 10) sb.append(0);
sb.append(second);
return sb;
}
private static StringBuffer getVMInfo() {
StringBuffer sb = new StringBuffer(40);
String vm = System.getProperty("java.vm.vendor");
if(vm.equals("IBM Corporation")) {
String vminfo = System.getProperty("java.vm.info");
String[] vminfoComponents = split(vminfo);
sb.append(vminfoComponents[2] + ("_"));
sb.append(vminfoComponents[3] + ("_"));
sb.append(vminfoComponents[4] + ("_"));
sb.append(vminfoComponents[6]);
}
else if(vm.equals("Sun Microsystems Inc.")) {
String vminfo = System.getProperty("java.vm.name");
String[] vminfoComponents = split(vminfo);

sb.append("Sun_");
sb.append(System.getProperty("java.vm.version") + "_");
sb.append(vminfoComponents[2]);
}

return sb;
}
}

+ 596
- 0
org.aspectj.ajdt.core/testsrc/WeaveTests.java View File

@@ -0,0 +1,596 @@
/* *******************************************************************
* Copyright (c) 2004 IBM Corporation
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Common Public License v1.0
* which accompanies this distribution and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* Noel Markham, Matthew Webster initial implementation
* ******************************************************************/

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
* @author Noel Markham
*/
public class WeaveTests {
private static final String OUTPUT_PACKAGE = "out";
private static final int WEAVE_FAST = 1;
private static final int WEAVE_MED = 2;
private static final int WEAVE_SLOW = 3;
public static final String EXECUTION_SLOW = "execution(void *(..))";
public static final String EXECUTION_MED = "args(" + OUTPUT_PACKAGE + ".C0) && execution(void m0(..))";
public static final String EXECUTION_FAST = "within(" + OUTPUT_PACKAGE + ".C0) && execution(void m0(..))";
public static final String GET_SLOW = "get(int *)";
public static final String GET_MED = "target(" + OUTPUT_PACKAGE + ".C0) && get(int i0)";
public static final String GET_FAST = "get(int " + OUTPUT_PACKAGE + ".C0.i0)";
// Defaults, can be changed with command-line args
private static int NUMCLASSES = 5;
private static int ITERATIONS = 3;
private static int METHODLINES = 20;
private static int NUMMETHODS = 100;
private static boolean INCLUDE_TEST_CLASSES = false;
private static boolean TEST_GET = true;
private static boolean TEST_EXECUTION = true;

private static boolean ALL_POINTCUT_TESTS = true;
private static boolean TEST_ONE = false;
private static boolean TEST_ONE_SEARCH_ALL = false;
private static boolean TEST_ALL = false;
private static boolean ECHO = false;

public static long[] compileTimes = new long[ITERATIONS];
public static long[] executionSlowTimes = new long[ITERATIONS];
public static long[] executionMedTimes = new long[ITERATIONS];
public static long[] executionFastTimes = new long[ITERATIONS];
public static long[] getSlowTimes = new long[ITERATIONS];
public static long[] getMedTimes = new long[ITERATIONS];
public static long[] getFastTimes = new long[ITERATIONS];

private static final String NL = System.getProperty("line.separator", "\n");
private static final File outputDir = new File(System.getProperty("user.dir") + File.separatorChar + OUTPUT_PACKAGE);

static {
outputDir.mkdirs();
}

public static void main(String[] args) throws IOException {

//if (args.length > 0) parseArgs(args);
parseArgs(args);
if(ECHO) System.out.println("Weave-time Test");
if(ECHO) System.out.println("---------------");
if(ECHO) System.out.println("Number of classes: " + NUMCLASSES);
if(ECHO) System.out.println("Number of methods: " + NUMMETHODS);
if(ECHO) System.out.println("Number of method lines: " + METHODLINES);
if(ECHO) System.out.println("Number of test iterations: " + ITERATIONS);
if(ECHO)
if(INCLUDE_TEST_CLASSES) System.out.println("Including advice test classes");
if(ECHO)
if(TEST_GET && !TEST_EXECUTION) System.out.println("Weaving only get advice");
if(ECHO)
if(TEST_EXECUTION && !TEST_GET) System.out.println("Weaving only execution advice");
if(ECHO) {
if(!ALL_POINTCUT_TESTS) {
if(TEST_ONE) System.out.println("Weaving one poinctcut");
if(TEST_ONE_SEARCH_ALL) System.out.println("Weaving one pointcut, searching all");
if(TEST_ALL) System.out.println("Weaving all");
}
}

if(ECHO) System.out.println();
createClasses();
compileClasses();

boolean warm = false;

if (TEST_EXECUTION) {
String advice = "execution";
createAspects(advice);
//Warm up the weaver
weaveAllAspects(advice, WEAVE_FAST);
warm = true;
weaveAspects(advice);
}
if (TEST_GET) {
String advice = "get";
createAspects(advice);
if(!warm) weaveAllAspects(advice, WEAVE_FAST);
weaveAspects(advice);
}
}
private static void parseArgs(String[] args) {
if(args == null || args.length <= 0) return;

int i = 0;
boolean error = false;
while(i < args.length) {
String arg = args[i++];
try {
if(arg.equals("-c")) { // Number of classes
if(i < args.length)
NUMCLASSES = Integer.parseInt(args[i++]);
else error = true;
}
else if(arg.equals("-m")) { // Number of methods
if(i < args.length)
NUMMETHODS = Integer.parseInt(args[i++]);
else error = true;
}
else if(arg.equals("-l")) { // Number of method lines
if(i < args.length)
METHODLINES = Integer.parseInt(args[i++]);
else error = true;
}
else if(arg.equals("-i")) { // Number of iterations
if(i < args.length)
ITERATIONS = Integer.parseInt(args[i++]);
else error = true;
}
else if(arg.equals("-include-tests")) {
if(i < args.length) {
arg = args[i++];
if(arg.equalsIgnoreCase("y")) INCLUDE_TEST_CLASSES = true;
else if(arg.equalsIgnoreCase("n")) INCLUDE_TEST_CLASSES = false;
else error = true;
}
}
else if(arg.equals("-advice")) {
String advice = args[i++];
if(advice.equals("get")){
TEST_GET = true;
TEST_EXECUTION = false;
}
else if(advice.equals("execution")){
TEST_EXECUTION = true;
TEST_GET = false;
}
else error = true;
}
else if(arg.equals("-pointcut")) {
ALL_POINTCUT_TESTS = false;
String advice = args[i++];
if(advice.equals("fast")) TEST_ONE = true;
else if(advice.equals("meduim")) TEST_ONE_SEARCH_ALL = true;
else if(advice.equals("slow")) TEST_ALL = true;
else error = true;
}
else if(arg.equals("-echo")) {
ECHO = true;
}
else if (arg.equals("-help")) {
usage();
}
else error = true;
} catch (NumberFormatException e) {
usage();
}
if(error) usage();
compileTimes = new long[ITERATIONS];
executionSlowTimes = new long[ITERATIONS];
executionMedTimes = new long[ITERATIONS];
executionFastTimes = new long[ITERATIONS];
getSlowTimes = new long[ITERATIONS];
getMedTimes = new long[ITERATIONS];
getFastTimes = new long[ITERATIONS];

}
}

private static void usage() {
System.err.println("Usage:");
System.err.println("\tjava WeaveTests [-c num_of_classes] [-m num_of_methods] " +
"[-l num_of_method_lines] [-i num_of_iterations]" +
"\n\t\t[-include-tests y|n] [-advice get|execution] [-pointcut fast|medium|slow] [-echo] [-help]");
System.exit(-1);
}
/**
* Will create a number of classes of the following form:
*
* public class C0 {
*
* int i0;
* ...
* int iN;
*
* void m0(C0 arg) {
* i0++;
* ...
* iN++;
* }
* ...
* void mN(C0 arg) {
* ...
* }
*
*/
public static void createClasses() throws IOException {
if(ECHO) System.out.println("Creating classes");
for(int classcounter = 0; classcounter < NUMCLASSES; classcounter++) {
StringBuffer classfile = new StringBuffer(1000);
classfile.append("// Auto-generated" + NL);
classfile.append("package " + OUTPUT_PACKAGE + ";" + NL + NL);
classfile.append("public class C" + classcounter + " {" + NL + NL);
for(int intdeclaration = 0; intdeclaration < METHODLINES; intdeclaration++) {
classfile.append("\tint i" + intdeclaration + ";" + NL);
}
classfile.append("\tint getter;" + NL);
classfile.append(NL);
for(int methodcounter = 0; methodcounter < NUMMETHODS; methodcounter++) {
classfile.append("\tvoid m" + methodcounter + "(C" + classcounter + " arg) {" + NL);
for(int methodbody = 0; methodbody < METHODLINES; methodbody++) {
classfile.append("\t\ti" + methodbody + "++;" + NL);
}
classfile.append("\t}" + NL + NL);
}

classfile.append("}" + NL);
try {
File f = new File(outputDir, ("C" + classcounter + ".java"));
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(new String(classfile).getBytes());
bos.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
}
if (INCLUDE_TEST_CLASSES) {
StringBuffer testFiles = new StringBuffer(1000);

try {
testFiles.append("// Auto generated" + NL);
testFiles.append("package " + OUTPUT_PACKAGE + ";" + NL + NL);

testFiles.append("public class TestGet {" + NL + NL);
testFiles.append(
"\tpublic static void main(String args[]) {" + NL);
testFiles.append("\t\tC0 tester = new C0();" + NL);
testFiles.append("\t\tint i = tester.i0;" + NL);
testFiles.append("\t}" + NL);
testFiles.append("}" + NL);

File f = new File(outputDir, "TestGet.java");
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(fos);

bos.write(new String(testFiles).getBytes());
bos.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}

testFiles = new StringBuffer(1000);

try {
testFiles.append("// Auto generated" + NL);
testFiles.append("package " + OUTPUT_PACKAGE + ";" + NL + NL);

testFiles.append("public class TestExecution {" + NL + NL);
testFiles.append(
"\tpublic static void main(String args[]) {" + NL);
testFiles.append("\t\tC0 tester = new C0();" + NL);
testFiles.append("\t\ttester.m0(tester);" + NL);
testFiles.append("\t}" + NL);
testFiles.append("}" + NL);

File f = new File(outputDir, "TestExecution.java");
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(fos);

bos.write(new String(testFiles).getBytes());
bos.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
}

StringBuffer buildList = new StringBuffer(100);
for(int i = 0; i < NUMCLASSES; i++)
buildList.append("C" + i + ".java" + NL);
if (INCLUDE_TEST_CLASSES) {
buildList.append("TestGet.java" + NL);
buildList.append("TestExecution.java" + NL);
}
try {
File f = new File(outputDir, "build.lst");
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(new String(buildList).getBytes());
bos.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
}
/**
* @param adviceType Either "get" or "execution" depending on which test.
*
* Will create an aspect such as the following:
*
* public aspect GetAdviceWeaveOne {
*
* before() : get(int output.C0.getter) {
* System.out.println("In the aspect");
* }
* }
*/
public static void createAspects(String adviceType) {
adviceType = adviceType.toLowerCase();
if((!adviceType.equals("get")) && (!adviceType.equals("execution"))) {
System.err.println("Only get and execution advice is supported");
System.exit(-1);
}
if(ECHO) System.out.println("Creating aspects");
if(ALL_POINTCUT_TESTS || TEST_ONE)
createAllAspects(adviceType, WEAVE_FAST);
if(ALL_POINTCUT_TESTS || TEST_ONE_SEARCH_ALL)
createAllAspects(adviceType, WEAVE_MED);
if(ALL_POINTCUT_TESTS || TEST_ALL)
createAllAspects(adviceType, WEAVE_SLOW);
}
private static void createAllAspects(String adviceType, int pointcut) {
StringBuffer aspectFile = new StringBuffer(1000);

// Capitalises the first char in the adviceType String, and then adds "Advice" to it.
String adviceName = (char)(adviceType.charAt(0) - 32) + adviceType.substring(1) + "Advice";
switch(pointcut) {
case WEAVE_FAST:
adviceName += "WeaveFast";
break;
case WEAVE_MED:
adviceName += "WeaveMedium";
break;
case WEAVE_SLOW:
adviceName += "WeaveSlow";
break;
}
aspectFile.append("// Auto-generated" + NL + NL);
aspectFile.append("public aspect " + adviceName + " {" + NL + NL);
aspectFile.append("\tbefore() : ");
if(adviceType.equals("execution")) {
switch(pointcut) {
case WEAVE_FAST:
aspectFile.append(EXECUTION_FAST);
break;
case WEAVE_MED:
aspectFile.append(EXECUTION_MED);
break;
case WEAVE_SLOW:
aspectFile.append(EXECUTION_SLOW);
break;
}
}
else {
switch(pointcut) {
case WEAVE_FAST:
aspectFile.append(GET_FAST);
break;
case WEAVE_MED:
aspectFile.append(GET_MED);
break;
case WEAVE_SLOW:
aspectFile.append(GET_SLOW);
break;
}
}
aspectFile.append(" {" + NL);
aspectFile.append("\t\tSystem.out.println(\"In the aspect\");" + NL);
aspectFile.append("\t}" + NL);
aspectFile.append("}" + NL);

// Create the file
try {
File f = new File(outputDir, (adviceName + ".aj"));
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(new String(aspectFile).getBytes());
bos.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
}
public static void compileClasses() throws IOException {
if(ECHO) System.out.print("Compiling: ");

long average = 0;
for (int i = 0; i < ITERATIONS; i++) {
long time = performCompile();
compileTimes[i] = time;
average += time;
}
if(ECHO) System.out.println((average / ITERATIONS) + " millis");
}
private static long performCompile() throws IOException {
String ajcargs =
"-noExit -outjar " + OUTPUT_PACKAGE + File.separatorChar + "classes.jar " +
"-argfile " + OUTPUT_PACKAGE + File.separatorChar + "build.lst";

// split method creates a String array delimited on a space
String[] parsedArgs = ajcargs.split(" ");

long start = System.currentTimeMillis();
org.aspectj.tools.ajc.Main.main(parsedArgs);
long stop = System.currentTimeMillis();
return stop - start;
}
public static void weaveAspects(String adviceType) throws IOException {

adviceType = adviceType.toLowerCase();
if((!adviceType.equals("get")) && (!adviceType.equals("execution"))) {
System.err.println("Only get and execution advice is supported");
System.exit(-1);
}
long average = 0;
if(ECHO) System.out.println((char)(adviceType.charAt(0) - 32) + adviceType.substring(1));
if (ALL_POINTCUT_TESTS || TEST_ONE) {
if(ECHO) System.out.print("Weave Fast:");
for (int i = 0; i < ITERATIONS; i++) {
long time = weaveAllAspects(adviceType, WEAVE_FAST);
if(adviceType.equals("execution")) executionFastTimes[i] = time;
else getFastTimes[i] = time;
average += time;
if(ECHO) System.out.print(".");
}
if(ECHO) System.out.println(" " + (average / ITERATIONS) + " millis");
}
average = 0;
if (ALL_POINTCUT_TESTS || TEST_ONE_SEARCH_ALL) {
if(ECHO) System.out.print("Weave Medium:");
for (int i = 0; i < ITERATIONS; i++) {
long time = weaveAllAspects(adviceType, WEAVE_MED);
if(adviceType.equals("execution")) executionMedTimes[i] = time;
else getMedTimes[i] = time;
average += time;
if(ECHO) System.out.print(".");
}
if(ECHO) System.out.println(" " + (average / ITERATIONS) + " millis");
}
average = 0;
if (ALL_POINTCUT_TESTS || TEST_ALL) {
if(ECHO) System.out.print("Weave Slow:");
for (int i = 0; i < ITERATIONS; i++) {
long time = weaveAllAspects(adviceType, WEAVE_SLOW);

if(adviceType.equals("execution")) executionSlowTimes[i] = time;
else getSlowTimes[i] = time;
average += time;
if(ECHO) System.out.print(".");
}
if(ECHO) System.out.println(" " + (average / ITERATIONS) + " millis");
}

if(ECHO) System.out.println();
}
private static long weaveAllAspects(String adviceType, int pointcut) throws IOException {

// Capitalises the first char in the adviceType String, to keep to Java naming convention
String adviceName = (char)(adviceType.charAt(0) - 32) + adviceType.substring(1) + "Advice";
switch(pointcut) {
case WEAVE_FAST:
adviceName += "WeaveFast";
break;
case WEAVE_MED:
adviceName += "WeaveMedium";
break;
case WEAVE_SLOW:
adviceName += "WeaveSlow";
break;
}
String ajcargs =
"-noExit -injars " + OUTPUT_PACKAGE + File.separatorChar + "classes.jar " +
"-outjar " + OUTPUT_PACKAGE + File.separatorChar + adviceName + ".jar " +
OUTPUT_PACKAGE + File.separatorChar + adviceName + ".aj";
String[] parsedArgs = ajcargs.split(" ");
long start = System.currentTimeMillis();
org.aspectj.tools.ajc.Main.main(parsedArgs);
long stop = System.currentTimeMillis();
return stop - start;
}
}

Loading…
Cancel
Save