From cd480a5f90e846ec155e0d130fae600ba86f8df8 Mon Sep 17 00:00:00 2001 From: Dave Brosius Date: Sun, 17 Nov 2024 22:38:43 -0500 Subject: [PATCH] attempt to speed up OptionalIssues --- .../fbcontrib/instrument/Timing.java | 2 +- .../fbcontrib/detect/OptionalIssues.java | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/aj/com/mebigfatguy/fbcontrib/instrument/Timing.java b/src/main/aj/com/mebigfatguy/fbcontrib/instrument/Timing.java index c47ee860..3a027180 100644 --- a/src/main/aj/com/mebigfatguy/fbcontrib/instrument/Timing.java +++ b/src/main/aj/com/mebigfatguy/fbcontrib/instrument/Timing.java @@ -23,7 +23,7 @@ public class Timing { Thread t = new Thread(() -> { try { while (!Thread.interrupted()) { - Thread.sleep(16000L); + Thread.sleep(15000L); if (System.currentTimeMillis() - updateTime.get() > 15000L) { Map infoMap = timingInfo.getAndSet(null); if (infoMap != null && !infoMap.isEmpty()) { diff --git a/src/main/java/com/mebigfatguy/fbcontrib/detect/OptionalIssues.java b/src/main/java/com/mebigfatguy/fbcontrib/detect/OptionalIssues.java index 64c642d3..69ccb7d4 100644 --- a/src/main/java/com/mebigfatguy/fbcontrib/detect/OptionalIssues.java +++ b/src/main/java/com/mebigfatguy/fbcontrib/detect/OptionalIssues.java @@ -112,7 +112,7 @@ OPTIONAL_OR_ELSE_METHOD, new FQMethod("java/util/OptionalDouble", "orElse", "(D) private JavaClass currentClass; private Deque activeStackOps; private Map boxedItems = new HashMap<>(); - private boolean methodIsConstrained; + private Boolean methodIsConstrained; static { INVOKE_OPS.set(Const.INVOKEINTERFACE); @@ -170,13 +170,8 @@ public void visitCode(Code obj) { stack.resetForMethodEntry(this); activeStackOps.clear(); boxedItems.clear(); - methodIsConstrained = false; + methodIsConstrained = null; - String returnType = new SignatureParser(getMethodSig()).getReturnTypeSignature(); - if (OPTIONAL_SIGNATURE.equals(returnType)) { - MethodInfo mi = Statistics.getStatistics().getMethodStatistics(getClassName(), getMethodName(), getMethodSig()); - methodIsConstrained = mi != null && mi.isDerived(); - } super.visitCode(obj); for (SourceLineAnnotation slAnno : boxedItems.values()) { @@ -310,8 +305,11 @@ public void sawOpcode(int seen) { break; case Const.ARETURN: - if (methodIsConstrained && stack.getStackDepth() > 0) { - boxedItems.remove(stack.getStackItem(0)); + if (stack.getStackDepth() > 0) { + OpcodeStack.Item itm = stack.getStackItem(0); + if (boxedItems.containsKey(itm) && isMethodConstrained()) { + boxedItems.remove(itm); + } } break; } @@ -404,6 +402,20 @@ private boolean hasInvoke(byte[] byteCode) { return false; } + + private boolean isMethodConstrained() { + if (methodIsConstrained == null) { + String returnType = new SignatureParser(getMethodSig()).getReturnTypeSignature(); + if (OPTIONAL_SIGNATURE.equals(returnType)) { + MethodInfo mi = Statistics.getStatistics().getMethodStatistics(getClassName(), getMethodName(), getMethodSig()); + methodIsConstrained = Boolean.valueOf(mi != null && mi.isDerived()); + } else { + methodIsConstrained = Boolean.FALSE; + } + } + + return methodIsConstrained.booleanValue(); + } /** * represents an opcode that was issued while there is still active elements on