diff --git a/JavassistTest/src/tracer/Tracer.java b/JavassistTest/src/tracer/Tracer.java index 71a9460..3884e00 100644 --- a/JavassistTest/src/tracer/Tracer.java +++ b/JavassistTest/src/tracer/Tracer.java @@ -84,34 +84,34 @@ if (f.isReader()) { String thisOutput = ""; if ((m.getModifiers() & Modifier.STATIC) == 0 && m instanceof CtMethod) { - thisOutput = "System.out.print(\"get:\" + this.getClass().getName() + \":\" + System.identityHashCode(this) + \":\"); "; + thisOutput = "tracer.MyPrintStream.print(\"get:\" + this.getClass().getName() + \":\" + System.identityHashCode(this) + \":\"); "; } else { // static���\�b�h���R���X�g���N�^�̏ꍇ - thisOutput = "System.out.print(\"get:" + declaredClassName + ":0:\"); "; + thisOutput = "tracer.MyPrintStream.print(\"get:" + declaredClassName + ":0:\"); "; } f.replace("{$_ = $proceed(); " + thisOutput + "if ($0 != null) {" + // target - "System.out.print($0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\"); " + + "tracer.MyPrintStream.print($0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\"); " + "} else {" + - "System.out.print(\"---:0:\"); " + + "tracer.MyPrintStream.print(\"---:0:\"); " + "} " + "if ($_ != null) {" + // o - "System.out.println($_.getClass().getName() + \":\" + System.identityHashCode($_) + " + lineAndThread + ");" + + "tracer.MyPrintStream.println($_.getClass().getName() + \":\" + System.identityHashCode($_) + " + lineAndThread + ");" + "} else {" + - "System.out.println(\"---:0\" + " + lineAndThread + ");" + + "tracer.MyPrintStream.println(\"---:0\" + " + lineAndThread + ");" + "} " + "}"); } else { f.replace("{$proceed($$); " + "if ($0 != null) {" + // target - "System.out.print(\"set:\" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\"); " + + "tracer.MyPrintStream.print(\"set:\" + $0.getClass().getName() + \":\" + System.identityHashCode($0) + \":\"); " + "} else {" + - "System.out.print(\"set:" + declaredClassName + ":0:\"); " + + "tracer.MyPrintStream.print(\"set:" + declaredClassName + ":0:\"); " + "} " + "if ($1 != null) {" + // o[0] - "System.out.println($1.getClass().getName() + \":\" + System.identityHashCode($1) + " + lineAndThread + ");" + + "tracer.MyPrintStream.println($1.getClass().getName() + \":\" + System.identityHashCode($1) + " + lineAndThread + ");" + "} else {" + - "System.out.println(\"---:0\" + " + lineAndThread + ");" + + "tracer.MyPrintStream.println(\"---:0\" + " + lineAndThread + ");" + "}" + "}"); } } @@ -123,7 +123,7 @@ String argsOutput = ""; String returnOutput = ""; - String delimiter = "System.out.println(\"Args:\" + "; + String delimiter = "tracer.MyPrintStream.println(\"Args:\" + "; CtClass parameterClasses[] = m.getParameterTypes(); int p = 0; for (CtClass c : parameterClasses) { @@ -151,22 +151,22 @@ if ((m.getModifiers() & Modifier.STATIC) != 0) { // static���\�b�h�̏ꍇ longName = accessor + "static " + m.getLongName(); - methodOutput = "System.out.println(\"Method " + declaredClassName + "," + longName + methodOutput = "tracer.MyPrintStream.println(\"Method " + declaredClassName + "," + longName + ":\" + 0 + " + line + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; - classOutput = "System.out.println(\"Class " + declaredClassName + ":\" + 0 + " + lineAndThread + ");"; + classOutput = "tracer.MyPrintStream.println(\"Class " + declaredClassName + ":\" + 0 + " + lineAndThread + ");"; } else if (m instanceof CtConstructor) { // �R���X�g���N�^�̏ꍇ longName = accessor + m.getLongName(); - newOutput = "System.out.println(\"New " + declaredClassName + ":\" + 0 + " + lineAndThread + ");"; - methodOutput = "System.out.println(\"Method " + declaredClassName + "," + longName + newOutput = "tracer.MyPrintStream.println(\"New " + declaredClassName + ":\" + 0 + " + lineAndThread + ");"; + methodOutput = "tracer.MyPrintStream.println(\"Method " + declaredClassName + "," + longName + ":\" + 0 + " + line + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; - classOutput = "System.out.println(\"Class " + declaredClassName + ":\" + 0 + " + lineAndThread + ");"; + classOutput = "tracer.MyPrintStream.println(\"Class " + declaredClassName + ":\" + 0 + " + lineAndThread + ");"; } else { // �ʏ�̃��\�b�h�̏ꍇ longName = accessor + ((CtMethod)m).getReturnType().getName() + " " + m.getLongName(); - methodOutput = "System.out.println(\"Method \" + this.getClass().getName() + \"," + longName + methodOutput = "tracer.MyPrintStream.println(\"Method \" + this.getClass().getName() + \"," + longName + ":\" + System.identityHashCode(this) + " + line + " + System.nanoTime() + \":ThreadNo \" + Thread.currentThread().getId());"; - classOutput = "System.out.println(\"Class \" + this.getClass().getName() + \":\" + System.identityHashCode(this) + " + lineAndThread + ");"; + classOutput = "tracer.MyPrintStream.println(\"Class \" + this.getClass().getName() + \":\" + System.identityHashCode(this) + " + lineAndThread + ");"; } String shortName = null; @@ -174,25 +174,25 @@ // static���\�b�h�̏ꍇ shortName = cc.getSimpleName() + "." + m.getName() + "()"; returnOutput = "if ($_ != null) {" + - "System.out.print(\"Return execution(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + + "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + "} else {" + - "System.out.print(\"Return execution(" + shortName + "):void:0:\");" + + "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):void:0:\");" + "} " + - "System.out.println(\"0\" + " + lineAndThread + ");"; + "tracer.MyPrintStream.println(\"0\" + " + lineAndThread + ");"; } else if (m instanceof CtConstructor) { // �R���X�g���N�^�̏ꍇ shortName = m.getName() + "()"; - returnOutput = "System.out.print(\"Return initialization(" + shortName + "):" + declaredClassName + ":\" + System.identityHashCode($0) + \":\");" + - "System.out.println(\"\" + System.identityHashCode($0) + " + lineAndThread + ");"; + returnOutput = "tracer.MyPrintStream.print(\"Return initialization(" + shortName + "):" + declaredClassName + ":\" + System.identityHashCode($0) + \":\");" + + "tracer.MyPrintStream.println(\"\" + System.identityHashCode($0) + " + lineAndThread + ");"; } else { // �ʏ�̃��\�b�h�̏ꍇ shortName = cc.getSimpleName() + "." + m.getName() + "()"; returnOutput = "if ($_ != null) {" + - "System.out.print(\"Return execution(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + + "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):\" + $_.getClass().getName() + \":\" + System.identityHashCode($_) + \":\");" + "} else {" + - "System.out.print(\"Return execution(" + shortName + "):void:0:\");" + + "tracer.MyPrintStream.print(\"Return execution(" + shortName + "):void:0:\");" + "} " + - "System.out.println(\"\" + System.identityHashCode(this) + " + lineAndThread + ");"; + "tracer.MyPrintStream.println(\"\" + System.identityHashCode(this) + " + lineAndThread + ");"; } @@ -276,31 +276,31 @@ // m.getMethodInfo().getLineNumber(blocks[3].position()); // int block4 = // m.getMethodInfo().getLineNumber(blocks[4].position()); - //�@m.insertAt(block0, "System.out.println(\"block0:\" + " + block0 + ");"); - // m.insertAt(block1, "System.out.println(\"block1:\" + " + + //�@m.insertAt(block0, "tracer.MyPrintStream.println(\"block0:\" + " + block0 + ");"); + // m.insertAt(block1, "tracer.MyPrintStream.println(\"block1:\" + " + // block1 + ");"); - // m.insertAt(block2, "System.out.println(\"block2:\" + " + + // m.insertAt(block2, "tracer.MyPrintStream.println(\"block2:\" + " + // block2 + ");"); - // m.insertAt(block3, "System.out.println(\"block3:\" + " + + // m.insertAt(block3, "tracer.MyPrintStream.println(\"block3:\" + " + // block3 + ");"); - // m.insertAt(block4, "System.out.println(\"block4:\" + " + + // m.insertAt(block4, "tracer.MyPrintStream.println(\"block4:\" + " + // block4 + ");"); // int block0 = // m.getMethodInfo().getLineNumber(blocks[0].position()); - // m.insertAt(block0, "System.out.println(\"block0\");"); + // m.insertAt(block0, "tracer.MyPrintStream.println(\"block0\");"); // m = cc.getDeclaredMethod("getC"); // cf = new ControlFlow(m); // blocks = cf.basicBlocks(); // int block1 = // m.getMethodInfo().getLineNumber(blocks[1].position()); - // m.insertAt(block1, "System.out.println(\"block1\");"); + // m.insertAt(block1, "tracer.MyPrintStream.println(\"block1\");"); // m = cc.getDeclaredMethod("getC"); // cf = new ControlFlow(m); // blocks = cf.basicBlocks(); // int block2 = // m.getMethodInfo().getLineNumber(blocks[2].position()); - // m.insertAt(block2, "System.out.println(\"block2\");"); + // m.insertAt(block2, "tracer.MyPrintStream.println(\"block2\");"); // m.instrument(new ExprEditor() { // public void edit(MethodCall m) throws CannotCompileException