changeset 56890:2140069460ec records-and-sealed

adapting to new extractor bootstrap
author vromero
date Fri, 21 Jun 2019 11:37:08 -0400
parents d47c05ad75fe
children 512622f4dd81
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java
diffstat 3 files changed, 39 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java	Fri Jun 21 16:41:16 2019 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java	Fri Jun 21 11:37:08 2019 -0400
@@ -215,7 +215,8 @@
     public final Type documentedType;
     public final Type elementTypeType;
     public final Type functionalInterfaceType;
-    public final Type extractorType;
+    public final Type patternHandlesType;
+    public final Type patternHandleType;
     public final Type typeDescriptorType;
 
     /** The symbol representing the length field of an array.
@@ -574,7 +575,8 @@
         lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
         stringConcatFactory = enterClass("java.lang.invoke.StringConcatFactory");
         functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
-        extractorType = enterClass("java.lang.runtime.Extractor");
+        patternHandlesType = enterClass("java.lang.runtime.PatternHandles");
+        patternHandleType = enterClass("java.lang.runtime.PatternHandle");
         typeDescriptorType = enterClass("java.lang.invoke.TypeDescriptor");
 
         synthesizeEmptyInterfaceIfMissing(autoCloseableType);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Jun 21 16:41:16 2019 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java	Fri Jun 21 11:37:08 2019 -0400
@@ -28,12 +28,8 @@
 import sun.invoke.util.BytecodeName;
 
 import java.util.*;
-import java.util.Map.Entry;
-import java.util.function.Function;
-import java.util.stream.Stream;
 import java.util.stream.Collectors;
 
-import com.sun.source.tree.CaseTree.CaseKind;
 import com.sun.tools.javac.code.*;
 import com.sun.tools.javac.code.Kinds.KindSelector;
 import com.sun.tools.javac.code.Scope.WriteableScope;
@@ -61,7 +57,6 @@
 import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
 import static com.sun.tools.javac.code.TypeTag.*;
 import static com.sun.tools.javac.code.Kinds.Kind.*;
-import static com.sun.tools.javac.code.Symbol.OperatorSymbol.AccessCode.DEREF;
 import static com.sun.tools.javac.jvm.ByteCodes.*;
 import static com.sun.tools.javac.tree.JCTree.JCOperatorExpression.OperandPos.LEFT;
 import com.sun.tools.javac.tree.JCTree.JCSwitchExpression;
@@ -2545,41 +2540,47 @@
 
     JCTree recordExtractor(JCClassDecl tree, MethodHandleSymbol[] getterMethHandles) {
         make_at(tree.pos());
+
+        // let's generate the name of the extractor method
         List<Type> fieldTypes = TreeInfo.types(TreeInfo.recordFields(tree));
         String argsTypeSig = '(' + argsTypeSig(fieldTypes) + ')';
         String extractorStr = BytecodeName.toBytecodeName("$pattern$" + tree.sym.name + "$" + argsTypeSig);
         Name extractorName = names.fromString(extractorStr);
-        // public Extractor extractorName () { return ???; }
-        MethodType extractorMT = new MethodType(List.nil(), syms.extractorType, List.nil(), syms.methodClass);
+
+        // let's create the condy now
+        Name bsmName = names.ofLazyProjection;
+        List<Type> staticArgTypes = List.of(syms.classType,
+                new ArrayType(syms.methodHandleType, syms.arrayClass));
+        List<Type> bsm_staticArgs = List.of(syms.methodHandleLookupType,
+                syms.stringType,
+                syms.classType).appendList(staticArgTypes);
+
+        Symbol bsm = rs.resolveInternalMethod(tree, attrEnv, syms.patternHandlesType,
+                bsmName, bsm_staticArgs, List.nil());
+
+        LoadableConstant[] staticArgs = new LoadableConstant[1 + getterMethHandles.length];
+        staticArgs[0] = (ClassType)tree.sym.type;
+        int index = 1;
+        for (MethodHandleSymbol mho : getterMethHandles) {
+            staticArgs[index] = mho;
+            index++;
+        }
+
+        Symbol.DynamicVarSymbol dynSym = new Symbol.DynamicVarSymbol(extractorName,
+                syms.noSymbol,
+                ((MethodSymbol)bsm).asHandle(),
+                syms.patternHandleType,
+                staticArgs);
+        JCIdent ident = make.Ident(dynSym);
+        ident.type = syms.patternHandleType;
+
+        // public PatternHandle extractorName () { return ???; }
+        MethodType extractorMT = new MethodType(List.nil(), syms.patternHandleType, List.nil(), syms.methodClass);
         MethodSymbol extractorSym = new MethodSymbol(
                 Flags.PUBLIC | Flags.RECORD | Flags.STATIC,
                 extractorName, extractorMT, tree.sym);
         tree.sym.members().enter(extractorSym);
-
-        Name bootstrapName = names.makeLazyExtractor;
-        LoadableConstant[] staticArgsValues = new LoadableConstant[1 + getterMethHandles.length];
-        /** this method descriptor should have the same arguments as the record constructor and its
-         *  return type should be the same as the type of the record
-         */
-        MethodType mt = new MethodType(fieldTypes, tree.type, List.nil(), syms.methodClass);
-        staticArgsValues[0] = mt;
-        int index = 1;
-        for (MethodHandleSymbol mho : getterMethHandles) {
-            staticArgsValues[index] = mho;
-            index++;
-        }
-
-        List<Type> staticArgTypes = List.of(syms.methodTypeType,
-                new ArrayType(syms.methodHandleType, syms.arrayClass));
-        JCFieldAccess qualifier = makeIndyQualifier(syms.extractorType, tree, extractorSym,
-                List.of(syms.methodHandleLookupType,
-                        syms.stringType,
-                        syms.methodTypeType).appendList(staticArgTypes),
-                staticArgsValues, bootstrapName, bootstrapName, true);
-
-        JCMethodInvocation proxyCall = make.Apply(List.nil(), qualifier, List.nil());
-        proxyCall.type = qualifier.type;
-        return make.MethodDef(extractorSym, make.Block(0, List.of(make.Return(proxyCall))));
+        return make.MethodDef(extractorSym, make.Block(0, List.of(make.Return(ident))));
     }
 
     JCTree recordReadResolve(JCClassDecl tree) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java	Fri Jun 21 16:41:16 2019 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/util/Names.java	Fri Jun 21 11:37:08 2019 -0400
@@ -205,7 +205,7 @@
     public final Name record;
     public final Name where;
     public final Name non;
-    public final Name makeLazyExtractor;
+    public final Name ofLazyProjection;
 
     // sealed types
     public final Name permits;
@@ -372,7 +372,7 @@
         record = fromString("record");
         where = fromString("where");
         non = fromString("non");
-        makeLazyExtractor = fromString("makeLazyExtractor");
+        ofLazyProjection = fromString("ofLazyProjection");
 
         // sealed types
         permits = fromString("permits");