In JDK-8247536 (JDK 16), we added support for pre-generated java.lang.invoke classes in CDS static archive, so that we can avoid dynamic generation of classes at runtime.
However, we still see classes being generated in this test case:
[1] Download CDSLambdaInvokerTest.sh and CDSLambdaInvokerTest.java from attachments
[2] Run the following:
$ ${JAVA_HOME}/bin/java -version
java version "17" 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)
$ bash CDSLambdaInvokerTest.sh ${JAVA_HOME}
...
============ checking dumping status ==================================================
[0.171s][warning][cds] Preload Warning: Cannot find java/lang/invoke/BoundMethodHandle$Species_J
[0.171s][warning][cds] Preload Warning: Cannot find java/lang/invoke/BoundMethodHandle$Species_JL
[0.171s][warning][cds] Preload Warning: Cannot find java/lang/invoke/BoundMethodHandle$Species_F
[0.171s][warning][cds] Preload Warning: Cannot find java/lang/invoke/BoundMethodHandle$Species_FL
***** FAILED
============ checking if lambda form classes/methods are loaded from CDS ==============
[0.057s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800c00400 source: __JVM_LookupDefineClass__
[0.061s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800c01000 source: __JVM_LookupDefineClass__
[SPECIES_RESOLVE] java.lang.invoke.BoundMethodHandle$Species_J (generated)
[0.065s][info][class,load] java.lang.invoke.BoundMethodHandle$Species_J source: _ClassSpecializer_generateConcreteSpeciesCode
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeStatic L3J_L (fail)
[0.067s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800c01800 source: __JVM_LookupDefineClass__
[SPECIES_RESOLVE] java.lang.invoke.BoundMethodHandle$Species_JL (generated)
[0.070s][info][class,load] java.lang.invoke.BoundMethodHandle$Species_JL source: _ClassSpecializer_generateConcreteSpeciesCode
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeStatic L3JL_L (fail)
[0.071s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800c02000 source: __JVM_LookupDefineClass__
[0.073s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800c02400 source: __JVM_LookupDefineClass__
[0.075s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800c02800 source: __JVM_LookupDefineClass__
[SPECIES_RESOLVE] java.lang.invoke.BoundMethodHandle$Species_F (generated)
[0.077s][info][class,load] java.lang.invoke.BoundMethodHandle$Species_F source: _ClassSpecializer_generateConcreteSpeciesCode
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeStatic L3F_L (fail)
[0.079s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800c03000 source: __JVM_LookupDefineClass__
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeStatic LF_L (fail)
[SPECIES_RESOLVE] java.lang.invoke.BoundMethodHandle$Species_FL (generated)
[0.081s][info][class,load] java.lang.invoke.BoundMethodHandle$Species_FL source: _ClassSpecializer_generateConcreteSpeciesCode
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeStatic L3FL_L (fail)
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeSpecial LLF_L (fail)
[0.084s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800c04000 source: __JVM_LookupDefineClass__
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeStatic LFDIILJD_V (fail)
[LF_RESOLVE] java.lang.invoke.DirectMethodHandle$Holder invokeSpecial LLFDIILJD_V (fail)
[LF_RESOLVE] java.lang.invoke.Invokers$Holder invokeExact_MT LFDIILJDL_V (fail)
[0.086s][info][class,load] java.lang.invoke.LambdaForm$MH/0x0000000800c04c00 source: __JVM_LookupDefineClass__
***** FAILED