Skip to content

Commit

Permalink
8261030: Avoid loading GenerateJLIClassesHelper at runtime
Browse files Browse the repository at this point in the history
Reviewed-by: mchung
  • Loading branch information
cl4es committed Feb 4, 2021
1 parent 992b500 commit 83357b1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 37 deletions.
@@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -46,7 +46,6 @@
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function; import java.util.function.Function;


import static java.lang.invoke.GenerateJLIClassesHelper.traceSpeciesType;
import static java.lang.invoke.LambdaForm.*; import static java.lang.invoke.LambdaForm.*;
import static java.lang.invoke.MethodHandleNatives.Constants.REF_getStatic; import static java.lang.invoke.MethodHandleNatives.Constants.REF_getStatic;
import static java.lang.invoke.MethodHandleNatives.Constants.REF_putStatic; import static java.lang.invoke.MethodHandleNatives.Constants.REF_putStatic;
Expand Down Expand Up @@ -476,8 +475,10 @@ S loadSpecies(S speciesData) {
Class<?> salvage = null; Class<?> salvage = null;
try { try {
salvage = BootLoader.loadClassOrNull(className); salvage = BootLoader.loadClassOrNull(className);
traceSpeciesType(className, salvage);
} catch (Error ex) { } catch (Error ex) {
// ignore
} finally {
traceSpeciesType(className, salvage);
} }
final Class<? extends T> speciesCode; final Class<? extends T> speciesCode;
if (salvage != null) { if (salvage != null) {
Expand All @@ -488,7 +489,6 @@ S loadSpecies(S speciesData) {
// Not pregenerated, generate the class // Not pregenerated, generate the class
try { try {
speciesCode = generateConcreteSpeciesCode(className, speciesData); speciesCode = generateConcreteSpeciesCode(className, speciesData);
traceSpeciesType(className, salvage);
// This operation causes a lot of churn: // This operation causes a lot of churn:
linkSpeciesDataToCode(speciesData, speciesCode); linkSpeciesDataToCode(speciesData, speciesCode);
// This operation commits the relation, but causes little churn: // This operation commits the relation, but causes little churn:
Expand Down
@@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,7 +25,6 @@


package java.lang.invoke; package java.lang.invoke;


import jdk.internal.misc.CDS;
import jdk.internal.org.objectweb.asm.ClassWriter; import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Opcodes; import jdk.internal.org.objectweb.asm.Opcodes;
import sun.invoke.util.Wrapper; import sun.invoke.util.Wrapper;
Expand All @@ -39,10 +38,7 @@
import java.util.TreeSet; import java.util.TreeSet;
import java.util.stream.Stream; 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.LambdaForm.BasicType.*;
import static java.lang.invoke.MethodHandleStatics.TRACE_RESOLVE;
import static java.lang.invoke.MethodTypeForm.*; import static java.lang.invoke.MethodTypeForm.*;
import static java.lang.invoke.LambdaForm.Kind.*; import static java.lang.invoke.LambdaForm.Kind.*;


Expand All @@ -51,29 +47,6 @@
* generate classes ahead of time. * generate classes ahead of time.
*/ */
class GenerateJLIClassesHelper { 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 // Map from DirectMethodHandle method type name to index to LambdForms
static final Map<String, Integer> DMH_METHOD_TYPE_MAP = static final Map<String, Integer> DMH_METHOD_TYPE_MAP =
Map.of( Map.of(
Expand Down Expand Up @@ -323,7 +296,7 @@ static Map<String, byte[]> generateHolderClasses(Stream<String> traces) {
traces.map(line -> line.split(" ")) traces.map(line -> line.split(" "))
.forEach(parts -> { .forEach(parts -> {
switch (parts[0]) { switch (parts[0]) {
case SPECIES_RESOLVE: case "[SPECIES_RESOLVE]":
// Allow for new types of species data classes being resolved here // Allow for new types of species data classes being resolved here
assert parts.length >= 2; assert parts.length >= 2;
if (parts[1].startsWith(BMH_SPECIES_PREFIX)) { if (parts[1].startsWith(BMH_SPECIES_PREFIX)) {
Expand All @@ -333,7 +306,7 @@ static Map<String, byte[]> generateHolderClasses(Stream<String> traces) {
} }
} }
break; break;
case LF_RESOLVE: case "[LF_RESOLVE]":
assert parts.length > 3; assert parts.length > 3;
String methodType = parts[3]; String methodType = parts[3];
if (parts[1].equals(INVOKERS_HOLDER_CLASS_NAME)) { if (parts[1].equals(INVOKERS_HOLDER_CLASS_NAME)) {
Expand Down
@@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -46,7 +46,6 @@
import java.util.List; import java.util.List;
import java.util.stream.Stream; 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.BasicType.*; import static java.lang.invoke.LambdaForm.BasicType.*;
import static java.lang.invoke.LambdaForm.*; import static java.lang.invoke.LambdaForm.*;
Expand Down
@@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,11 +25,15 @@


package java.lang.invoke; package java.lang.invoke;


import jdk.internal.misc.CDS;
import jdk.internal.misc.Unsafe; import jdk.internal.misc.Unsafe;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;


import java.util.Properties; 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 * This class consists exclusively of static names internal to the
* method handle implementation. * method handle implementation.
Expand Down Expand Up @@ -108,6 +112,35 @@ static boolean debugEnabled() {
LOG_LF_COMPILATION_FAILURE); 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) // handy shared exception makers (they simplify the common case code)
/*non-public*/ /*non-public*/
static InternalError newInternalError(String message) { static InternalError newInternalError(String message) {
Expand Down

1 comment on commit 83357b1

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.