jdk/src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java
changeset 40419 20e2e4b25a40
parent 40408 cf7e826d4d63
child 40450 ff23a3122b79
--- a/jdk/src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java	Fri Aug 19 10:03:43 2016 +0200
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/GenerateJLIClassesHelper.java	Fri Aug 19 13:50:03 2016 +0200
@@ -38,6 +38,34 @@
  */
 class GenerateJLIClassesHelper {
 
+    static byte[] generateBasicFormsClassBytes(String className) {
+        ArrayList<LambdaForm> forms = new ArrayList<>();
+        ArrayList<String> names = new ArrayList<>();
+        HashSet<String> dedupSet = new HashSet<>();
+        for (LambdaForm.BasicType type : LambdaForm.BasicType.values()) {
+            LambdaForm zero = LambdaForm.zeroForm(type);
+            String name = zero.kind.defaultLambdaName
+                    + "_" + zero.returnType().basicTypeChar();
+            // since zero is the same as identity for Void, we deduplicate
+            // aggressively to guard against this specifically and not get
+            // caught on future equivalences
+            if (dedupSet.add(name)) {
+                names.add(name);
+                forms.add(zero);
+            }
+            LambdaForm identity = LambdaForm.identityForm(type);
+            name = identity.kind.defaultLambdaName
+                   + "_" + identity.returnType().basicTypeChar();
+            if (dedupSet.add(name)) {
+                names.add(name);
+                forms.add(identity);
+            }
+        }
+        return generateCodeBytesForLFs(className,
+                names.toArray(new String[0]),
+                forms.toArray(new LambdaForm[0]));
+    }
+
     static byte[] generateDirectMethodHandleHolderClassBytes(String className,
             MethodType[] methodTypes, int[] types) {
         LambdaForm[] forms = new LambdaForm[methodTypes.length];