< prev index next >

make/jdk/src/classes/build/tools/classlist/HelloClasslist.java

Print this page

 99         String CSCI   = "string" + s + "string" + i;
100         String CIC    = "string" + i + "string";
101         String CICI   = "string" + i + "string" + i;
102 
103         long l = System.currentTimeMillis();
104         String CJ     = "string" + l;
105         String JC     = l + "string";
106         String CJC    = "string" + l + "string";
107         String CJCJ   = "string" + l + "string" + l;
108         String CJCJC  = "string" + l + "string" + l + "string";
109         double d = i / 2.0;
110         String CD     = "string" + d;
111 
112         String newDate = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(
113                 LocalDateTime.now(ZoneId.of("GMT")));
114 
115         String oldDate = String.format("%s%n",
116                 DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.ROOT)
117                         .format(new Date()));
118 






119         // A selection of trivial and relatively common MH operations
120         invoke(MethodHandles.identity(double.class), 1.0);
121         invoke(MethodHandles.identity(int.class), 1);
122         invoke(MethodHandles.identity(String.class), "x");
123 
124         invoke(handle("staticMethod_V", MethodType.methodType(void.class)));
125 
126         LOGGER.log(Level.FINE, "New Date: " + newDate + " - old: " + oldDate);
127     }
128 




129     public static void staticMethod_V() {}
130 


131     private static MethodHandle handle(String name, MethodType type) throws Throwable {
132         return MethodHandles.lookup().findStatic(HelloClasslist.class, name, type);
133     }
134 
135     private static Object invoke(MethodHandle mh, Object ... args) throws Throwable {
136         try {
137             for (Object o : args) {
138                 mh = MethodHandles.insertArguments(mh, 0, o);
139             }
140             return mh.invoke();
141         } catch (Throwable t) {
142             LOGGER.warning("Failed to find, link and/or invoke " + mh.toString() + ": " + t.getMessage());
143             throw t;
144         }
145     }
146 }

 99         String CSCI   = "string" + s + "string" + i;
100         String CIC    = "string" + i + "string";
101         String CICI   = "string" + i + "string" + i;
102 
103         long l = System.currentTimeMillis();
104         String CJ     = "string" + l;
105         String JC     = l + "string";
106         String CJC    = "string" + l + "string";
107         String CJCJ   = "string" + l + "string" + l;
108         String CJCJC  = "string" + l + "string" + l + "string";
109         double d = i / 2.0;
110         String CD     = "string" + d;
111 
112         String newDate = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(
113                 LocalDateTime.now(ZoneId.of("GMT")));
114 
115         String oldDate = String.format("%s%n",
116                 DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.ROOT)
117                         .format(new Date()));
118 
119         // A selection of trivial and common reflection operations
120         var instance = HelloClasslist.class.getConstructor().newInstance();
121         HelloClasslist.class.getMethod("staticMethod_V").invoke(null);
122         var obj = HelloClasslist.class.getMethod("staticMethod_L_L", Object.class).invoke(null, instance);
123         HelloClasslist.class.getField("field").get(instance);
124 
125         // A selection of trivial and relatively common MH operations
126         invoke(MethodHandles.identity(double.class), 1.0);
127         invoke(MethodHandles.identity(int.class), 1);
128         invoke(MethodHandles.identity(String.class), "x");
129 
130         invoke(handle("staticMethod_V", MethodType.methodType(void.class)));
131 
132         LOGGER.log(Level.FINE, "New Date: " + newDate + " - old: " + oldDate);
133     }
134 
135     public HelloClasslist() {}
136 
137     public String field = "someValue";
138 
139     public static void staticMethod_V() {}
140 
141     public static Object staticMethod_L_L(Object o) { return o; }
142 
143     private static MethodHandle handle(String name, MethodType type) throws Throwable {
144         return MethodHandles.lookup().findStatic(HelloClasslist.class, name, type);
145     }
146 
147     private static Object invoke(MethodHandle mh, Object ... args) throws Throwable {
148         try {
149             for (Object o : args) {
150                 mh = MethodHandles.insertArguments(mh, 0, o);
151             }
152             return mh.invoke();
153         } catch (Throwable t) {
154             LOGGER.warning("Failed to find, link and/or invoke " + mh.toString() + ": " + t.getMessage());
155             throw t;
156         }
157     }
158 }
< prev index next >