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