< prev index next >

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

Print this page
*** 1,7 ***
  /*
!  * Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this
--- 1,7 ---
  /*
!  * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Oracle designates this

*** 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;

*** 78,26 ***
                                           returnType,
                                           checkedExceptions,
                                           modifiers,
                                           false,
                                           false,
                                           null);
      }
  
      /** This routine is not thread-safe */
      public ConstructorAccessor generateConstructor(Class<?> declaringClass,
                                                     Class<?>[] parameterTypes,
                                                     Class<?>[] checkedExceptions,
                                                     int modifiers)
      {
          return (ConstructorAccessor) generate(declaringClass,
                                                "<init>",
                                                parameterTypes,
!                                               Void.TYPE,
                                                checkedExceptions,
                                                modifiers,
                                                true,
                                                false,
                                                null);
      }
  
      /** This routine is not thread-safe */
--- 81,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.isValue();
          return (ConstructorAccessor) generate(declaringClass,
                                                "<init>",
                                                parameterTypes,
!                                               isStaticFactory ? PrimitiveClass.asValueType(declaringClass) : Void.TYPE,
                                                checkedExceptions,
                                                modifiers,
                                                true,
+                                               isStaticFactory,
                                                false,
                                                null);
      }
  
      /** This routine is not thread-safe */

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

*** 127,20 ***
--- 134,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 ***
          // 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
--- 348,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

*** 429,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();
--- 438,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();

*** 619,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,
--- 628,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 >