diff --git a/JavassistTest/src/tracer/MyPrintStream.java b/JavassistTest/src/tracer/MyPrintStream.java index c703ffb..bb76bfb 100644 --- a/JavassistTest/src/tracer/MyPrintStream.java +++ b/JavassistTest/src/tracer/MyPrintStream.java @@ -2,6 +2,12 @@ import java.util.ArrayList; +/** + * �g���[�X�o�͗p���[�e�B���e�B + * + * @author Nitta + * + */ public class MyPrintStream extends Thread { private static MyPrintStream theInstance; private static ArrayList output; diff --git a/JavassistTest/src/tracer/OutputStatementsGenerator.java b/JavassistTest/src/tracer/OutputStatementsGenerator.java new file mode 100644 index 0000000..e60398d --- /dev/null +++ b/JavassistTest/src/tracer/OutputStatementsGenerator.java @@ -0,0 +1,227 @@ +package tracer; + +import javassist.CtBehavior; +import javassist.CtClass; +import javassist.CtConstructor; +import javassist.CtMethod; +import javassist.Modifier; +import javassist.NotFoundException; + +/** + * �g���[�X�o�͗p�̎��s���𐶐�����N���X�i�o�̓t�H�[�}�b�g�ւ̈ˑ��������B������Ă���j + * + * @author Nitta + * + */ +public class OutputStatementsGenerator { + static final String LINE_AND_THREAD = "\":Line \" + (tracer.Tracer.lineNo++) + \":ThreadNo \" + Thread.currentThread().getId()"; + static final String LINE = "\":Line \" + (tracer.Tracer.lineNo++) + \":\""; + + static String generateReplaceStatementsForFieldSet(CtClass cc) { + String declaredClassName = cc.getName(); + return "{$proceed($$); " + + "if ($0 != null) {" + // target + "tracer.MyPrintStream.print(\"set:\" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\"); " + + "} else {" + + "tracer.MyPrintStream.print(\"set:" + declaredClassName + ":0:\"); " + + "} " + + "if ($1 != null) {" + // o[0] + "tracer.MyPrintStream.println($1.getClass().getName() + \":\" + System.identityHashCode($1) + " + OutputStatementsGenerator.LINE_AND_THREAD + ");" + + "} else {" + + "tracer.MyPrintStream.println(\"---:0\" + " + OutputStatementsGenerator.LINE_AND_THREAD + ");" + + "}" + "}"; + } + + static String generateReplaceStatementsForFieldGet(CtClass cc, CtBehavior m) { + String declaredClassName = cc.getName(); + String thisOutput = ""; + if ((m.getModifiers() & Modifier.STATIC) == 0 && m instanceof CtMethod) { + thisOutput = "tracer.MyPrintStream.print(\"get:\" + this.getClass().getName() + \":\" + System.identityHashCode(this) + \":\"); "; + } else { + // static���\�b�h���R���X�g���N�^�̏ꍇ + thisOutput = "tracer.MyPrintStream.print(\"get:" + declaredClassName + ":0:\"); "; + } + return "{$_ = $proceed(); " + + thisOutput + + "if ($0 != null) {" + // target + "tracer.MyPrintStream.print($0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\"); " + + "} else {" + + "tracer.MyPrintStream.print(\"---:0:\"); " + + "} " + + "if ($_ != null) {" + // o + "tracer.MyPrintStream.println($_.getClass().getName() + \":\" + System.identityHashCode($_) + " + LINE_AND_THREAD + ");" + + "} else {" + + "tracer.MyPrintStream.println(\"---:0\" + " + LINE_AND_THREAD + ");" + + "} " + "}"; + } + + static String generateReplaceStatementsForCall(CtClass cls, CtBehavior m) throws NotFoundException { + return "{" + OutputStatementsGenerator.generateInsertBeforeStatements(cls, m, true) + " $_ = $proceed($$); " + OutputStatementsGenerator.generateInsertAfterStatements(cls, m, true) + "}"; + } + + static String generateInsertBeforeStatementsForMethodBody(CtClass cls, CtBehavior m) throws NotFoundException { + return "{" + OutputStatementsGenerator.generateInsertBeforeStatements(cls, m, false) + "}"; + } + + static String generateInsertAfterStatementsForMethodBody(CtClass cls, CtBehavior m) throws NotFoundException { + return "{" + OutputStatementsGenerator.generateInsertAfterStatements(cls, m, false) + "}"; + } + + /** + * �g���[�X�o�͗p�̖��ߗ�𐶐����� + * @param cls �ΏۃN���X + * @param m �Ώۃ��\�b�h(�R���X�g���N�^) + * @param isCallerSideInstrumentation ���ߗ���Ăяo�����ɑ}�����邩�Ăяo����鑤�ɑ}�����邩? + * @return + * @throws NotFoundException + */ + static String generateInsertBeforeStatements(CtClass cls, CtBehavior m, boolean isCallerSideInstrumentation) throws NotFoundException { + String declaredClassName = cls.getName(); + String delimiter = "tracer.MyPrintStream.println(\"Args:\" + "; + CtClass parameterClasses[] = m.getParameterTypes(); + int p = 0; + + String newOutput = ""; + String methodOutput = ""; + String classOutput = ""; + String argsOutput = ""; + for (CtClass c : parameterClasses) { + if (!c.isPrimitive()) { + argsOutput += delimiter + "$args[" + p + "].getClass().getName() + " + "\":\" + System.identityHashCode($" + (p + 1) + ")"; + } else { + argsOutput += delimiter + "$args[" + p + "].getClass().getName() + " + "\":\" + $" + (p + 1); + } + p++; + delimiter = " + \":\" + "; + } + if (p > 0) { + argsOutput += " + " + LINE_AND_THREAD + ");"; + } + String modifiers = ""; + if ((m.getModifiers() & Modifier.PUBLIC) != 0) { + modifiers = "public "; + } else if ((m.getModifiers() & Modifier.PRIVATE) != 0) { + modifiers = "private "; + } else if ((m.getModifiers() & Modifier.PROTECTED) != 0) { + modifiers = "protected "; + } + if ((m.getModifiers() & Modifier.STATIC) != 0) { + modifiers += "static "; + } + if ((m.getModifiers() & Modifier.FINAL) != 0) { + modifiers += "final "; + } + if ((m.getModifiers() & Modifier.SYNCHRONIZED) != 0) { + modifiers += "synchronized "; + } + String longName = null; + if ((m.getModifiers() & Modifier.STATIC) != 0) { + // static���\�b�h�̏ꍇ + longName = modifiers + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� + methodOutput = "tracer.MyPrintStream.println(\"Method " + declaredClassName + "," + longName + + ":\" + 0 + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; + classOutput = "tracer.MyPrintStream.println(\"Class " + declaredClassName + ":\" + 0 + " + LINE_AND_THREAD + ");"; + } else if (m instanceof CtConstructor) { + // �R���X�g���N�^�̏ꍇ + longName = modifiers + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� + newOutput = "tracer.MyPrintStream.println(\"New " + declaredClassName + ":\" + 0 + " + LINE_AND_THREAD + ");"; + methodOutput = "tracer.MyPrintStream.println(\"Method " + declaredClassName + "," + longName + + ":\" + 0 + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; + classOutput = "tracer.MyPrintStream.println(\"Class " + declaredClassName + ":\" + 0 + " + LINE_AND_THREAD + ");"; + } else { + // �ʏ�̃��\�b�h�̏ꍇ + longName = modifiers + ((CtMethod)m).getReturnType().getName() + " " + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� + if (!isCallerSideInstrumentation) { + // �Ăяo����ɖ��ߍ��ޏꍇ(�ʏ�) + methodOutput = "tracer.MyPrintStream.println(\"Method \" + this.getClass().getName() + \"," + longName + + ":\" + System.identityHashCode(this) + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; + classOutput = "tracer.MyPrintStream.println(\"Class \" + this.getClass().getName() + \":\" + System.identityHashCode(this) + " + LINE_AND_THREAD + ");"; + } else { + // �ďo�����ɖ��ߍ��ޏꍇ(�W���N���X�̌ďo��) + methodOutput = "tracer.MyPrintStream.println(\"Method \" + $0.getClass().getName() + \"," + longName + + ":\" + System.identityHashCode($0) + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; + classOutput = "tracer.MyPrintStream.println(\"Class \" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");"; + } + } + + return newOutput + methodOutput + classOutput + argsOutput; + } + + static String generateInsertAfterStatements(CtClass cls, CtBehavior m, boolean isCallerSideInstrumentation) throws NotFoundException { + String returnOutput = null; + String shortName = null; + if ((m.getModifiers() & Modifier.STATIC) != 0) { + // static���\�b�h�̏ꍇ + shortName = cls.getSimpleName().replace('$', '.') + "." + m.getName() + "()"; // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� + String invocationType = null; + if (!isCallerSideInstrumentation) { + // �Ăяo����ɖ��ߍ��ޏꍇ(�ʏ�) + invocationType = "execution"; + } else { + // �ďo�����ɖ��ߍ��ޏꍇ(�W���N���X�̌ďo��) + invocationType = "call"; + } + if (!((CtMethod)m).getReturnType().isPrimitive() || ((CtMethod)m).getReturnType() == CtClass.voidType) { + returnOutput = "if ($_ != null) {" + + "tracer.MyPrintStream.print(\"Return " + invocationType + "(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + + "} else {" + + "tracer.MyPrintStream.print(\"Return " + invocationType + "(" + shortName + "):void:0:\");" + + "} " + + "tracer.MyPrintStream.println(\"0\" + " + LINE_AND_THREAD + ");"; + } else { + returnOutput = "tracer.MyPrintStream.print(\"Return " + invocationType + "(" + shortName + "):" + ((CtMethod)m).getReturnType().getName() + ":\" + $_ + \":\");" + + "tracer.MyPrintStream.println(\"0\" + " + LINE_AND_THREAD + ");"; + } + } else if (m instanceof CtConstructor) { + // �R���X�g���N�^�̏ꍇ + shortName = m.getName().replace('$', '.') + "()"; // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� + if (!isCallerSideInstrumentation) { + // �Ăяo����ɖ��ߍ��ޏꍇ(�ʏ�) + returnOutput = "tracer.MyPrintStream.print(\"Return initialization(" + shortName + "):\" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\");" + + "tracer.MyPrintStream.println(\"\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");"; + } else { + // �ďo�����ɖ��ߍ��ޏꍇ(�W���N���X�������̓f�t�H���g�R���X�g���N�^�̌ďo��) + returnOutput = "if ($_ != null) {" + + "tracer.MyPrintStream.print(\"Return initialization(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + + "tracer.MyPrintStream.println(\"\" + System.identityHashCode($_) + " + LINE_AND_THREAD + ");" + + "} else {" + + // �e�R���X�g���N�^�ďo���̏ꍇ(�߂�l�͂Ȃ�) + "tracer.MyPrintStream.print(\"Return initialization(" + shortName + "):\" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\");" + + "tracer.MyPrintStream.println(\"\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");" + + "}"; + } + } else { + // �ʏ�̃��\�b�h�̏ꍇ + shortName = cls.getSimpleName().replace('$', '.') + "." + m.getName() + "()"; // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� + if (!isCallerSideInstrumentation) { + // �Ăяo����ɖ��ߍ��ޏꍇ(�ʏ�) + if (!((CtMethod)m).getReturnType().isPrimitive() || ((CtMethod)m).getReturnType() == CtClass.voidType) { + returnOutput = "if ($_ != null) {" + + "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + + "} else {" + + "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):void:0:\");" + + "} " + + "tracer.MyPrintStream.println(\"\" + System.identityHashCode(this) + " + LINE_AND_THREAD + ");"; + } else { + returnOutput = "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):" + ((CtMethod)m).getReturnType().getName() + ":\" + $_ + \":\");" + + "tracer.MyPrintStream.println(\"\" + System.identityHashCode(this) + " + LINE_AND_THREAD + ");"; + } + } else { + // �ďo�����ɖ��ߍ��ޏꍇ(�W���N���X�̌ďo��) + if (!((CtMethod)m).getReturnType().isPrimitive() || ((CtMethod)m).getReturnType() == CtClass.voidType) { + returnOutput = "if ($_ != null) {" + + "tracer.MyPrintStream.print(\"Return call(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + + "} else {" + + "tracer.MyPrintStream.print(\"Return call(" + shortName + "):void:0:\");" + + "} " + + "tracer.MyPrintStream.println(\"\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");"; + } else { + returnOutput = "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):" + ((CtMethod)m).getReturnType().getName() + ":\" + $_ + \":\");" + + "tracer.MyPrintStream.println(\"\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");"; + } + } + } + return returnOutput; + } + +} diff --git a/JavassistTest/src/tracer/Tracer.java b/JavassistTest/src/tracer/Tracer.java index 1d16290..3e42622 100644 --- a/JavassistTest/src/tracer/Tracer.java +++ b/JavassistTest/src/tracer/Tracer.java @@ -16,7 +16,6 @@ import javassist.CtConstructor; import javassist.CtField; import javassist.CtMethod; -import javassist.Modifier; import javassist.NotFoundException; import javassist.bytecode.BadBytecode; import javassist.bytecode.analysis.ControlFlow; @@ -27,10 +26,14 @@ import javassist.expr.MethodCall; import javassist.expr.NewExpr; +/** + * �g���[�X�o�͕���Ώۃp�b�P�[�W���ɐD�荞�ރN���X + * + * @author Nitta + * + */ public class Tracer { public static int lineNo = 1; - private static final String LINE_AND_THREAD = "\":Line \" + (tracer.Tracer.lineNo++) + \":ThreadNo \" + Thread.currentThread().getId()"; - private static final String LINE = "\":Line \" + (tracer.Tracer.lineNo++) + \":\""; private static final String STANDARD_CLASSES = "java.util.ListIterator|java.util.Iterator|java.util.List|java.util.Vector|java.util.ArrayList|java.util.Stack|java.util.Map|java.util.HashMap|java.util.Set|java.util.HashSet|java.util.Hashtable|java.util.LinkedList|java.lang.Thread"; private static final String CONCRETE_STANDARD_CLASSES = "java.util.Vector|java.util.ArrayList|java.util.Stack |java.util.HashMap|java.util.HashSet|java.util.Hashtable|java.util.LinkedList|java.lang.Thread"; @@ -77,50 +80,20 @@ } } - private static void methodInstrumentation(CtClass cc, final CtBehavior m) - throws BadBytecode, NotFoundException, CannotCompileException { + private static void methodInstrumentation(final CtClass cc, final CtBehavior m) throws BadBytecode, NotFoundException, CannotCompileException { // ControlFlow cf = new ControlFlow(m); - final String declaredClassName = cc.getName(); - String methodSignature = m.getSignature(); +// String methodSignature = m.getSignature(); // ���\�b�h�{�̓��̃t�B�[���h�A�N�Z�X�ƃ��\�b�h�Ăяo����u�������� m.instrument(new ExprEditor() { public void edit(FieldAccess f) throws CannotCompileException { if (f.isReader()) { if (!f.getFieldName().contains("$")) { // AspectJ�ł� final local �ϐ�����̃Q�b�g�͖��������̂ŁA����ɍ��킹�ď��O���� - String thisOutput = ""; - if ((m.getModifiers() & Modifier.STATIC) == 0 && m instanceof CtMethod) { - thisOutput = "tracer.MyPrintStream.print(\"get:\" + this.getClass().getName() + \":\" + System.identityHashCode(this) + \":\"); "; - } else { - // static���\�b�h���R���X�g���N�^�̏ꍇ - thisOutput = "tracer.MyPrintStream.print(\"get:" + declaredClassName + ":0:\"); "; - } - f.replace("{$_ = $proceed(); " + - thisOutput + - "if ($0 != null) {" + // target - "tracer.MyPrintStream.print($0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\"); " + - "} else {" + - "tracer.MyPrintStream.print(\"---:0:\"); " + - "} " + - "if ($_ != null) {" + // o - "tracer.MyPrintStream.println($_.getClass().getName() + \":\" + System.identityHashCode($_) + " + LINE_AND_THREAD + ");" + - "} else {" + - "tracer.MyPrintStream.println(\"---:0\" + " + LINE_AND_THREAD + ");" + - "} " + "}"); + f.replace(OutputStatementsGenerator.generateReplaceStatementsForFieldGet(cc, m)); } } else { if (!f.getFieldName().contains("$")) { // ���̏������Ȃ��ƂȂ���������i�����t�B�[���h?�ւ̃Z�b�g�������āA������E���ė����Ă�?�j - f.replace("{$proceed($$); " + - "if ($0 != null) {" + // target - "tracer.MyPrintStream.print(\"set:\" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\"); " + - "} else {" + - "tracer.MyPrintStream.print(\"set:" + declaredClassName + ":0:\"); " + - "} " + - "if ($1 != null) {" + // o[0] - "tracer.MyPrintStream.println($1.getClass().getName() + \":\" + System.identityHashCode($1) + " + LINE_AND_THREAD + ");" + - "} else {" + - "tracer.MyPrintStream.println(\"---:0\" + " + LINE_AND_THREAD + ");" + - "}" + "}"); + f.replace(OutputStatementsGenerator.generateReplaceStatementsForFieldSet(cc)); } } } @@ -128,8 +101,7 @@ try { CtMethod m = c.getMethod(); if (m.getDeclaringClass().getName().matches(STANDARD_CLASSES)) { - Outputs out = generateOutputs(m.getDeclaringClass(), m, true); - c.replace("{" + out.newOutput + out.methodOutput + out.classOutput + out.argsOutput + " $_ = $proceed($$); " + out.returnOutput + "}"); + c.replace(OutputStatementsGenerator.generateReplaceStatementsForCall(m.getDeclaringClass(), m)); } } catch (NotFoundException e) { e.printStackTrace(); @@ -139,8 +111,7 @@ try { CtConstructor m = n.getConstructor(); if (m.getDeclaringClass().getName().matches(CONCRETE_STANDARD_CLASSES)) { - Outputs out = generateOutputs(m.getDeclaringClass(), m, true); - n.replace("{" + out.newOutput + out.methodOutput + out.classOutput + out.argsOutput + " $_ = $proceed($$); " + out.returnOutput + "}"); + n.replace(OutputStatementsGenerator.generateReplaceStatementsForCall(m.getDeclaringClass(), m)); } } catch (NotFoundException e) { e.printStackTrace(); @@ -150,8 +121,7 @@ // try { // CtConstructor m = c.getConstructor(); // if (m.getDeclaringClass().getName().matches(CONCRETE_STANDARD_CLASSES)) { -// Outputs out = generateOutputs(m.getDeclaringClass(), m, true); -// c.replace("{" + out.newOutput + out.methodOutput + out.classOutput + out.argsOutput + " $_ = $proceed($$); " + out.returnOutput + "}"); +// c.replace(generateReplaceStatementsForCall(m.getDeclaringClass(), m)); // } // } catch (NotFoundException e) { // e.printStackTrace(); @@ -160,16 +130,15 @@ }); // ���\�b�h�p�̏o�͕��𐶐����� - Outputs outputs = generateOutputs(cc, m, false); if (!m.isEmpty()) { // ���\�b�h�̎��s�O��ɏo�͕���}������ - m.insertBefore("{" + outputs.newOutput + outputs.methodOutput + outputs.classOutput + outputs.argsOutput + "}"); - m.insertAfter("{" + outputs.returnOutput + "}"); + m.insertBefore(OutputStatementsGenerator.generateInsertBeforeStatementsForMethodBody(cc, m)); + m.insertAfter(OutputStatementsGenerator.generateInsertAfterStatementsForMethodBody(cc, m)); } else { // ���\�b�h�{�̂���̂Ƃ��̓R���X�g���N�^�̏ꍇ�̂�(=�f�t�H���g�R���X�g���N�^)�{�̂ɏo�͕���ݒ肷�� if (m instanceof CtConstructor) { - m.setBody("{" + outputs.returnOutput + "}"); - m.insertBefore("{" + outputs.newOutput + outputs.methodOutput + outputs.classOutput + outputs.argsOutput + "}"); + m.setBody(OutputStatementsGenerator.generateInsertAfterStatementsForMethodBody(cc, m)); + m.insertBefore(OutputStatementsGenerator.generateInsertBeforeStatementsForMethodBody(cc, m)); } } @@ -286,161 +255,4 @@ // } // }); } - - /** - * �g���[�X�o�͗p�̖��ߗ�𐶐����� - * @param cls �ΏۃN���X - * @param m �Ώۃ��\�b�h(�R���X�g���N�^) - * @param isCallerSideInstrumentation ���ߗ���Ăяo�����ɑ}�����邩�Ăяo����鑤�ɑ}�����邩? - * @return - * @throws NotFoundException - */ - private static Outputs generateOutputs(CtClass cls, CtBehavior m, boolean isCallerSideInstrumentation) throws NotFoundException { - Outputs outputs = new Outputs(); - String declaredClassName = cls.getName(); - String delimiter = "tracer.MyPrintStream.println(\"Args:\" + "; - CtClass parameterClasses[] = m.getParameterTypes(); - int p = 0; - for (CtClass c : parameterClasses) { - if (!c.isPrimitive()) { - outputs.argsOutput += delimiter + "$args[" + p + "].getClass().getName() + " + "\":\" + System.identityHashCode($" + (p + 1) + ")"; - } else { - outputs.argsOutput += delimiter + "$args[" + p + "].getClass().getName() + " + "\":\" + $" + (p + 1); - } - p++; - delimiter = " + \":\" + "; - } - if (p > 0) { - outputs.argsOutput += " + " + LINE_AND_THREAD + ");"; - } - - String modifiers = ""; - if ((m.getModifiers() & Modifier.PUBLIC) != 0) { - modifiers = "public "; - } else if ((m.getModifiers() & Modifier.PRIVATE) != 0) { - modifiers = "private "; - } else if ((m.getModifiers() & Modifier.PROTECTED) != 0) { - modifiers = "protected "; - } - if ((m.getModifiers() & Modifier.STATIC) != 0) { - modifiers += "static "; - } - if ((m.getModifiers() & Modifier.FINAL) != 0) { - modifiers += "final "; - } - if ((m.getModifiers() & Modifier.SYNCHRONIZED) != 0) { - modifiers += "synchronized "; - } - String longName = null; - if ((m.getModifiers() & Modifier.STATIC) != 0) { - // static���\�b�h�̏ꍇ - longName = modifiers + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� - outputs.methodOutput = "tracer.MyPrintStream.println(\"Method " + declaredClassName + "," + longName - + ":\" + 0 + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; - outputs.classOutput = "tracer.MyPrintStream.println(\"Class " + declaredClassName + ":\" + 0 + " + LINE_AND_THREAD + ");"; - } else if (m instanceof CtConstructor) { - // �R���X�g���N�^�̏ꍇ - longName = modifiers + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� - outputs.newOutput = "tracer.MyPrintStream.println(\"New " + declaredClassName + ":\" + 0 + " + LINE_AND_THREAD + ");"; - outputs.methodOutput = "tracer.MyPrintStream.println(\"Method " + declaredClassName + "," + longName - + ":\" + 0 + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; - outputs.classOutput = "tracer.MyPrintStream.println(\"Class " + declaredClassName + ":\" + 0 + " + LINE_AND_THREAD + ");"; - } else { - // �ʏ�̃��\�b�h�̏ꍇ - longName = modifiers + ((CtMethod)m).getReturnType().getName() + " " + m.getLongName().replace('$', '.'); // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� - if (!isCallerSideInstrumentation) { - // �Ăяo����ɖ��ߍ��ޏꍇ(�ʏ�) - outputs.methodOutput = "tracer.MyPrintStream.println(\"Method \" + this.getClass().getName() + \"," + longName - + ":\" + System.identityHashCode(this) + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; - outputs.classOutput = "tracer.MyPrintStream.println(\"Class \" + this.getClass().getName() + \":\" + System.identityHashCode(this) + " + LINE_AND_THREAD + ");"; - } else { - // �ďo�����ɖ��ߍ��ޏꍇ(�W���N���X�̌ďo��) - outputs.methodOutput = "tracer.MyPrintStream.println(\"Method \" + $0.getClass().getName() + \"," + longName - + ":\" + System.identityHashCode($0) + " + LINE + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; - outputs.classOutput = "tracer.MyPrintStream.println(\"Class \" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");"; - } - } - - String shortName = null; - if ((m.getModifiers() & Modifier.STATIC) != 0) { - // static���\�b�h�̏ꍇ - shortName = cls.getSimpleName().replace('$', '.') + "." + m.getName() + "()"; // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� - String invocationType = null; - if (!isCallerSideInstrumentation) { - // �Ăяo����ɖ��ߍ��ޏꍇ(�ʏ�) - invocationType = "execution"; - } else { - // �ďo�����ɖ��ߍ��ޏꍇ(�W���N���X�̌ďo��) - invocationType = "call"; - } - if (!((CtMethod)m).getReturnType().isPrimitive() || ((CtMethod)m).getReturnType() == CtClass.voidType) { - outputs.returnOutput = "if ($_ != null) {" + - "tracer.MyPrintStream.print(\"Return " + invocationType + "(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + - "} else {" + - "tracer.MyPrintStream.print(\"Return " + invocationType + "(" + shortName + "):void:0:\");" + - "} " + - "tracer.MyPrintStream.println(\"0\" + " + LINE_AND_THREAD + ");"; - } else { - outputs.returnOutput = "tracer.MyPrintStream.print(\"Return " + invocationType + "(" + shortName + "):" + ((CtMethod)m).getReturnType().getName() + ":\" + $_ + \":\");" + - "tracer.MyPrintStream.println(\"0\" + " + LINE_AND_THREAD + ");"; - } - } else if (m instanceof CtConstructor) { - // �R���X�g���N�^�̏ꍇ - shortName = m.getName().replace('$', '.') + "()"; // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� - if (!isCallerSideInstrumentation) { - // �Ăяo����ɖ��ߍ��ޏꍇ(�ʏ�) - outputs.returnOutput = "tracer.MyPrintStream.print(\"Return initialization(" + shortName + "):\" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\");" + - "tracer.MyPrintStream.println(\"\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");"; - } else { - // �ďo�����ɖ��ߍ��ޏꍇ(�W���N���X�������̓f�t�H���g�R���X�g���N�^�̌ďo��) - outputs.returnOutput = "if ($_ != null) {" + - "tracer.MyPrintStream.print(\"Return initialization(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + - "tracer.MyPrintStream.println(\"\" + System.identityHashCode($_) + " + LINE_AND_THREAD + ");" + - "} else {" + - // �e�R���X�g���N�^�ďo���̏ꍇ(�߂�l�͂Ȃ�) - "tracer.MyPrintStream.print(\"Return initialization(" + shortName + "):\" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\");" + - "tracer.MyPrintStream.println(\"\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");" + - "}"; - } - } else { - // �ʏ�̃��\�b�h�̏ꍇ - shortName = cls.getSimpleName().replace('$', '.') + "." + m.getName() + "()"; // AspectJ�ł̓��\�b�h�V�O�j�`�����ł͖����N���X�̓h�b�g�ŋ�؂��� - if (!isCallerSideInstrumentation) { - // �Ăяo����ɖ��ߍ��ޏꍇ(�ʏ�) - if (!((CtMethod)m).getReturnType().isPrimitive() || ((CtMethod)m).getReturnType() == CtClass.voidType) { - outputs.returnOutput = "if ($_ != null) {" + - "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + - "} else {" + - "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):void:0:\");" + - "} " + - "tracer.MyPrintStream.println(\"\" + System.identityHashCode(this) + " + LINE_AND_THREAD + ");"; - } else { - outputs.returnOutput = "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):" + ((CtMethod)m).getReturnType().getName() + ":\" + $_ + \":\");" + - "tracer.MyPrintStream.println(\"\" + System.identityHashCode(this) + " + LINE_AND_THREAD + ");"; - } - } else { - // �ďo�����ɖ��ߍ��ޏꍇ(�W���N���X�̌ďo��) - if (!((CtMethod)m).getReturnType().isPrimitive() || ((CtMethod)m).getReturnType() == CtClass.voidType) { - outputs.returnOutput = "if ($_ != null) {" + - "tracer.MyPrintStream.print(\"Return call(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + - "} else {" + - "tracer.MyPrintStream.print(\"Return call(" + shortName + "):void:0:\");" + - "} " + - "tracer.MyPrintStream.println(\"\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");"; - } else { - outputs.returnOutput = "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):" + ((CtMethod)m).getReturnType().getName() + ":\" + $_ + \":\");" + - "tracer.MyPrintStream.println(\"\" + System.identityHashCode($0) + " + LINE_AND_THREAD + ");"; - } - } - } - return outputs; - } - - private static class Outputs { - String newOutput = ""; - String methodOutput = ""; - String classOutput = ""; - String argsOutput = ""; - String returnOutput = ""; - } }