Hello Remi, > int.class is compiled by javac as Integer.TYPE
so this is the reason why assertion works in the test. > the opcode ldc only works with an object/interface class, not with a > primitive type [1]. Thanks for pointing this out, I think I should read that whole chapter again. Regards, Sergey Tsypanov 26.11.2019, 21:45, "Remi Forax" <fo...@univ-mlv.fr>: > Hi Sergey, > hum, it doesn't work :) > > int.class is compiled by javac as Integer.TYPE, > the opcode ldc only works with an object/interface class, not with a > primitive type [1]. > > regards, > Rémi > > [1] > https://docs.oracle.com/javase/specs/jvms/se13/html/jvms-6.html#jvms-6.5.ldc > > ----- Mail original ----- >> De: "Сергей Цыпанов" <sergei.tsypa...@yandex.ru> >> À: "core-libs-dev" <core-libs-dev@openjdk.java.net> >> Envoyé: Mardi 26 Novembre 2019 20:29:06 >> Objet: [PATCH] Simplification proposal regarding TYPE-field initialization >> in primitive wrappers > >> Hello, >> >> while using java.lang.Integer.TYPE I've found out that currently wrapper >> classes >> for primitives initialize their own TYPE-fields by calling native method >> java.lang.Class.getPrimitiveClass(). >> >> This can be simplified by changing existing declaration (here for >> java.lang.Integer) >> >> @SuppressWarnings("unchecked") >> public static final Class<Integer> TYPE = (Class<Integer>) >> Class.getPrimitiveClass("int"); >> >> to >> >> public static final Class<Integer> TYPE = int.class; >> >> This is likely to improve start-up time as Class.getPrimitiveClass() is >> called 9 >> times (8 primitive type wrappers + java.lang.Void), after the change this >> method is not called at all and thus can be removed along with its backing >> C++ >> code on VM-side. The fields are initialized purely on Java side. >> >> I've verified correctness of the substitution with this test run on JDK 11 >> >> @Test >> void name() { >> assert void.class == Void.TYPE; >> assert boolean.class == Boolean.TYPE; >> assert byte.class == Byte.TYPE; >> assert char.class == Character.TYPE; >> assert short.class == Short.TYPE; >> assert int.class == Integer.TYPE; >> assert long.class == Long.TYPE; >> assert float.class == Float.TYPE; >> assert double.class == Double.TYPE; >> } >> >> The patch is attached. >> >> Regards, >> Sergey Tsypanov