< prev index next >

src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java

Print this page
*** 863,11 ***
                      mv.visitInsn(DRETURN);
                  } else {
                      throw new AssertionError();
                  }
              } else {
!                 mv.visitTypeInsn(CHECKCAST, dotToSlash(type.getName()));
                  mv.visitInsn(ARETURN);
              }
          }
  
          /**
--- 863,15 ---
                      mv.visitInsn(DRETURN);
                  } else {
                      throw new AssertionError();
                  }
              } else {
!                 String internalName = dotToSlash(type.getName());
+                 if (type.isValueType()) {
+                     internalName = 'Q' + internalName + ";";
+                 }
+                 mv.visitTypeInsn(CHECKCAST, internalName);
                  mv.visitInsn(ARETURN);
              }
          }
  
          /**

*** 914,19 ***
           * =============== Code Generation Utility Methods ===============
           */
  
          /**
           * Generate code to invoke the Class.forName with the name of the given
!          * class to get its Class object at runtime.  The code is written to
!          * the supplied stream.  Note that the code generated by this method
!          * may cause the checked ClassNotFoundException to be thrown.
           */
          private void codeClassForName(MethodVisitor mv, Class<?> cl) {
              mv.visitLdcInsn(cl.getName());
              mv.visitMethodInsn(INVOKESTATIC,
                      JL_CLASS,
                      "forName", "(Ljava/lang/String;)Ljava/lang/Class;", false);
          }
  
          /**
           * Visit a bytecode for a constant.
           *
--- 918,26 ---
           * =============== Code Generation Utility Methods ===============
           */
  
          /**
           * Generate code to invoke the Class.forName with the name of the given
!          * class to get its Class object at runtime.  And also generate code
!          * to invoke Class::asValueType if the class is a primitive value type.
!          *
+          * The code is written to the supplied stream.  Note that the code generated
+          * by this method may caused the checked ClassNotFoundException to be thrown.
           */
          private void codeClassForName(MethodVisitor mv, Class<?> cl) {
              mv.visitLdcInsn(cl.getName());
              mv.visitMethodInsn(INVOKESTATIC,
                      JL_CLASS,
                      "forName", "(Ljava/lang/String;)Ljava/lang/Class;", false);
+             if (cl.isValueType()) {
+               mv.visitMethodInsn(INVOKEVIRTUAL,
+                                  JL_CLASS,
+                                  "asValueType", "()Ljava/lang/Class;", false);
+             }
          }
  
          /**
           * Visit a bytecode for a constant.
           *
< prev index next >