src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java
changeset 47753 a2008587c13f
parent 47216 71c04702a3d5
child 49240 5290e816c64c
equal deleted inserted replaced
47752:e0041b182e31 47753:a2008587c13f
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package java.lang.invoke;
    26 package java.lang.invoke;
    27 
    27 
    28 import java.util.Map;
       
    29 import jdk.internal.org.objectweb.asm.ClassWriter;
    28 import jdk.internal.org.objectweb.asm.ClassWriter;
    30 import jdk.internal.org.objectweb.asm.Opcodes;
    29 import jdk.internal.org.objectweb.asm.Opcodes;
       
    30 import sun.invoke.util.Wrapper;
       
    31 
    31 import java.util.ArrayList;
    32 import java.util.ArrayList;
    32 import java.util.HashSet;
    33 import java.util.HashSet;
    33 import sun.invoke.util.Wrapper;
    34 import java.util.List;
    34 
    35 import java.util.Map;
    35 import static java.lang.invoke.MethodHandleNatives.Constants.*;
       
    36 
    36 
    37 /**
    37 /**
    38  * Helper class to assist the GenerateJLIClassesPlugin to get access to
    38  * Helper class to assist the GenerateJLIClassesPlugin to get access to
    39  * generate classes ahead of time.
    39  * generate classes ahead of time.
    40  */
    40  */
   116                 // the basic reinvokers associated with Species_L. Ultimately we
   116                 // the basic reinvokers associated with Species_L. Ultimately we
   117                 // may want to consider pregenerating more of these, which will
   117                 // may want to consider pregenerating more of these, which will
   118                 // require an even more complex naming scheme
   118                 // require an even more complex naming scheme
   119                 LambdaForm reinvoker = makeReinvokerFor(methodTypes[i]);
   119                 LambdaForm reinvoker = makeReinvokerFor(methodTypes[i]);
   120                 forms.add(reinvoker);
   120                 forms.add(reinvoker);
   121                 String speciesSig = BoundMethodHandle
   121                 String speciesSig = BoundMethodHandle.speciesDataFor(reinvoker).key();
   122                         .speciesData(reinvoker).fieldSignature();
       
   123                 assert(speciesSig.equals("L"));
   122                 assert(speciesSig.equals("L"));
   124                 names.add(reinvoker.kind.defaultLambdaName + "_" + speciesSig);
   123                 names.add(reinvoker.kind.defaultLambdaName + "_" + speciesSig);
   125 
   124 
   126                 LambdaForm delegate = makeDelegateFor(methodTypes[i]);
   125                 LambdaForm delegate = makeDelegateFor(methodTypes[i]);
   127                 forms.add(delegate);
   126                 forms.add(delegate);
   203                 MethodTypeForm.LF_DELEGATE,
   202                 MethodTypeForm.LF_DELEGATE,
   204                 DelegatingMethodHandle.class,
   203                 DelegatingMethodHandle.class,
   205                 DelegatingMethodHandle.NF_getTarget);
   204                 DelegatingMethodHandle.NF_getTarget);
   206     }
   205     }
   207 
   206 
   208     static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(
   207     @SuppressWarnings({"rawtypes", "unchecked"})
   209             final String types) {
   208     static Map.Entry<String, byte[]> generateConcreteBMHClassBytes(final String types) {
   210         for (char c : types.toCharArray()) {
   209         for (char c : types.toCharArray()) {
   211             if ("LIJFD".indexOf(c) < 0) {
   210             if ("LIJFD".indexOf(c) < 0) {
   212                 throw new IllegalArgumentException("All characters must "
   211                 throw new IllegalArgumentException("All characters must "
   213                         + "correspond to a basic field type: LIJFD");
   212                         + "correspond to a basic field type: LIJFD");
   214             }
   213             }
   215         }
   214         }
   216         String shortTypes = LambdaForm.shortenSignature(types);
   215         final BoundMethodHandle.SpeciesData species = BoundMethodHandle.SPECIALIZER.findSpecies(types);
   217         final String className =
   216         final String className = species.speciesCode().getName();
   218                 BoundMethodHandle.Factory.speciesInternalClassName(shortTypes);
   217         final ClassSpecializer.Factory factory = BoundMethodHandle.SPECIALIZER.factory();
   219         return Map.entry(className,
   218         final byte[] code = factory.generateConcreteSpeciesCodeFile(className, species);
   220                          BoundMethodHandle.Factory.generateConcreteBMHClassBytes(
   219         return Map.entry(className.replace('.', '/'), code);
   221                                  shortTypes, types, className));
       
   222     }
   220     }
   223 
   221 
   224 }
   222 }