Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 83357b1

Browse files
committedFeb 4, 2021
8261030: Avoid loading GenerateJLIClassesHelper at runtime
Reviewed-by: mchung
1 parent 992b500 commit 83357b1

File tree

4 files changed

+42
-37
lines changed

4 files changed

+42
-37
lines changed
 

‎src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,7 +46,6 @@
4646
import java.util.concurrent.ConcurrentHashMap;
4747
import java.util.function.Function;
4848

49-
import static java.lang.invoke.GenerateJLIClassesHelper.traceSpeciesType;
5049
import static java.lang.invoke.LambdaForm.*;
5150
import static java.lang.invoke.MethodHandleNatives.Constants.REF_getStatic;
5251
import static java.lang.invoke.MethodHandleNatives.Constants.REF_putStatic;
@@ -476,8 +475,10 @@ S loadSpecies(S speciesData) {
476475
Class<?> salvage = null;
477476
try {
478477
salvage = BootLoader.loadClassOrNull(className);
479-
traceSpeciesType(className, salvage);
480478
} catch (Error ex) {
479+
// ignore
480+
} finally {
481+
traceSpeciesType(className, salvage);
481482
}
482483
final Class<? extends T> speciesCode;
483484
if (salvage != null) {
@@ -488,7 +489,6 @@ S loadSpecies(S speciesData) {
488489
// Not pregenerated, generate the class
489490
try {
490491
speciesCode = generateConcreteSpeciesCode(className, speciesData);
491-
traceSpeciesType(className, salvage);
492492
// This operation causes a lot of churn:
493493
linkSpeciesDataToCode(speciesData, speciesCode);
494494
// This operation commits the relation, but causes little churn:

‎src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java

+3-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,6 @@
2525

2626
package java.lang.invoke;
2727

28-
import jdk.internal.misc.CDS;
2928
import jdk.internal.org.objectweb.asm.ClassWriter;
3029
import jdk.internal.org.objectweb.asm.Opcodes;
3130
import sun.invoke.util.Wrapper;
@@ -39,10 +38,7 @@
3938
import java.util.TreeSet;
4039
import java.util.stream.Stream;
4140

42-
import static java.lang.invoke.LambdaForm.basicTypeSignature;
43-
import static java.lang.invoke.LambdaForm.shortenSignature;
4441
import static java.lang.invoke.LambdaForm.BasicType.*;
45-
import static java.lang.invoke.MethodHandleStatics.TRACE_RESOLVE;
4642
import static java.lang.invoke.MethodTypeForm.*;
4743
import static java.lang.invoke.LambdaForm.Kind.*;
4844

@@ -51,29 +47,6 @@
5147
* generate classes ahead of time.
5248
*/
5349
class GenerateJLIClassesHelper {
54-
private static final String LF_RESOLVE = "[LF_RESOLVE]";
55-
private static final String SPECIES_RESOLVE = "[SPECIES_RESOLVE]";
56-
57-
static void traceLambdaForm(String name, MethodType type, Class<?> holder, MemberName resolvedMember) {
58-
if (TRACE_RESOLVE) {
59-
System.out.println(LF_RESOLVE + " " + holder.getName() + " " + name + " " +
60-
shortenSignature(basicTypeSignature(type)) +
61-
(resolvedMember != null ? " (success)" : " (fail)"));
62-
}
63-
if (CDS.isDumpingClassList()) {
64-
CDS.traceLambdaFormInvoker(LF_RESOLVE, holder.getName(), name, shortenSignature(basicTypeSignature(type)));
65-
}
66-
}
67-
68-
static void traceSpeciesType(String cn, Class<?> salvage) {
69-
if (TRACE_RESOLVE) {
70-
System.out.println(SPECIES_RESOLVE + " " + cn + (salvage != null ? " (salvaged)" : " (generated)"));
71-
}
72-
if (CDS.isDumpingClassList()) {
73-
CDS.traceSpeciesType(SPECIES_RESOLVE, cn);
74-
}
75-
}
76-
7750
// Map from DirectMethodHandle method type name to index to LambdForms
7851
static final Map<String, Integer> DMH_METHOD_TYPE_MAP =
7952
Map.of(
@@ -323,7 +296,7 @@ static Map<String, byte[]> generateHolderClasses(Stream<String> traces) {
323296
traces.map(line -> line.split(" "))
324297
.forEach(parts -> {
325298
switch (parts[0]) {
326-
case SPECIES_RESOLVE:
299+
case "[SPECIES_RESOLVE]":
327300
// Allow for new types of species data classes being resolved here
328301
assert parts.length >= 2;
329302
if (parts[1].startsWith(BMH_SPECIES_PREFIX)) {
@@ -333,7 +306,7 @@ static Map<String, byte[]> generateHolderClasses(Stream<String> traces) {
333306
}
334307
}
335308
break;
336-
case LF_RESOLVE:
309+
case "[LF_RESOLVE]":
337310
assert parts.length > 3;
338311
String methodType = parts[3];
339312
if (parts[1].equals(INVOKERS_HOLDER_CLASS_NAME)) {

‎src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,7 +46,6 @@
4646
import java.util.List;
4747
import java.util.stream.Stream;
4848

49-
import static java.lang.invoke.GenerateJLIClassesHelper.traceLambdaForm;
5049
import static java.lang.invoke.LambdaForm.BasicType;
5150
import static java.lang.invoke.LambdaForm.BasicType.*;
5251
import static java.lang.invoke.LambdaForm.*;

‎src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,11 +25,15 @@
2525

2626
package java.lang.invoke;
2727

28+
import jdk.internal.misc.CDS;
2829
import jdk.internal.misc.Unsafe;
2930
import sun.security.action.GetPropertyAction;
3031

3132
import java.util.Properties;
3233

34+
import static java.lang.invoke.LambdaForm.basicTypeSignature;
35+
import static java.lang.invoke.LambdaForm.shortenSignature;
36+
3337
/**
3438
* This class consists exclusively of static names internal to the
3539
* method handle implementation.
@@ -108,6 +112,35 @@ static boolean debugEnabled() {
108112
LOG_LF_COMPILATION_FAILURE);
109113
}
110114

115+
/**
116+
* If requested, logs the result of resolving the LambdaForm to stdout
117+
* and informs the CDS subsystem about it.
118+
*/
119+
/*non-public*/
120+
static void traceLambdaForm(String name, MethodType type, Class<?> holder, MemberName resolvedMember) {
121+
if (TRACE_RESOLVE) {
122+
System.out.println("[LF_RESOLVE] " + holder.getName() + " " + name + " " +
123+
shortenSignature(basicTypeSignature(type)) +
124+
(resolvedMember != null ? " (success)" : " (fail)"));
125+
}
126+
if (CDS.isDumpingClassList()) {
127+
CDS.traceLambdaFormInvoker("[LF_RESOLVE]", holder.getName(), name, shortenSignature(basicTypeSignature(type)));
128+
}
129+
}
130+
131+
/**
132+
* If requested, logs the result of resolving the species type to stdout
133+
* and the CDS subsystem.
134+
*/
135+
/*non-public*/
136+
static void traceSpeciesType(String cn, Class<?> salvage) {
137+
if (TRACE_RESOLVE) {
138+
System.out.println("[SPECIES_RESOLVE] " + cn + (salvage != null ? " (salvaged)" : " (generated)"));
139+
}
140+
if (CDS.isDumpingClassList()) {
141+
CDS.traceSpeciesType("[SPECIES_RESOLVE]", cn);
142+
}
143+
}
111144
// handy shared exception makers (they simplify the common case code)
112145
/*non-public*/
113146
static InternalError newInternalError(String message) {

0 commit comments

Comments
 (0)
This repository has been archived.