Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2024, Oracle 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
Expand Down Expand Up @@ -28,6 +28,7 @@
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Opcodes;
import sun.invoke.util.Wrapper;
import sun.util.logging.PlatformLogger;

import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -136,9 +137,7 @@ Map<String, byte[]> build() {
for (String invokerType : invokerTypes) {
MethodType mt = asMethodType(invokerType);
final int lastParam = mt.parameterCount() - 1;
if (mt.parameterCount() < 2 ||
mt.parameterType(0) != Object.class ||
mt.parameterType(lastParam) != Object.class) {
if (!checkInvokerTypeParams(mt)) {
throw new RuntimeException(
"Invoker type parameter must start and end with Object: " + invokerType);
}
Expand Down Expand Up @@ -190,7 +189,7 @@ Map<String, byte[]> build() {
return result;
}

private static MethodType asMethodType(String basicSignatureString) {
public static MethodType asMethodType(String basicSignatureString) {
String[] parts = basicSignatureString.split("_");
assert (parts.length == 2);
assert (parts[1].length() == 1);
Expand All @@ -207,6 +206,13 @@ private static MethodType asMethodType(String basicSignatureString) {
}
}

public static boolean checkInvokerTypeParams(MethodType mt) {
final int lastParam = mt.parameterCount() - 1;
return (mt.parameterCount() >= 2 &&
mt.parameterType(0) == Object.class &&
mt.parameterType(lastParam) == Object.class);
}

private void addDMHMethodType(String dmh, String methodType) {
validateMethodType(methodType);
Set<String> methodTypes = dmhMethods.get(dmh);
Expand Down Expand Up @@ -315,7 +321,14 @@ static Map<String, byte[]> generateHolderClasses(Stream<String> traces) {
"linkToCallSite".equals(parts[2])) {
builder.addCallSiteType(methodType);
} else {
builder.addInvokerType(methodType);
MethodType mt = HolderClassBuilder.asMethodType(methodType);
// Work around JDK-8327499
if (HolderClassBuilder.checkInvokerTypeParams(mt)) {
builder.addInvokerType(methodType);
} else {
PlatformLogger.getLogger("java.lang.invoke")
.warning("Invalid LF_RESOLVE " + parts[1] + " " + parts[2] + " " + parts[3]);
}
}
} else if (parts[1].contains("DirectMethodHandle")) {
String dmh = parts[2];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2020, 2024, Oracle 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
Expand Down Expand Up @@ -31,7 +31,7 @@ do
fname="$i$name_suffix"
cat << EOF > $fname
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle 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
Expand Down Expand Up @@ -81,6 +81,7 @@ import org.junit.Test;
import java.io.File;
import java.nio.file.Path;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;

public class $i extends DynamicArchiveTestBase {
@Test
Expand All @@ -98,6 +99,12 @@ public class $i extends DynamicArchiveTestBase {
private static final String lambdaLoadedFromArchive =
".class.load. test.java.lang.invoke.$i[$][$]Lambda.*/0x.*source:.*shared.*objects.*file.*(top)";

static void checkError(OutputAnalyzer output) throws Exception {
if (testClassName.equals("MethodHandlesInvokersTest")) {
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
}
}

static void testImpl() throws Exception {
String topArchiveName = getNewArchiveName();
String appJar = JarBuilder.build("MH", new File(classDir), null);
Expand All @@ -111,6 +118,7 @@ public class $i extends DynamicArchiveTestBase {
String className = testPackageName + "." + testClassName;

dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
.assertNormalExit(output -> checkError(output))
.assertNormalExit(output -> {
output.shouldContain("Written dynamic archive 0x");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle 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
Expand All @@ -21,7 +21,7 @@
* questions.
*
*/
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.

/*
* @test
Expand Down Expand Up @@ -49,6 +49,7 @@
import java.io.File;
import java.nio.file.Path;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;

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

static void checkError(OutputAnalyzer output) throws Exception {
if (testClassName.equals("MethodHandlesInvokersTest")) {
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
}
}

static void testImpl() throws Exception {
String topArchiveName = getNewArchiveName();
String appJar = JarBuilder.build("MH", new File(classDir), null);
Expand All @@ -79,6 +86,7 @@ static void testImpl() throws Exception {
String className = testPackageName + "." + testClassName;

dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
.assertNormalExit(output -> checkError(output))
.assertNormalExit(output -> {
output.shouldContain("Written dynamic archive 0x");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle 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
Expand All @@ -21,7 +21,7 @@
* questions.
*
*/
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.

/*
* @test
Expand Down Expand Up @@ -49,6 +49,7 @@
import java.io.File;
import java.nio.file.Path;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;

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

static void checkError(OutputAnalyzer output) throws Exception {
if (testClassName.equals("MethodHandlesInvokersTest")) {
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
}
}

static void testImpl() throws Exception {
String topArchiveName = getNewArchiveName();
String appJar = JarBuilder.build("MH", new File(classDir), null);
Expand All @@ -79,6 +86,7 @@ static void testImpl() throws Exception {
String className = testPackageName + "." + testClassName;

dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
.assertNormalExit(output -> checkError(output))
.assertNormalExit(output -> {
output.shouldContain("Written dynamic archive 0x");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle 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
Expand All @@ -21,7 +21,7 @@
* questions.
*
*/
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.

/*
* @test
Expand Down Expand Up @@ -49,6 +49,7 @@
import java.io.File;
import java.nio.file.Path;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;

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

static void checkError(OutputAnalyzer output) throws Exception {
if (testClassName.equals("MethodHandlesInvokersTest")) {
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
}
}

static void testImpl() throws Exception {
String topArchiveName = getNewArchiveName();
String appJar = JarBuilder.build("MH", new File(classDir), null);
Expand All @@ -79,6 +86,7 @@ static void testImpl() throws Exception {
String className = testPackageName + "." + testClassName;

dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
.assertNormalExit(output -> checkError(output))
.assertNormalExit(output -> {
output.shouldContain("Written dynamic archive 0x");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle 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
Expand All @@ -21,7 +21,7 @@
* questions.
*
*/
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.

/*
* @test
Expand Down Expand Up @@ -49,6 +49,7 @@
import java.io.File;
import java.nio.file.Path;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;

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

static void checkError(OutputAnalyzer output) throws Exception {
if (testClassName.equals("MethodHandlesInvokersTest")) {
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
}
}

static void testImpl() throws Exception {
String topArchiveName = getNewArchiveName();
String appJar = JarBuilder.build("MH", new File(classDir), null);
Expand All @@ -79,6 +86,7 @@ static void testImpl() throws Exception {
String className = testPackageName + "." + testClassName;

dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
.assertNormalExit(output -> checkError(output))
.assertNormalExit(output -> {
output.shouldContain("Written dynamic archive 0x");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle 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
Expand All @@ -21,7 +21,7 @@
* questions.
*
*/
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.

/*
* @test
Expand Down Expand Up @@ -49,6 +49,7 @@
import java.io.File;
import java.nio.file.Path;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;

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

static void checkError(OutputAnalyzer output) throws Exception {
if (testClassName.equals("MethodHandlesInvokersTest")) {
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
}
}

static void testImpl() throws Exception {
String topArchiveName = getNewArchiveName();
String appJar = JarBuilder.build("MH", new File(classDir), null);
Expand All @@ -79,6 +86,7 @@ static void testImpl() throws Exception {
String className = testPackageName + "." + testClassName;

dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
.assertNormalExit(output -> checkError(output))
.assertNormalExit(output -> {
output.shouldContain("Written dynamic archive 0x");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2024, Oracle 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
Expand All @@ -21,7 +21,7 @@
* questions.
*
*/
// this file is auto-generated by ./CDSMHTest_generate.sh. Do not edit manually.
// this file is auto-generated by CDSMHTest_generate.sh. Do not edit manually.

/*
* @test
Expand Down Expand Up @@ -49,6 +49,7 @@
import java.io.File;
import java.nio.file.Path;
import jdk.test.lib.Platform;
import jdk.test.lib.process.OutputAnalyzer;

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

static void checkError(OutputAnalyzer output) throws Exception {
if (testClassName.equals("MethodHandlesInvokersTest")) {
output.shouldNotContain("Failed to generate LambdaForm holder classes. Was the base archive generated with an outdated classlist?");
}
}

static void testImpl() throws Exception {
String topArchiveName = getNewArchiveName();
String appJar = JarBuilder.build("MH", new File(classDir), null);
Expand All @@ -79,6 +86,7 @@ static void testImpl() throws Exception {
String className = testPackageName + "." + testClassName;

dump(topArchiveName, loggingOpts, "-cp", jars, verifyOpt, mainClass, className)
.assertNormalExit(output -> checkError(output))
.assertNormalExit(output -> {
output.shouldContain("Written dynamic archive 0x");
});
Expand Down
Loading