changeset 54953:fd7c4baf9faf intrinsics-project

refactoring, extracting common class descriptors
author vromero
date Tue, 19 Feb 2019 17:28:45 -0500
parents 1ecccc7748df
children 4c07ffe82f92
files src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/FormatterProcessor.java src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/HashProcessor.java
diffstat 2 files changed, 17 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/FormatterProcessor.java	Fri Feb 15 17:28:59 2019 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/FormatterProcessor.java	Tue Feb 19 17:28:45 2019 -0500
@@ -35,6 +35,9 @@
 import java.util.Formatter;
 import java.util.Locale;
 
+import static java.lang.constant.ConstantDescs.CD_CallSite;
+import static java.lang.constant.ConstantDescs.CD_String;
+
 /**
  *  <p><b>This is NOT part of any supported API.
  *  If you write code that depends on this, you do so at your own risk.
@@ -103,6 +106,9 @@
         return sb.toString();
     }
 
+    private static final ClassDesc CD_Locale = ClassDesc.of("java.util.Locale");
+    private static final ClassDesc CD_IntrinsicFactory = ClassDesc.of("java.lang.invoke.IntrinsicFactory");
+
     @Override
     public Result tryIntrinsify(ClassDesc ownerDesc,
                                 String methodName,
@@ -114,10 +120,10 @@
             return new Result.None();
         }
 
-        boolean hasLocale = ClassDesc.of("java.util.Locale").equals(methodType.parameterType(0));
+        boolean hasLocale = CD_Locale.equals(methodType.parameterType(0));
         int formatArg = hasLocale ? 2 : 1;
 
-        if (ClassDesc.of("java.lang.String").equals(ownerDesc)) {
+        if (CD_String.equals(ownerDesc)) {
             formatArg = isStatic && hasLocale ? 1 : 0;
         }
 
@@ -129,14 +135,13 @@
 
         String bsmName = getBSMName(ownerDesc, methodName, isStatic, hasLocale);
 
-        MethodTypeDesc methodTypeLessFormat = methodType.dropParameterTypes(formatArg,
-                                                                            formatArg + 1);
+        MethodTypeDesc methodTypeLessFormat = methodType.dropParameterTypes(formatArg, formatArg + 1);
         return new Result.Indy(
                 DynamicCallSiteDesc.of(
                         ConstantDescs.ofCallsiteBootstrap(
-                                ClassDesc.of("java.lang.invoke.IntrinsicFactory"),
+                                CD_IntrinsicFactory,
                                 bsmName,
-                                ClassDesc.of("java.lang.invoke.CallSite")
+                                CD_CallSite
                         ),
                         methodName,
                         methodTypeLessFormat,
@@ -144,6 +149,4 @@
                         intrinsics.dropArg(argClassDescs.length, formatArg)
         );
     }
-
  }
-
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/HashProcessor.java	Fri Feb 15 17:28:59 2019 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/intrinsics/HashProcessor.java	Tue Feb 19 17:28:45 2019 -0500
@@ -49,6 +49,9 @@
 
     Intrinsics intrinsics;
 
+    private static final ClassDesc CD_Objects = ClassDesc.of("java.util.Objects");
+    private static final ClassDesc CD_IntrinsicFactory = ClassDesc.of("java.lang.invoke.IntrinsicFactory");
+
     @Override
     public Result tryIntrinsify(ClassDesc ownerDesc,
                                 String methodName,
@@ -56,7 +59,7 @@
                                 boolean isStatic,
                                 ClassDesc[] argClassDescs,
                                 ConstantDesc[] constantArgs) {
-        if (ClassDesc.of("java.util.Objects").equals(ownerDesc)) {
+        if (CD_Objects.equals(ownerDesc)) {
             switch (methodName) {
                 case "hash":
                     if (intrinsics.isAllConstants(constantArgs, false)) {
@@ -70,9 +73,9 @@
                         return new Result.Indy(
                                 DynamicCallSiteDesc.of(
                                         ConstantDescs.ofCallsiteBootstrap(
-                                                ClassDesc.of("java.lang.invoke.IntrinsicFactory"),
+                                                CD_IntrinsicFactory,
                                                 "objectsHashBootstrap",
-                                                ClassDesc.of("java.lang.invoke.CallSite")
+                                                ConstantDescs.CD_CallSite
                                         ),
                                         methodName,
                                         methodType,