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..2a3b809 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)); + } + } } } @@ -161,34 +187,46 @@ removeList.add(thisObjectId); // ��ň�U�AthisObject ����菜�� } } - + + // 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 +250,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 +264,7 @@ } } } else if (statement instanceof MethodInvocation) { + // ���s�������\�b�h�Ăяo���������ꍇ MethodExecution prevChildMethodExecution = ((MethodInvocation)statement).getCalledMethodExecution(); if (!prevChildMethodExecution.equals(childMethodExecution)) { // �߂�l @@ -237,13 +281,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 +306,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 +358,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 +380,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 +428,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 +450,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 +473,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 +504,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 +537,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 +552,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�[�^�����‚����� } @@ -506,7 +598,7 @@ finalCount = 0; return methodExecution; } - + /** * �f���^���o�A���S���Y���̌Ăяo����T������(�ċA�Ăяo���ɂȂ��Ă���) * @param trace ��͑Ώۃg���[�X @@ -514,8 +606,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 +620,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 +642,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 +710,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 +724,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 +732,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 +746,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 +778,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 +800,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 +818,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 +843,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 +864,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 +887,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 +920,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�̐擪�Ő������ꂽ���̂Ɖ��肷�� } } } diff --git a/src/org/ntlab/deltaExtractor/Test.java b/src/org/ntlab/deltaExtractor/Test.java index a88c719..019e86a 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; @@ -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,6 +331,57 @@ // e = s.extract(r, m.getEntryPoint()); // } + + /////////////////////////////////////////////////////////////////////////////////// + // // + // MagnetRON�p // + // // + /////////////////////////////////////////////////////////////////////////////////// + + +// // --------------- Eclipse JDT (2015/10/31 �A�[�L�e�N�`���������؎��� �ۑ�2) --------------- +// // ��1,2(1st�f���^), �ȉ��̃f���^(���o�Ƃ��Ă�2��) +// 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); +// Reference nextTarget = e.getDelta().getDstSide().get(3); // EventDispatcher$1 -> EventSetImpl +// e = s.extract(nextTarget, m.getEntryPoint()); +// System.out.println(System.nanoTime() - time); +// System.out.println("//////////////////////////////////"); +// +// // ��3(2nd�f���^), �ȉ��̃f���^ +// MethodExecution m2 = e.getCoordinator().getChildren().get(21); +// e = s.extract(m2.getExitPoint(), new ObjectReference("859038530", "org.eclipse.jdi.internal.jdwp.JdwpCommandPacket")); +// System.out.println(System.nanoTime() - time); +// System.out.println("//////////////////////////////////"); +// +// +// // ��4(3rd�f���^), �ȉ��̃f���^ +// 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("//////////////////////////////////"); diff --git a/src/org/ntlab/deltaViewer/MagnetRONFrame.java b/src/org/ntlab/deltaViewer/MagnetRONFrame.java index 0a98b7b..e9cf877 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); 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/Trace.java b/src/org/ntlab/trace/Trace.java index 5b86def..f220323 100644 --- a/src/org/ntlab/trace/Trace.java +++ b/src/org/ntlab/trace/Trace.java @@ -71,101 +71,139 @@ 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); + if (thread != null) thread.fieldAccess(accessData[5], accessData[6], accessData[3], accessData[4], accessData[1], accessData[2]); + } + } } 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); + if (thread != null) thread.fieldUpdate(updateData[3], updateData[4], updateData[1], updateData[2]); + } + } } 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 +838,9 @@ traceLastThread2 = traceLastThread; traceLastTime = threadLastTime; traceLastThread = threadId; + } else if (traceLastTime2 < threadLastTime) { + traceLastTime2 = threadLastTime; + traceLastThread2 = threadId; } } } @@ -821,7 +862,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 +1142,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); }