Skip to content

Commit

Permalink
update fix
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinccheung committed Mar 6, 2024
1 parent 93ed6e6 commit 092171f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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 @@ -137,10 +138,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) &&
!CDS.isDumpingArchive()) {
if (!checkInvokerTypeParams(mt)) {
throw new RuntimeException(
"Invoker type parameter must start and end with Object: " + invokerType);
}
Expand Down Expand Up @@ -192,7 +190,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 @@ -209,6 +207,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 @@ -317,7 +322,15 @@ static Map<String, byte[]> generateHolderClasses(Stream<String> traces) {
"linkToCallSite".equals(parts[2])) {
builder.addCallSiteType(methodType);
} else {
builder.addInvokerType(methodType);
MethodType mt = HolderClassBuilder.asMethodType(methodType);
if (HolderClassBuilder.checkInvokerTypeParams(mt)) {
builder.addInvokerType(methodType);
} else {
if (CDS.isDumpingArchive()) {
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
Expand Up @@ -135,7 +135,7 @@ static void traceLambdaForm(String name, MethodType type, Class<?> holder, Membe
(resolvedMember != null ? " (success)" : " (fail)"));
}
if (CDS.isDumpingClassList()) {
CDS.traceLambdaFormInvoker("[LF_RESOLVE]", holder.getName(), name, shortenSignature(basicTypeSignature(type)));
CDS.traceLambdaFormInvoker("[LF_RESOLVE]", holder.getName(), name, shortenSignature(basicTypeSignature(type)), type);
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/java.base/share/classes/jdk/internal/misc/CDS.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.stream.Stream;

import jdk.internal.access.SharedSecrets;
import java.lang.invoke.MethodType;

public class CDS {
private static final boolean isDumpingClassList;
Expand Down Expand Up @@ -109,11 +110,21 @@ public static boolean isDumpingStaticArchive() {
*/
public static native long getRandomSeedForDumping();

/**
* Checks if the lambda form invoker is archivable. This is to avoid RuntimeException
* during CDS archive dumping.
*/
private static boolean isInvokerArchivable(MethodType mt, String holder) {
final int lastParam = mt.parameterCount() - 1;
return ((mt.parameterCount() >= 2 && mt.parameterType(0) == Object.class
&& mt.parameterType(lastParam) == Object.class) || isValidHolderName(holder));
}

/**
* log lambda form invoker holder, name and method type
*/
public static void traceLambdaFormInvoker(String prefix, String holder, String name, String type) {
if (isDumpingClassList) {
public static void traceLambdaFormInvoker(String prefix, String holder, String name, String type, MethodType mt) {
if (isDumpingClassList && isInvokerArchivable(mt, holder)) {
logLambdaFormInvoker(prefix + " " + holder + " " + name + " " + type);
}
}
Expand Down

0 comments on commit 092171f

Please sign in to comment.