package org.ntlab.deltaViewer; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import org.ntlab.deltaExtractor.Alias; import org.ntlab.deltaExtractor.DeltaExtractorJSON; import org.ntlab.deltaExtractor.ExtractedStructure; import org.ntlab.trace.FieldAccess; import org.ntlab.trace.FieldUpdate; import org.ntlab.trace.IStatementVisitor; import org.ntlab.trace.MethodExecution; import org.ntlab.trace.MethodInvocation; import org.ntlab.trace.Reference; import org.ntlab.trace.Statement; import org.ntlab.trace.ThreadInstance; import org.ntlab.trace.Trace; import org.ntlab.trace.TraceJSON; import org.ntlab.trace.TracePoint; /** * Delta viewer sample for MagnetRON. * * @author Nitta Lab. */ public class DeltaViewerSample { /** * @param args */ public static void main(String[] args) { // DeltaExtractorJSON dex = new DeltaExtractorJSON(trace); // HashMap<String, ThreadInstance> threads = trace.getAllThreads(); // ThreadInstance thread = threads.values().iterator().next(); // 最後のスレッドを見ているだけ… // TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); // System.out.println("===== All Statements Backward ====="); // TracePoint tp = null; // ExtractedStructure e = null; // DeltaAliasCollector dac = new DeltaAliasCollector(); // long restart = 0L; // for(;;) { // tp = trace.traverseStatementsInTraceBackward(new IStatementVisitor() { // @Override // public boolean preVisitStatement(Statement statement) { // System.out.println("pre:" + statement.getThreadNo() + ":" + statement.getTimeStamp()); // if(statement instanceof FieldUpdate) { // FieldUpdate fu = (FieldUpdate) statement; // if(!Trace.isNull(fu.getValueObjId()) && !Trace.isPrimitive(fu.getValueClassName())) { // return true; // } // } // return false; // } // // @Override // public boolean postVisitStatement(Statement statement) { // System.out.println("post:" + statement.getThreadNo() + ":" + statement.getTimeStamp()); // return false; // } // }, restart); // if(tp == null || !tp.isValid()) break; // e = dex.extract(new Reference(jHotDrawSelect3_1[0], jHotDrawSelect3_1[1], jHotDrawSelect3_1[2], jHotDrawSelect3_1[3]), tp, dac); // dex.extract(tp); // Statement statement = tp.getStatement(); // if(statement instanceof MethodInvocation) { // restart = ((MethodInvocation)tp.getStatement()).getCalledMethodExecution().getExitTime(); // } else { // restart = tp.getStatement().getTimeStamp(); // } // } // trace.traverseStatementsInTraceBackward(new IStatementVisitor() { // @Override // public boolean preVisitStatement(Statement statement) { // System.out.println("post:" + statement.getClass().getName() + ":" + statement.getTimeStamp()); // return false; // } // @Override // public boolean postVisitStatement(Statement statement) { // System.out.println("pre:" + statement.getClass().getName() + ":" + statement.getTimeStamp()); // return false; // } // }); // } // HashSet<String> marked = trace.getMarkedMethodSignatures(1255991806833871L, 1255991808597322L); // HashSet<String> marked = trace.getMarkedMethodSignatures(1699553004208835L, 1699553004739523L); // System.out.println("===== Marked Methods ====="); // for (String method: marked) { // System.out.println(method); // } // HashSet<String> unmarked = trace.getUnmarkedMethodSignatures(1255991806833871L, 1255991808597322L); // HashSet<String> unmarked = trace.getUnmarkedMethodSignatures(1699553004208835L, 1699553004739523L); // System.out.println("===== Unmarked Methods ====="); // for (String method: unmarked) { // System.out.println(method); // } // Change! // setArray, setCollection(2回目以降は必要なし) , foreach(thread) // ArrayListにaddされてない // フィールドに代入されていない // HashMap<String, ThreadInstance> threads = trace.getAllThreads(); // for(ThreadInstance ti: threads.values()) { // ArrayList<MethodExecution> roots = ti.getRoot(); // for(MethodExecution root: roots) { // traverseMethodExecution(root); // } // } Map<String, String[]> argsMap = new HashMap<>(); setArgmentsForDeltaExtract(argsMap); //抽出したいデルタの引数を格納したMapのkey // String argsKey = "ArgoUMLPlace1_1"; String argsKey = "ArgoUMLSelect0_1"; // String argsKey = "ArgoUMLSelect1_2"; // String argsKey = "sampleArray"; // String argsKey = "sampleCollection"; // String argsKey = "sampleCreate"; // String argsKey = "sampleStatic"; // String argsKey = "delta_eg1"; // String argsKey = "delta_eg5"; // String argsKey = "worstCase"; // String argsKey = "sample1"; long time = System.nanoTime(); TraceJSON trace = new TraceJSON(argsMap.get(argsKey)[4]); DeltaExtractorJSON s = new DeltaExtractorJSON(trace); HashMap<String, ThreadInstance> threads = trace.getAllThreads(); List<ExtractedStructure> eList = new ArrayList<>(); List<DeltaAliasCollector> dacList = new ArrayList<>(); if (threads.values().size() == 1) { ThreadInstance thread = threads.values().iterator().next(); // 最後のスレッドを見ているだけ… TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); Reference reference = new Reference(argsMap.get(argsKey)[0], argsMap.get(argsKey)[1], argsMap.get(argsKey)[2], argsMap.get(argsKey)[3]); DeltaAliasCollector dac = new DeltaAliasCollector(); ExtractedStructure e = s.extract(reference, tp, dac); eList.add(e); dacList.add(dac); } else { for (ThreadInstance thread: threads.values()) { TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); Reference reference = new Reference(argsMap.get(argsKey)[0], argsMap.get(argsKey)[1], argsMap.get(argsKey)[2], argsMap.get(argsKey)[3]); reference.setCollection(true); // reference.setArray(true); // reference.setFinalLocal(true); // reference.setCreation(true); DeltaAliasCollector dac = new DeltaAliasCollector(); ExtractedStructure e = s.extract(reference, tp, dac); System.out.println(e); if (e != null) { eList.add(e); dacList.add(dac); System.out.println("add" + eList.size() + ", " + dacList.size()); } System.out.println("---------------------------"); } } startDeltaViewer(eList.get(0), dacList.get(0)); } private static void startDeltaViewer(ExtractedStructure e, DeltaAliasCollector dac) { DeltaViewer dv = new DeltaViewer(e, dac); List<Alias> aliasList = new ArrayList<>(dac.getAliasList()); // dv.setCoordinatorPoint(1200, 100); dv.init(); // for(int i = 0; i < aliasList.size(); i++) { // System.out.println(aliasList.get(i).getObjectId() + ", " + aliasList.get(i).getMethodSignature() + " l." + aliasList.get(i).getLineNo() + " : " + aliasList.get(i).getAliasType().toString()); // } for(int i = 0; i <= aliasList.size(); i++) { dv.stepToAnimation(i); } } private static void setArgmentsForDeltaExtract(Map map){ // one delta extract String[] traceSample1 = {null, null, "","", "traces/traceSample1.txt"}; map.put("traceSample1", traceSample1); String[] traceSample2 = {null, null, "","", "traces/traceSample2.txt"}; map.put("traceSample2", traceSample2); String[] presenSample = {null, null, "","", "traces/presenSample.txt"}; map.put("presenSample", presenSample); String[] worstCase = {null, null, "worstCase.P", "worstCase.M", "traces/_worstCase.txt"}; map.put("worstCase", worstCase); String[] sample1 = {null, null, "sample1.D", "sample1.C", "traces\\sample1.trace"}; map.put("sample1", sample1); String[] sampleArray = {null, null, "sampleArray.D", "sampleArray.C", "traces\\sampleArray.trace"}; map.put("sampleArray", sampleArray); String[] sampleCollection = {null, null, "sampleCollection.D", "sampleCollection.C", "traces\\sampleCollection.trace"}; map.put("sampleCollection", sampleCollection); String[] sampleCreate = {null, null, "sampleCreate.D", "sampleCreate.C", "traces\\sampleCreate.trace"}; map.put("sampleCreate", sampleCreate); String[] sampleStatic = {null, null, "sampleStatic.D", "sampleStatic.C", "traces\\sampleStatic.trace"}; map.put("sampleStatic", sampleStatic); String[] delta_eg1 = {null, null, "E","C", "traces/testTrace.txt"}; map.put("delta_eg1", delta_eg1); String[] delta_eg5 = {null, null, "E","C", "traces/testTrace5.txt"}; map.put("delta_eg5", delta_eg5); String[] testTrace2 = {null, null, "","", "traces/testTrace2.txt"}; map.put("testTrace2", testTrace2); String[] testTrace3 = {null, null, "","", "traces/testTrace3.txt"}; map.put("testTrace3", testTrace3); String[] test = {null, null, "org.argouml.uml.diagram.static_structure.ui.FigClass","org.tigris.gef.base.LayerPerspectiveMutable", "traces\\ArgoUMLBenchmarkWithMoreStandardClasses.trace"}; map.put("test", test); String[] testVectorAddElement = {null, null, "java.util.Vector", "org.tigris.gef.base.LayerPerspective", "traces\\ArgoUMLBenchmarkWithMoreStandardClasses.trace"}; map.put("testVectorAddElement", testVectorAddElement);//trace.javaに"addElement("に対応するように追加 String[] ArgoUMLBenchmark = {"", "", "", "", "traces/ArgoUMLBenchmark.trace"}; map.put("ArgoUMLBenchmark", ArgoUMLBenchmark); String[] ArgoUMLBenchmarkWithMoreStandardClasses = {"", "", "", "", "traces/ArgoUMLBenchmarkWithMoreStandardClasses.trace"}; map.put("ArgoUMLBenchmarkWithMoreStandardClasses", ArgoUMLBenchmarkWithMoreStandardClasses); // String[] ArgoUMLSelect0_1 = {"1994249754", "1141430801", "java.util.ArrayList", "org.argouml.uml.diagram.static_structure.ui.SelectionClass","traces\\ArgoUMLBenchmarkWithMoreStandardClasses.trace"}; map.put("ArgoUMLSelect0_1", ArgoUMLSelect0_1); String[] ArgoUMLSelect0_1 = {"1994249754", "1141430801", null, null,"traces\\ArgoUMLBenchmarkWithMoreStandardClasses.trace"}; map.put("ArgoUMLSelect0_1", ArgoUMLSelect0_1); /*Vector.addElemnt()に対応済み*/String[] ArgoUMLDelete0_2 = {"1784213708", "1337038091", "java.util.Vector", "org.argouml.uml.diagram.static_structure.ui.FigClass", "traces\\ArgoUMLBenchmarkWithMoreStandardClasses.trace"}; map.put("ArgoUMLDelete0_2", ArgoUMLDelete0_2); /*更に過去mouse.Pressed(), mouseReleased()*/String[] ArgoUMLPlace1_1 = {null, null, "java.util.ArrayList", "org.argouml.uml.diagram.static_structure.ui.FigClass", "traces\\ArgoUMLBenchmarkWithMoreStandardClasses.trace"}; map.put("ArgoUMLPlace1_1", ArgoUMLPlace1_1); String[] ArgoUMLSelect1_2 = {"1994249754", "1141430801", "java.util.ArrayList", "org.argouml.uml.diagram.static_structure.ui.SelectionClass", "traces\\ArgoUMLBenchmarkWithMoreStandardClasses.trace"}; map.put("ArgoUMLSelect1_2", ArgoUMLSelect1_2); String[] jEditBenchmark = {"", "", "", "", "traces/jEditBenchmark.trace"}; map.put("jEditBenchmark", jEditBenchmark); String[] jEditSelect2_1 = {"932187140", "1572482885", "java.util.ArrayList", "org.gjt.sp.jedit.textarea.Selection$Range", "traces\\jEditBenchmarkWithMoreStandardClasses.trace"}; map.put("jEditSelect2_1", jEditSelect2_1); String[] jHotDrawBenchmark = {"", "", "", "", "traces/jHotDrawBenchmark.trace"}; map.put("jHotDrawBenchmark", jHotDrawBenchmark); String[] jHotDrawBenchmarkWithMoreStandardClasses = {"", "", "", "", "traces/jHotDrawBenchmarkWithMoreStandardClasses.trace"}; map.put("jHotDrawBenchmarkWithMoreStandardClasses", jHotDrawBenchmarkWithMoreStandardClasses); /*List.toArray()に対応させる必要がある?*/String[] jEditDelete2_2 = {null, null, "org.gjt.sp.jedit.buffer.ContentManager", "java.util.ArrayList", "traces\\jEditBenchmarkWithMoreStandardClasses.trace"}; map.put("jEditDelete2_2", jEditDelete2_2); String[] jHotDrawSelect3_1 = {"361298449", "212532447", "java.util.LinkedHashSet", "org.jhotdraw.draw.RectangleFigure", "traces\\jHotDrawBenchmarkWithMoreStandardClasses.trace"}; map.put("jHotDrawSelect3_1", jHotDrawSelect3_1); String[] jHotDrawMove3_2 = {"778703711", "212532447", "org.jhotdraw.draw.tool.DefaultDragTracker", "org.jhotdraw.draw.RectangleFigure", "traces\\jHotDrawBenchmarkWithMoreStandardClasses.trace"}; map.put("jHotDrawMove3_2", jHotDrawMove3_2); /*不明*/String[] jHotDrawMove3_2_1 = {null, null, "java.util.ArrayList", "org.jhotdraw.draw.RectangleFigure", "traces\\jHotDrawBenchmarkWithMoreStandardClasses.trace"}; map.put("jHotDrawMove3_2_1", jHotDrawMove3_2_1); String[] jHotDrawPlace4_1 = {"1284329882", "212532447", "java.util.HashMap", "org.jhotdraw.draw.RectangleFigure", "traces\\jHotDrawBenchmarkWithMoreStandardClasses.trace"}; map.put("jHotDrawPlace4_1", jHotDrawPlace4_1); String[] jHotDrawSelect4_2 = {"361298449", "212532447", "java.util.LinkedHashSet", "org.jhotdraw.draw.RectangleFigure", "traces\\jHotDrawBenchmarkWithMoreStandardClasses.trace"}; map.put("jHotDrawSelect4_2", jHotDrawSelect4_2); } private static void traverseMethodExecution(MethodExecution m) { System.out.println(m.getSignature()); for(Statement ms :m.getStatements()) { if(ms instanceof FieldAccess) { System.out.println(((FieldAccess)ms).getFieldName()); } } for(MethodExecution m2: m.getChildren()) { traverseMethodExecution(m2); } } }