From 62977739f5b519d5ed27a365e0b878b40739c851 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Wed, 1 Apr 2020 11:09:26 -0700 Subject: [PATCH] Cleaning up and refactoring. --- .../gov/nasa/jpf/listener/StateReducer.java | 50 ++++++++++++------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/main/gov/nasa/jpf/listener/StateReducer.java b/src/main/gov/nasa/jpf/listener/StateReducer.java index 78f1fed..ba5994d 100644 --- a/src/main/gov/nasa/jpf/listener/StateReducer.java +++ b/src/main/gov/nasa/jpf/listener/StateReducer.java @@ -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(); -- 2.34.1