8261030: Avoid loading GenerateJLIClassesHelper at runtime

Reviewed-by: mchung
This commit is contained in:
Claes Redestad 2021-02-04 10:47:03 +00:00
parent 992b50087d
commit 83357b1196
4 changed files with 42 additions and 37 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, 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
@ -46,7 +46,6 @@ import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import static java.lang.invoke.GenerateJLIClassesHelper.traceSpeciesType;
import static java.lang.invoke.LambdaForm.*;
import static java.lang.invoke.MethodHandleNatives.Constants.REF_getStatic;
import static java.lang.invoke.MethodHandleNatives.Constants.REF_putStatic;
@ -476,8 +475,10 @@ abstract class ClassSpecializer<T,K,S extends ClassSpecializer<T,K,S>.SpeciesDat
Class<?> salvage = null;
try {
salvage = BootLoader.loadClassOrNull(className);
traceSpeciesType(className, salvage);
} catch (Error ex) {
// ignore
} finally {
traceSpeciesType(className, salvage);
}
final Class<? extends T> speciesCode;
if (salvage != null) {
@ -488,7 +489,6 @@ abstract class ClassSpecializer<T,K,S extends ClassSpecializer<T,K,S>.SpeciesDat
// Not pregenerated, generate the class
try {
speciesCode = generateConcreteSpeciesCode(className, speciesData);
traceSpeciesType(className, salvage);
// This operation causes a lot of churn:
linkSpeciesDataToCode(speciesData, speciesCode);
// This operation commits the relation, but causes little churn:

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, 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
@ -25,7 +25,6 @@
package java.lang.invoke;
import jdk.internal.misc.CDS;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Opcodes;
import sun.invoke.util.Wrapper;
@ -39,10 +38,7 @@ import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Stream;
import static java.lang.invoke.LambdaForm.basicTypeSignature;
import static java.lang.invoke.LambdaForm.shortenSignature;
import static java.lang.invoke.LambdaForm.BasicType.*;
import static java.lang.invoke.MethodHandleStatics.TRACE_RESOLVE;
import static java.lang.invoke.MethodTypeForm.*;
import static java.lang.invoke.LambdaForm.Kind.*;
@ -51,29 +47,6 @@ import static java.lang.invoke.LambdaForm.Kind.*;
* generate classes ahead of time.
*/
class GenerateJLIClassesHelper {
private static final String LF_RESOLVE = "[LF_RESOLVE]";
private static final String SPECIES_RESOLVE = "[SPECIES_RESOLVE]";
static void traceLambdaForm(String name, MethodType type, Class<?> holder, MemberName resolvedMember) {
if (TRACE_RESOLVE) {
System.out.println(LF_RESOLVE + " " + holder.getName() + " " + name + " " +
shortenSignature(basicTypeSignature(type)) +
(resolvedMember != null ? " (success)" : " (fail)"));
}
if (CDS.isDumpingClassList()) {
CDS.traceLambdaFormInvoker(LF_RESOLVE, holder.getName(), name, shortenSignature(basicTypeSignature(type)));
}
}
static void traceSpeciesType(String cn, Class<?> salvage) {
if (TRACE_RESOLVE) {
System.out.println(SPECIES_RESOLVE + " " + cn + (salvage != null ? " (salvaged)" : " (generated)"));
}
if (CDS.isDumpingClassList()) {
CDS.traceSpeciesType(SPECIES_RESOLVE, cn);
}
}
// Map from DirectMethodHandle method type name to index to LambdForms
static final Map<String, Integer> DMH_METHOD_TYPE_MAP =
Map.of(
@ -323,7 +296,7 @@ class GenerateJLIClassesHelper {
traces.map(line -> line.split(" "))
.forEach(parts -> {
switch (parts[0]) {
case SPECIES_RESOLVE:
case "[SPECIES_RESOLVE]":
// Allow for new types of species data classes being resolved here
assert parts.length >= 2;
if (parts[1].startsWith(BMH_SPECIES_PREFIX)) {
@ -333,7 +306,7 @@ class GenerateJLIClassesHelper {
}
}
break;
case LF_RESOLVE:
case "[LF_RESOLVE]":
assert parts.length > 3;
String methodType = parts[3];
if (parts[1].equals(INVOKERS_HOLDER_CLASS_NAME)) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, 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
@ -46,7 +46,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.stream.Stream;
import static java.lang.invoke.GenerateJLIClassesHelper.traceLambdaForm;
import static java.lang.invoke.LambdaForm.BasicType;
import static java.lang.invoke.LambdaForm.BasicType.*;
import static java.lang.invoke.LambdaForm.*;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, 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
@ -25,11 +25,15 @@
package java.lang.invoke;
import jdk.internal.misc.CDS;
import jdk.internal.misc.Unsafe;
import sun.security.action.GetPropertyAction;
import java.util.Properties;
import static java.lang.invoke.LambdaForm.basicTypeSignature;
import static java.lang.invoke.LambdaForm.shortenSignature;
/**
* This class consists exclusively of static names internal to the
* method handle implementation.
@ -108,6 +112,35 @@ class MethodHandleStatics {
LOG_LF_COMPILATION_FAILURE);
}
/**
* If requested, logs the result of resolving the LambdaForm to stdout
* and informs the CDS subsystem about it.
*/
/*non-public*/
static void traceLambdaForm(String name, MethodType type, Class<?> holder, MemberName resolvedMember) {
if (TRACE_RESOLVE) {
System.out.println("[LF_RESOLVE] " + holder.getName() + " " + name + " " +
shortenSignature(basicTypeSignature(type)) +
(resolvedMember != null ? " (success)" : " (fail)"));
}
if (CDS.isDumpingClassList()) {
CDS.traceLambdaFormInvoker("[LF_RESOLVE]", holder.getName(), name, shortenSignature(basicTypeSignature(type)));
}
}
/**
* If requested, logs the result of resolving the species type to stdout
* and the CDS subsystem.
*/
/*non-public*/
static void traceSpeciesType(String cn, Class<?> salvage) {
if (TRACE_RESOLVE) {
System.out.println("[SPECIES_RESOLVE] " + cn + (salvage != null ? " (salvaged)" : " (generated)"));
}
if (CDS.isDumpingClassList()) {
CDS.traceSpeciesType("[SPECIES_RESOLVE]", cn);
}
}
// handy shared exception makers (they simplify the common case code)
/*non-public*/
static InternalError newInternalError(String message) {