That is actually really easy to prove. Here is some very simple code:
for (int i = 0; i < 100_000; ++i) {
Stream.of(1, 2, 3, 4)
.map(x -> x * 2)
.collect(Collectors.toList());
}
When I compile this I can see that the generated de-sugared method (via javap
) for the lambda expression is called : lambda$main$0
(in jdk-9, but this does not matter much).
And then I can simply run this code with:
java -XX:-TieredCompilation
-XX:CICompilerCount=1
-XX:+UnlockDiagnosticVMOptions
-XX:+PrintCompilation
-XX:+PrintInlining
-XX:CompileCommand="print, *.lambda"
InlineLambdaTest
> inline.txt
And looking at the file there are lines like this:
Inline::lambda$main$0 (10 bytes) inline (hot)
So inlining for such a method works the usual way. Notice that the will be many more lines that start with ...lambda...
as there are many other places internally that use lambda expression that are considered hot too.