diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/Alias.java b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/Alias.java new file mode 100644 index 0000000..dac8427 --- /dev/null +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/Alias.java @@ -0,0 +1,72 @@ +package org.ntlab.deltaExtractor; +import org.ntlab.trace.MethodExecution; +import org.ntlab.trace.Statement; +import org.ntlab.trace.TracePoint; +/** + * �I�u�W�F�N�g�̎Q�Ə��(�G�C���A�X)��\���N���X + * @author Isitani + * + */ +public class Alias { + private String objectId; + private TracePoint occurrencePoint; // ���Y�I�u�W�F�N�g�̎Q�Ƃ��s���Ă�����s�ӏ��ɑΉ�����TracePoint + private AliasType aliasType; + private int index; + + public enum AliasType { + // ���\�b�h�ւ̓��� + FORMAL_PARAMETER, + THIS, + METHOD_INVOCATION, + CONSTRACTOR_INVOCATION, + + // �ǐՃI�u�W�F�N�g�̐؂�ւ� + FIELD, + CONTAINER, + ARRAY_ELEMENT, + ARRAY, + ARRAY_CREATE, + + // ���\�b�h����̏o�� + ACTUAL_ARGUMENT, + RECEIVER, + RETURN_VALUE + } + + public Alias(AliasType aliasType, int index, String objectId, TracePoint occurrencePoint) { + this.aliasType = aliasType; + this.index = index; + this.objectId = objectId; + this.occurrencePoint = occurrencePoint; + } + + public AliasType getAliasType() { + return aliasType; + } + + public int getIndex() { + return index; + } + + public String getObjectId() { + return objectId; + } + + public TracePoint getOccurrencePoint() { + return occurrencePoint; + } + + public MethodExecution getMethodExecution() { + return occurrencePoint.getMethodExecution(); + } + + public String getMethodSignature() { + return occurrencePoint.getMethodExecution().getCallerSideSignature(); + } + + public int getLineNo() { + Statement statement = occurrencePoint.getStatement(); + return statement.getLineNo(); + } + +} \ No newline at end of file diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/DeltaExtractor.java b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/DeltaExtractor.java index d7a16df..3eeece6 100644 --- a/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/DeltaExtractor.java +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/DeltaExtractor.java @@ -36,6 +36,14 @@ protected static final boolean DEBUG1 = true; protected static final boolean DEBUG2 = true; + protected final IAliasCollector defaultAliasCollector = new IAliasCollector() { + @Override + public void changeTrackingObject(String from, String to) { + } + @Override + public void addAlias(Alias alias) { + } + }; public DeltaExtractor(String traceFile) { trace = new Trace(traceFile); @@ -83,6 +91,19 @@ * @throws TraceFileException */ protected MethodExecution callerSearch(Trace trace, TracePoint tracePoint, ArrayList objList, MethodExecution childMethodExecution) { + return callerSearch(trace, tracePoint, objList, childMethodExecution, defaultAliasCollector); + } + + /** + * �f���^���o�A���S���Y���̌Ăяo�����T�������icalleeSearch�Ƒ��ݍċA�ɂȂ��Ă���j + * @param trace�@��͑Ώۃg���[�X + * @param methodExecution �T�����郁�\�b�h���s + * @param objList�@�ǐՒ��̃I�u�W�F�N�g + * @param child�@���O�ɒT�����Ă����Ăяo����̃��\�b�h���s + * @return ���‚������R�[�f�B�l�[�^ + * @throws TraceFileException + */ + protected MethodExecution callerSearch(Trace trace, TracePoint tracePoint, ArrayList objList, MethodExecution childMethodExecution, IAliasCollector aliasCollector) { MethodExecution methodExecution = tracePoint.getMethodExecution(); methodExecution.setAugmentation(new DeltaAugmentationInfo()); eStructure.createParent(methodExecution); @@ -228,7 +249,7 @@ ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(retObj)); // �ǐՑΏ� TracePoint prevChildTracePoint = tracePoint.duplicate(); prevChildTracePoint.stepBackNoReturn(); - calleeSearch(trace, prevChildTracePoint, objList, prevChildMethodExecution.isStatic(), retIndex); // �Ăяo�����T�� + calleeSearch(trace, prevChildTracePoint, objList, prevChildMethodExecution.isStatic(), retIndex, aliasCollector); // �Ăяo�����T�� if (objList.get(retIndex) != null && objList.get(retIndex).equals(prevChildMethodExecution.getThisObjId()) && thisObjectId.equals(prevChildMethodExecution.getThisObjId())) { // �Ăяo����Ńt�B�[���h�Ɉˑ����Ă����ꍇ�̏��� @@ -418,7 +439,7 @@ // } if (tracePoint.isValid()) { finalCount = 0; - return callerSearch(trace, tracePoint, objList, methodExecution); // �Ăяo����������ɒT�� + return callerSearch(trace, tracePoint, objList, methodExecution, aliasCollector); // �Ăяo����������ɒT�� } } @@ -434,7 +455,7 @@ if (finalCount <= LOST_DECISION_EXTENSION) { // final�ϐ����Q�Ƃ��Ă���ꍇ�R���������ł��Ȃ��”\��������̂ŁA�ǐՂ������I�������P�\���Ԃ�݂��� if (tracePoint.isValid()) { - MethodExecution c = callerSearch(trace, tracePoint, objList, methodExecution); // �Ăяo����������ɒT�� + MethodExecution c = callerSearch(trace, tracePoint, objList, methodExecution, aliasCollector); // �Ăяo����������ɒT�� if (((DeltaAugmentationInfo)c.getAugmentation()).isCoodinator()) { methodExecution = c; // �ǐՂ𑱂������ʃR�[�f�B�l�[�^�����‚����� } @@ -489,7 +510,7 @@ * @param index�@objList���̂ǂ̃I�u�W�F�N�g��ǐՂ��Ă��̃��\�b�h���s�ɓ����Ă����̂� * @throws TraceFileException */ - protected void calleeSearch(Trace trace, TracePoint tracePoint, ArrayList objList, Boolean isStatic, int index) { + protected void calleeSearch(Trace trace, TracePoint tracePoint, ArrayList objList, Boolean isStatic, int index, IAliasCollector aliasCollector) { MethodExecution methodExecution = tracePoint.getMethodExecution(); Boolean isResolved = false; String objectId = objList.get(index); // calleeSearch() �ł͒ǐՑΏۂ̃I�u�W�F�N�g�͈�‚����A��objList��index�Ԗڂ̗v�f�ȊO�ύX���Ă͂����Ȃ� @@ -589,7 +610,7 @@ ((DeltaAugmentationInfo)childMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(objectId)); TracePoint childTracePoint = tracePoint.duplicate(); childTracePoint.stepBackNoReturn(); - calleeSearch(trace, childTracePoint, objList, childMethodExecution.isStatic(), index); // �Ăяo���������ɒT�� + calleeSearch(trace, childTracePoint, objList, childMethodExecution.isStatic(), index, aliasCollector); // �Ăяo���������ɒT�� if (childMethodExecution.isConstructor()) { // �R���X�g���N�^�Ăяo���������ꍇ if (objectId.equals(srcObject.getId())) { @@ -770,6 +791,17 @@ * @return ���o���� */ public ExtractedStructure extract(Reference targetRef, TracePoint before) { + return extract(targetRef, before, defaultAliasCollector); + } + + /** + * �݌v�ύX��̃A���S���Y���̋N�����\�b�h(������) + * @param targetRef �ΏۂƂȂ�Q�� + * @param before �T���J�n�g���[�X�|�C���g(������ȑO��T��) + * @param aliasCollector �f���^���o���ɒǐՂ����I�u�W�F�N�g�̑S�G�C���A�X�����W���郊�X�i + * @return ���o���� + */ + public ExtractedStructure extract(Reference targetRef, TracePoint before, IAliasCollector aliasCollector) { TracePoint creationTracePoint; if (targetRef.isArray()) { // srcId �̔z��� dstId ���������Ă���”\�������郁�\�b�h���s���擾�i�z���p�̏����j @@ -788,7 +820,7 @@ if (creationTracePoint == null) { return null; } - return extractSub(creationTracePoint, targetRef); + return extractSub(creationTracePoint, targetRef, aliasCollector); } /** @@ -801,13 +833,30 @@ Statement statement = creationTracePoint.getStatement(); if (statement instanceof FieldUpdate) { Reference targetRef = ((FieldUpdate)statement).getReference(); - return extractSub(creationTracePoint, targetRef); + return extractSub(creationTracePoint, targetRef, defaultAliasCollector); + } else { + return null; + } + } + + /** + * �݌v�ύX��̃A���S���Y���̋N�����\�b�h(������) + * @param creationTracePoint �I�u�W�F�N�g�ԎQ�Ɛ����g���[�X�|�C���g(�t�B�[���h�ւ̑��) + * @param aliasCollector �f���^���o���ɒǐՂ����I�u�W�F�N�g�̑S�G�C���A�X�����W���郊�X�i + * @return ���o���� + */ + public ExtractedStructure extract(TracePoint creationTracePoint, IAliasCollector aliasCollector) { + creationTracePoint = creationTracePoint.duplicate(); + Statement statement = creationTracePoint.getStatement(); + if (statement instanceof FieldUpdate) { + Reference targetRef = ((FieldUpdate)statement).getReference(); + return extractSub(creationTracePoint, targetRef, aliasCollector); } else { return null; } } - private ExtractedStructure extractSub(TracePoint creationTracePoint, Reference targetRef) { + private ExtractedStructure extractSub(TracePoint creationTracePoint, Reference targetRef, IAliasCollector aliasCollector) { eStructure = new ExtractedStructure(); ArrayList objList = new ArrayList(); srcObject = targetRef.getSrcObject(); @@ -825,10 +874,14 @@ } else { objList.add(null); } - return extractSub2(creationTracePoint, objList); + return extractSub2(creationTracePoint, objList, aliasCollector); + } + + public ExtractedStructure extract(TracePoint tracePoint, ObjectReference argObj) { + return extract(tracePoint, argObj, defaultAliasCollector); } - public ExtractedStructure extract(TracePoint tracePoint, ObjectReference argObj) { + public ExtractedStructure extract(TracePoint tracePoint, ObjectReference argObj, IAliasCollector aliasCollector) { MethodExecution methodExecution = tracePoint.getMethodExecution(); eStructure = new ExtractedStructure(); ArrayList objList = new ArrayList(); @@ -841,12 +894,12 @@ if (DEBUG1) { System.out.println("extract delta of:" + methodExecution.getSignature() + " -> " + argObj.getActualType() + "(" + argObj.getId() + ")"); } - return extractSub2(tracePoint, objList); + return extractSub2(tracePoint, objList, aliasCollector); } - private ExtractedStructure extractSub2(TracePoint creationTracePoint, ArrayList objList) { + private ExtractedStructure extractSub2(TracePoint creationTracePoint, ArrayList objList, IAliasCollector aliasCollector) { eStructure.setCreationMethodExecution(creationTracePoint.getMethodExecution()); - MethodExecution coordinator = callerSearch(trace, creationTracePoint, objList, null); + MethodExecution coordinator = callerSearch(trace, creationTracePoint, objList, null, aliasCollector); eStructure.setCoordinator(coordinator); if (DEBUG2) { if (((DeltaAugmentationInfo)coordinator.getAugmentation()).isCoodinator()) { @@ -880,32 +933,53 @@ } /** - * �Q�ƌ��ƎQ�Ɛ�̃I�u�W�F�N�g���w�肵�ăf���^�𒊏o����(�I�����C����͗p) - * @param srcObj �Q�ƌ��I�u�W�F�N�g - * @param dstObj �Q�Ɛ�I�u�W�F�N�g + * ���ۂ̎Q�ƌ��ƎQ�Ɛ�̃I�u�W�F�N�g���w�肵�ăf���^�𒊏o����(�I�����C����͗p) + * @param srcObj ��������ɂ���Q�ƌ��I�u�W�F�N�g + * @param dstObj ��������ɂ���Q�Ɛ�I�u�W�F�N�g * @param before �T���J�n�g���[�X�|�C���g(������ȑO��T��) * @return�@���o���� */ public ExtractedStructure extract(Object srcObj, Object dstObj, TracePoint before) { - Reference targetRef = new Reference(Integer.toString(System.identityHashCode(srcObj)), Integer.toString(System.identityHashCode(dstObj)), null, null); - return extract(targetRef, before); + return extract(srcObj, dstObj, before, defaultAliasCollector); } - /** - * ���\�b�h���s���̃g���[�X�|�C���g�ƎQ�Ɛ�I�u�W�F�N�g���w�肵�ăf���^�𒊏o����(�I�����C����͗p) + * ���ۂ̎Q�ƌ��ƎQ�Ɛ�̃I�u�W�F�N�g���w�肵�ăf���^�𒊏o����(�I�����C����͗p) + * @param srcObj ��������ɂ���Q�ƌ��I�u�W�F�N�g + * @param dstObj ��������ɂ���Q�Ɛ�I�u�W�F�N�g + * @param before �T���J�n�g���[�X�|�C���g(������ȑO��T��) + * @param aliasCollector �f���^���o���ɒǐՂ����I�u�W�F�N�g�̑S�G�C���A�X�����W���郊�X�i + * @return�@���o���� + */ + public ExtractedStructure extract(Object srcObj, Object dstObj, TracePoint before, IAliasCollector aliasCollector) { + Reference targetRef = new Reference(Integer.toString(System.identityHashCode(srcObj)), Integer.toString(System.identityHashCode(dstObj)), null, null); + return extract(targetRef, before, aliasCollector); + } + + /** + * ���\�b�h���s���̃g���[�X�|�C���g�Ǝ��ۂ̎Q�Ɛ�I�u�W�F�N�g���w�肵�ăf���^�𒊏o����(�I�����C����͗p) * @param tracePoint ���\�b�h���s���̃g���[�X�|�C���g - * @param arg �Q�Ɛ�I�u�W�F�N�g(���[�J���ϐ�������ɂ��Q�Ɛ�) + * @param arg ��������ɂ���Q�Ɛ�I�u�W�F�N�g(���[�J���ϐ�������ɂ��Q�Ɛ�) * @return ���o���� */ public ExtractedStructure extract(TracePoint tracePoint, Object arg) { - ObjectReference argObj = new ObjectReference(Integer.toString(System.identityHashCode(arg))); - return extract(tracePoint, argObj); + return extract(tracePoint, arg, defaultAliasCollector); } /** - * �w�肵���X���b�h��Ō��ݎ��s���̃��\�b�h���s���擾����(�I�����C����͗p) - * @param thread �ΏۃX���b�h + * ���\�b�h���s���̃g���[�X�|�C���g�Ǝ��ۂ̎Q�Ɛ�I�u�W�F�N�g���w�肵�ăf���^�𒊏o����(�I�����C����͗p) + * @param tracePoint ���\�b�h���s���̃g���[�X�|�C���g + * @param arg ��������ɂ���Q�Ɛ�I�u�W�F�N�g(���[�J���ϐ�������ɂ��Q�Ɛ�) + * @return ���o���� + */ + public ExtractedStructure extract(TracePoint tracePoint, Object arg, IAliasCollector aliasCollector) { + ObjectReference argObj = new ObjectReference(Integer.toString(System.identityHashCode(arg))); + return extract(tracePoint, argObj, aliasCollector); + } + + /** + * �w�肵�����ۂ̃X���b�h��Ō��ݎ��s���̃��\�b�h���s���擾����(�I�����C����͗p) + * @param thread ���ݎ��s���̑ΏۃX���b�h * @return thread ��Ō��ݎ��s���̃��\�b�h���s */ public MethodExecution getCurrentMethodExecution(Thread thread) { diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/DeltaExtractorJSON.java b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/DeltaExtractorJSON.java index 04bf900..8b2cf63 100644 --- a/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/DeltaExtractorJSON.java +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/DeltaExtractorJSON.java @@ -1,6 +1,11 @@ package org.ntlab.deltaExtractor; +import java.util.AbstractMap; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map.Entry; import org.ntlab.trace.ArrayAccess; import org.ntlab.trace.ArrayCreate; @@ -29,7 +34,7 @@ public DeltaExtractorJSON(TraceJSON trace) { super(trace); } - + /** * �f���^���o�A���S���Y���̌Ăяo�����T�������icalleeSearch�Ƒ��ݍċA�ɂȂ��Ă���j * @param trace�@��͑Ώۃg���[�X @@ -39,7 +44,7 @@ * @return ���‚������R�[�f�B�l�[�^ * @throws TraceFileException */ - protected MethodExecution callerSearch(Trace trace, TracePoint tracePoint, ArrayList objList, MethodExecution childMethodExecution) { + protected MethodExecution callerSearch(Trace trace, TracePoint tracePoint, ArrayList objList, MethodExecution childMethodExecution, IAliasCollector aliasCollector) { MethodExecution methodExecution = tracePoint.getMethodExecution(); methodExecution.setAugmentation(new DeltaAugmentationInfo()); eStructure.createParent(methodExecution); @@ -52,6 +57,8 @@ ObjectReference thisObj = new ObjectReference(thisObjectId, methodExecution.getThisClassName(), Trace.getDeclaringType(methodExecution.getSignature(), methodExecution.isConstructor()), Trace.getDeclaringType(methodExecution.getCallerSideSignature(), methodExecution.isConstructor())); + HashMap aliasList = new HashMap<>(); + if (childMethodExecution == null) { // �T���J�n���͈�U�폜���A�Ăяo�����̒T���𑱂���ۂɕ��������� removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� @@ -65,6 +72,16 @@ removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� isTrackingThis = true; // �Ăяo�����T���O�ɕ��� } + + aliasCollector.addAlias(new Alias(Alias.AliasType.RECEIVER, 0, childMethodExecution.getThisObjId(), tracePoint.duplicate())); + } + + if (childMethodExecution != null) { + for (String objId : objList) { + if (!objId.equals(childMethodExecution.getThisObjId())) { + aliasCollector.addAlias(new Alias(Alias.AliasType.ACTUAL_ARGUMENT, -1, objId, tracePoint.duplicate())); // argIndex�͕s�� + } + } } if (childMethodExecution != null && childMethodExecution.isConstructor()) { @@ -100,11 +117,13 @@ int index = objList.indexOf(refObjectId); if (index != -1) { String ownerObjectId = fs.getContainerObjId(); + if (ownerObjectId.equals(thisObjectId)) { // �t�B�[���h�Q�Ƃ̏ꍇ removeList.add(refObjectId); existsInFields++; // set�������get�����o���Ă���”\�������� - removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� + removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� + aliasList.put(refObjectId, new Alias(Alias.AliasType.FIELD, 0, refObjectId, tracePoint.duplicate())); } else { // ���ڎQ�Ƃ̏ꍇ if (refObjectId.equals(srcObject.getId())) { @@ -117,6 +136,9 @@ dstObject = new ObjectReference(ownerObjectId, fs.getContainerClassName()); } objList.set(index, ownerObjectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.FIELD, 0, refObjectId, tracePoint.duplicate())); + aliasCollector.changeTrackingObject(refObjectId, ownerObjectId); //�ǐՑΏۃI�u�W�F�N�g�̐؂�ւ� + aliasCollector.addAlias(new Alias(Alias.AliasType.CONTAINER, 0, ownerObjectId, tracePoint.duplicate())); } } } else if (statement instanceof ArrayAccess) { @@ -136,6 +158,9 @@ dstObject = new ObjectReference(arrayObjectId, aa.getArrayClassName()); } objList.set(index, arrayObjectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY_ELEMENT, aa.getIndex(), elementObjectId, tracePoint.duplicate())); + aliasCollector.changeTrackingObject(elementObjectId, arrayObjectId); //�ǐՑΏۃI�u�W�F�N�g�̐؂�ւ� + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY, 0, arrayObjectId, tracePoint.duplicate())); } } else if (statement instanceof ArrayCreate) { ArrayCreate ac = (ArrayCreate)statement; @@ -147,6 +172,7 @@ removeList.add(arrayObjectId); existsInFields++; removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� + aliasList.put(arrayObjectId, new Alias(Alias.AliasType.ARRAY_CREATE, 0, arrayObjectId, tracePoint.duplicate())); } } else if (statement instanceof MethodInvocation) { MethodExecution prevChildMethodExecution = ((MethodInvocation)statement).getCalledMethodExecution(); @@ -159,6 +185,7 @@ if (retIndex != -1) { // �߂�l���R�������� prevChildMethodExecution.setAugmentation(new DeltaAugmentationInfo()); + if (prevChildMethodExecution.isConstructor()) { // �ǐՑΏۂ�constractor���Ă�ł�����(�I�u�W�F�N�g�̐�����������)field�Ɠ��l�ɏ��� String newObjId = ret.getId(); @@ -168,9 +195,11 @@ removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(newObjId)); // �ǐՑΏ� ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setSetterSide(false); // getter�Ăяo���Ɠ��l + aliasList.put(newObjId, new Alias(Alias.AliasType.CONSTRACTOR_INVOCATION, 0, newObjId, tracePoint.duplicate())); continue; } String retObj = objList.get(retIndex); + aliasCollector.addAlias(new Alias(Alias.AliasType.METHOD_INVOCATION, 0, retObj, tracePoint.duplicate())); if (removeList.contains(retObj)) { // ��xget�Ō��o���ăt�B�[���h�Ɉˑ����Ă���Ɣ��f�������{���̗R�����߂�l���������Ƃ����������̂ŁA�t�B�[���h�ւ̈ˑ����L�����Z������ removeList.remove(retObj); @@ -182,12 +211,14 @@ ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(retObj)); // �ǐՑΏ� TracePoint prevChildTracePoint = tracePoint.duplicate(); prevChildTracePoint.stepBackNoReturn(); - calleeSearch(trace, prevChildTracePoint, objList, prevChildMethodExecution.isStatic(), retIndex); // �Ăяo�����T�� - if (objList.get(retIndex) != null && objList.get(retIndex).equals(prevChildMethodExecution.getThisObjId()) - && thisObjectId.equals(prevChildMethodExecution.getThisObjId())) { - // �Ăяo����Ńt�B�[���h�Ɉˑ����Ă����ꍇ�̏��� - removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� - isTrackingThis = true; // �Ăяo�����T���O�ɕ��� + calleeSearch(trace, prevChildTracePoint, objList, prevChildMethodExecution.isStatic(), retIndex, aliasCollector); // �Ăяo�����T�� + if (objList.get(retIndex) != null && objList.get(retIndex).equals(prevChildMethodExecution.getThisObjId())) { + if ( thisObjectId.equals(prevChildMethodExecution.getThisObjId())) { + // �Ăяo����Ńt�B�[���h�Ɉˑ����Ă����ꍇ�̏��� + removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� + isTrackingThis = true; // �Ăяo�����T���O�ɕ��� + } + aliasCollector.addAlias(new Alias(Alias.AliasType.RECEIVER, 0, objList.get(retIndex), tracePoint.duplicate())); } if (isLost) { checkList.add(objList.get(retIndex)); @@ -206,14 +237,14 @@ } // �����̎擾 - ArrayList argments = methodExecution.getArguments(); + ArrayList arguments = methodExecution.getArguments(); // �����ƃt�B�[���h�ɓ���ID�̃I�u�W�F�N�g������ꍇ��z�� Reference r; for (int i = 0; i < removeList.size(); i++) { String removeId = removeList.get(i); - if (argments.contains(new ObjectReference(removeId))) { - removeList.remove(removeId); // �t�B�[���h�ƈ����̗����ɒǐՑΏۂ����݂����ꍇ�A������D�� + if (arguments.contains(new ObjectReference(removeId))) { + removeList.remove(removeId); // �t�B�[���h�ƈ����̗����ɒǐՑΏۂ����݂����ꍇ�A������D��(���A�P�[�X) } else if(objList.contains(removeId)) { // �t�B�[���h�ɂ����Ȃ������ꍇ(�������A�I�u�W�F�N�g�̐������t�B�[���h�Ɠ��l�Ɉ���) objList.remove(removeId); // �ǐՑΏۂ���O�� @@ -231,7 +262,10 @@ eStructure.addDstSide(r); dstObject = thisObj; isSrcSide = false; - } + } + aliasCollector.addAlias(aliasList.get(removeId)); + aliasCollector.changeTrackingObject(removeId, thisObjectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, aliasList.get(removeId).getOccurrencePoint())); } } } @@ -243,10 +277,11 @@ String objectId = objList.get(i); if (objectId != null) { ObjectReference trackingObj = new ObjectReference(objectId); - if (argments.contains(trackingObj)) { + if (arguments.contains(trackingObj)) { // �������R�������� existsInAnArgument = true; ((DeltaAugmentationInfo)methodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(objectId)); + aliasCollector.addAlias(new Alias(Alias.AliasType.FORMAL_PARAMETER, arguments.indexOf(trackingObj), trackingObj.getId(), methodExecution.getEntryPoint())); } else { // �R�����ǂ��ɂ����‚���Ȃ����� boolean isSrcSide2 = true; @@ -266,14 +301,14 @@ if (existsInFields > 0 || isTrackingThis) { // this�I�u�W�F�N�g��ǐՒ��̏ꍇ if (!Trace.isNull(thisObjectId)) { - objList.add(thisObjectId); // ����ɒT������ꍇ�A��U��菜���� thisObject �𕜊� + objList.add(thisObjectId); // ����ɒT������ꍇ�A��U��菜���� thisObject �𕜊� } else { objList.add(null); // ������static�Ăяo���������ꍇ�A����ȏ�ǐՂ��Ȃ� } } if (tracePoint.isValid()) { finalCount = 0; - return callerSearch(trace, tracePoint, objList, methodExecution); // �Ăяo����������ɒT�� + return callerSearch(trace, tracePoint, objList, methodExecution, aliasCollector); // �Ăяo����������ɒT�� } } @@ -289,7 +324,7 @@ if (finalCount <= LOST_DECISION_EXTENSION) { // final�ϐ����Q�Ƃ��Ă���ꍇ�R���������ł��Ȃ��”\��������̂ŁA�ǐՂ������I�������P�\���Ԃ�݂��� if (tracePoint.isValid()) { - MethodExecution c = callerSearch(trace, tracePoint, objList, methodExecution); // �Ăяo����������ɒT�� + MethodExecution c = callerSearch(trace, tracePoint, objList, methodExecution, aliasCollector); // �Ăяo����������ɒT�� if (((DeltaAugmentationInfo)c.getAugmentation()).isCoodinator()) { methodExecution = c; // �ǐՂ𑱂������ʃR�[�f�B�l�[�^�����‚����� } @@ -344,7 +379,7 @@ * @param index�@objList���̂ǂ̃I�u�W�F�N�g��ǐՂ��Ă��̃��\�b�h���s�ɓ����Ă����̂� * @throws TraceFileException */ - protected void calleeSearch(Trace trace, TracePoint tracePoint, ArrayList objList, Boolean isStatic, int index) { + protected void calleeSearch(Trace trace, TracePoint tracePoint, ArrayList objList, Boolean isStatic, int index, IAliasCollector aliasCollector) { MethodExecution methodExecution = tracePoint.getMethodExecution(); Boolean isResolved = false; String objectId = objList.get(index); // calleeSearch() �ł͒ǐՑΏۂ̃I�u�W�F�N�g�͈�‚����A��objList��index�Ԗڂ̗v�f�ȊO�ύX���Ă͂����Ȃ� @@ -354,8 +389,10 @@ Trace.getDeclaringType(methodExecution.getCallerSideSignature(), methodExecution.isConstructor())); ((DeltaAugmentationInfo)methodExecution.getAugmentation()).setSetterSide(false); // ��{�I��getter�Ăяo���̂͂������A���� - ArrayList argments = methodExecution.getArguments(); + ArrayList arguments = methodExecution.getArguments(); ObjectReference trackingObj = null; + + aliasCollector.addAlias(new Alias(Alias.AliasType.RETURN_VALUE, 0, objectId, tracePoint.duplicate())); //static���o�R�����null�������Ă��鎞������ if (objectId != null) { String returnType = Trace.getReturnType(methodExecution.getSignature()); @@ -377,7 +414,7 @@ // ���ڎQ�Ƃ���уt�B�[���h�Q�Ƃ̒T�� if (statement instanceof FieldAccess) { FieldAccess fs = (FieldAccess)statement; - if (objectId != null && objectId.equals(fs.getValueObjId())) { + if (objectId != null && objectId.equals(fs.getValueObjId())) { String ownerObjectId = fs.getContainerObjId(); if (ownerObjectId.equals(thisObjectId)) { // �t�B�[���h�Q�Ƃ̏ꍇ @@ -390,6 +427,9 @@ dstObject = thisObj; trackingObj = dstObject; } + aliasCollector.addAlias(new Alias(Alias.AliasType.FIELD, 0, objectId, tracePoint.duplicate())); + aliasCollector.changeTrackingObject(objectId, ownerObjectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, ownerObjectId, tracePoint.duplicate())); if (Trace.isNull(thisObjectId)) objectId = null; // static�ϐ��̏ꍇ else objectId = thisObjectId; objList.set(index, objectId); @@ -406,6 +446,9 @@ dstObject = new ObjectReference(ownerObjectId, fs.getContainerClassName()); trackingObj = dstObject; } + aliasCollector.addAlias(new Alias(Alias.AliasType.FIELD, 0, objectId, tracePoint.duplicate())); + aliasCollector.changeTrackingObject(objectId, ownerObjectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.CONTAINER, 0, ownerObjectId, tracePoint.duplicate())); if (Trace.isNull(ownerObjectId)) objectId = null; // static�ϐ��̏ꍇ else objectId = ownerObjectId; objList.set(index, objectId); @@ -428,6 +471,9 @@ dstObject = new ObjectReference(arrayObjectId, aa.getArrayClassName()); trackingObj = dstObject; } + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY_ELEMENT, aa.getIndex(), objectId, tracePoint.duplicate())); + aliasCollector.changeTrackingObject(objectId, arrayObjectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY, 0, arrayObjectId, tracePoint.duplicate())); objectId = arrayObjectId; objList.set(index, objectId); isResolved = true; @@ -445,6 +491,9 @@ dstObject = thisObj; trackingObj = dstObject; } + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY_CREATE, 0, ac.getArrayObjectId(), tracePoint.duplicate())); + aliasCollector.changeTrackingObject(ac.getArrayObjectId(), thisObjectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, tracePoint.duplicate())); if (Trace.isNull(thisObjectId)) objectId = null; // static�ϐ��̏ꍇ else objectId = thisObjectId; objList.set(index, objectId); @@ -458,7 +507,8 @@ ((DeltaAugmentationInfo)childMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(objectId)); TracePoint childTracePoint = tracePoint.duplicate(); childTracePoint.stepBackNoReturn(); - calleeSearch(trace, childTracePoint, objList, childMethodExecution.isStatic(), index); // �Ăяo���������ɒT�� + aliasCollector.addAlias(new Alias(Alias.AliasType.METHOD_INVOCATION, 0, ret.getId(), tracePoint.duplicate())); + calleeSearch(trace, childTracePoint, objList, childMethodExecution.isStatic(), index, aliasCollector); // �Ăяo���������ɒT�� if (childMethodExecution.isConstructor()) { // �R���X�g���N�^�Ăяo���������ꍇ if (objectId.equals(srcObject.getId())) { @@ -495,14 +545,20 @@ checkList.add(objList.get(index)); isLost = false; } + if (objectId != null) { + if (childMethodExecution.getThisObjId().equals(objectId)) { + aliasCollector.addAlias(new Alias(Alias.AliasType.RECEIVER, 0, objectId, tracePoint.duplicate())); + } + } } } } while (tracePoint.stepBackOver()); //�����T�� - if (argments.contains(new ObjectReference(objectId))) { + if (arguments.contains(new ObjectReference(objectId))) { ((DeltaAugmentationInfo)methodExecution.getAugmentation()).setSetterSide(true); // �������K�v? isResolved = true; + aliasCollector.addAlias(new Alias(Alias.AliasType.FORMAL_PARAMETER, arguments.indexOf(new ObjectReference(objectId)), objectId, methodExecution.getEntryPoint())); } } diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/IAliasCollector.java b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/IAliasCollector.java new file mode 100644 index 0000000..d3b807f --- /dev/null +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/IAliasCollector.java @@ -0,0 +1,9 @@ +package org.ntlab.deltaExtractor; + +public interface IAliasCollector { + + void addAlias(Alias alias); + + void changeTrackingObject(String from, String to); + +} \ No newline at end of file diff --git a/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/Test.java b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/Test.java index c6c4834..623b166 100644 --- a/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/Test.java +++ b/org.ntlab.traceAnalyzer/src/org/ntlab/deltaExtractor/Test.java @@ -20,12 +20,20 @@ public static void main(String[] args) { // TODO Auto-generated method stub long time = System.nanoTime(); -// TraceJSON trace = new TraceJSON("traces\\_worstCase.txt"); -// DeltaExtractorJSON s = new DeltaExtractorJSON(trace); -// HashMap threads = trace.getAllThreads(); -// ThreadInstance thread = threads.values().iterator().next(); -// TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); -// ExtractedStructure e = s.extract(new Reference(null, null, "worstCase.P", "worstCase.M"), tp); + TraceJSON trace = new TraceJSON("traces\\_worstCase.txt"); + DeltaExtractorJSON s = new DeltaExtractorJSON(trace); + HashMap threads = trace.getAllThreads(); + ThreadInstance thread = threads.values().iterator().next(); + TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); + ExtractedStructure e = s.extract(new Reference(null, null, "worstCase.P", "worstCase.M"), tp, new IAliasCollector() { + @Override + public void addAlias(Alias alias) { + System.out.println(alias.getAliasType().toString() + ":" + alias.getIndex() + "," + alias.getMethodSignature() + "," + alias.getLineNo()); + } + @Override + public void changeTrackingObject(String from, String to) { + } + }); // TraceJSON trace = new TraceJSON("traces\\_finalLocal.txt"); // DeltaExtractorJSON s = new DeltaExtractorJSON(trace); @@ -34,12 +42,15 @@ // TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); // ExtractedStructure e = s.extract(new Reference(null, null, "finalLocal.Main$1Test", "finalLocal.Main$A"), tp); - TraceJSON trace = new TraceJSON("traces\\__arraySample.txt"); - DeltaExtractorJSON s = new DeltaExtractorJSON(trace); - HashMap threads = trace.getAllThreads(); - ThreadInstance thread = threads.values().iterator().next(); - TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); - ExtractedStructure e = s.extract(new Reference(null, null, "arraySample.D", "arraySample.C"), tp); +// TraceJSON trace = new TraceJSON("traces\\__arraySample.txt"); +// DeltaExtractorJSON s = new DeltaExtractorJSON(trace); +// HashMap threads = trace.getAllThreads(); +// for (ThreadInstance thread: threads.values()) { +// TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); +// ExtractedStructure e = s.extract(new Reference(null, null, "arraySample.D", "arraySample.C"), tp); +// s.extract(e.getDelta().getSrcSide().get(2), e.getCoordinator().getEntryPoint()); +// break; +// } // TraceJSON trace = new TraceJSON("traces\\__arraySample.txt"); // DeltaExtractorJSON s = new DeltaExtractorJSON(trace);