Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize graph building #111

Open
wants to merge 7 commits into
base: mixed-granularity
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ public interface StartsConstants {
String TARGET = "target";
String METHODS_TEST_DEPS_ZLC_FILE = "methods-deps.zlc";
String METHODS_CHECKSUMS_SERIALIZED_FILE = "methods-checksums.ser";
String METHODS_DEPENDENCIES_SERIALIZED_FILE = "methods-dependencies.ser";
String CLASSES_ZLC_FILE = "classes-checksums.zlc";
String CLASSES_CHECKSUM_SERIALIZED_FILE = "classes-checksums.ser";
String CLASSES_DEPENDENCIES_SERIALIZED_FILE = "classes-dependencies.ser";
String HIERARCHY_CHILDREN_SERIALIZED_FILE = "hierarchy-children.ser";
String HIERARCHY_PARENTS_SERIALIZED_FILE = "hierarchy-parents.ser";

// Used in smethods
String SMETHODS_ROOT_DIR_NAME = ".smethods";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,30 @@ public class ZLCHelperMethods implements StartsConstants {

/**
* This helper method is used in method-level analysis returns a list of sets
* containing information about changed methods, new methods, affected tests,
* old classes, and changed classes.
* containing information about changed methods, new methods, old classes, and
* changed classes.
* This method is called from MethodMojo.java from the setChangedMethods()
* method.
*
* @param artifactsDir The directory where the serialized file is saved.
* @param newMethodsChecksums A map containing the method names and their
* checksums.
* @param methodToTestClasses A map from method names to their test classes/
* @return A list of sets containing all the information described above.
*/

public static List<Set<String>> getChangedDataMethods(Map<String, String> newMethodsChecksums,
Map<String, Set<String>> methodToTestClasses, String artifactsDir, String filepath) {
public static List<Set<String>> getChangedDataMethods(Map<String, String> newMethodsChecksums, String artifactsDir,
String filepath) {
long start = System.currentTimeMillis();

Map<String, String> oldMethodChecksums = deserializeMapping(artifactsDir, filepath);

Set<String> changedMethods = new HashSet<>();
Set<String> affectedTests = new HashSet<>();
Set<String> oldClasses = new HashSet<>();
Set<String> changedClasses = new HashSet<>();
Set<String> newMethods = new HashSet<>(newMethodsChecksums.keySet());

for (String method : oldMethodChecksums.keySet()) {
String oldChecksum = oldMethodChecksums.get(method);
String newChecksum = newMethodsChecksums.get(method);
Set<String> deps = methodToTestClasses.getOrDefault(method, new HashSet<>());
String className = method.split("#")[0];

oldClasses.add(className);
Expand All @@ -77,7 +73,6 @@ public static List<Set<String>> getChangedDataMethods(Map<String, String> newMet
continue;
} else {
changedMethods.add(method);
affectedTests.addAll(deps);
changedClasses.add(className);
}
}
Expand All @@ -87,7 +82,7 @@ public static List<Set<String>> getChangedDataMethods(Map<String, String> newMet
for (String method : newMethods) {
changedClasses.add(method.split("#")[0]);
}
Collections.addAll(result, changedMethods, newMethods, affectedTests, oldClasses, changedClasses);
Collections.addAll(result, changedMethods, newMethods, oldClasses, changedClasses);
LOGGER.log(Level.FINEST, TIME_COMPUTING_NON_AFFECTED + (end - start) + MILLISECOND);
return result;
}
Expand Down Expand Up @@ -129,7 +124,8 @@ public static List<Set<String>> getChangedDataHybridClassLevel(Map<String, List<
* classes without changed headers.
* It also constructs a methods checksums map for next run.
*/
public static List<Set<String>> getChangedDataHybridMethodLevel(Set<String> addedClasses, Set<String> deletedClasses,
public static List<Set<String>> getChangedDataHybridMethodLevel(Set<String> addedClasses,
Set<String> deletedClasses,
Set<String> changedClassesWithChangedHeaders, Set<String> changedClassesWithoutChangedHeaders,
Map<String, String> methodChecksums,
ClassLoader loader,
Expand All @@ -147,11 +143,9 @@ public static List<Set<String>> getChangedDataHybridMethodLevel(Set<String> adde
Map<String, String> changedClassesWithoutChangedHeadersMethodsChecksums = MethodLevelStaticDepsBuilder
.getMethodsChecksumsForClasses(changedClassesWithoutChangedHeaders, loader);


List<Set<String>> changedAndNewMethodsForMethodAnalysis = findChangedAndNewMethods(oldMethodsChecksums,
changedClassesWithoutChangedHeadersMethodsChecksums);


// Constructing a methods checksums map for next run
Set<String> modifiedOldClasses = new HashSet<>();
modifiedOldClasses.addAll(deletedClasses);
Expand Down Expand Up @@ -313,7 +307,7 @@ public static <T> void serializeMapping(Map<String, T> map, String artifactsDir,
* found.
*/
@SuppressWarnings("unchecked")
private static <T> Map<String, T> deserializeMapping(String artifactsDir, String filename) {
public static <T> Map<String, T> deserializeMapping(String artifactsDir, String filename) {
Map<String, T> map = new HashMap<>();
try {
FileInputStream fis = new FileInputStream(artifactsDir + filename);
Expand Down
Loading