< prev index next >

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

Print this page

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

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


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

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

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

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

 89                     checkAssemblyOutput(args, out);
 90                 })
 91             .setProductionChecker((OutputAnalyzer out) -> {
 92                     out.shouldContain("Hello ResolvedConstantsApp");
 93                 })
 94             .run(args);
 95     }
 96 
 97     static void checkAssemblyOutput(String args[], OutputAnalyzer out) {
 98         testGroup("Class References", out)
 99             // Always resolve reference when a class references itself
100             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => ResolvedConstantsApp app"))
101 
102             // Always resolve reference when a class references a super class
103             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => java/lang/Object boot"))
104             .shouldMatch(ALWAYS("klass.* ResolvedConstantsBar app => ResolvedConstantsFoo app"))
105 
106             // Always resolve reference when a class references a super interface
107             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => java/lang/Runnable boot"))
108 
109 /** premain allows static method pre-resolution
110             // Without -XX:+AOTClassLinking:
111             //   java/lang/System is in the boot loader but ResolvedConstantsApp is loaded by the app loader.
112             //   Even though System is in the vmClasses list, when ResolvedConstantsApp looks up
113             //   "java/lang/System" in its ConstantPool, the app loader may not have resolved the System
114             //   class yet (i.e., there's no initiaited class entry for System in the app loader's dictionary)
115             .shouldMatch(AOTLINK_ONLY("klass.* ResolvedConstantsApp .*java/lang/System"))
116 **/
117           ;
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 /** premain allows static method pre-resolution
153             // Should not resolve references to static method
154             .shouldNotMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.staticCall:"))
155 **/
156 
157             // Should resolve references to method in super type
158             .shouldMatch(ALWAYS("method.*: ResolvedConstantsBar ResolvedConstantsFoo.doBar:"))
159 
160             // Without -XX:+AOTClassLinking App class cannot resolve references to methods in boot classes:
161             //    When the app class loader tries to resolve a class X that's normally loaded by
162             //    the boot loader, it's possible for the app class loader to get a different copy of
163             //    X (by using MethodHandles.Lookup.defineClass(), etc). Therefore, let's be on
164             //    the side of safety and revert all such references.
165             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsApp java/io/PrintStream.println:"))
166             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsBar java/lang/Class.getName:"))
167 
168             // Resole resolve methods in unrelated classes ONLY when using -XX:+AOTClassLinking
169             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsApp ResolvedConstantsBar.doit:"))
170 
171           // End ---
172             ;
173 
174 
175         // Indy References ---
176         if (aotClassLinking) {
177 /** premain allows Old classes to be linked
178             testGroup("Indy References", out)
179                .shouldContain("Cannot aot-resolve Lambda proxy because OldConsumer is excluded")
180                .shouldContain("Cannot aot-resolve Lambda proxy because OldProvider is excluded")
181                .shouldContain("Cannot aot-resolve Lambda proxy because OldClass is excluded")
182                .shouldContain("Cannot aot-resolve Lambda proxy of interface type InterfaceWithClinit")
183                .shouldMatch("klasses.* app *NormalClass[$][$]Lambda/.* hidden aot-linked inited")
184                .shouldNotMatch("klasses.* app *SubOfOldClass[$][$]Lambda/")
185                .shouldMatch("archived indy *CP entry.*StringConcatTest .* => java/lang/invoke/StringConcatFactory.makeConcatWithConstants")
186                .shouldNotMatch("archived indy *CP entry.*StringConcatTestOld .* => java/lang/invoke/StringConcatFactory.makeConcatWithConstants");
187 **/
188         }
189     }
190 
191     static String ALWAYS(String s) {
192         return "cds,resolve.*archived " + s;
193     }
194 
195     static String AOTLINK_ONLY(String s) {
196         if (aotClassLinking) {
197             return ALWAYS(s);
198         } else {
199             return "cds,resolve.*reverted " + s;
200         }
201     }
202 
203     static OutputAnalyzer testGroup(String name, OutputAnalyzer out) {
204         System.out.println("Checking for: " + name);
205         return out;
206     }
207 }
< prev index next >