src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java
Print this page
rev 17771 : 8184777: species logic for BoundMethodHandle doesn't scale, needs refactor
@@ -23,18 +23,18 @@
* questions.
*/
package java.lang.invoke;
-import java.util.Map;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Opcodes;
-import java.util.ArrayList;
-import java.util.HashSet;
import sun.invoke.util.Wrapper;
-import static java.lang.invoke.MethodHandleNatives.Constants.*;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
/**
* Helper class to assist the GenerateJLIClassesPlugin to get access to
* generate classes ahead of time.
*/
@@ -116,12 +116,11 @@
// the basic reinvokers associated with Species_L. Ultimately we
// may want to consider pregenerating more of these, which will
// require an even more complex naming scheme
LambdaForm reinvoker = makeReinvokerFor(methodTypes[i]);
forms.add(reinvoker);
- String speciesSig = BoundMethodHandle
- .speciesData(reinvoker).fieldSignature();
+ String speciesSig = BoundMethodHandle.formSpeciesData(reinvoker).key();
assert(speciesSig.equals("L"));
names.add(reinvoker.kind.defaultLambdaName + "_" + speciesSig);
LambdaForm delegate = makeDelegateFor(methodTypes[i]);
forms.add(delegate);
@@ -203,22 +202,22 @@
MethodTypeForm.LF_DELEGATE,
DelegatingMethodHandle.class,
DelegatingMethodHandle.NF_getTarget);
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(
final String types) {
for (char c : types.toCharArray()) {
if ("LIJFD".indexOf(c) < 0) {
throw new IllegalArgumentException("All characters must "
+ "correspond to a basic field type: LIJFD");
}
}
- String shortTypes = LambdaForm.shortenSignature(types);
- final String className =
- BoundMethodHandle.Factory.speciesInternalClassName(shortTypes);
- return Map.entry(className,
- BoundMethodHandle.Factory.generateConcreteBMHClassBytes(
- shortTypes, types, className));
+ final BoundMethodHandle.BMHSpecies species = BoundMethodHandle.SPECIALIZER.findSpecies(types);
+ final String className = species.speciesCode().getName();
+ final ClassSpecializer.Factory factory = BoundMethodHandle.SPECIALIZER.factory();
+ final byte[] code = factory.generateConcreteSpeciesCodeFile(className, species);
+ return Map.entry(className, code);
}
}