Skip to content
Permalink
Browse files
8261030: Avoid loading GenerateJLIClassesHelper at runtime
Reviewed-by: mchung
  • Loading branch information
cl4es committed Feb 4, 2021
1 parent 992b500 commit 83357b11967c30df42ca802a560cc163e8945689
@@ -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.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 @@ S loadSpecies(S speciesData) {
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 @@ S loadSpecies(S speciesData) {
// 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:
@@ -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.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 @@
* 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 @@ private static void requireBasicType(char c) {
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 @@ private static void requireBasicType(char c) {
}
}
break;
case LF_RESOLVE:
case "[LF_RESOLVE]":
assert parts.length > 3;
String methodType = parts[3];
if (parts[1].equals(INVOKERS_HOLDER_CLASS_NAME)) {
@@ -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.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.*;
@@ -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 @@ static boolean debugEnabled() {
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) {

1 comment on commit 83357b1

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 83357b1 Feb 4, 2021

Please sign in to comment.