diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java index 22cb796870b..7d0c5192039 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java @@ -142,6 +142,9 @@ public class LambdaToMethod extends TreeTranslator { /** dump statistics about lambda code generation */ private final boolean dumpLambdaToMethodStats; + /** dump statistics about lambda deserialization code generation */ + private final boolean dumpLambdaDeserializationStats; + /** force serializable representation, for stress testing **/ private final boolean forceSerializable; @@ -187,6 +190,7 @@ public class LambdaToMethod extends TreeTranslator { transTypes = TransTypes.instance(context); Options options = Options.instance(context); dumpLambdaToMethodStats = options.isSet("debug.dumpLambdaToMethodStats"); + dumpLambdaDeserializationStats = options.isSet("debug.dumpLambdaDeserializationStats"); attr = Attr.instance(context); forceSerializable = options.isSet("forceSerializable"); boolean lineDebugInfo = @@ -714,8 +718,9 @@ public class LambdaToMethod extends TreeTranslator { String implMethodName = refSym.getQualifiedName().toString(); String implMethodSignature = typeSig(types.erasure(refSym.type)); + int implMethodKind = refSym.referenceKind(); JCExpression kindTest = eqTest(syms.intType, deserGetter("getImplMethodKind", syms.intType), - make.Literal(refSym.referenceKind())); + make.Literal(implMethodKind)); ListBuffer serArgs = new ListBuffer<>(); int i = 0; for (Type t : indyType.getParameterTypes()) { @@ -743,16 +748,16 @@ public class LambdaToMethod extends TreeTranslator { stmts = new ListBuffer<>(); kInfo.deserializeCases.put(implMethodName, stmts); } - /* ** - System.err.printf("+++++++++++++++++\n"); - System.err.printf("*functionalInterfaceClass: '%s'\n", functionalInterfaceClass); - System.err.printf("*functionalInterfaceMethodName: '%s'\n", functionalInterfaceMethodName); - System.err.printf("*functionalInterfaceMethodSignature: '%s'\n", functionalInterfaceMethodSignature); - System.err.printf("*implMethodKind: %d\n", implMethodKind); - System.err.printf("*implClass: '%s'\n", implClass); - System.err.printf("*implMethodName: '%s'\n", implMethodName); - System.err.printf("*implMethodSignature: '%s'\n", implMethodSignature); - ****/ + if (dumpLambdaDeserializationStats) { + log.note(pos, Notes.LambdaDeserializationStat( + functionalInterfaceClass, + functionalInterfaceMethodName, + functionalInterfaceMethodSignature, + implMethodKind, + implClass, + implMethodName, + implMethodSignature)); + } stmts.append(stmt); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index 95a7546e2b3..2ba9122c04a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -1701,6 +1701,17 @@ compiler.note.mref.stat.1=\ alternate metafactory = {0}\n\ bridge method = {1} +# 0: string, 1: string, 2: string, 3: number, 4: string, 5: string, 6: string +compiler.note.lambda.deserialization.stat=\ + Generating lambda deserialization\n\ + functionalInterfaceClass: {0}\n\ + functionalInterfaceMethodName: {1}\n\ + functionalInterfaceMethodSignature:{2}\n\ + implMethodKind: {3}\n\ + implClass: {4}\n\ + implMethodName: {5}\n\ + implMethodSignature: {6} + compiler.note.note=\ Note:\u0020 diff --git a/test/langtools/tools/javac/diags/examples/LambdaDeserializationStat.java b/test/langtools/tools/javac/diags/examples/LambdaDeserializationStat.java new file mode 100644 index 00000000000..4ab23ed0b3d --- /dev/null +++ b/test/langtools/tools/javac/diags/examples/LambdaDeserializationStat.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2026, Google LLC and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.note.lambda.deserialization.stat +// options: --debug=dumpLambdaDeserializationStats + +import java.io.Serializable; + +class LambdaDeserializationStat { + Runnable r = (Runnable & Serializable) () -> {}; +} diff --git a/test/langtools/tools/javac/lambda/SerializableObjectMethods.java b/test/langtools/tools/javac/lambda/SerializableObjectMethods.java index 52d4cfc7bf6..b489a22c7b4 100644 --- a/test/langtools/tools/javac/lambda/SerializableObjectMethods.java +++ b/test/langtools/tools/javac/lambda/SerializableObjectMethods.java @@ -25,7 +25,7 @@ * @test * @bug 8282080 * @summary Check that serializable lambdas referring to j.l.Object methods work. - * @compile SerializableObjectMethods.java + * @compile/ref=SerializableObjectMethods.out -XDrawDiagnostics --debug=dumpLambdaDeserializationStats SerializableObjectMethods.java * @run main SerializableObjectMethods */ import java.io.ByteArrayInputStream; diff --git a/test/langtools/tools/javac/lambda/SerializableObjectMethods.out b/test/langtools/tools/javac/lambda/SerializableObjectMethods.out new file mode 100644 index 00000000000..d03cc145794 --- /dev/null +++ b/test/langtools/tools/javac/lambda/SerializableObjectMethods.out @@ -0,0 +1,4 @@ +SerializableObjectMethods.java:59:35: compiler.note.lambda.deserialization.stat: SerializableObjectMethods$F, apply, (Ljava/lang/Object;)Ljava/lang/Object;, 5, java/lang/Object, hashCode, ()I +SerializableObjectMethods.java:60:35: compiler.note.lambda.deserialization.stat: SerializableObjectMethods$F, apply, (Ljava/lang/Object;)Ljava/lang/Object;, 9, SerializableObjectMethods$I2, hashCode, ()I +- compiler.note.unchecked.filename: SerializableObjectMethods.java +- compiler.note.unchecked.recompile