Skip to content

Commit

Permalink
attempt to speed up OptionalIssues
Browse files Browse the repository at this point in the history
  • Loading branch information
mebigfatguy committed Nov 18, 2024
1 parent ed6c561 commit cd480a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, TimingInfo> infoMap = timingInfo.getAndSet(null);
if (infoMap != null && !infoMap.isEmpty()) {
Expand Down
30 changes: 21 additions & 9 deletions src/main/java/com/mebigfatguy/fbcontrib/detect/OptionalIssues.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ OPTIONAL_OR_ELSE_METHOD, new FQMethod("java/util/OptionalDouble", "orElse", "(D)
private JavaClass currentClass;
private Deque<ActiveStackOp> activeStackOps;
private Map<OpcodeStack.Item, SourceLineAnnotation> boxedItems = new HashMap<>();
private boolean methodIsConstrained;
private Boolean methodIsConstrained;

static {
INVOKE_OPS.set(Const.INVOKEINTERFACE);
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cd480a5

Please sign in to comment.