< prev index next >

test/hotspot/jtreg/runtime/cds/appcds/resolvedConstants/ResolvedConstants.java

Print this page

 92                     checkAssemblyOutput(args, out);
 93                 })
 94             .setProductionChecker((OutputAnalyzer out) -> {
 95                     out.shouldContain("Hello ResolvedConstantsApp");
 96                 })
 97             .run(args);
 98     }
 99 
100     static void checkAssemblyOutput(String args[], OutputAnalyzer out) {
101         testGroup("Class References", out)
102             // Always resolve reference when a class references itself
103             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => ResolvedConstantsApp app"))
104 
105             // Always resolve reference when a class references a super class
106             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => java/lang/Object boot"))
107             .shouldMatch(ALWAYS("klass.* ResolvedConstantsBar app => ResolvedConstantsFoo app"))
108 
109             // Always resolve reference when a class references a super interface
110             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => java/lang/Runnable boot"))
111 

112             // Without -XX:+AOTClassLinking:
113             //   java/lang/System is in the boot loader but ResolvedConstantsApp is loaded by the app loader.
114             //   Even though System is in the vmClasses list, when ResolvedConstantsApp looks up
115             //   "java/lang/System" in its ConstantPool, the app loader may not have resolved the System
116             //   class yet (i.e., there's no initiaited class entry for System in the app loader's dictionary)
117             .shouldMatch(AOTLINK_ONLY("klass.* ResolvedConstantsApp .*java/lang/System"));


118 
119         testGroup("Field References", out)
120             // Always resolve references to fields in the current class or super class(es)
121             .shouldMatch(ALWAYS("field.* ResolvedConstantsBar => ResolvedConstantsBar.b:I"))
122             .shouldMatch(ALWAYS("field.* ResolvedConstantsBar => ResolvedConstantsBar.a:I"))
123             .shouldMatch(ALWAYS("field.* ResolvedConstantsBar => ResolvedConstantsFoo.a:I"))
124             .shouldMatch(ALWAYS("field.* ResolvedConstantsFoo => ResolvedConstantsFoo.a:I"))
125 
126             // Resolve field references to child classes ONLY when using -XX:+AOTClassLinking
127             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsFoo => ResolvedConstantsBar.a:I"))
128             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsFoo => ResolvedConstantsBar.b:I"))
129 
130             // Resolve field references to unrelated classes ONLY when using -XX:+AOTClassLinking
131             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsApp => ResolvedConstantsBar.a:I"))
132             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsApp => ResolvedConstantsBar.b:I"));
133 
134         if (args[0].equals("DYNAMIC")) {
135             // AOT resolution of CP methods/indy references is not implemeted
136             return;
137         }
138 
139         testGroup("Method References", out)
140             // Should resolve references to own constructor
141             .shouldMatch(ALWAYS("method.* ResolvedConstantsApp ResolvedConstantsApp.<init>:"))
142             // Should resolve references to super constructor
143             .shouldMatch(ALWAYS("method.* ResolvedConstantsApp java/lang/Object.<init>:"))
144 
145             // Should resolve interface methods in VM classes
146             .shouldMatch(ALWAYS("interface method .* ResolvedConstantsApp java/lang/Runnable.run:"))
147 
148             // Should resolve references to own non-static method (private or public)
149             .shouldMatch(ALWAYS("method.*: ResolvedConstantsBar ResolvedConstantsBar.doBar:"))
150             .shouldMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.privateInstanceCall:"))
151             .shouldMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.publicInstanceCall:"))
152 
153             // Should not resolve references to static method
154             .shouldNotMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.staticCall:"))

155 
156             // Should resolve references to method in super type
157             .shouldMatch(ALWAYS("method.*: ResolvedConstantsBar ResolvedConstantsFoo.doBar:"))
158 
159             // Without -XX:+AOTClassLinking App class cannot resolve references to methods in boot classes:
160             //    When the app class loader tries to resolve a class X that's normally loaded by
161             //    the boot loader, it's possible for the app class loader to get a different copy of
162             //    X (by using MethodHandles.Lookup.defineClass(), etc). Therefore, let's be on
163             //    the side of safety and revert all such references.
164             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsApp java/io/PrintStream.println:"))
165             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsBar java/lang/Class.getName:"))
166 
167             // Resole resolve methods in unrelated classes ONLY when using -XX:+AOTClassLinking
168             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsApp ResolvedConstantsBar.doit:"))
169 
170           // End ---
171             ;
172 
173 
174         // Indy References ---
175         if (aotClassLinking) {

176             testGroup("Indy References", out)
177                .shouldContain("Cannot aot-resolve Lambda proxy because OldConsumer is excluded")
178                .shouldContain("Cannot aot-resolve Lambda proxy because OldProvider is excluded")
179                .shouldContain("Cannot aot-resolve Lambda proxy because OldClass is excluded")
180                .shouldContain("Cannot aot-resolve Lambda proxy of interface type InterfaceWithClinit")
181                .shouldMatch("klasses.* app *NormalClass[$][$]Lambda/.* hidden aot-linked inited")
182                .shouldNotMatch("klasses.* app *SubOfOldClass[$][$]Lambda/")
183                .shouldMatch("archived indy *CP entry.*StringConcatTest .* => java/lang/invoke/StringConcatFactory.makeConcatWithConstants")
184                .shouldNotMatch("archived indy *CP entry.*StringConcatTestOld .* => java/lang/invoke/StringConcatFactory.makeConcatWithConstants");

185         }
186     }
187 
188     static String ALWAYS(String s) {
189         return ",resolve.*archived " + s;
190     }
191 
192     static String AOTLINK_ONLY(String s) {
193         if (aotClassLinking) {
194             return ALWAYS(s);
195         } else {
196             return ",resolve.*reverted " + s;
197         }
198     }
199 
200     static OutputAnalyzer testGroup(String name, OutputAnalyzer out) {
201         System.out.println("Checking for: " + name);
202         return out;
203     }
204 }

 92                     checkAssemblyOutput(args, out);
 93                 })
 94             .setProductionChecker((OutputAnalyzer out) -> {
 95                     out.shouldContain("Hello ResolvedConstantsApp");
 96                 })
 97             .run(args);
 98     }
 99 
