< prev index next >

src/java.base/share/classes/jdk/internal/reflect/MethodAccessorGenerator.java

Print this page
@@ -50,10 +50,11 @@
  
      private Class<?>   declaringClass;
      private Class<?>[] parameterTypes;
      private Class<?>   returnType;
      private boolean    isConstructor;
+     private boolean    isStaticFactory;
      private boolean    forSerialization;
  
      private short targetMethodRef;
      private short invokeIdx;
      private short invokeDescriptorIdx;

@@ -78,26 +79,29 @@
                                           returnType,
                                           checkedExceptions,
                                           modifiers,
                                           false,
                                           false,
+                                          false,
                                           null);
      }
  
      /** This routine is not thread-safe */
      public ConstructorAccessor generateConstructor(Class<?> declaringClass,
                                                     Class<?>[] parameterTypes,
                                                     Class<?>[] checkedExceptions,
                                                     int modifiers)
      {
+         boolean isStaticFactory = declaringClass.isPrimitiveClass();
          return (ConstructorAccessor) generate(declaringClass,
                                                "<init>",
                                                parameterTypes,
-                                               Void.TYPE,
+                                               isStaticFactory ? declaringClass.asValueType() : Void.TYPE,
                                                checkedExceptions,
                                                modifiers,
                                                true,
+                                               isStaticFactory,
                                                false,
                                                null);
      }
  
      /** This routine is not thread-safe */

@@ -114,10 +118,11 @@
                       parameterTypes,
                       Void.TYPE,
                       checkedExceptions,
                       modifiers,
                       true,
+                      false,
                       true,
                       targetConstructorClass);
      }
  
      /** This routine is not thread-safe */

@@ -127,20 +132,22 @@
                                         Class<?>[] parameterTypes,
                                         Class<?>   returnType,
                                         Class<?>[] checkedExceptions,
                                         int modifiers,
                                         boolean isConstructor,
+                                        boolean isStaticFactory,
                                         boolean forSerialization,
                                         Class<?> serializationTargetClass)
      {
          ByteVector vec = ByteVectorFactory.create();
          asm = new ClassFileAssembler(vec);
          this.declaringClass = declaringClass;
          this.parameterTypes = parameterTypes;
          this.returnType = returnType;
          this.modifiers = modifiers;
          this.isConstructor = isConstructor;
+         this.isStaticFactory = isStaticFactory;
          this.forSerialization = forSerialization;
  
          asm.emitMagicAndVersion();
  
          // Constant pool entries:

@@ -339,11 +346,11 @@
          // Output class information for non-primitive parameter types
          nonPrimitiveParametersBaseIdx = add(asm.cpi(), S2);
          for (int i = 0; i < parameterTypes.length; i++) {
              Class<?> c = parameterTypes[i];
              if (!isPrimitive(c)) {
-                 asm.emitConstantPoolUTF8(getClassName(c, false));
+                 asm.emitConstantPoolUTF8(getClassName(c, true));
                  asm.emitConstantPoolClass(asm.cpi());
              }
          }
  
          // Entries common to FieldAccessor, MethodAccessor and ConstructorAccessor

@@ -429,11 +436,11 @@
              cb.setMaxLocals(3);
          }
  
          short illegalArgStartPC = 0;
  
-         if (isConstructor) {
+         if (isConstructor && !isStaticFactory) {
              // Instantiate target class before continuing
              // new <target class type>
              // dup
              cb.opc_new(targetClass);
              cb.opc_dup();

@@ -619,11 +626,11 @@
          }
  
          short invokeStartPC = cb.getLength();
  
          // OK, ready to perform the invocation.
-         if (isConstructor) {
+         if (isConstructor && !isStaticFactory) {
              cb.opc_invokespecial(targetMethodRef, count, 0);
          } else {
              if (isStatic()) {
                  cb.opc_invokestatic(targetMethodRef,
                                      count,
< prev index next >