diff --git a/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/OnlineTraceOutput.java b/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/OnlineTraceOutput.java index 0dee3a8..60fcff7 100644 --- a/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/OnlineTraceOutput.java +++ b/org.ntlab.traceCollector/src/org/ntlab/traceCollector/tracer/OnlineTraceOutput.java @@ -1,100 +1,195 @@ package org.ntlab.traceCollector.tracer; -import java.util.HashMap; +import java.util.ArrayList; +import java.util.Stack; -import org.ntlab.traceCollector.tracer.trace.ArrayUpdate; -import org.ntlab.traceCollector.tracer.trace.ClassInfo; -import org.ntlab.traceCollector.tracer.trace.FieldUpdate; -import org.ntlab.traceCollector.tracer.trace.MethodExecution; -import org.ntlab.traceCollector.tracer.trace.MethodInvocation; +import org.ntlab.traceCollector.tracer.trace.ObjectReference; import org.ntlab.traceCollector.tracer.trace.ThreadInstance; import org.ntlab.traceCollector.tracer.trace.TraceJSON; -import org.ntlab.traceCollector.tracer.trace.TracePoint; public class OnlineTraceOutput { + private static ThreadInstance thread = null; - public static void onlineTraceClassDefinition(String className, - String classPath, String loaderPath) { - TraceJSON.onlineTraceClassDefinition(className, classPath, loaderPath); + public static void onlineTraceClassDefinition(String className, String classPath, String loaderPath) { + // classPath��loaderPath�ɂ‚��Ă͐擪�� / ����菜���ċL�^���� + TraceJSON.initializeClass(className, classPath.substring(1), loaderPath.substring(1)); } - public static void onlineTracePreCallMethod(String signature, - String threadId, String lineNum) { - TraceJSON.onlineTracePreCallMethod(signature, threadId, lineNum); - } - - public static void onlineTraceMethodEntry(String signature, - String thisClassName, String thisObjectId, String threadId, - long timeStamp, String argList) { - TraceJSON.onlineTraceMethodEntry(signature, thisClassName, - thisObjectId, threadId, timeStamp, argList); + public static void onlineTracePreCallMethod(String signature, String threadId, String lineNum) { + TraceJSON.getThreadInstance(threadId).preCallMethod(signature, Integer.parseInt(lineNum)); } - public static void onlineTraceConstructorEntry(String signature, - String thisClassName, String thisObjectId, String threadId, - long timeStamp, String argList) { - TraceJSON.onlineTraceConstructorEntry(signature, thisClassName, - thisObjectId, threadId, timeStamp, argList); + public static void onlineTraceMethodEntry(String signature, String thisClassName, String thisObjectId, + String threadId, long timeStamp, String argList) { + boolean isConstractor = false; + boolean isStatic = false; + if (signature.contains("static ")) { + isStatic = true; + } + thread = TraceJSON.getThreadInstance(threadId); + Stack stack; + if (thread == null) { + thread = new ThreadInstance(threadId); + TraceJSON.getThreads().put(threadId, thread); + stack = new Stack(); + TraceJSON.getStacks().put(threadId, stack); + } else { + stack = TraceJSON.getStacks().get(threadId); + } + stack.push(signature); + // ���\�b�h�Ăяo���̐ݒ� + thread.callMethod(signature, null, thisClassName, thisObjectId, isConstractor, isStatic, timeStamp); + // �����̐ݒ� + ArrayList arguments = new ArrayList<>(); + String[] args = argList.split(","); + for (int i = 0; i < args.length - 1; i += 2) { + arguments.add(new ObjectReference(args[i + 1], args[i])); + } + thread.setArgments(arguments); } - public static void onlineTraceMethodExit(String shortSignature, - String thisClassName, String thisObjectId, String returnClassName, - String returnObjectId, String threadId, long timeStamp) { - TraceJSON.onlineTraceMethodExit(shortSignature, thisClassName, - thisObjectId, returnClassName, returnObjectId, threadId, - timeStamp); + public static void onlineTraceConstructorEntry(String signature, String thisClassName, String thisObjectId, + String threadId, long timeStamp, String argList) { + boolean isConstractor = true; + boolean isStatic = false; + thread = TraceJSON.getThreadInstance(threadId); + Stack stack; + if (thread == null) { + thread = new ThreadInstance(threadId); + TraceJSON.getThreads().put(threadId, thread); + stack = new Stack(); + TraceJSON.getStacks().put(threadId, stack); + } else { + stack = TraceJSON.getStacks().get(threadId); + } + stack.push(signature); + // ���\�b�h�Ăяo���̐ݒ� + thread.callMethod(signature, null, thisClassName, thisObjectId, isConstractor, isStatic, timeStamp); + // �����̐ݒ� + ArrayList arguments = new ArrayList<>(); + String[] args = argList.split(","); + for (int i = 0; i < args.length - 1; i += 2) { + arguments.add(new ObjectReference(args[i + 1], args[i])); + } + thread.setArgments(arguments); } - public static void onlineTraceConstructorExit(String shortSignature, - String returnClassName, String returnObjectId, String threadId, - long timeStamp) { - TraceJSON.onlineTraceConstructorExit(shortSignature, returnClassName, - returnObjectId, threadId, timeStamp); + public static void onlineTraceMethodExit(String shortSignature, String thisClassName, String thisObjectId, + String returnClassName, String returnObjectId, String threadId, long timeStamp) { + Stack stack = TraceJSON.getStacks().get(threadId); + if (!stack.isEmpty()) { + String line2 = stack.peek(); + if (line2.endsWith(shortSignature)) { + stack.pop(); + } else { + do { + stack.pop(); + thread.terminateMethod(); + if (stack.isEmpty()) break; + line2 = stack.peek(); + } while (!stack.isEmpty() && !line2.endsWith(shortSignature)); + if (!stack.isEmpty()) stack.pop(); + } + thread = TraceJSON.getThreadInstance(threadId); + ObjectReference returnVal = new ObjectReference(returnObjectId, returnClassName); + boolean isCollectionType = false; + if (thisClassName.contains("java.util.List") || thisClassName.contains("java.util.Vector") + || thisClassName.contains("java.util.Iterator") || thisClassName.contains("java.util.ListIterator") + || thisClassName.contains("java.util.ArrayList") || thisClassName.contains("java.util.Stack") + || thisClassName.contains("java.util.Hash") || thisClassName.contains("java.util.Map") + || thisClassName.contains("java.util.Set") || thisClassName.contains("java.util.Linked") + || thisClassName.contains("java.lang.Thread")) { + isCollectionType = true; + } + // ���\�b�h����̕��A�̐ݒ� + thread.returnMethod(returnVal, thisObjectId, isCollectionType, timeStamp); + } } - public static void onlineTraceFieldGet(String fieldName, - String thisClassName, String thisObjectId, - String containerClassName, String containerObjectId, - String valueClassName, String valueObjectId, String threadId, - String lineNum, long timeStamp) { - TraceJSON.onlineTraceFieldGet(fieldName, thisClassName, thisObjectId, - containerClassName, containerObjectId, valueClassName, - valueObjectId, threadId, lineNum, timeStamp); + public static void onlineTraceConstructorExit(String shortSignature, String returnClassName, String returnObjectId, + String threadId, long timeStamp) { + String thisClassName = returnClassName; + String thisObjectId = returnObjectId; + Stack stack = TraceJSON.getStacks().get(threadId); + if (!stack.isEmpty()) { + String line2 = stack.peek(); + if (line2.endsWith(shortSignature)) { + stack.pop(); + } else { + do { + stack.pop(); + thread.terminateMethod(); + if (stack.isEmpty()) break; // ���̈ꕶ�����ɒlj�(MethodExit�̕������l) + line2 = stack.peek(); + } while (!stack.isEmpty() && !line2.endsWith(shortSignature)); + if (!stack.isEmpty()) stack.pop(); + } + thread = TraceJSON.getThreadInstance(threadId); + ObjectReference returnVal = new ObjectReference(returnObjectId, returnClassName); + boolean isCollectionType = false; + if (thisClassName.contains("java.util.List") || thisClassName.contains("java.util.Vector") + || thisClassName.contains("java.util.Iterator") || thisClassName.contains("java.util.ListIterator") + || thisClassName.contains("java.util.ArrayList") || thisClassName.contains("java.util.Stack") + || thisClassName.contains("java.util.Hash") || thisClassName.contains("java.util.Map") + || thisClassName.contains("java.util.Set") || thisClassName.contains("java.util.Linked") + || thisClassName.contains("java.lang.Thread")) { + isCollectionType = true; + } + // ���\�b�h����̕��A�̐ݒ� + thread.returnMethod(returnVal, thisObjectId, isCollectionType, timeStamp); + } } - public static void onlineTraceFieldSet(String fieldName, - String containerClassName, String containerObjectId, - String valueClassName, String valueObjectId, String threadId, - String lineNum, long timeStamp) { - TraceJSON.onlineTraceFieldSet(fieldName, containerClassName, - containerObjectId, valueClassName, valueObjectId, threadId, - lineNum, timeStamp); - } - - public static void onlineTraceArrayCreate(String arrayClassName, - String arrayObjectId, String dimension, String threadId, - String lineNum, long timeStamp) { - TraceJSON.onlineTraceArrayCreate(arrayClassName, arrayObjectId, - dimension, threadId, lineNum, timeStamp); - } - - public static void onlineTraceArraySet(String arrayClassName, - String arrayObjectId, int index, String valueClassName, - String valueObjectId, String threadId, long timeStamp) { - TraceJSON.onlineTraceArraySet(arrayClassName, arrayObjectId, index, - valueClassName, valueObjectId, threadId, timeStamp); - } - - public static void onlineTraceArrayGet(String arrayClassName, - String arrayObjectId, int index, String valueClassName, - String valueObjectId, String threadId, long timeStamp) { - TraceJSON.onlineTraceArrayGet(arrayClassName, arrayObjectId, index, - valueClassName, valueObjectId, threadId, timeStamp); - } - - public static void onlineTraceBlockEntry(String blockId, String incomings, + public static void onlineTraceFieldGet(String fieldName, String thisClassName, String thisObjectId, + String containerClassName, String containerObjectId, String valueClassName, String valueObjectId, String threadId, String lineNum, long timeStamp) { - TraceJSON.onlineTraceBlockEntry(blockId, incomings, threadId, lineNum, - timeStamp); + thread = TraceJSON.getThreadInstance(threadId); + if (thread != null) { + thread.fieldAccess(fieldName, valueClassName, valueObjectId, containerClassName, containerObjectId, + thisClassName, thisObjectId, Integer.parseInt(lineNum), timeStamp); + } } -} + + public static void onlineTraceFieldSet(String fieldName, String containerClassName, String containerObjectId, + String valueClassName, String valueObjectId, String threadId, String lineNum, long timeStamp) { + thread = TraceJSON.getThreadInstance(threadId); + if (thread != null) { + thread.fieldUpdate(fieldName, valueClassName, valueObjectId, containerClassName, containerObjectId, + Integer.parseInt(lineNum), timeStamp); + } + } + + public static void onlineTraceArrayCreate(String arrayClassName, String arrayObjectId, String dimension, + String threadId, String lineNum, long timeStamp) { + thread = TraceJSON.getThreadInstance(threadId); + if (thread != null) { + thread.arrayCreate(arrayClassName, arrayObjectId, Integer.parseInt(dimension), Integer.parseInt(lineNum), + timeStamp); + } + } + + public static void onlineTraceArraySet(String arrayClassName, String arrayObjectId, int index, + String valueClassName, String valueObjectId, String threadId, long timeStamp) { + thread = TraceJSON.getThreadInstance(threadId); + if (thread != null) { + thread.arraySet(arrayClassName, arrayObjectId, index, valueClassName, valueObjectId, 0, timeStamp); + } + } + + public static void onlineTraceArrayGet(String arrayClassName, String arrayObjectId, int index, + String valueClassName, String valueObjectId, String threadId, long timeStamp) { + thread = TraceJSON.getThreadInstance(threadId); + if (thread != null) { + thread.arrayGet(arrayClassName, arrayObjectId, index, valueClassName, valueObjectId, 0, timeStamp); + } + } + + public static void onlineTraceBlockEntry(String blockId, String incomings, String threadId, String lineNum, + long timeStamp) { + thread = TraceJSON.getThreadInstance(threadId); + if (thread != null) { + thread.blockEnter(Integer.parseInt(blockId), Integer.parseInt(incomings), Integer.parseInt(lineNum), + timeStamp); + } + } +} \ No newline at end of file