< prev index next >

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

Print this page
*** 23,10 ***
--- 23,12 ---
   * questions.
   */
  
  package jdk.internal.reflect;
  
+ import jdk.internal.value.PrimitiveClass;
+ 
  import java.security.AccessController;
  import java.security.PrivilegedAction;
  
  /** Generator for jdk.internal.reflect.MethodAccessor and
      jdk.internal.reflect.ConstructorAccessor objects using bytecodes to

*** 50,10 ***
--- 52,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;

*** 76,24 ***
                                           parameterTypes,
                                           returnType,
                                           modifiers,
                                           false,
                                           false,
                                           null);
      }
  
      /** This routine is not thread-safe */
      public ConstructorAccessor generateConstructor(Class<?> declaringClass,
                                                     Class<?>[] parameterTypes,
                                                     int modifiers)
      {
          return (ConstructorAccessor) generate(declaringClass,
                                                "<init>",
                                                parameterTypes,
!                                               Void.TYPE,
                                                modifiers,
                                                true,
                                                false,
                                                null);
      }
  
      /** This routine is not thread-safe */
--- 79,27 ---
                                           parameterTypes,
                                           returnType,
                                           modifiers,
                                           false,
                                           false,
+                                          false,
                                           null);
      }
  
      /** This routine is not thread-safe */
      public ConstructorAccessor generateConstructor(Class<?> declaringClass,
                                                     Class<?>[] parameterTypes,
                                                     int modifiers)
      {
+         boolean isStaticFactory = declaringClass.isValue();
          return (ConstructorAccessor) generate(declaringClass,
                                                "<init>",
                                                parameterTypes,
!                                               isStaticFactory ? PrimitiveClass.asValueType(declaringClass) : Void.TYPE,
                                                modifiers,
                                                true,
+                                               isStaticFactory,
                                                false,
                                                null);
      }
  
      /** This routine is not thread-safe */

*** 108,10 ***
--- 114,11 ---
                       "<init>",
                       parameterTypes,
                       Void.TYPE,
                       modifiers,
                       true,
+                      false,
                       true,
                       targetConstructorClass);
      }
  
      /** This routine is not thread-safe */

*** 120,20 ***
--- 127,22 ---
                                         String name,
                                         Class<?>[] parameterTypes,
                                         Class<?>   returnType,
                                         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:

*** 332,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.emitConstantPoolClass(asm.cpi());
              }
          }
  
          // Entries common to FieldAccessor, MethodAccessor and ConstructorAccessor
--- 341,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, true));
                  asm.emitConstantPoolClass(asm.cpi());
              }
          }
  
          // Entries common to FieldAccessor, MethodAccessor and ConstructorAccessor

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

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