< prev index next >

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

Print this page

 70                        "-Xlog:cds+class=debug");
 71         if (aotClassLinking) {
 72             opts.addPrefix("-XX:+AOTClassLinking");
 73         } else {
 74             opts.addPrefix("-XX:-AOTClassLinking");
 75         }
 76 
 77         OutputAnalyzer out = CDSTestUtils.createArchiveAndCheck(opts);
 78           // Class References ---
 79 
 80             // Always resolve reference when a class references itself
 81         out.shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => ResolvedConstantsApp app"))
 82 
 83             // Always resolve reference when a class references a super class
 84             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => java/lang/Object boot"))
 85             .shouldMatch(ALWAYS("klass.* ResolvedConstantsBar app => ResolvedConstantsFoo app"))
 86 
 87             // Always resolve reference when a class references a super interface
 88             .shouldMatch(ALWAYS("klass.* ResolvedConstantsApp app => java/lang/Runnable boot"))
 89 

 90             // Without -XX:+AOTClassLinking:
 91             //   java/lang/System is in the boot loader but ResolvedConstantsApp is loaded by the app loader.
 92             //   Even though System is in the vmClasses list, when ResolvedConstantsApp looks up
 93             //   "java/lang/System" in its ConstantPool, the app loader may not have resolved the System
 94             //   class yet (i.e., there's no initiaited class entry for System in the app loader's dictionary)
 95             .shouldMatch(AOTLINK_ONLY("klass.* ResolvedConstantsApp .*java/lang/System"))
 96 
 97           // Field References ---
 98 
 99             // Always resolve references to fields in the current class or super class(es)
100             .shouldMatch(ALWAYS("field.* ResolvedConstantsBar => ResolvedConstantsBar.b:I"))
101             .shouldMatch(ALWAYS("field.* ResolvedConstantsBar => ResolvedConstantsBar.a:I"))
102             .shouldMatch(ALWAYS("field.* ResolvedConstantsBar => ResolvedConstantsFoo.a:I"))
103             .shouldMatch(ALWAYS("field.* ResolvedConstantsFoo => ResolvedConstantsFoo.a:I"))
104 
105             // Resolve field references to child classes ONLY when using -XX:+AOTClassLinking
106             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsFoo => ResolvedConstantsBar.a:I"))
107             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsFoo => ResolvedConstantsBar.b:I"))
108 
109             // Resolve field references to unrelated classes ONLY when using -XX:+AOTClassLinking
110             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsApp => ResolvedConstantsBar.a:I"))
111             .shouldMatch(AOTLINK_ONLY("field.* ResolvedConstantsApp => ResolvedConstantsBar.b:I"))
112 
113           // Method References ---
114 
115             // Should resolve references to own constructor
116             .shouldMatch(ALWAYS("method.* ResolvedConstantsApp ResolvedConstantsApp.<init>:"))
117             // Should resolve references to super constructor
118             .shouldMatch(ALWAYS("method.* ResolvedConstantsApp java/lang/Object.<init>:"))
119 
120             // Should resolve interface methods in VM classes
121             .shouldMatch(ALWAYS("interface method .* ResolvedConstantsApp java/lang/Runnable.run:"))
122 
123             // Should resolve references to own non-static method (private or public)
124             .shouldMatch(ALWAYS("method.*: ResolvedConstantsBar ResolvedConstantsBar.doBar:"))
125             .shouldMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.privateInstanceCall:"))
126             .shouldMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.publicInstanceCall:"))
127 
128             // Should not resolve references to static method
129             .shouldNotMatch(ALWAYS("method.*: ResolvedConstantsApp ResolvedConstantsApp.staticCall:"))

130 
131             // Should resolve references to method in super type
132             .shouldMatch(ALWAYS("method.*: ResolvedConstantsBar ResolvedConstantsFoo.doBar:"))
133 
134             // Without -XX:+AOTClassLinking App class cannot resolve references to methods in boot classes:
135             //    When the app class loader tries to resolve a class X that's normally loaded by
136             //    the boot loader, it's possible for the app class loader to get a different copy of
137             //    X (by using MethodHandles.Lookup.defineClass(), etc). Therefore, let's be on
138             //    the side of safety and revert all such references.
139             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsApp java/io/PrintStream.println:"))
140             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsBar java/lang/Class.getName:"))
141 
142             // Resole resolve methods in unrelated classes ONLY when using -XX:+AOTClassLinking
143             .shouldMatch(AOTLINK_ONLY("method.*: ResolvedConstantsApp ResolvedConstantsBar.doit:"))
144 
145           // End ---
146             ;
147 
148 
149         // Indy References ---
150         if (aotClassLinking) {

151             out.shouldContain("Cannot aot-resolve Lambda proxy because OldConsumer is excluded")
152                .shouldContain("Cannot aot-resolve Lambda proxy because OldProvider is excluded")
153                .shouldContain("Cannot aot-resolve Lambda proxy because OldClass is excluded")
154                .shouldContain("Cannot aot-resolve Lambda proxy of interface type InterfaceWithClinit")
155                .shouldMatch("klasses.* app *NormalClass[$][$]Lambda/.* hidden aot-linked inited")
156                .shouldNotMatch("klasses.* app *SubOfOldClass[$][$]Lambda/")
157                .shouldMatch("archived indy *CP entry.*StringConcatTest .* => java/lang/invoke/StringConcatFactory.makeConcatWithConstants")
158                .shouldNotMatch("archived indy *CP entry.*StringConcatTestOld .* => java/lang/invoke/StringConcatFactory.makeConcatWithConstants");

159         }
160     }
161 
162     static String ALWAYS(String s) {
163         return "cds,resolve.*archived " + s;
164     }
165 
166     static String AOTLINK_ONLY(String s) {
167         if (aotClassLinking) {
168             return ALWAYS(s);
169         } else {
170             return "cds,resolve.*reverted " + s;
171         }
172     }
173 }
174 
175 class ResolvedConstantsApp implements Runnable {
176     public static void main(String args[]) {
177         System.out.println("Hello ResolvedConstantsApp");
178         ResolvedConstantsApp app = new ResolvedConstantsApp();

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