Seem to be a JIT bug to me, the fields of Set12 are declared final not @Stable (even if the field storing the instanceof of Set&2 itself is marked @Stable) so there is no reason not not let the constant folding happen.
Rémi ----- Mail original ----- > De: "Claes Redestad" <claes.redes...@oracle.com> > À: "core-libs-dev" <core-libs-dev@openjdk.java.net> > Envoyé: Vendredi 10 Janvier 2020 18:01:40 > Objet: RFR: 8236850: Operations on constant List/Set.of(element) instances > does not consistently constant fold > Hi, > > this patch ensures operations on constant (static final) single-element > lists and sets created via List.of(foo) and Set.of(bar) to constant fold > properly. > > Bug: https://bugs.openjdk.java.net/browse/JDK-8236850 > Webrev: http://cr.openjdk.java.net/~redestad/8236850/open.00 > > On micros that are set up to test constant folding, e.g. > sumSizesFinalList, we see improvements around 10-15%. > > I also cleaned up and consolidated the heap archiving interaction a > notch. It was needed in an earlier prototype version of the patch, but > no longer.. since it's a cleanup I kept the changes. > > Testing: tier1-3 > > Thanks! > > /Claes