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,40 **** * 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.*; /** * Helper class to assist the GenerateJLIClassesPlugin to get access to * generate classes ahead of time. */ --- 23,40 ---- * questions. */ package java.lang.invoke; import jdk.internal.org.objectweb.asm.ClassWriter; import jdk.internal.org.objectweb.asm.Opcodes; import sun.invoke.util.Wrapper; ! 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,127 **** // 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(); assert(speciesSig.equals("L")); names.add(reinvoker.kind.defaultLambdaName + "_" + speciesSig); LambdaForm delegate = makeDelegateFor(methodTypes[i]); forms.add(delegate); --- 116,126 ---- // 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.formSpeciesData(reinvoker).key(); assert(speciesSig.equals("L")); names.add(reinvoker.kind.defaultLambdaName + "_" + speciesSig); LambdaForm delegate = makeDelegateFor(methodTypes[i]); forms.add(delegate);
*** 203,224 **** MethodTypeForm.LF_DELEGATE, DelegatingMethodHandle.class, DelegatingMethodHandle.NF_getTarget); } 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)); } } --- 202,223 ---- 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"); } } ! 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); } }