On Wed, 11 Jan 2023 15:59:29 GMT, Maurizio Cimadamore <mcimadam...@openjdk.org> 
wrote:

> What I'm interested in though is what incremental improvement is brought by 
> the more complex analysis you have in this PR?

It's a good question. Here are some thoughts...

One meta-goal is that this analysis be conservative. In other words, if your 
code does NOT generate any warnings, then you should feel confident that there 
is a high probability that there are no leaks.

This is analogous to how you can be confident that you won't get any 
`ClassCastExceptions` at runtime if your code doesn't generate any `unchecked` 
warnings at compile time.

I think this point is generally agreed upon.

If so, then we would want any simpler analysis to err on the side of generating 
more false positives rather than more false negatives.

Assuming that, then the question comes down to a trade-off between code 
complexity vs. rate of false positives.

>From my casual looking over the JDK, the current algorithm generates very few 
>false positives - almost all of the warnings represent actual leaks (I'd be 
>interested in any false positives you do see).
 
(Of course, an irony is that most of these leaks have no real-world effect. For 
example package-private classes in the JDK (a) have already been debugged long 
ago, so any intra-package bugs due to 'this' escapes have already been fixed; 
and (b) are unlikely to be subclassed by anyone. And the ones that have a 
real-world effect (e.g., `HashSet(Collection)`) can't be fixed because of 
backward compatibility concerns. So this warning is most useful when writing 
new code.)

So the current code is clearly "complex enough" already. FWIW that's ~975 lines 
of code excluding blank lines and comments.

Now to answer your question about a theoretical simpler analysis:

> let's say that we don't care about tracking where `this` ends up going 
> exactly (e.g. if it's aliased by another variable) - and perhaps also let's 
> say we don't care about inspecting the method to which `this` is leaked too 
> closely - e.g. we treat any early escape of this as a possible issue.

I'm not sure I completely understand the semantics. But are you saying that if 
a constructor invokes a private or static method, then this simpler analysis 
would always declare a leak?

If that's the case then I think there are a lot of new false positives, because 
this is common in constructors.

I would then worry that if we dilute the warnings with a bunch of new false 
positives people are just going to get discouraged and turn the warning off 
completely.

-------------

PR: https://git.openjdk.org/jdk/pull/11874

Reply via email to