Cleaning up and refactoring.
authorrtrimana <rtrimana@uci.edu>
Wed, 1 Apr 2020 18:09:26 +0000 (11:09 -0700)
committerrtrimana <rtrimana@uci.edu>
Wed, 1 Apr 2020 18:09:26 +0000 (11:09 -0700)
src/main/gov/nasa/jpf/listener/StateReducer.java

index 78f1fed2237a3352556a1e6594525b8b86ed9c8e..ba5994d752e9917b306ade42615d8cebc6349eff 100644 (file)
@@ -562,7 +562,7 @@ public class StateReducer extends ListenerAdapter {
     // Record the field in the map
     if (executedInsn instanceof WriteInstruction) {
       // Exclude certain field writes because of infrastructure needs, e.g., Event class field writes
-      for (String str : EXCLUDED_FIELDS_WRITE_INSTRUCTIONS_STARTS_WITH_LIST) {
+      for (String str : EXCLUDED_FIELDS_READ_WRITE_INSTRUCTIONS_STARTS_WITH_LIST) {
         if (fieldClass.startsWith(str)) {
           return;
         }
@@ -688,27 +688,42 @@ public class StateReducer extends ListenerAdapter {
           "sendEvent", "Object", "reference", "location", "app", "state", "log", "functionList", "objectList",
           "eventList", "valueList", "settings", "printToConsole", "app1", "app2"};
   private final static String[] EXCLUDED_FIELDS_CONTAINS_LIST = {"_closure"};
-  private final static String[] EXCLUDED_FIELDS_WRITE_INSTRUCTIONS_STARTS_WITH_LIST = {"Event"};
+  private final static String[] EXCLUDED_FIELDS_READ_WRITE_INSTRUCTIONS_STARTS_WITH_LIST = {"Event"};
 
-  private boolean isFieldExcluded(String field) {
-    // Check against "starts-with" list
-    for(String str : EXCLUDED_FIELDS_STARTS_WITH_LIST) {
-      if (field.startsWith(str)) {
+  private boolean excludeThisForItStartsWith(String[] excludedStrings, String className) {
+    for (String excludedField : excludedStrings) {
+      if (className.startsWith(excludedField)) {
         return true;
       }
     }
-    // Check against "ends-with" list
-    for(String str : EXCLUDED_FIELDS_ENDS_WITH_LIST) {
-      if (field.endsWith(str)) {
+    return false;
+  }
+
+  private boolean excludeThisForItEndsWith(String[] excludedStrings, String className) {
+    for (String excludedField : excludedStrings) {
+      if (className.endsWith(excludedField)) {
         return true;
       }
     }
-    // Check against "contains" list
-    for(String str : EXCLUDED_FIELDS_CONTAINS_LIST) {
-      if (field.contains(str)) {
+    return false;
+  }
+
+  private boolean excludeThisForItContains(String[] excludedStrings, String className) {
+    for (String excludedField : excludedStrings) {
+      if (className.contains(excludedField)) {
         return true;
       }
     }
+    return false;
+  }
+
+  private boolean isFieldExcluded(String field) {
+    // Check against "starts-with", "ends-with", and "contains" list
+    if (excludeThisForItStartsWith(EXCLUDED_FIELDS_STARTS_WITH_LIST, field) ||
+        excludeThisForItEndsWith(EXCLUDED_FIELDS_ENDS_WITH_LIST, field) ||
+        excludeThisForItContains(EXCLUDED_FIELDS_CONTAINS_LIST, field)) {
+      return true;
+    }
 
     return false;
   }
@@ -769,7 +784,6 @@ public class StateReducer extends ListenerAdapter {
   private final static String DO_CALL_METHOD = "doCall";
   private final static String GET_PROPERTY_METHOD =
           "invokeinterface org.codehaus.groovy.runtime.callsite.CallSite.callGetProperty";
-  private final static String[] EXCLUDED_FIELDS_ITERATOR = {"java.util.LinkedHashMap"};
 
   private ReadWriteSet getReadWriteSet(int currentChoice) {
     // Do the analysis to get Read and Write accesses to fields
@@ -799,11 +813,11 @@ public class StateReducer extends ListenerAdapter {
       }
       // Get the iterated object whose property is accessed
       ElementInfo eiAccessObj = VM.getVM().getHeap().get(frameSlots[1]);
-      // TODO: MIGHT NEED TO EXCLUDE OTHER UNRELATED OBJECTS!
-      for (String excludedField : EXCLUDED_FIELDS_ITERATOR) {
-        if (eiAccessObj.getClassInfo().getName().startsWith(excludedField)) {
-          return;
-        }
+      // We exclude library classes (they start with java, org, etc.) and some more
+      String objClassName = eiAccessObj.getClassInfo().getName();
+      if (excludeThisForItStartsWith(EXCLUDED_FIELDS_STARTS_WITH_LIST, objClassName) ||
+          excludeThisForItStartsWith(EXCLUDED_FIELDS_READ_WRITE_INSTRUCTIONS_STARTS_WITH_LIST, objClassName)) {
+        return;
       }
       // Extract fields from this object and put them into the read write
       int numOfFields = eiAccessObj.getNumberOfFields();