Skip to content

Commit 41450e9

Browse files
committed
8314250: CDS dump error message: Invoker type parameter must start and end with Object: L3I_L
Reviewed-by: iklam, matsaave
1 parent 0a6e64e commit 41450e9

15 files changed

+138
-48
lines changed

src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -28,6 +28,7 @@
2828
import jdk.internal.org.objectweb.asm.ClassWriter;
2929
import jdk.internal.org.objectweb.asm.Opcodes;
3030
import sun.invoke.util.Wrapper;
31+
import sun.util.logging.PlatformLogger;
3132

3233
import java.util.ArrayList;
3334
import java.util.HashSet;
@@ -136,9 +137,7 @@ Map<String, byte[]> build() {
136137
for (String invokerType : invokerTypes) {
137138
MethodType mt = asMethodType(invokerType);
138139
final int lastParam = mt.parameterCount() - 1;
139-
if (mt.parameterCount() < 2 ||
140-
mt.parameterType(0) != Object.class ||
141-
mt.parameterType(lastParam) != Object.class) {
140+
if (!checkInvokerTypeParams(mt)) {
142141
throw new RuntimeException(
143142
"Invoker type parameter must start and end with Object: " + invokerType);
144143
}
@@ -190,7 +189,7 @@ Map<String, byte[]> build() {
190189
return result;
191190
}
192191

193-
private static MethodType asMethodType(String basicSignatureString) {
192+
public static MethodType asMethodType(String basicSignatureString) {
194193
String[] parts = basicSignatureString.split("_");
195194
assert (parts.length == 2);
196195
assert (parts[1].length() == 1);
@@ -207,6 +206,13 @@ private static MethodType asMethodType(String basicSignatureString) {
207206
}
208207
}
209208

209+
public static boolean checkInvokerTypeParams(MethodType mt) {
210+
final int lastParam = mt.parameterCount() - 1;
211+
return (mt.parameterCount() >= 2 &&
212+
mt.parameterType(0) == Object.class &&
213+
mt.parameterType(lastParam) == Object.class);
214+
}
215+
210216
private void addDMHMethodType(String dmh, String methodType) {
211217
validateMethodType(methodType);
212218
Set<String> methodTypes = dmhMethods.get(dmh);
@@ -315,7 +321,14 @@ static Map<String, byte[]> generateHolderClasses(Stream<String> traces) {
315321
"linkToCallSite".equals(parts[2])) {
316322
builder.addCallSiteType(methodType);
317323
} else {
318-
builder.addInvokerType(methodType);
324+
MethodType mt = HolderClassBuilder.asMethodType(methodType);
325+
// Work around JDK-8327499
326+
if (HolderClassBuilder.checkInvokerTypeParams(mt)) {
327+
builder.addInvokerType(methodType);
328+
} else {
329+
PlatformLogger.getLogger("java.lang.invoke")
330+
.warning("Invalid LF_RESOLVE " + parts[1] + " " + parts[2] + " " + parts[3]);
331+
}
319332
}
320333
} else if (parts[1].contains("DirectMethodHandle")) {
321334
String dmh = parts[2];

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/CDSMHTest_generate.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,7 @@ do
3131
fname="$i$name_suffix"
3232
cat << EOF > $fname
3333
/*
34-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
34+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
3535
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3636
*
3737
* This code is free software; you can redistribute it and/or modify it
@@ -81,6 +81,7 @@ import org.junit.Test;
8181
import java.io.File;
8282
import java.nio.file.Path;
8383
import jdk.test.lib.Platform;
84+
import jdk.test.lib.process.OutputAnalyzer;
8485
8586
public class $i extends DynamicArchiveTestBase {
8687
@Test
@@ -98,6 +99,12 @@ public class $i extends DynamicArchiveTestBase {
9899
private static final String lambdaLoadedFromArchive =
99100
".class.load. test.java.lang.invoke.$i[$][$]Lambda.*/0x.*source:.*shared.*objects.*file.*(top)";
100101
102+
static void checkError(OutputAnalyzer output) throws Exception {
103+
if (testClassName.equals("MethodHandlesInvokersTest")) {
104+
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
105+
}
106+
}
107+
101108
static void testImpl() throws Exception {
102109
String topArchiveName = getNewArchiveName();
103110
String appJar = JarBuilder.build("MH", new File(classDir), null);
@@ -111,6 +118,7 @@ public class $i extends DynamicArchiveTestBase {
111118
String className = testPackageName + "." + testClassName;
112119
113120
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
121+
.assertNormalExit(output -> checkError(output))
114122
.assertNormalExit(output -> {
115123
output.shouldContain("Written dynamic archive 0x");
116124
});

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesAsCollectorTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,7 @@
2121
* questions.
2222
*
2323
*/
24-
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
24+
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.
2525

2626
/*
2727
* @test
@@ -49,6 +49,7 @@
4949
import java.io.File;
5050
import java.nio.file.Path;
5151
import jdk.test.lib.Platform;
52+
import jdk.test.lib.process.OutputAnalyzer;
5253

5354
public class MethodHandlesAsCollectorTest extends DynamicArchiveTestBase {
5455
@Test
@@ -66,6 +67,12 @@ public void test() throws Exception {
6667
private static final String lambdaLoadedFromArchive =
6768
".class.load. test.java.lang.invoke.MethodHandlesAsCollectorTest[$][$]Lambda.*/0x.*source:.*shared.*objects.*file.*(top)";
6869

70+
static void checkError(OutputAnalyzer output) throws Exception {
71+
if (testClassName.equals("MethodHandlesInvokersTest")) {
72+
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
73+
}
74+
}
75+
6976
static void testImpl() throws Exception {
7077
String topArchiveName = getNewArchiveName();
7178
String appJar = JarBuilder.build("MH", new File(classDir), null);
@@ -79,6 +86,7 @@ static void testImpl() throws Exception {
7986
String className = testPackageName + "." + testClassName;
8087

8188
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
89+
.assertNormalExit(output -> checkError(output))
8290
.assertNormalExit(output -> {
8391
output.shouldContain("Written dynamic archive 0x");
8492
});

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesCastFailureTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,7 @@
2121
* questions.
2222
*
2323
*/
24-
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
24+
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.
2525

2626
/*
2727
* @test
@@ -49,6 +49,7 @@
4949
import java.io.File;
5050
import java.nio.file.Path;
5151
import jdk.test.lib.Platform;
52+
import jdk.test.lib.process.OutputAnalyzer;
5253

5354
public class MethodHandlesCastFailureTest extends DynamicArchiveTestBase {
5455
@Test
@@ -66,6 +67,12 @@ public void test() throws Exception {
6667
private static final String lambdaLoadedFromArchive =
6768
".class.load. test.java.lang.invoke.MethodHandlesCastFailureTest[$][$]Lambda.*/0x.*source:.*shared.*objects.*file.*(top)";
6869

70+
static void checkError(OutputAnalyzer output) throws Exception {
71+
if (testClassName.equals("MethodHandlesInvokersTest")) {
72+
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
73+
}
74+
}
75+
6976
static void testImpl() throws Exception {
7077
String topArchiveName = getNewArchiveName();
7178
String appJar = JarBuilder.build("MH", new File(classDir), null);
@@ -79,6 +86,7 @@ static void testImpl() throws Exception {
7986
String className = testPackageName + "." + testClassName;
8087

8188
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
89+
.assertNormalExit(output -> checkError(output))
8290
.assertNormalExit(output -> {
8391
output.shouldContain("Written dynamic archive 0x");
8492
});

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesGeneralTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,7 @@
2121
* questions.
2222
*
2323
*/
24-
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
24+
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.
2525

2626
/*
2727
* @test
@@ -49,6 +49,7 @@
4949
import java.io.File;
5050
import java.nio.file.Path;
5151
import jdk.test.lib.Platform;
52+
import jdk.test.lib.process.OutputAnalyzer;
5253

5354
public class MethodHandlesGeneralTest extends DynamicArchiveTestBase {
5455
@Test
@@ -66,6 +67,12 @@ public void test() throws Exception {
6667
private static final String lambdaLoadedFromArchive =
6768
".class.load. test.java.lang.invoke.MethodHandlesGeneralTest[$][$]Lambda.*/0x.*source:.*shared.*objects.*file.*(top)";
6869

70+
static void checkError(OutputAnalyzer output) throws Exception {
71+
if (testClassName.equals("MethodHandlesInvokersTest")) {
72+
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
73+
}
74+
}
75+
6976
static void testImpl() throws Exception {
7077
String topArchiveName = getNewArchiveName();
7178
String appJar = JarBuilder.build("MH", new File(classDir), null);
@@ -79,6 +86,7 @@ static void testImpl() throws Exception {
7986
String className = testPackageName + "." + testClassName;
8087

8188
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
89+
.assertNormalExit(output -> checkError(output))
8290
.assertNormalExit(output -> {
8391
output.shouldContain("Written dynamic archive 0x");
8492
});

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesInvokersTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,7 @@
2121
* questions.
2222
*
2323
*/
24-
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
24+
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.
2525

2626
/*
2727
* @test
@@ -49,6 +49,7 @@
4949
import java.io.File;
5050
import java.nio.file.Path;
5151
import jdk.test.lib.Platform;
52+
import jdk.test.lib.process.OutputAnalyzer;
5253

5354
public class MethodHandlesInvokersTest extends DynamicArchiveTestBase {
5455
@Test
@@ -66,6 +67,12 @@ public void test() throws Exception {
6667
private static final String lambdaLoadedFromArchive =
6768
".class.load. test.java.lang.invoke.MethodHandlesInvokersTest[$][$]Lambda.*/0x.*source:.*shared.*objects.*file.*(top)";
6869

70+
static void checkError(OutputAnalyzer output) throws Exception {
71+
if (testClassName.equals("MethodHandlesInvokersTest")) {
72+
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
73+
}
74+
}
75+
6976
static void testImpl() throws Exception {
7077
String topArchiveName = getNewArchiveName();
7178
String appJar = JarBuilder.build("MH", new File(classDir), null);
@@ -79,6 +86,7 @@ static void testImpl() throws Exception {
7986
String className = testPackageName + "." + testClassName;
8087

8188
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
89+
.assertNormalExit(output -> checkError(output))
8290
.assertNormalExit(output -> {
8391
output.shouldContain("Written dynamic archive 0x");
8492
});

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesPermuteArgumentsTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,7 @@
2121
* questions.
2222
*
2323
*/
24-
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
24+
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.
2525

2626
/*
2727
* @test
@@ -49,6 +49,7 @@
4949
import java.io.File;
5050
import java.nio.file.Path;
5151
import jdk.test.lib.Platform;
52+
import jdk.test.lib.process.OutputAnalyzer;
5253

5354
public class MethodHandlesPermuteArgumentsTest extends DynamicArchiveTestBase {
5455
@Test
@@ -66,6 +67,12 @@ public void test() throws Exception {
6667
private static final String lambdaLoadedFromArchive =
6768
".class.load. test.java.lang.invoke.MethodHandlesPermuteArgumentsTest[$][$]Lambda.*/0x.*source:.*shared.*objects.*file.*(top)";
6869

70+
static void checkError(OutputAnalyzer output) throws Exception {
71+
if (testClassName.equals("MethodHandlesInvokersTest")) {
72+
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
73+
}
74+
}
75+
6976
static void testImpl() throws Exception {
7077
String topArchiveName = getNewArchiveName();
7178
String appJar = JarBuilder.build("MH", new File(classDir), null);
@@ -79,6 +86,7 @@ static void testImpl() throws Exception {
7986
String className = testPackageName + "." + testClassName;
8087

8188
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
89+
.assertNormalExit(output -> checkError(output))
8290
.assertNormalExit(output -> {
8391
output.shouldContain("Written dynamic archive 0x");
8492
});

test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/methodHandles/MethodHandlesSpreadArgumentsTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,7 @@
2121
* questions.
2222
*
2323
*/
24-
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
24+
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.
2525

2626
/*
2727
* @test
@@ -49,6 +49,7 @@
4949
import java.io.File;
5050
import java.nio.file.Path;
5151
import jdk.test.lib.Platform;
52+
import jdk.test.lib.process.OutputAnalyzer;
5253

5354
public class MethodHandlesSpreadArgumentsTest extends DynamicArchiveTestBase {
5455
@Test
@@ -66,6 +67,12 @@ public void test() throws Exception {
6667
private static final String lambdaLoadedFromArchive =
6768
".class.load. test.java.lang.invoke.MethodHandlesSpreadArgumentsTest[$][$]Lambda.*/0x.*source:.*shared.*objects.*file.*(top)";
6869

70+
static void checkError(OutputAnalyzer output) throws Exception {
71+
if (testClassName.equals("MethodHandlesInvokersTest")) {
72+
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
73+
}
74+
}
75+
6976
static void testImpl() throws Exception {
7077
String topArchiveName = getNewArchiveName();
7178
String appJar = JarBuilder.build("MH", new File(classDir), null);
@@ -79,6 +86,7 @@ static void testImpl() throws Exception {
7986
String className = testPackageName + "." + testClassName;
8087

8188
dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
89+
.assertNormalExit(output -> checkError(output))
8290
.assertNormalExit(output -> {
8391
output.shouldContain("Written dynamic archive 0x");
8492
});

0 commit comments

Comments
 (0)