diff --git a/TracerOnJavassist/src/tracer/JSONArrayAdvisor.java b/TracerOnJavassist/src/tracer/JSONArrayAdvisor.java index 8bcbe47..5095460 100644 --- a/TracerOnJavassist/src/tracer/JSONArrayAdvisor.java +++ b/TracerOnJavassist/src/tracer/JSONArrayAdvisor.java @@ -86,7 +86,7 @@ public static void arrayWriteChar(Object array, int index, char value) { long threadId = Thread.currentThread().getId(); long timeStamp = System.nanoTime(); - JSONTraceGenerator.arraySetOutput(array.getClass().getName(), Integer.toString(System.identityHashCode(array)), index, "char", Character.toString(value), threadId, timeStamp); + JSONTraceGenerator.arraySetOutput(array.getClass().getName(), Integer.toString(System.identityHashCode(array)), index, "char", Integer.toString(Character.getNumericValue(value)), threadId, timeStamp); ((char [])array)[index] = value; } @@ -94,7 +94,7 @@ char value = ((char [])array)[index]; long threadId = Thread.currentThread().getId(); long timeStamp = System.nanoTime(); - JSONTraceGenerator.arrayGetOutput(array.getClass().getName(), Integer.toString(System.identityHashCode(array)), index, "char", Character.toString(value), threadId, timeStamp); + JSONTraceGenerator.arrayGetOutput(array.getClass().getName(), Integer.toString(System.identityHashCode(array)), index, "char", Integer.toString(Character.getNumericValue(value)), threadId, timeStamp); return value; } diff --git a/TracerOnJavassist/src/tracer/MyPrintStream.java b/TracerOnJavassist/src/tracer/MyPrintStream.java index bb76bfb..0c93477 100644 --- a/TracerOnJavassist/src/tracer/MyPrintStream.java +++ b/TracerOnJavassist/src/tracer/MyPrintStream.java @@ -1,6 +1,8 @@ package tracer; +import java.io.PrintStream; import java.util.ArrayList; +import java.util.LinkedList; /** * �g���[�X�o�͗p���[�e�B���e�B @@ -10,15 +12,17 @@ */ public class MyPrintStream extends Thread { private static MyPrintStream theInstance; - private static ArrayList output; - private static String s; + private static LinkedList output; + private static String s = null; + private static PrintStream sysout = null; // private static boolean bFlushed = false; // private static int count = 0; private static MyPrintStream getInstance() { if (theInstance == null) { theInstance = new MyPrintStream(); - output = new ArrayList(); + output = new LinkedList(); + sysout = System.out; Runtime.getRuntime().addShutdownHook(theInstance); // �V���b�g�_�E���p // theInstance.start(); } @@ -63,36 +67,43 @@ // } else { // �V���b�g�_�E�����Ƀo�b�t�@�Ɏc�����g���[�X���o�͂��؂� // bFlushed = true; - for (int n = 0; n < output.size(); n++) { - System.out.println(output.get(n)); + for (String s: output) { + sysout.println(s); } // } } - private void _print(int n) { - if (s == null) s = new String(); - s += n; + private synchronized void _print(int n) { + if (s == null) { + s = Integer.toString(n); + } else { + s += n; + } } - private void _print(String s1) { - if (s == null) s = new String(); - s += s1; + private synchronized void _print(String s1) { + if (s == null) { + s = s1; + } else { + s += s1; + } } - private void _println() { - if (s == null) s = new String(); - synchronized (output) { - output.add(s); + private synchronized void _println() { + if (s == null) { + s = ""; } - s = new String(); + output.add(s); + s = null; } - private void _println(String s1) { - if (s == null) s = new String(); - s += s1; - synchronized (output) { - output.add(s); + private synchronized void _println(String s1) { + if (s == null) { + s = s1; + } else { + s += s1; } - s = new String(); + output.add(s); + s = null; } } diff --git a/TracerOnJavassist/src/tracer/OutputStatementsGenerator.java b/TracerOnJavassist/src/tracer/OutputStatementsGenerator.java index 4f28a5c..975e6e6 100644 --- a/TracerOnJavassist/src/tracer/OutputStatementsGenerator.java +++ b/TracerOnJavassist/src/tracer/OutputStatementsGenerator.java @@ -42,7 +42,11 @@ valueObject = "(($1 != null)?System.identityHashCode($1):0)"; } else { valueClass = "\"" + f.getField().getType().getName() + "\""; // ��{�^�̏ꍇ�AgetClass()�ł��Ȃ����� - valueObject = "$1"; + if (f.getField().getType() != CtClass.charType) { + valueObject = "$1"; + } else { + valueObject = "Character.getNumericValue($1)"; // �����^�̏ꍇ�������o�͂���Ă��܂����� + } } String threadId = "Thread.currentThread().getId()"; String lineNum = "\"" + line + "\""; @@ -71,7 +75,11 @@ valueObject = "(($_ != null)?System.identityHashCode($_):0)"; } else { valueClass = "\"" + f.getField().getType().getName() + "\""; // ��{�^�̏ꍇ�AgetClass()�ł��Ȃ����� - valueObject = "$_"; + if (f.getField().getType() != CtClass.charType) { + valueObject = "$_"; + } else { + valueObject = "Character.getNumericValue($_)"; // �����^�̏ꍇ�������o�͂���Ă��܂����� + } } String threadId = "Thread.currentThread().getId()"; String lineNum = "\"" + line + "\""; @@ -172,8 +180,12 @@ argClasses.add("(($" + (p + 1) + " != null)?($" + (p + 1) + ").getClass().getName():\"" + c.getName() + "\")"); argObjects.add("(($" + (p + 1) + " != null)?System.identityHashCode($" + (p + 1) + "):0)"); } else { - argClasses.add("\"" + c.getName() + "\""); // ��{�^�̏ꍇ�AgetClass()�ł��Ȃ����� - argObjects.add("$" + (p + 1)); + argClasses.add("\"" + c.getName() + "\""); // ��{�^�̏ꍇ�AgetClass()�ł��Ȃ����� + if (c != CtClass.charType) { + argObjects.add("$" + (p + 1)); + } else { + argObjects.add("Character.getNumericValue($" + (p + 1) + ")"); // �����^�̏ꍇ�������o�͂���Ă��܂����� + } } p++; } @@ -197,8 +209,12 @@ thisClass = "\"" + declaredClassName + "\""; thisObject = "\"0\""; } else { - returnedClass = "\"" + ((CtMethod)m).getReturnType().getName() +"\""; - returnedObject = "$_"; + returnedClass = "\"" + ((CtMethod)m).getReturnType().getName() +"\""; // void �Ɗ�{�^�̏ꍇ�AgetClass()�ł��Ȃ����� + if (((CtMethod)m).getReturnType() != CtClass.charType) { + returnedObject = "$_"; + } else { + returnedObject = "Character.getNumericValue($_)"; // �����^�̏ꍇ�������o�͂���Ă��܂����� + } thisClass = "\"" + declaredClassName + "\""; thisObject = "\"0\""; } @@ -236,8 +252,12 @@ thisClass = "this.getClass().getName()"; thisObject = "System.identityHashCode(this)"; } else { - returnedClass = "\"" + ((CtMethod)m).getReturnType().getName() +"\""; // ��{�^�̏ꍇ�AgetClass()�ł��Ȃ����� - returnedObject = "$_"; + returnedClass = "\"" + ((CtMethod)m).getReturnType().getName() +"\""; // void �Ɗ�{�^�̏ꍇ�AgetClass()�ł��Ȃ����� + if (((CtMethod)m).getReturnType() != CtClass.charType) { + returnedObject = "$_"; + } else { + returnedObject = "Character.getNumericValue($_)"; // �����^�̏ꍇ�������o�͂���Ă��܂����� + } thisClass = "this.getClass().getName()"; thisObject = "System.identityHashCode(this)"; } @@ -249,8 +269,12 @@ thisClass = "$0.getClass().getName()"; thisObject = "System.identityHashCode($0)"; } else { - returnedClass = "\"" + ((CtMethod)m).getReturnType().getName() +"\""; // ��{�^�̏ꍇ�AgetClass()�ł��Ȃ����� - returnedObject = "$_"; + returnedClass = "\"" + ((CtMethod)m).getReturnType().getName() +"\""; // void �Ɗ�{�^�̏ꍇ�AgetClass()�ł��Ȃ����� + if (((CtMethod)m).getReturnType() != CtClass.charType) { + returnedObject = "$_"; + } else { + returnedObject = "Character.getNumericValue($_)"; // �����^�̏ꍇ�������o�͂���Ă��܂����� + } thisClass = "$0.getClass().getName()"; thisObject = "System.identityHashCode($0)"; }