diff --git a/src/org/ntlab/deltaExtractor/DeltaAlias.java b/src/org/ntlab/deltaExtractor/DeltaAlias.java new file mode 100644 index 0000000..3fd1953 --- /dev/null +++ b/src/org/ntlab/deltaExtractor/DeltaAlias.java @@ -0,0 +1,16 @@ +package org.ntlab.deltaExtractor; + +import org.ntlab.trace.TracePoint; + +public class DeltaAlias extends Alias { + boolean bSrcSide = false; + + public DeltaAlias(AliasType aliasType, int index, String objectId, TracePoint occurrencePoint, boolean isSrcSide) { + super(aliasType, index, objectId, occurrencePoint); + bSrcSide = isSrcSide; + } + + public boolean isSrcSide() { + return bSrcSide; + } +} diff --git a/src/org/ntlab/deltaExtractor/DeltaExtractor.java b/src/org/ntlab/deltaExtractor/DeltaExtractor.java index 5082dd9..11dd99a 100644 --- a/src/org/ntlab/deltaExtractor/DeltaExtractor.java +++ b/src/org/ntlab/deltaExtractor/DeltaExtractor.java @@ -1,6 +1,7 @@ package org.ntlab.deltaExtractor; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import org.ntlab.trace.FieldAccess; @@ -103,12 +104,13 @@ /** * �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 methodExecution �T�����n�߂郁�\�b�h���s + * @param objList�@�ǐՒ��̃I�u�W�F�N�g�̃��X�g * @param child�@���O�ɒT�����Ă����Ăяo����̃��\�b�h���s + * @param aliasCollector �G�C���A�X�����W���邽�߂̃r�W�^�[ * @return ���‚������R�[�f�B�l�[�^ - * @throws TraceFileException */ + @Deprecated protected MethodExecution callerSearch(Trace trace, TracePoint tracePoint, ArrayList objList, MethodExecution childMethodExecution, IAliasTracker aliasCollector) { MethodExecution methodExecution = tracePoint.getMethodExecution(); methodExecution.setAugmentation(new DeltaAugmentationInfo()); @@ -124,6 +126,9 @@ ObjectReference thisObj = new ObjectReference(thisObjectId, methodExecution.getThisClassName(), Trace.getDeclaringType(methodExecution.getSignature(), methodExecution.isConstructor()), Trace.getDeclaringType(methodExecution.getCallerSideSignature(), methodExecution.isConstructor())); + HashMap srcAliasList = new HashMap<>(); + HashMap dstAliasList = new HashMap<>(); + if (childMethodExecution == null) { // �T���J�n���͈�U�폜���A�Ăяo�����̒T���𑱂���ۂɕ��������� removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� @@ -136,6 +141,19 @@ // �I�u�W�F�N�g���Ăяo���̂Ƃ��݈̂�U�폜���A�Ăяo�����̒T���𑱂���ۂɕ��������� removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� isTrackingThis = true; // �Ăяo�����T���O�ɕ��� + // �I�u�W�F�N�g���Ăяo���̏ꍇ [case 1] + aliasCollector.addAlias(new Alias(Alias.AliasType.RECEIVER, 0, childMethodExecution.getThisObjId(), tracePoint.duplicate())); + } else if (!childMethodExecution.isConstructor()) { + // �I�u�W�F�N�g�Ԃ̔�R���X�g���N�^�Ăяo���̏ꍇ [case 2] + 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())); // �����ԍ����킩��Ȃ� + } } } @@ -147,6 +165,14 @@ removeList.add(childMethodExecution.getThisObjId()); existsInFields++; removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� + if (!thisObjectId.equals(childMethodExecution.getThisObjId())) { + // �I�u�W�F�N�g�Ԃ̃R���X�g���N�^�Ăяo���̏ꍇl [case 3] + if (childMethodExecution.getThisObjId().equals(srcObject.getId())) { + srcAliasList.put(childMethodExecution.getThisObjId(), new DeltaAlias(Alias.AliasType.RECEIVER, 0, childMethodExecution.getThisObjId(), tracePoint.duplicate(), true)); + } else if (childMethodExecution.getThisObjId().equals(dstObject.getId())) { + dstAliasList.put(childMethodExecution.getThisObjId(), new DeltaAlias(Alias.AliasType.RECEIVER, 0, childMethodExecution.getThisObjId(), tracePoint.duplicate(), false)); + } + } } } @@ -159,36 +185,53 @@ removeList.add(enclosingObj); existsInFields++; removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� + if (enclosingObj.equals(srcObject.getId())) { + srcAliasList.put(enclosingObj, new DeltaAlias(Alias.AliasType.FIELD, 0, enclosingObj, tracePoint.duplicate(), true)); + } else if (enclosingObj.equals(dstObject.getId())) { + dstAliasList.put(enclosingObj, new DeltaAlias(Alias.AliasType.FIELD, 0, enclosingObj, tracePoint.duplicate(), false)); + } } } - + + // callerSearch �̃��C�����[�v�D���݂̃��\�b�h�̃X�e�[�g�����g�̎��s�����s�Ƌt�����ɒT�������D // �߂�l�ɒT���Ώۂ��܂܂�Ă����calleeSearch���ċA�Ăяo�� while (tracePoint.stepBackOver()) { Statement statement = tracePoint.getStatement(); - // ���ڎQ�Ƃ���уt�B�[���h�Q�Ƃ̒T�� if (statement instanceof FieldAccess) { + // ���s�����t�B�[���h�Q�Ƃ������ꍇ FieldAccess fs = (FieldAccess)statement; String refObjectId = fs.getValueObjId(); int index = objList.indexOf(refObjectId); if (index != -1) { String ownerObjectId = fs.getContainerObjId(); if (ownerObjectId.equals(thisObjectId)) { - // �t�B�[���h�Q�Ƃ̏ꍇ + // �����̃t�B�[���h�̎Q�Ƃ̏ꍇ removeList.add(refObjectId); - existsInFields++; // set�������get�����o���Ă���”\�������� removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� + if (refObjectId.equals(srcObject.getId())) { + srcAliasList.put(refObjectId, new DeltaAlias(Alias.AliasType.FIELD, 0, refObjectId, tracePoint.duplicate(), true)); + } else if (refObjectId.equals(dstObject.getId())) { + dstAliasList.put(refObjectId, new DeltaAlias(Alias.AliasType.FIELD, 0, refObjectId, tracePoint.duplicate(), false)); + } + existsInFields++; // set�������get�����o���Ă���”\�������� } else { - // ���ڎQ�Ƃ̏ꍇ + // ���̃I�u�W�F�N�g�̃t�B�[���h�̎Q�Ƃ̏ꍇ + boolean isSrcSideChanged = false; if (refObjectId.equals(srcObject.getId())) { eStructure.addSrcSide(new Reference(ownerObjectId, refObjectId, fs.getContainerClassName(), srcObject.getActualType())); srcObject = new ObjectReference(ownerObjectId, fs.getContainerClassName()); + isSrcSideChanged = true; } else if(refObjectId.equals(dstObject.getId())) { eStructure.addDstSide(new Reference(ownerObjectId, refObjectId, fs.getContainerClassName(), dstObject.getActualType())); dstObject = new ObjectReference(ownerObjectId, fs.getContainerClassName()); + isSrcSideChanged = false; } objList.set(index, ownerObjectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.FIELD, 0, refObjectId, tracePoint.duplicate())); + aliasCollector.changeTrackingObject(refObjectId, ownerObjectId, isSrcSideChanged); // �ǐՑΏۂ��t�B�[���h�ɂ��Q�Ɛ�I�u�W�F�N�g����Q�ƌ��I�u�W�F�N�g�i�R���e�i�j�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.CONTAINER, 0, ownerObjectId, tracePoint.duplicate())); } } else { // �ŏI�I�ɃI�u�W�F�N�g�̗R�������‚���Ȃ������ꍇ�ɁA�����ŎQ�Ƃ����z������̗v�f�ɗR�����Ă���”\�������� @@ -212,6 +255,11 @@ // �t�B�[���h�Q�Ƃ̏ꍇ�i���ɗR���̉”\�����Ȃ��Ƃ킩�������_�ŁA���̔z��̗v�f�ɗR�����Ă�����̂Ɛ�������B�j fieldArrays.add(new ObjectReference(refObjectId, refObjType)); fieldArrayElements.add(trackingObj); + if (trackingObj.getId().equals(srcObject.getId())) { + srcAliasList.put(trackingObj.getId(), new DeltaAlias(Alias.AliasType.ARRAY_ELEMENT, 0, trackingObj.getId(), tracePoint.duplicate(), true)); + } else if (trackingObj.getId().equals(dstObject.getId())) { + dstAliasList.put(trackingObj.getId(), new DeltaAlias(Alias.AliasType.ARRAY_ELEMENT, 0, trackingObj.getId(), tracePoint.duplicate(), false)); + } } else { // ���ڎQ�Ƃ̏ꍇ(�{���ɂ��̔z��̗v�f����擾���ꂽ���̂Ȃ炱���ŒǐՑΏۂ�u��������ׂ������A // ���̎��_�ő��̗R���̉”\����r���ł��Ȃ��B�����ŒǐՑΏۂ�u�������Ă��܂��ƁA��ŕʂɗR�������邱�Ƃ��킩�����ꍇ�� @@ -221,6 +269,7 @@ } } } else if (statement instanceof MethodInvocation) { + // ���s�������\�b�h�Ăяo���������ꍇ MethodExecution prevChildMethodExecution = ((MethodInvocation)statement).getCalledMethodExecution(); if (!prevChildMethodExecution.equals(childMethodExecution)) { // �߂�l @@ -237,13 +286,23 @@ creationList.add(newObjId); removeList.add(newObjId); existsInFields++; - // objList.remove(callTree.getThisObjId()); removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� - ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(newObjId)); // �ǐՑΏ� - ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setSetterSide(false); // getter�Ăяo���Ɠ��l + ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(newObjId)); // �ǐՑΏ� + ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setSetterSide(false); // �Q�Ƒ��̌Ăяo���Ɠ��l + if (newObjId.equals(srcObject.getId())) { + srcAliasList.put(newObjId, new DeltaAlias(Alias.AliasType.CONSTRACTOR_INVOCATION, 0, newObjId, tracePoint.duplicate(), true)); + } else if (newObjId.equals(dstObject.getId())) { + dstAliasList.put(newObjId, new DeltaAlias(Alias.AliasType.CONSTRACTOR_INVOCATION, 0, newObjId, tracePoint.duplicate(), false)); + } continue; } String retObj = objList.get(retIndex); + if (retObj.equals(srcObject.getId())) { + isSrcSide = true; + } else if (retObj.equals(dstObject.getId())) { + isSrcSide = false; + } + 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); @@ -252,15 +311,21 @@ removeList.remove(thisObjectId); } } - ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(retObj)); // �ǐՑΏ� + ((DeltaAugmentationInfo)prevChildMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(retObj)); // �ǐՑΏ� TracePoint prevChildTracePoint = tracePoint.duplicate(); prevChildTracePoint.stepBackNoReturn(); - 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�Ɉˑ����Ă����ꍇ�̏��� - removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� - isTrackingThis = true; // �Ăяo�����T���O�ɕ��� + calleeSearch(trace, prevChildTracePoint, objList, prevChildMethodExecution.isStatic(), retIndex, aliasCollector); // �Ăяo���惁�\�b�h���s�̒T���̂��ߍċA�Ăяo�� + 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�ɕ��� + } + if (isSrcSide) { + aliasCollector.addAlias(new DeltaAlias(Alias.AliasType.RECEIVER, 0, objList.get(retIndex), tracePoint.duplicate(), true)); + } else { + aliasCollector.addAlias(new DeltaAlias(Alias.AliasType.RECEIVER, 0, objList.get(retIndex), tracePoint.duplicate(), false)); + } } if (isLost) { checkList.add(objList.get(retIndex)); @@ -298,16 +363,16 @@ // �R���N�V�����^�Ή� if (methodExecution.isCollectionType()) { objList.add(thisObjectId); - } - + } + // �����̎擾 - ArrayList argments = methodExecution.getArguments(); + ArrayList arguments = methodExecution.getArguments(); - // �����ƃt�B�[���h�ɓ���ID�̃I�u�W�F�N�g������ꍇ��z�� + // �����ƃt�B�[���h�ɓ���ID�̃I�u�W�F�N�g������ꍇ��z��i�R���Ƃ��Ĉ����ƃt�B�[���h�̗������^����ꍇ�j Reference r; for (int i = 0; i < removeList.size(); i++) { String removeId = removeList.get(i); - if (argments.contains(new ObjectReference(removeId))) { + if (arguments.contains(new ObjectReference(removeId))) { removeList.remove(removeId); // �t�B�[���h�ƈ����̗����ɒǐՑΏۂ����݂����ꍇ�A������D�� } else if(objList.contains(removeId)) { // �t�B�[���h�ɂ����Ȃ������ꍇ(�������A�I�u�W�F�N�g�̐������t�B�[���h�Ɠ��l�Ɉ���) @@ -320,28 +385,41 @@ eStructure.addSrcSide(r); srcObject = thisObj; isSrcSide = true; + if (srcAliasList.containsKey(removeId)) { + aliasCollector.addAlias(srcAliasList.get(removeId)); + aliasCollector.changeTrackingObject(removeId, thisObjectId, isSrcSide); + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, srcAliasList.get(removeId).getOccurrencePoint())); + srcAliasList.remove(removeId); + } } else if (removeId.equals(dstObject.getId())) { r = new Reference(thisObj, dstObject); r.setCreation(creationList.contains(removeId)); // �I�u�W�F�N�g�̐�����? eStructure.addDstSide(r); dstObject = thisObj; isSrcSide = false; + if (dstAliasList.containsKey(removeId)) { + aliasCollector.addAlias(dstAliasList.get(removeId)); + aliasCollector.changeTrackingObject(removeId, thisObjectId, isSrcSide); + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, dstAliasList.get(removeId).getOccurrencePoint())); + dstAliasList.remove(removeId); + } } } } } // --- ���̎��_�� this ���ǐՑΏۂł������Ƃ��Ă� objList �̒����炢������폜����Ă��� --- - // �����T�� + // �R���Ƃ��Ĉ�����T�� boolean existsInAnArgument = false; for (int i = 0; i < objList.size(); i++) { 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; @@ -355,8 +433,8 @@ } if (trackingObj != null) { // �܂��z������̗v�f��R���Ƃ��ċ^��(������D��) - for (int j = 0; j < argments.size(); j++) { - ObjectReference argArray = argments.get(j); + for (int j = 0; j < arguments.size(); j++) { + ObjectReference argArray = arguments.get(j); if (argArray.getActualType().startsWith("[L") && (trackingObj.getActualType() != null && (argArray.getActualType().endsWith(trackingObj.getActualType() + ";")) || (trackingObj.getCalleeType() != null && argArray.getActualType().endsWith(trackingObj.getCalleeType() + ";")) @@ -377,6 +455,10 @@ dstObject = new ObjectReference(argArray.getId(), argArray.getActualType()); } objectId = null; + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY_ELEMENT, 0, trackingObj.getId(), methodExecution.getEntryPoint())); // �z��v�f�̓��\�b�h�̐擪�Ŏ擾���ꂽ�Ɖ��肷�� + aliasCollector.changeTrackingObject(trackingObj.getId(), argArray.getId(), isSrcSide2); // �ǐՑΏۂ�z��v�f����z��ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY, 0, argArray.getId(), methodExecution.getEntryPoint())); // �z��̓��\�b�h�̐擪�ŃA�N�Z�X���ꂽ�Ɖ��肷�� + aliasCollector.addAlias(new Alias(Alias.AliasType.FORMAL_PARAMETER, arguments.indexOf(argArray), trackingObj.getId(), methodExecution.getEntryPoint())); break; } } @@ -396,13 +478,27 @@ eStructure.addSrcSide(new Reference(thisObjectId, fieldArray.getId(), methodExecution.getThisClassName(), fieldArray.getActualType())); srcObject = thisObj; - isSrcSide = true; + if (srcAliasList.containsKey(trackingObj.getId())) { + aliasCollector.addAlias(srcAliasList.get(trackingObj.getId())); + aliasCollector.changeTrackingObject(trackingObj.getId(), fieldArray.getId(), isSrcSide2); // �ǐՑΏۂ�z��v�f����z��t�B�[���h�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY, 0, fieldArray.getId(), srcAliasList.get(trackingObj.getId()).getOccurrencePoint())); + aliasCollector.changeTrackingObject(fieldArray.getId(), thisObjectId, isSrcSide2); // �ǐՑΏۂ�z��t�B�[���h����this�I�u�W�F�N�g�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, srcAliasList.get(trackingObj.getId()).getOccurrencePoint())); + srcAliasList.remove(trackingObj.getId()); + } } else { eStructure.addDstSide(r); eStructure.addDstSide(new Reference(thisObjectId, fieldArray.getId(), methodExecution.getThisClassName(), fieldArray.getActualType())); dstObject = thisObj; - isSrcSide = false; + if (dstAliasList.containsKey(trackingObj.getId())) { + aliasCollector.addAlias(dstAliasList.get(trackingObj.getId())); + aliasCollector.changeTrackingObject(trackingObj.getId(), fieldArray.getId(), isSrcSide2); // �ǐՑΏۂ�z��v�f����z��t�B�[���h�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY, 0, fieldArray.getId(), dstAliasList.get(trackingObj.getId()).getOccurrencePoint())); + aliasCollector.changeTrackingObject(fieldArray.getId(), thisObjectId, isSrcSide2); // �ǐՑΏۂ�z��t�B�[���h����this�I�u�W�F�N�g�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, dstAliasList.get(trackingObj.getId()).getOccurrencePoint())); + dstAliasList.remove(trackingObj.getId()); + } } } } @@ -413,13 +509,14 @@ eStructure.addSrcSide(new Reference(thisObjectId, trackingObj.getId(), methodExecution.getThisClassName(), trackingObj.getActualType())); srcObject = thisObj; - isSrcSide = true; } else { eStructure.addDstSide(new Reference(thisObjectId, trackingObj.getId(), methodExecution.getThisClassName(), trackingObj.getActualType())); dstObject = thisObj; - isSrcSide = false; } + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY_CREATE, 0, trackingObj.getId(), methodExecution.getEntryPoint())); // �z��̓��\�b�h�̐擪�Ő������ꂽ���̂Ɖ��肷�� + aliasCollector.changeTrackingObject(trackingObj.getId(), thisObjectId, isSrcSide2); // �ǐՑΏۂ�z�񂩂�this�I�u�W�F�N�g�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, methodExecution.getEntryPoint())); // �z��̓��\�b�h�̐擪�Ő������ꂽ���̂Ɖ��肷�� } } } @@ -445,7 +542,7 @@ // } if (tracePoint.isValid()) { finalCount = 0; - return callerSearch(trace, tracePoint, objList, methodExecution, aliasCollector); // �Ăяo����������ɒT�� + return callerSearch(trace, tracePoint, objList, methodExecution, aliasCollector); // �Ăяo����������ɒT�����邽�ߍċA�Ăяo�� } } @@ -460,8 +557,8 @@ finalCount++; if (finalCount <= LOST_DECISION_EXTENSION) { // final�ϐ����Q�Ƃ��Ă���ꍇ�R���������ł��Ȃ��”\��������̂ŁA�ǐՂ������I�������P�\���Ԃ�݂��� - if (tracePoint.isValid()) { - MethodExecution c = callerSearch(trace, tracePoint, objList, methodExecution, aliasCollector); // �Ăяo����������ɒT�� + if (tracePoint.isValid()) { + MethodExecution c = callerSearch(trace, tracePoint, objList, methodExecution, aliasCollector); // �Ăяo����������ɒT�����邽�ߍċA�Ăяo�� if (((DeltaAugmentationInfo)c.getAugmentation()).isCoodinator()) { methodExecution = c; // �ǐՂ𑱂������ʃR�[�f�B�l�[�^�����‚����� } @@ -496,6 +593,9 @@ } existsInFields++; objList.remove(objectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.FIELD, 0, objectId, methodExecution.getEntryPoint())); + aliasCollector.changeTrackingObject(objectId, thisObjectId, isSrcSide2); // �ǐՑΏۂ� final �ϐ����Q�Ƃ���I�u�W�F�N�g���� this �ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, methodExecution.getEntryPoint())); } } } @@ -506,7 +606,7 @@ finalCount = 0; return methodExecution; } - + /** * �f���^���o�A���S���Y���̌Ăяo����T������(�ċA�Ăяo���ɂȂ��Ă���) * @param trace ��͑Ώۃg���[�X @@ -514,8 +614,9 @@ * @param objList �ǐՒ��̃I�u�W�F�N�g * @param isStatic�@�ÓI���\�b�h���ۂ� * @param index�@objList���̂ǂ̃I�u�W�F�N�g��ǐՂ��Ă��̃��\�b�h���s�ɓ����Ă����̂� - * @throws TraceFileException + * @param aliasCollector �G�C���A�X�����W���邽�߂̃r�W�^�[ */ + @Deprecated protected void calleeSearch(Trace trace, TracePoint tracePoint, ArrayList objList, Boolean isStatic, int index, IAliasTracker aliasCollector) { MethodExecution methodExecution = tracePoint.getMethodExecution(); Boolean isResolved = false; @@ -527,9 +628,14 @@ Trace.getDeclaringType(methodExecution.getSignature(), methodExecution.isConstructor()), Trace.getDeclaringType(methodExecution.getCallerSideSignature(), methodExecution.isConstructor())); - ((DeltaAugmentationInfo)methodExecution.getAugmentation()).setSetterSide(false); // ��{�I��getter�Ăяo���̂͂������A���� - ArrayList argments = methodExecution.getArguments(); + ((DeltaAugmentationInfo)methodExecution.getAugmentation()).setSetterSide(false); // ��{�I�ɎQ�Ɛ摤�̌Ăяo���̂͂������A���� + ArrayList arguments = methodExecution.getArguments(); ObjectReference trackingObj = null; + + HashMap srcAliasList = new HashMap<>(); + HashMap dstAliasList = new HashMap<>(); + + 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()); @@ -544,42 +650,55 @@ } Reference r; + // calleeSearch �̃��C�����[�v�D���݂̃��\�b�h�̃X�e�[�g�����g�̎��s�����s�Ƌt�����ɒT�������D // �߂�l�ɒT���Ώۂ��܂܂�Ă����calleeSearch�Ăяo�� do { if (!tracePoint.isValid()) break; Statement statement = tracePoint.getStatement(); - // ���ڎQ�Ƃ���уt�B�[���h�Q�Ƃ̒T�� if (statement instanceof FieldAccess) { + // ���s�����t�B�[���h�Q�Ƃ������ꍇ FieldAccess fs = (FieldAccess)statement; if (objectId != null && objectId.equals(fs.getValueObjId())) { String ownerObjectId = fs.getContainerObjId(); - if (ownerObjectId.equals(thisObjectId)) { - // �t�B�[���h�Q�Ƃ̏ꍇ + if (ownerObjectId.equals(thisObjectId)) { + // �����̃t�B�[���h�̎Q�Ƃ̏ꍇ + boolean isSrcSideChanged = false; if (objectId.equals(srcObject.getId())) { eStructure.addSrcSide(new Reference(thisObj, srcObject)); srcObject = thisObj; trackingObj = srcObject; + isSrcSideChanged = true; } else if(objectId.equals(dstObject.getId())) { eStructure.addDstSide(new Reference(thisObj, dstObject)); dstObject = thisObj; trackingObj = dstObject; + isSrcSideChanged = false; } + aliasCollector.addAlias(new Alias(Alias.AliasType.FIELD, 0, objectId, tracePoint.duplicate())); + aliasCollector.changeTrackingObject(objectId, ownerObjectId, isSrcSideChanged); + 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); } else { - // ���ڎQ�Ƃ̏ꍇ + // ���̃I�u�W�F�N�g�̃t�B�[���h�̎Q�Ƃ̏ꍇ + boolean isSrcSideChanged = false; if (objectId.equals(srcObject.getId())) { eStructure.addSrcSide(new Reference(ownerObjectId, objectId, fs.getContainerClassName(), srcObject.getActualType())); srcObject = new ObjectReference(ownerObjectId, fs.getContainerClassName()); trackingObj = srcObject; + isSrcSideChanged = true; } else if(objectId.equals(dstObject.getId())) { eStructure.addDstSide(new Reference(ownerObjectId, objectId, fs.getContainerClassName(), dstObject.getActualType())); dstObject = new ObjectReference(ownerObjectId, fs.getContainerClassName()); trackingObj = dstObject; + isSrcSideChanged = false; } + aliasCollector.addAlias(new Alias(Alias.AliasType.FIELD, 0, objectId, tracePoint.duplicate())); + aliasCollector.changeTrackingObject(objectId, ownerObjectId, isSrcSideChanged); + 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); @@ -599,6 +718,11 @@ // �t�B�[���h�Q�Ƃ̏ꍇ�i���ɗR���̉”\�����Ȃ��Ƃ킩�������_�ŁA���̔z��̗v�f�ɗR�����Ă�����̂Ɛ�������B�j fieldArrays.add(new ObjectReference(fs.getValueObjId(), refObjType)); fieldArrayElements.add(trackingObj); + if (objectId.equals(srcObject.getId())) { + srcAliasList.put(objectId, new DeltaAlias(Alias.AliasType.ARRAY_ELEMENT, 0, objectId, tracePoint.duplicate(), true)); + } else if(objectId.equals(dstObject.getId())) { + dstAliasList.put(objectId, new DeltaAlias(Alias.AliasType.ARRAY_ELEMENT, 0, objectId, tracePoint.duplicate(), false)); + } } else { // ���ڎQ�Ƃ̏ꍇ(�{���ɂ��̔z��̗v�f����擾���ꂽ���̂Ȃ炱���ŒǐՑΏۂ�u��������ׂ������A // ���̎��_�ő��̗R���̉”\����r���ł��Ȃ��B�����ŒǐՑΏۂ�u�������Ă��܂��ƁA��ŕʂɗR�������邱�Ƃ��킩�����ꍇ�� @@ -608,7 +732,7 @@ } } } else if (statement instanceof MethodInvocation) { - // �߂�l + // ���s�������\�b�h�Ăяo���������ꍇ MethodExecution childMethodExecution = ((MethodInvocation)statement).getCalledMethodExecution(); ObjectReference ret = childMethodExecution.getReturnValue(); if (ret != null && objectId != null && objectId.equals(ret.getId())) { @@ -616,7 +740,12 @@ ((DeltaAugmentationInfo)childMethodExecution.getAugmentation()).setTraceObjectId(Integer.parseInt(objectId)); TracePoint childTracePoint = tracePoint.duplicate(); childTracePoint.stepBackNoReturn(); - calleeSearch(trace, childTracePoint, objList, childMethodExecution.isStatic(), index, aliasCollector); // �Ăяo���������ɒT�� + if (!childMethodExecution.isConstructor()) { + aliasCollector.addAlias(new Alias(Alias.AliasType.METHOD_INVOCATION, 0, ret.getId(), tracePoint.duplicate())); + calleeSearch(trace, childTracePoint, objList, childMethodExecution.isStatic(), index, aliasCollector); // �Ăяo���������ɒT�����邽�ߍċA�Ăяo�� + } else { + aliasCollector.addAlias(new Alias(Alias.AliasType.CONSTRACTOR_INVOCATION, 0, ret.getId(), tracePoint.duplicate())); + } if (childMethodExecution.isConstructor()) { // �R���X�g���N�^�Ăяo���������ꍇ if (objectId.equals(srcObject.getId())) { @@ -625,12 +754,16 @@ eStructure.addSrcSide(r); srcObject = thisObj; trackingObj = srcObject; + aliasCollector.changeTrackingObject(objectId, thisObjectId, true); + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, tracePoint.duplicate())); } else if (objectId.equals(dstObject.getId())) { r = new Reference(thisObj, dstObject); r.setCreation(true); eStructure.addDstSide(r); dstObject = thisObj; trackingObj = dstObject; + aliasCollector.changeTrackingObject(objectId, thisObjectId, false); + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, tracePoint.duplicate())); } if (Trace.isNull(thisObjectId)) objectId = null; // static�ϐ��̏ꍇ else objectId = thisObjectId; @@ -653,6 +786,11 @@ 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())); + } + } } else { // �I�u�W�F�N�g�̗R�������ڌ��‚���Ȃ������ꍇ�ł��A�ǂ����̔z��̗v�f�ɗR�����Ă���”\�������� String retType = ret.getActualType(); @@ -670,14 +808,15 @@ } } while (tracePoint.stepBackOver()); - //�����T�� - if (argments.contains(new ObjectReference(objectId))) { + // �����T�� + 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())); } } - //�R���N�V�����^�Ή� + // �R���N�V�����^�Ή� Reference r; if (methodExecution.isCollectionType()) { if (objectId != null) { @@ -687,11 +826,15 @@ r.setCollection(true); eStructure.addSrcSide(r); srcObject = thisObj; + aliasCollector.changeTrackingObject(objectId, thisObjectId, true); + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, tracePoint.duplicate())); } else if(objectId.equals(dstObject.getId())) { r = new Reference(thisObj, dstObject); r.setCollection(true); eStructure.addDstSide(r); dstObject =thisObj; + aliasCollector.changeTrackingObject(objectId, thisObjectId, false); + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, tracePoint.duplicate())); } } objList.set(index, methodExecution.getThisObjId()); @@ -708,8 +851,8 @@ } if (trackingObj != null) { // �܂��z������̗v�f��R���Ƃ��ċ^��(�������D��) - for (int i = 0; i < argments.size(); i++) { - ObjectReference argArray = argments.get(i); + for (int i = 0; i < arguments.size(); i++) { + ObjectReference argArray = arguments.get(i); if (argArray.getActualType().startsWith("[L") && ((trackingObj.getActualType() != null && argArray.getActualType().endsWith(trackingObj.getActualType() + ";")) || (trackingObj.getCalleeType() != null && argArray.getActualType().endsWith(trackingObj.getCalleeType() + ";")) @@ -729,6 +872,10 @@ dstObject = new ObjectReference(argArray.getId(), argArray.getActualType()); } objectId = null; + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY_ELEMENT, 0, trackingObj.getId(), methodExecution.getEntryPoint())); // �z��v�f�̓��\�b�h�̐擪�Ŏ擾���ꂽ���̂Ɖ��肷�� + aliasCollector.changeTrackingObject(trackingObj.getId(), argArray.getId(), isSrcSide); // �ǐՑΏۂ�z��v�f����z��ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY, 0, argArray.getId(), methodExecution.getEntryPoint())); // �z��̓��\�b�h�̐擪�ŃA�N�Z�X���ꂽ���̂Ɖ��肷�� + aliasCollector.addAlias(new Alias(Alias.AliasType.FORMAL_PARAMETER, arguments.indexOf(argArray), trackingObj.getId(), methodExecution.getEntryPoint())); break; } } @@ -748,11 +895,23 @@ eStructure.addSrcSide(new Reference(thisObjectId, fieldArray.getId(), methodExecution.getThisClassName(), fieldArray.getActualType())); srcObject = thisObj; + aliasCollector.addAlias(srcAliasList.get(trackingObj.getId())); + aliasCollector.changeTrackingObject(trackingObj.getId(), fieldArray.getId(), isSrcSide); // �ǐՑΏۂ�z��v�f����z��t�B�[���h�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY, 0, fieldArray.getId(), srcAliasList.get(trackingObj.getId()).getOccurrencePoint())); + aliasCollector.changeTrackingObject(fieldArray.getId(), thisObjectId, isSrcSide); // �ǐՑΏۂ�z��t�B�[���h����this�I�u�W�F�N�g�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, srcAliasList.get(trackingObj.getId()).getOccurrencePoint())); + srcAliasList.remove(trackingObj.getId()); } else { eStructure.addDstSide(r); eStructure.addDstSide(new Reference(thisObjectId, fieldArray.getId(), methodExecution.getThisClassName(), fieldArray.getActualType())); dstObject = thisObj; + aliasCollector.addAlias(dstAliasList.get(trackingObj.getId())); + aliasCollector.changeTrackingObject(trackingObj.getId(), fieldArray.getId(), isSrcSide); // �ǐՑΏۂ�z��v�f����z��t�B�[���h�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY, 0, fieldArray.getId(), dstAliasList.get(trackingObj.getId()).getOccurrencePoint())); + aliasCollector.changeTrackingObject(fieldArray.getId(), thisObjectId, isSrcSide); // �ǐՑΏۂ�z��t�B�[���h����this�I�u�W�F�N�g�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, dstAliasList.get(trackingObj.getId()).getOccurrencePoint())); + dstAliasList.remove(trackingObj.getId()); } } } @@ -769,6 +928,9 @@ methodExecution.getThisClassName(), trackingObj.getActualType())); dstObject = thisObj; } + aliasCollector.addAlias(new Alias(Alias.AliasType.ARRAY_CREATE, 0, trackingObj.getId(), methodExecution.getEntryPoint())); // �z��̓��\�b�h�̐擪�Ő������ꂽ���̂Ɖ��肷�� + aliasCollector.changeTrackingObject(trackingObj.getId(), thisObjectId, isSrcSide); // �ǐՑΏۂ�z�񂩂�this�I�u�W�F�N�g�ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, methodExecution.getEntryPoint())); // �z��̓��\�b�h�̐擪�Ő������ꂽ���̂Ɖ��肷�� } } } @@ -925,9 +1087,7 @@ eStructure = new ExtractedStructure(); eStructure.setRelatedTracePoint(thisTracePoint.duplicate()); MethodExecution methodExecution = thisTracePoint.getMethodExecution(); - if (!thisTracePoint.isMethodEntry()) { - thisTracePoint.stepNext(); - } + thisTracePoint.stepNext(); ArrayList objList = new ArrayList(); String thisObjectId = methodExecution.getThisObjId(); objList.add(thisObjectId); diff --git a/src/org/ntlab/deltaExtractor/DeltaExtractorJSON.java b/src/org/ntlab/deltaExtractor/DeltaExtractorJSON.java index 242797f..1358ee3 100644 --- a/src/org/ntlab/deltaExtractor/DeltaExtractorJSON.java +++ b/src/org/ntlab/deltaExtractor/DeltaExtractorJSON.java @@ -112,6 +112,7 @@ removeList.add(enclosingObj); existsInFields++; removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� + aliasList.put(enclosingObj, new Alias(Alias.AliasType.FIELD, 0, enclosingObj, tracePoint.duplicate())); } } @@ -376,6 +377,9 @@ } existsInFields++; objList.remove(objectId); + aliasCollector.addAlias(new Alias(Alias.AliasType.FIELD, 0, objectId, methodExecution.getEntryPoint())); + aliasCollector.changeTrackingObject(objectId, thisObjectId, isSrcSide2); // �ǐՑΏۂ� final �ϐ����Q�Ƃ���I�u�W�F�N�g���� this �ɒu������ + aliasCollector.addAlias(new Alias(Alias.AliasType.THIS, 0, thisObjectId, methodExecution.getEntryPoint())); } } } diff --git a/src/org/ntlab/deltaExtractor/Test.java b/src/org/ntlab/deltaExtractor/Test.java index a88c719..c8fb35e 100644 --- a/src/org/ntlab/deltaExtractor/Test.java +++ b/src/org/ntlab/deltaExtractor/Test.java @@ -1,10 +1,15 @@ package org.ntlab.deltaExtractor; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import org.ntlab.trace.MethodExecution; +import org.ntlab.trace.ObjectReference; import org.ntlab.trace.Reference; import org.ntlab.trace.ThreadInstance; +import org.ntlab.trace.Trace; import org.ntlab.trace.TraceJSON; import org.ntlab.trace.TracePoint; @@ -20,25 +25,25 @@ */ public static void main(String[] args) { long time = System.nanoTime(); - TraceJSON trace = new TraceJSON("traces\\sampleCollection.trace"); - 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, "sampleCollection.D", "sampleCollection.C"), tp, new IAliasTracker() { - @Override - public void addAlias(Alias alias) { - System.out.println(alias.getAliasType().toString() + ":" + alias.getObjectId() +"," + alias.getIndex() + "," + alias.getMethodSignature() + "," + alias.getLineNo()); - } - @Override - public void changeTrackingObject(String from, String to, boolean isSrcSide) { - System.out.println("Change:" + from + "�@=>�@" + to); - } - @Override - public List getAliasList() { - return null; - } - }); +// TraceJSON trace = new TraceJSON("traces\\sampleCollection.trace"); +// 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, "sampleCollection.D", "sampleCollection.C"), tp, new IAliasTracker() { +// @Override +// public void addAlias(Alias alias) { +// System.out.println(alias.getAliasType().toString() + ":" + alias.getObjectId() +"," + alias.getIndex() + "," + alias.getMethodSignature() + "," + alias.getLineNo()); +// } +// @Override +// public void changeTrackingObject(String from, String to, boolean isSrcSide) { +// System.out.println("Change:" + from + "�@=>�@" + to); +// } +// @Override +// public List getAliasList() { +// return null; +// } +// }); // TraceJSON trace = new TraceJSON("traces\\_finalLocal.trace"); // DeltaExtractorJSON s = new DeltaExtractorJSON(trace); @@ -159,7 +164,7 @@ // --------------- Eclipse (2014/12/19-20 �v���O�����������؎��� �ۑ�2, �ȉ���2��ڂ̃f���^) --------------- -// DeltaExtractor s = new DeltaExtractor("documents\\eclipse-JavaEditor.trace"); +// DeltaExtractor s = new DeltaExtractor("documents\\eclipse-JavaEditor.txt"); // ExtractedStructure e = null; // do { // System.out.println(System.nanoTime() - time); @@ -174,7 +179,8 @@ // // --------------- ArgoUML (2014/12/19-20 �v���O�����������؎��� �ۑ�3, �ȉ���1��ڂ̃f���^) --------------- -// DeltaExtractor s = new DeltaExtractor("documents\\ArgoUML-3.trace"); +//// DeltaExtractor s = new DeltaExtractor("traces\\ArgoUML-3.txt"); +// DeltaExtractorJSON s = new DeltaExtractorJSON("traces\\ArgoUMLBenchmarkWithMoreStandardClasses.trace"); // MethodExecution m = null; // ExtractedStructure e = null; // do { @@ -182,7 +188,9 @@ // if (m == null) { // m = s.getLastMethodExecution("protected void org.tigris.gef.base.SelectionManager.addFig("); // } else { -// m = s.getLastMethodExecution("protected void org.tigris.gef.base.SelectionManager.addFig(", m.getEntryPoint()); +// TracePoint tp = m.getEntryPoint(); +// tp.stepBackOver(); +// m = s.getLastMethodExecution("protected void org.tigris.gef.base.SelectionManager.addFig(", tp); // } // if (m != null) { // ArrayList argments = m.getArguments(); @@ -198,15 +206,20 @@ // // --------------- ArgoUML (2014/12/19-20 �v���O�����������؎��� �ۑ�4, �ȉ���3��ڂ̃f���^) --------------- -// DeltaExtractor s = new DeltaExtractor("documents\\ArgoUML-3.trace"); +//// DeltaExtractor s = new DeltaExtractor("traces\\ArgoUML-3.txt"); +// DeltaExtractorJSON s = new DeltaExtractorJSON("traces\\ArgoUMLBenchmarkWithMoreStandardClasses.trace"); // MethodExecution m = null; // ExtractedStructure e = null; // do { // System.out.println(System.nanoTime() - time); // if (m == null) { -// m = s.getLastMethodExecution("public abstract interface boolean java.util.List.add("); +//// m = s.getLastMethodExecution("public abstract interface boolean java.util.List.add("); +// m = s.getLastMethodExecution("public boolean java.util.List.add("); // } else { -// m = s.getLastMethodExecution("public abstract interface boolean java.util.List.add(", m.getEntryPoint()); +// TracePoint tp = m.getEntryPoint(); +// tp.stepBackOver(); +//// m = s.getLastMethodExecution("public abstract interface boolean java.util.List.add(", tp); +// m = s.getLastMethodExecution("public boolean java.util.List.add(", tp); // } // if (m != null) { // ArrayList argments = m.getArguments(); @@ -228,7 +241,7 @@ // --------------- Eclipse SWT (2015/10/31 �A�[�L�e�N�`���������؎��� �ۑ�1) --------------- // ��1(1st�f���^), �ȉ��̃f���^ -// DeltaExtractor s = new DeltaExtractor("documents\\eclipse-Console2.trace"); +// DeltaExtractor s = new DeltaExtractor("documents\\eclipse-Console2.txt"); // MethodExecution m = null; // ExtractedStructure e = null; // System.out.println(System.nanoTime() - time); @@ -261,7 +274,7 @@ // // --------------- Eclipse JDT (2015/10/31 �A�[�L�e�N�`���������؎��� �ۑ�2) --------------- // // ��1,2(1st�f���^), �ȉ��̃f���^(���o�Ƃ��Ă�2��) -// DeltaExtractor s = new DeltaExtractor("documents\\eclipse-Debug1.trace"); +// DeltaExtractor s = new DeltaExtractor("documents\\eclipse-Debug1.txt"); // MethodExecution m = null; // // System.out.println(System.nanoTime() - time); @@ -305,7 +318,7 @@ // // --------------- ArgoUML + GEF (2014/12/19-20 �v���O�����������؎��� �ۑ�3, �ȉ��̃f���^) --------------- -// DeltaExtractor s = new DeltaExtractor("documents\\ArgoUML-3.trace"); +// DeltaExtractor s = new DeltaExtractor("documents\\ArgoUML-3.txt"); // MethodExecution m = null; // ExtractedStructure e = null; // System.out.println(System.nanoTime() - time); @@ -318,9 +331,137 @@ // e = s.extract(r, m.getEntryPoint()); // } - + + ///////////////////////////////////////////////////////// + // // + // MagnetRON�p // + // // + ///////////////////////////////////////////////////////// + + + // --------------- Eclipse JDT (2015/10/31 �A�[�L�e�N�`���������؎��� �ۑ�2) --------------- + // 1��ڂ̃f���^���o + // { + // "src": { + // "class": "public boolean org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint.handleBreakpointEvent(", + // "id": "666051245" + // }, + // "dst": { + // "class": "org.eclipse.jdi.internal.event.BreakpointEventImpl", + // "id": "907205473" + // }, + // "type": "This-Another", + // "order": "0" + // } + DeltaExtractor s = new DeltaExtractor("traces\\eclipse-Debug1.txt"); + MethodExecution m = null; + + System.out.println(System.nanoTime() - time); + ExtractedStructure e = null; + do { + if (m == null) { + m = s.getLastMethodExecution("public boolean org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint.handleBreakpointEvent("); + } else { + TracePoint nextTp = m.getEntryPoint(); + nextTp.stepBackOver(); + m = s.getLastMethodExecution("public boolean org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint.handleBreakpointEvent(", nextTp); + } + if (m != null) { + ArrayList argments = m.getArguments(); + for (int i = 0; i < argments.size(); i++) { + if (argments.get(i).getActualType().equals("org.eclipse.jdi.internal.event.BreakpointEventImpl")) { + System.out.println(System.nanoTime() - time); + e = s.extract(m.getEntryPoint(), argments.get(i)); + break; + } + } + } + } while (e == null); System.out.println(System.nanoTime() - time); System.out.println("//////////////////////////////////"); + + // 2��ڂ̃f���^���o + // { + // "src": { + // "class": "org.eclipse.jdi.internal.event.EventIteratorImpl", + // "id": "239180057" + // }, + // "dst": { + // "class": "java.util.ArrayList$ListItr", + // "id": "316502076" + // }, + // "type": "Container-Component", + // "order": "0" + // }, + Reference nextTarget = e.getDelta().getDstSide().get(1); // EventIteratorImpl -> ArrayList$ListItr + ExtractedStructure e2 = s.extract(nextTarget, m.getEntryPoint()); + System.out.println(System.nanoTime() - time); + System.out.println("//////////////////////////////////"); + + // 3��ڂ̃f���^���o + // { + // "src": { + // "class": "java.util.ArrayList", + // "id": "1121573201" + // }, + // "dst": { + // "class": "org.eclipse.jdi.internal.event.BreakpointEventImpl", + // "id": "907205473" + // }, + // "type": "Container-Component(Collection)", + // "order": "0" + // }, + Reference nextnextTarget = new Reference("1121573201", "907205473", null, null); // ArrayList -> BreakpointEventImpl + nextnextTarget.setCollection(true); + e2 = s.extract(nextnextTarget, m.getEntryPoint()); + System.out.println(System.nanoTime() - time); + System.out.println("//////////////////////////////////"); + + // 4��ڂ̃f���^���o + // { + // "src": { + // "class": "public void org.eclipse.jdt.internal.debug.core.EventDispatcher.run(", + // "id": "629542817" + // }, + // "dst": { + // "class": "org.eclipse.jdi.internal.event.EventSetImpl", + // "id": "1400795012" + // }, + // "type": "This-Another", + // "order": "0" + // }, + Reference nextnextnextTarget = e.getDelta().getDstSide().get(3); // EventDispatcher$1 -> EventSetImpl + e2 = s.extract(nextnextnextTarget, m.getEntryPoint()); + System.out.println(System.nanoTime() - time); + System.out.println("//////////////////////////////////"); + + // 5��ڂ̃f���^���o + // { + // "src": { + // "class": "public com.sun.jdi.event.EventSet org.eclipse.jdi.internal.event.EventQueueImpl.remove(", + // "id": null + // }, + // "dst": { + // "class": "org.eclipse.jdi.internal.jdwp.JdwpCommandPacket", + // "id": "859038530" + // }, + // "type": "This-Another", + // "order": "0" + // } + MethodExecution m2 = e2.getCoordinator().getChildren().get(21); + e2 = s.extract(m2.getExitPoint(), new ObjectReference("859038530", "org.eclipse.jdi.internal.jdwp.JdwpCommandPacket")); + System.out.println(System.nanoTime() - time); + System.out.println("//////////////////////////////////"); + + +// // 6��ڂ̃f���^���o(�ۑ�ɂ͊܂߂Ȃ�) +// m = e.getCoordinator().getChildren().get(0).getChildren().get(1).getChildren().get(4); +// Reference lastTarget = new Reference(e.getDelta().getDstSide().get(1).getSrcObject(), e.getDelta().getDstSide().get(0).getDstObject()); +// lastTarget.setCollection(true); +// e = s.extract(lastTarget, m.getExitPoint()); +// System.out.println(System.nanoTime() - time); +// System.out.println("//////////////////////////////////"); + // // s.extractArg(e.getCoodinator(), 123456789); // // s.getCallHistory(e.getCoodinator()); diff --git a/src/org/ntlab/deltaViewer/CollaborationLayout.java b/src/org/ntlab/deltaViewer/CollaborationLayout.java index 0cc39a0..6b428c8 100644 --- a/src/org/ntlab/deltaViewer/CollaborationLayout.java +++ b/src/org/ntlab/deltaViewer/CollaborationLayout.java @@ -77,8 +77,17 @@ for (Alias a: aliasCollector.getAliasList()) { int idx = -1; if (a.getAliasType() == AliasType.FIELD) { - FieldAccess f = (FieldAccess) a.getOccurrencePoint().getStatement(); - idx = references.indexOf(new Reference(f.getContainerObjId(), f.getValueObjId(), f.getContainerClassName(), f.getValueClassName())); + Reference ref = null; + if (a.getOccurrencePoint().getStatement() instanceof FieldAccess) { + FieldAccess f = (FieldAccess) a.getOccurrencePoint().getStatement(); + ref = new Reference(f.getContainerObjId(), f.getValueObjId(), f.getContainerClassName(), f.getValueClassName()); + } else if (a.getOccurrencePoint().getStatement() instanceof MethodInvocation) { + // A call to an enclosing instance. + MethodExecution m = a.getMethodExecution(); + MethodInvocation i = (MethodInvocation) a.getOccurrencePoint().getStatement() ; + ref = new Reference(m.getThisObjId(), a.getObjectId(), m.getThisClassName(), i.getCalledMethodExecution().getArguments().get(0).getActualType()); + } + idx = references.indexOf(ref); } else if (a.getAliasType() == AliasType.ARRAY_ELEMENT) { ArrayAccess aa = (ArrayAccess) a.getOccurrencePoint().getStatement(); idx = references.indexOf(new Reference(aa.getArrayObjectId(), aa.getValueObjectId(), aa.getArrayClassName(), aa.getValueClassName())); diff --git a/src/org/ntlab/deltaViewer/CollaborationViewer.java b/src/org/ntlab/deltaViewer/CollaborationViewer.java index 6cbb48d..2483043 100644 --- a/src/org/ntlab/deltaViewer/CollaborationViewer.java +++ b/src/org/ntlab/deltaViewer/CollaborationViewer.java @@ -141,8 +141,13 @@ if(statement instanceof FieldUpdate) { // Format fieldName. FieldUpdate fieldUpdateStatement = (FieldUpdate) statement; - String fieldNames[] = formatFieldName(fieldUpdateStatement.getFieldName()); - String fieldName = fieldNames[fieldNames.length-1]; + String fieldName; + if (fieldUpdateStatement.getFieldName() != null) { + String fieldNames[] = formatFieldName(fieldUpdateStatement.getFieldName()); + fieldName = fieldNames[fieldNames.length-1]; + } else { + fieldName = ""; + } String sourceObjectId = fieldUpdateStatement.getContainerObjId(); createObjectRefrence(fieldUpdateStatement, fieldName); @@ -501,9 +506,14 @@ } else { Statement statement = nextAlias.getOccurrencePoint().getStatement(); if(statement instanceof FieldAccess && curAliasObjId.equals(((FieldAccess)statement).getContainerObjId())) { - String fieldNames[] = formatFieldName(((FieldAccess)statement).getFieldName()); - srcClassName = fieldNames[0]; - fieldName = fieldNames[1]; + if (((FieldAccess)statement).getFieldName() != null) { + String fieldNames[] = formatFieldName(((FieldAccess)statement).getFieldName()); + srcClassName = fieldNames[0]; + fieldName = fieldNames[1]; + } else { + srcClassName = ((FieldAccess)statement).getContainerClassName(); + fieldName = ""; + } } } System.out.println("THIS " + srcClassName + "(" + curAliasObjId + ") -> " + "(" + nextAliasObjId + "), "+ fieldName); diff --git a/src/org/ntlab/deltaViewer/DeltaViewer.java b/src/org/ntlab/deltaViewer/DeltaViewer.java index 6bbc6de..49b1f40 100644 --- a/src/org/ntlab/deltaViewer/DeltaViewer.java +++ b/src/org/ntlab/deltaViewer/DeltaViewer.java @@ -130,8 +130,13 @@ if(statement instanceof FieldUpdate) { // Format fieldName. FieldUpdate fieldUpdateStatement = (FieldUpdate) statement; - String fieldNames[] = formatFieldName(fieldUpdateStatement.getFieldName()); - String fieldName = fieldNames[fieldNames.length-1]; + String fieldName; + if (fieldUpdateStatement.getFieldName() != null) { + String fieldNames[] = formatFieldName(fieldUpdateStatement.getFieldName()); + fieldName = fieldNames[fieldNames.length-1]; + } else { + fieldName = ""; + } String sourceObjectId = fieldUpdateStatement.getContainerObjId(); createObjectRefrence(fieldUpdateStatement, fieldName); @@ -552,9 +557,14 @@ } else { Statement statement = nextAlias.getOccurrencePoint().getStatement(); if(statement instanceof FieldAccess && curAlias.getObjectId().equals(((FieldAccess)statement).getContainerObjId())) { - String fieldNames[] = formatFieldName(((FieldAccess)statement).getFieldName()); - srcClassName = fieldNames[0]; - fieldName = fieldNames[1]; + if (((FieldAccess)statement).getFieldName() != null) { + String fieldNames[] = formatFieldName(((FieldAccess)statement).getFieldName()); + srcClassName = fieldNames[0]; + fieldName = fieldNames[1]; + } else { + srcClassName = ((FieldAccess)statement).getContainerClassName(); + fieldName = ""; + } } } System.out.println("THIS " + srcClassName + "(" + curAlias.getObjectId() + ") -> " + "(" + nextAlias.getObjectId() + "), "+ fieldName); diff --git a/src/org/ntlab/deltaViewer/MagnetRONFrame.java b/src/org/ntlab/deltaViewer/MagnetRONFrame.java index 0a98b7b..25b5126 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONFrame.java +++ b/src/org/ntlab/deltaViewer/MagnetRONFrame.java @@ -27,6 +27,7 @@ import org.ntlab.actions.StartAnimationAction; import org.ntlab.actions.StopAnimationAction; import org.ntlab.deltaExtractor.Alias; +import org.ntlab.deltaExtractor.DeltaExtractor; import org.ntlab.deltaExtractor.DeltaExtractorJSON; import org.ntlab.deltaExtractor.ExtractedStructure; import org.ntlab.deltaExtractor.IAliasCollector; @@ -42,6 +43,7 @@ import org.ntlab.trace.ObjectReference; import org.ntlab.trace.Reference; import org.ntlab.trace.ThreadInstance; +import org.ntlab.trace.Trace; import org.ntlab.trace.TraceJSON; import org.ntlab.trace.TracePoint; @@ -57,8 +59,8 @@ private static Dimension DEFAULT_SIZE = new Dimension(1300, 700); private static String WINDOW_TITLE = "MagnetRON Viewer "; - private TraceJSON trace = null; - private DeltaExtractorJSON s = null; + private Trace trace = null; + private DeltaExtractor s = null; private List features = new ArrayList<>(); private CollaborationViewer viewer = null; @@ -112,7 +114,7 @@ return viewer; } - public TraceJSON getTrace() { + public Trace getTrace() { return trace; } @@ -162,8 +164,13 @@ Map magnetJson = MagnetronParser.doParse(reader); reader.close(); if (magnetJson.get("trace") != null) { - trace = new TraceJSON(file.getParent() + "\\" + magnetJson.get("trace")); - s = new DeltaExtractorJSON(trace); + if (magnetJson.get("format") != null && magnetJson.get("format").equals("PlainText")) { + trace = new Trace(file.getParent() + "\\" + magnetJson.get("trace")); + s = new DeltaExtractor(trace); + } else { + trace = new TraceJSON(file.getParent() + "\\" + magnetJson.get("trace")); + s = new DeltaExtractorJSON((TraceJSON) trace); + } if (magnetJson.get("features") != null) { features = (List) magnetJson.get("features"); menuBar.updateExtractsMenu(features); @@ -228,12 +235,12 @@ index = Integer.parseInt(splitKeys[splitKeys.length-1]); if (trace == null && s == null) { trace = new TraceJSON(argsMap.get(key)[4]); - s = new DeltaExtractorJSON(trace); + s = new DeltaExtractorJSON((TraceJSON) trace); } } else { if (trace == null && s == null) { trace = new TraceJSON(argsMap.get(key)[4]); - s = new DeltaExtractorJSON(trace); + s = new DeltaExtractorJSON((TraceJSON) trace); } } Map.Entry extracted = extract(key, index); @@ -256,29 +263,37 @@ } private Entry extract(Extract extract) { + int index = extract.getOrder(); if (extract.getType().equals(Extract.CONTAINER_COMPONENT) || extract.getType().equals(Extract.CONTAINER_COMPONENT_COLLECTION)) { HashMap threads = trace.getAllThreads(); - List eList = new ArrayList<>(); - List dacList = new ArrayList<>(); if (threads.values().size() == 1) { ThreadInstance thread = threads.values().iterator().next(); // �Ō�̃X���b�h�����Ă��邾���c TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); Reference reference = new Reference(extract.getSrcId(), extract.getDstId(), extract.getSrcClass(), extract.getDstClass()); - IAliasTracker dac = new DeltaAliasCollector(); - ExtractedStructure e = s.extract(reference, tp, dac); - eList.add(e); - dacList.add(dac); + if (extract.getType().equals(Extract.CONTAINER_COMPONENT_COLLECTION)) { + reference.setCollection(true); + } + ExtractedStructure e = null; + for (int i = 0; ; i++) { + IAliasTracker dac = new DeltaAliasCollector(); + e = s.extract(reference, tp, dac); + if (e == null) break; + if (i == index) { + return new AbstractMap.SimpleEntry(e, dac); + } + tp = e.getRelatedTracePoint().duplicate(); + tp.stepBackOver(); + } + return null; } else { + int i = 0; for (ThreadInstance thread: threads.values()) { TracePoint tp = thread.getRoot().get(thread.getRoot().size() - 1).getExitPoint(); Reference reference = new Reference(extract.getSrcId(), extract.getDstId(), extract.getSrcClass(), extract.getDstClass()); if (extract.getType().equals(Extract.CONTAINER_COMPONENT_COLLECTION)) { reference.setCollection(true); } -// reference.setArray(true); -// reference.setFinalLocal(true); -// reference.setCreation(true); ExtractedStructure e = null; do { if (e == null) { @@ -286,8 +301,10 @@ e = s.extract(reference, tp, dac); System.out.println(e); if (e != null) { - eList.add(e); - dacList.add(dac); + if (i == index) { + return new AbstractMap.SimpleEntry(e, dac); + } + i++; } } else { tp = e.getRelatedTracePoint().duplicate(); @@ -296,23 +313,47 @@ 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()); + if (i == index) { + return new AbstractMap.SimpleEntry(e, dac); + } + i++; } } } while (e != null); System.out.println("---------------------------"); } } - return new AbstractMap.SimpleEntry(eList.get(extract.getOrder()), dacList.get(extract.getOrder())); + return null; } else { IAliasTracker dac = new DeltaAliasCollector(); - MethodExecution me = trace.getLastMethodExecution(extract.getSrcClass()); - Map refs = me.getObjectReferences(extract.getDstClass()); - ObjectReference ref = refs.keySet().iterator().next(); - ExtractedStructure e = s.extract(refs.get(ref), ref, dac); - return new AbstractMap.SimpleEntry(e, dac); + int i = 0; + List mes = trace.getMethodExecutions(extract.getSrcClass()); + while (mes.size() > 0) { + MethodExecution lastExec = null; + long lastExecTime = 0L; + for (MethodExecution me: mes) { + if (lastExec == null || me.getEntryTime() > lastExecTime) { + lastExec = me; + lastExecTime = me.getEntryTime(); + } + } + mes.remove(lastExec); + Map refs = lastExec.getObjectReferences(extract.getDstClass()); + if (refs.size() > 0) { + for (ObjectReference ref: refs.keySet()) { + if (extract.getDstId() == null || extract.getDstId().equals(ref.getId())) { + ExtractedStructure e = s.extract(refs.get(ref), ref, dac); + if (e != null) { + if (i == index) { + return new AbstractMap.SimpleEntry(e, dac); + } + i++; + } + } + } + } + } + return null; } } diff --git a/src/org/ntlab/deltaViewer/MagnetRONViewer.java b/src/org/ntlab/deltaViewer/MagnetRONViewer.java index 560da96..743b3e9 100644 --- a/src/org/ntlab/deltaViewer/MagnetRONViewer.java +++ b/src/org/ntlab/deltaViewer/MagnetRONViewer.java @@ -1563,10 +1563,15 @@ FieldUpdate rpFieldUpdateStatement = (FieldUpdate) rpStatement; rpSrcObjId = rpFieldUpdateStatement.getContainerObjId(); rpDstObjId = rpFieldUpdateStatement.getValueObjId(); - String rpFieldNames[] = formatFieldName(rpFieldUpdateStatement.getFieldName()); - rpSrcClassName = rpFieldNames[0]; + if (rpFieldUpdateStatement.getFieldName() != null) { + String rpFieldNames[] = formatFieldName(rpFieldUpdateStatement.getFieldName()); + rpSrcClassName = rpFieldNames[0]; + rpFieldName = rpFieldNames[rpFieldNames.length-1]; + } else { + rpSrcClassName = rpFieldUpdateStatement.getContainerClassName(); + rpFieldName = ""; + } rpDstClassName = rpFieldUpdateStatement.getValueClassName(); - rpFieldName = rpFieldNames[rpFieldNames.length-1]; } else if (rpStatement instanceof ArrayUpdate) { // container to component ArrayUpdate rpArrayUpdateStatement = (ArrayUpdate) rpStatement; diff --git a/src/org/ntlab/featureExtractor/MagnetronParser.java b/src/org/ntlab/featureExtractor/MagnetronParser.java index 350c40b..14e284e 100644 --- a/src/org/ntlab/featureExtractor/MagnetronParser.java +++ b/src/org/ntlab/featureExtractor/MagnetronParser.java @@ -27,8 +27,23 @@ line = line.substring(1); String keys[] = new String[1]; - line = parseKey(line, reader, keys); // Features in the trace file - if (line == null || !keys[0].equals("features")) new ExpectedFeatures(); + line = parseKey(line, reader, keys); + if (line == null) new ExpectedFeatures(); + if (keys[0].equals("format")) { + // Trace file format + Object[] values = new Object[1]; + line = parseValue(line, reader, values); + magnet.put("format", values[0]); // JSON or PlainText + if (line == null || !line.startsWith(",")) throw new ExpectedFeatures(); + line = line.substring(1); + line = parseKey(line, reader, keys); + if (line == null) new ExpectedFeatures(); + } else { + // JSON format is default. + magnet.put("format", "JSON"); + } + // Features in the trace file + if (!keys[0].equals("features")) new ExpectedFeatures(); List freatures = new ArrayList<>(); line = parseFeatures(line, reader, freatures); magnet.put("features", freatures); diff --git a/src/org/ntlab/trace/MethodExecution.java b/src/org/ntlab/trace/MethodExecution.java index d1797de..9553e15 100644 --- a/src/org/ntlab/trace/MethodExecution.java +++ b/src/org/ntlab/trace/MethodExecution.java @@ -204,7 +204,7 @@ } else if (s instanceof MethodInvocation) { MethodInvocation m = (MethodInvocation) s; ObjectReference ret = m.getCalledMethodExecution().getReturnValue(); - if (ret.getActualType().equals(actualTypeName)) { + if (ret != null && ret.getActualType().equals(actualTypeName)) { objectRefMap.put(ret, tp.duplicate()); } } diff --git a/src/org/ntlab/trace/Trace.java b/src/org/ntlab/trace/Trace.java index 5b86def..11c5439 100644 --- a/src/org/ntlab/trace/Trace.java +++ b/src/org/ntlab/trace/Trace.java @@ -71,101 +71,141 @@ methodData = line.split(":"); int n = methodData[0].indexOf(','); signature = methodData[0].substring(n + 1); - threadNo = methodData[methodData.length - 1].split(" ")[1]; - thisObjectId = methodData[1]; - thisClassName = methodData[0].substring(0, n).split(" ")[1]; - isConstractor = false; - isStatic = false; - if (signature.contains("static ")) { - isStatic = true; - } - callerSideSignature = signature; - timeStamp = Long.parseLong(methodData[methodData.length - 2]); - if (prevLine != null) { - if (prevLine.startsWith("New")) { - isConstractor = true; - } else if (prevLine.startsWith("Invoke")) { - callerSideSignature = prevLine.split(":")[1]; + threadNo = getThreadNo(line); +// threadNo = methodData[methodData.length - 1].split(" ")[1]; + if (threadNo != null) { + thisObjectId = methodData[1]; + thisClassName = methodData[0].substring(0, n).split(" ")[1]; + isConstractor = false; + isStatic = false; + if (signature.contains("static ")) { + isStatic = true; } + callerSideSignature = signature; + timeStamp = Long.parseLong(methodData[methodData.length - 2]); + if (prevLine != null) { + if (prevLine.startsWith("New")) { + isConstractor = true; + } else if (prevLine.startsWith("Invoke")) { + callerSideSignature = prevLine.split(":")[1]; + } + } + thread = threads.get(threadNo); + Stack stack; + if (thread == null) { + thread = new ThreadInstance(threadNo); + threads.put(threadNo, thread); + stack = new Stack(); + stacks.put(threadNo, stack); + } else { + stack = stacks.get(threadNo); + } + stack.push(line); + thread.callMethod(signature, callerSideSignature, thisClassName, thisObjectId, isConstractor, isStatic, timeStamp); } - thread = threads.get(threadNo); - Stack stack; - if (thread == null) { - thread = new ThreadInstance(threadNo); - threads.put(threadNo, thread); - stack = new Stack(); - stacks.put(threadNo, stack); - } else { - stack = stacks.get(threadNo); - } - stack.push(line); - thread.callMethod(signature, callerSideSignature, thisClassName, thisObjectId, isConstractor, isStatic, timeStamp); } else if (line.startsWith("Args")) { // ���\�b�h�Ăяo���̈��� argData = line.split(":"); - threadNo = argData[argData.length - 1].split(" ")[1]; - thread = threads.get(threadNo); - ArrayList arguments = new ArrayList(); - for (int k = 1; k < argData.length - 2; k += 2) { - arguments.add(new ObjectReference(argData[k+1], argData[k])); + threadNo = getThreadNo(line); +// threadNo = argData[argData.length - 1].split(" ")[1]; + if (threadNo != null) { + thread = threads.get(threadNo); + ArrayList arguments = new ArrayList(); + for (int k = 1; k < argData.length - 2; k += 2) { + arguments.add(new ObjectReference(argData[k+1], argData[k])); + } + thread.setArgments(arguments); } - thread.setArgments(arguments); } else if (line.startsWith("Return")) { // ���\�b�h����̕��A returnData = line.split(":"); - threadNo = returnData[returnData.length - 1].split(" ")[1]; - Stack stack = stacks.get(threadNo); - if (!stack.isEmpty()) { - String line2 = stack.peek(); - if (line2.split("\\(")[0].endsWith(line.split("\\(")[1])) { - stack.pop(); - } else { - do { + threadNo = getThreadNo(line); +// threadNo = returnData[returnData.length - 1].split(" ")[1]; + if (threadNo != null) { + Stack stack = stacks.get(threadNo); + if (!stack.isEmpty()) { + String line2 = stack.peek(); + if (line2.split("\\(")[0].endsWith(line.split("\\(")[1])) { stack.pop(); - thread.terminateMethod(); - line2 = stack.peek(); - } while (!stack.isEmpty() && !line2.split("\\(")[0].endsWith(line.split("\\(")[1])); - if (!stack.isEmpty()) stack.pop(); + } else { + do { + stack.pop(); + thread.terminateMethod(); + if (!stack.isEmpty()) line2 = stack.peek(); + } while (!stack.isEmpty() && !line2.split("\\(")[0].endsWith(line.split("\\(")[1])); + if (!stack.isEmpty()) stack.pop(); + } + thread = threads.get(threadNo); + ObjectReference returnValue = new ObjectReference(returnData[2], returnData[1]); + thisObjectId = returnData[2]; + isCollectionType = false; + String curLine = returnData[0]; + if(curLine.contains("Return call(List") + || curLine.contains("Return call(Vector") + || curLine.contains("Return call(Iterator") + || curLine.contains("Return call(ListIterator") + || curLine.contains("Return call(ArrayList") + || curLine.contains("Return call(Stack") + || curLine.contains("Return call(Hash") + || curLine.contains("Return call(Map") + || curLine.contains("Return call(Set") + || curLine.contains("Return call(Linked") + || curLine.contains("Return call(Collection") + || curLine.contains("Return call(Arrays") + || curLine.contains("Return call(Thread")) { + isCollectionType = true; + } + thread.returnMethod(returnValue, thisObjectId, isCollectionType); } - thread = threads.get(threadNo); - ObjectReference returnValue = new ObjectReference(returnData[2], returnData[1]); - thisObjectId = returnData[2]; - isCollectionType = false; - String curLine = returnData[0]; - if(curLine.contains("Return call(List") - || curLine.contains("Return call(Vector") - || curLine.contains("Return call(Iterator") - || curLine.contains("Return call(ListIterator") - || curLine.contains("Return call(ArrayList") - || curLine.contains("Return call(Stack") - || curLine.contains("Return call(Hash") - || curLine.contains("Return call(Map") - || curLine.contains("Return call(Set") - || curLine.contains("Return call(Linked") - || curLine.contains("Return call(Collection") - || curLine.contains("Return call(Arrays") - || curLine.contains("Return call(Thread")) { - isCollectionType = true; - } - thread.returnMethod(returnValue, thisObjectId, isCollectionType); } } else if (line.startsWith("get")) { // �t�B�[���h�A�N�Z�X accessData = line.split(":"); - threadNo = accessData[8].split(" ")[1]; - thread = threads.get(threadNo); - if (thread != null) thread.fieldAccess(accessData[5], accessData[6], accessData[3], accessData[4], accessData[1], accessData[2]); + if (accessData.length >= 9) { + threadNo = getThreadNo(line); +// threadNo = accessData[8].split(" ")[1]; + if (threadNo != null) { + thread = threads.get(threadNo); + timeStamp++; // ���̃^�C���X�^���v(���s����ێ����邽��) + if (thread != null) thread.fieldAccess(accessData[5], accessData[6], accessData[3], accessData[4], accessData[1], accessData[2], 0, timeStamp); + } + } } else if (line.startsWith("set")) { // �t�B�[���h�X�V updateData = line.split(":"); - threadNo = updateData[6].split(" ")[1]; - thread = threads.get(threadNo); - if (thread != null) thread.fieldUpdate(updateData[3], updateData[4], updateData[1], updateData[2]); + if (updateData.length >= 7) { + threadNo = getThreadNo(line); +// threadNo = updateData[6].split(" ")[1]; + if (threadNo != null) { + thread = threads.get(threadNo); + timeStamp++; // ���̃^�C���X�^���v(���s����ێ����邽��) + if (thread != null) thread.fieldUpdate(updateData[3], updateData[4], updateData[1], updateData[2], 0, timeStamp); + } + } } prevLine = line; } } + private String getThreadNo(String line) { + int tidx = line.indexOf("ThreadNo "); + if (tidx == -1) return null; + String threadNo = line.substring(tidx + 9); + try { + Integer.parseInt(threadNo); + } catch (NumberFormatException e) { + for (int i = 1; i <= threadNo.length(); i++) { + try { + Integer.parseInt(threadNo.substring(0, i)); + } catch (NumberFormatException e2) { + threadNo = threadNo.substring(0, i - 1); + break; + } + } + } + return threadNo; + } + /** * �I�����C����͗p�V���O���g���̎擾 * @return �I�����C����͗p�g���[�X @@ -800,6 +840,9 @@ traceLastThread2 = traceLastThread; traceLastTime = threadLastTime; traceLastThread = threadId; + } else if (traceLastTime2 < threadLastTime) { + traceLastTime2 = threadLastTime; + traceLastThread2 = threadId; } } } @@ -821,7 +864,11 @@ String traceLastThread = null; long traceLastTime2 = 0; String traceLastThread2 = null; - ThreadInstance thread = threads.get(before.getStatement().getThreadNo()); + Statement st = before.getStatement(); + if (st == null) { + st = before.getMethodExecution().getCallerTracePoint().getStatement(); + } + ThreadInstance thread = threads.get(st.getThreadNo()); ArrayList rootExecutions = (ArrayList)thread.getRoot().clone(); for (int n = rootExecutions.size() - 1; n >= 0; n--) { MethodExecution root = rootExecutions.get(n); @@ -1097,7 +1144,11 @@ String traceLastThread = null; long traceLastTime2 = 0; String traceLastThread2 = null; - ThreadInstance thread = threads.get(before.getStatement().getThreadNo()); + Statement st = before.getStatement(); + if (st == null) { + st = before.getMethodExecution().getCallerTracePoint().getStatement(); + } + ThreadInstance thread = threads.get(st.getThreadNo()); for (String threadId: threads.keySet()) { ThreadInstance t = threads.get(threadId); ArrayList rootExecutions = (ArrayList)t.getRoot().clone(); diff --git a/src/org/ntlab/trace/TraceJSON.java b/src/org/ntlab/trace/TraceJSON.java index 7ef09a5..a397549 100644 --- a/src/org/ntlab/trace/TraceJSON.java +++ b/src/org/ntlab/trace/TraceJSON.java @@ -200,7 +200,7 @@ do { stack.pop(); thread.terminateMethod(); - line2 = stack.peek(); + if (!stack.isEmpty()) line2 = stack.peek(); } while (!stack.isEmpty() && !line2.endsWith(shortSignature)); if (!stack.isEmpty()) stack.pop(); } @@ -733,7 +733,11 @@ String traceLastThread = null; long traceLastTime2 = 0; String traceLastThread2 = null; - ThreadInstance thread = threads.get(before.getStatement().getThreadNo()); + Statement st = before.getStatement(); + if (st == null) { + st = before.getMethodExecution().getCallerTracePoint().getStatement(); + } + ThreadInstance thread = threads.get(st.getThreadNo()); for (String threadId: threads.keySet()) { ThreadInstance t = threads.get(threadId); ArrayList rootExecutions = (ArrayList)t.getRoot().clone(); diff --git a/src/org/ntlab/trace/TracePoint.java b/src/org/ntlab/trace/TracePoint.java index 0b90e02..11b8f57 100644 --- a/src/org/ntlab/trace/TracePoint.java +++ b/src/org/ntlab/trace/TracePoint.java @@ -16,6 +16,7 @@ } public Statement getStatement() { + if (methodExecution.getStatements().size() <= order) return null; return methodExecution.getStatements().get(order); } diff --git a/traces/EclipseDebug.magnet b/traces/EclipseDebug.magnet new file mode 100644 index 0000000..dff8124 --- /dev/null +++ b/traces/EclipseDebug.magnet @@ -0,0 +1,173 @@ +{ + "trace": "eclipse-Debug1.txt", + "format": "PlainText", + "features": [ + { + "feature": "Eclipse (Debug All)", + "extracts": [ + { + "src": { + "class": "public boolean org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint.handleBreakpointEvent(", + "id": "666051245" + }, + "dst": { + "class": "org.eclipse.jdi.internal.event.BreakpointEventImpl", + "id": "907205473" + }, + "type": "This-Another", + "order": "0" + }, + { + "src": { + "class": "org.eclipse.jdi.internal.event.EventIteratorImpl", + "id": "239180057" + }, + "dst": { + "class": "java.util.ArrayList$ListItr", + "id": "316502076" + }, + "type": "Container-Component", + "order": "0" + }, + { + "src": { + "class": "java.util.ArrayList", + "id": "1121573201" + }, + "dst": { + "class": "org.eclipse.jdi.internal.event.BreakpointEventImpl", + "id": "907205473" + }, + "type": "Container-Component(Collection)", + "order": "0" + }, + { + "src": { + "class": "public void org.eclipse.jdt.internal.debug.core.EventDispatcher.run(", + "id": "629542817" + }, + "dst": { + "class": "org.eclipse.jdi.internal.event.EventSetImpl", + "id": "1400795012" + }, + "type": "This-Another", + "order": "0" + }, + { + "src": { + "class": "public com.sun.jdi.event.EventSet org.eclipse.jdi.internal.event.EventQueueImpl.remove(", + "id": null + }, + "dst": { + "class": "org.eclipse.jdi.internal.jdwp.JdwpCommandPacket", + "id": "859038530" + }, + "type": "This-Another", + "order": "0" + } + ] + }, + { + "feature": "Eclipse (Debug 1st)", + "extracts": [ + { + "src": { + "class": "public boolean org.eclipse.jdt.internal.debug.core.breakpoints.JavaBreakpoint.handleBreakpointEvent(", + "id": "666051245" + }, + "dst": { + "class": "org.eclipse.jdi.internal.event.BreakpointEventImpl", + "id": "907205473" + }, + "type": "This-Another", + "order": "0" + } + ] + }, + { + "feature": "Eclipse (Debug 2nd)", + "extracts": [ + { + "src": { + "class": "org.eclipse.jdi.internal.event.EventIteratorImpl", + "id": "239180057" + }, + "dst": { + "class": "java.util.ArrayList$ListItr", + "id": "316502076" + }, + "type": "Container-Component", + "order": "0" + } + ] + }, + { + "feature": "Eclipse (Debug 3rd)", + "extracts": [ + { + "src": { + "class": "java.util.ArrayList", + "id": "1121573201" + }, + "dst": { + "class": "org.eclipse.jdi.internal.event.BreakpointEventImpl", + "id": "907205473" + }, + "type": "Container-Component(Collection)", + "order": "0" + } + ] + }, + { + "feature": "Eclipse (Debug 4th)", + "extracts": [ + { + "src": { + "class": "public void org.eclipse.jdt.internal.debug.core.EventDispatcher.run(", + "id": "629542817" + }, + "dst": { + "class": "org.eclipse.jdi.internal.event.EventSetImpl", + "id": "1400795012" + }, + "type": "This-Another", + "order": "0" + } + ] + }, + { + "feature": "Eclipse (Debug 5th)", + "extracts": [ + { + "src": { + "class": "public com.sun.jdi.event.EventSet org.eclipse.jdi.internal.event.EventQueueImpl.remove(", + "id": null + }, + "dst": { + "class": "org.eclipse.jdi.internal.jdwp.JdwpCommandPacket", + "id": "859038530" + }, + "type": "This-Another", + "order": "0" + } + ] + }, + { + "feature": "Eclipse (Debug 6th, Not included in the task)", + "extracts": [ + { + "src": { + "class": "java.util.LinkedList", + "id": "682960638" + }, + "dst": { + "class": "org.eclipse.jdi.internal.jdwp.JdwpCommandPacket", + "id": "859038530" + }, + "type": "Container-Component(Collection)", + "order": "0" + } + ] + } + ] +} \ No newline at end of file diff --git a/traces/eclipse-Debug1.txt b/traces/eclipse-Debug1.txt new file mode 100644 index 0000000..70afab5 --- /dev/null +++ b/traces/eclipse-Debug1.txt Binary files differ