Find code patterns that appear to assume identity of boxes. That is where two box values are
compared via
== or
!=. Boxing operations in such patterns are shielded from
optimizations such as PEA and canonicalization that do not respect box identity.
A common example is a utility that tries to find the values cached by the boxing methods. It does
this by probing the result of methods such as
Long.valueOf(long) to find the highest (or
lowest) value for which 2 successive calls return objects with different identities. For example:
long maxCachedLong = -1;
while (maxCachedLong < Long.MAX_VALUE && Long.valueOf(maxCachedLong + 1) == Long.valueOf(maxCachedLong + 1)) {
maxCachedLong += 1;
}
In the context of PEA, such code can run for a very long time since it is legal to reduce
Long.valueOf(maxCachedLong + 1) == Long.valueOf(maxCachedLong + 1) to
true.