100     static void checkAssemblyOutput(String args[], OutputAnalyzer out) {
101         testGroup("Class References", out)
102             // Always resolve reference when a class references itself
103             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => ResolvedConstantsApp app"))
104 
105             // Always resolve reference when a class references a super class
106             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => java/lang/Object boot"))
107             .shouldMatch(ALWAYS("klass.* ResolvedConstantsBar app => ResolvedConstantsFoo app"))
108 
109             // Always resolve reference when a class references a super interface
110             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => java/lang/Runnable boot"))
111 
112 /** premain allows static method pre-resolution
113             // Without -XX:+AOTClassLinking:
114             //   java/lang/System is in the boot loader but ResolvedConstantsApp is loaded by the app loader.
115             //   Even though System is in the vmClasses list, when ResolvedConstantsApp looks up
116             //   "java/lang/System" in its ConstantPool, the app loader may not have resolved the System
117             //   class yet (i.e., there's no initiaited class entry for System in the app loader's dictionary)
118             .shouldMatch(AOTLINK_ONLY("klass.* ResolvedConstantsApp .*java/lang/System"))
119 **/
120           ;
121 
122         testGroup("Field References", out)
123             // Always resolve references to fields in the current class or super class(es)
124             .shouldMatch(ALWAYS("field.* ResolvedConstantsBar => ResolvedConstantsBar.b:I"))
125             .shouldMatch(ALWAYS("field.* ResolvedConstantsBar => ResolvedConstantsBar.a:I"))
126             .shouldMatch(ALWAYS("field.* ResolvedConstantsBar => ResolvedConstantsFoo.a:I"))
127             .shouldMatch(ALWAYS("field.* ResolvedConstantsFoo => ResolvedConstantsFoo.a:I"))
128 
129             // Resolve field references to child classes ONLY when using -XX:+AOTClassLinking
130             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsFoo => ResolvedConstantsBar.a:I"))
131             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsFoo => ResolvedConstantsBar.b:I"))
132 
133             // Resolve field references to unrelated classes ONLY when using -XX:+AOTClassLinking
134             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsApp => ResolvedConstantsBar.a:I"))
135             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsApp => ResolvedConstantsBar.b:I"));
136 
137         if (args[0].equals("DYNAMIC")) {
138             // AOT resolution of CP methods/indy references is not implemeted
139             return;
140         }
141 
142         testGroup("Method References", out)
143             // Should resolve references to own constructor
144             .shouldMatch(ALWAYS("method.* ResolvedConstantsApp ResolvedConstantsApp.<init>:"))
145             // Should resolve references to super constructor
146             .shouldMatch(ALWAYS("method.* ResolvedConstantsApp java/lang/Object.<init>:"))
147 
148             // Should resolve interface methods in VM classes
149             .shouldMatch(ALWAYS("interface method .* ResolvedConstantsApp java/lang/Runnable.run:"))
150 
151             // Should resolve references to own non-static method (private or public)
152             .shouldMatch(ALWAYS("method.*: ResolvedConstantsBar ResolvedConstantsBar.doBar:"))
153             .shouldMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.privateInstanceCall:"))
154             .shouldMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.publicInstanceCall:"))
155 /** premain allows static method pre-resolution
156             // Should not resolve references to static method
157             .shouldNotMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.staticCall:"))
158 **/
159 
160             // Should resolve references to method in super type
161             .shouldMatch(ALWAYS("method.*: ResolvedConstantsBar ResolvedConstantsFoo.doBar:"))
162 
163             // Without -XX:+AOTClassLinking App class cannot resolve references to methods in boot classes:
164             //    When the app class loader tries to resolve a class X that's normally loaded by
165             //    the boot loader, it's possible for the app class loader to get a different copy of
166             //    X (by using MethodHandles.Lookup.defineClass(), etc). Therefore, let's be on
167             //    the side of safety and revert all such references.
168             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsApp java/io/PrintStream.println:"))
169             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsBar java/lang/Class.getName:"))
170 
171             // Resole resolve methods in unrelated classes ONLY when using -XX:+AOTClassLinking
172             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsApp ResolvedConstantsBar.doit:"))
173 
174           // End ---
175             ;
176 
177 
178         // Indy References ---
179         if (aotClassLinking) {
180 /** premain allows Old classes to be linked
181             testGroup("Indy References", out)
182                .shouldContain("Cannot aot-resolve Lambda proxy because OldConsumer is excluded")
183                .shouldContain("Cannot aot-resolve Lambda proxy because OldProvider is excluded")
184                .shouldContain("Cannot aot-resolve Lambda proxy because OldClass is excluded")
185                .shouldContain("Cannot aot-resolve Lambda proxy of interface type InterfaceWithClinit")
186                .shouldMatch("klasses.* app *NormalClass[$][$]Lambda/.* hidden aot-linked inited")
187                .shouldNotMatch("klasses.* app *SubOfOldClass[$][$]Lambda/")
188                .shouldMatch("archived indy *CP entry.*StringConcatTest .* => java/lang/invoke/StringConcatFactory.makeConcatWithConstants")
189                .shouldNotMatch("archived indy *CP entry.*StringConcatTestOld .* => java/lang/invoke/StringConcatFactory.makeConcatWithConstants");
190 **/
191         }
192     }
193 
194     static String ALWAYS(String s) {
195         return ",resolve.*archived " + s;
196     }
197 
198     static String AOTLINK_ONLY(String s) {
199         if (aotClassLinking) {
200             return ALWAYS(s);
201         } else {
202             return ",resolve.*reverted " + s;
203         }
204     }
205 
206     static OutputAnalyzer testGroup(String name, OutputAnalyzer out) {
207         System.out.println("Checking for: " + name);
208         return out;
209     }
210 }
< prev index next >