45 import java.io.File;
46 import java.lang.reflect.Array;
47 import java.lang.reflect.InvocationHandler;
48 import java.lang.reflect.Method;
49 import java.lang.reflect.Proxy;
50 import java.net.URL;
51 import java.net.URLClassLoader;
52 import java.security.ProtectionDomain;
53 import java.util.Map;
54
55 import jdk.jfr.Event;
56 import jdk.test.lib.cds.CDSAppTester;
57 import jdk.test.lib.helpers.ClassFileInstaller;
58 import jdk.test.lib.process.OutputAnalyzer;
59
60 public class ExcludedClasses {
61 static final String appJar = ClassFileInstaller.getJarPath("app.jar");
62 static final String mainClass = "TestApp";
63
64 public static void main(String[] args) throws Exception {
65 Tester tester = new Tester();
66 tester.runAOTWorkflow();
67 }
68
69 static class Tester extends CDSAppTester {
70 public Tester() {
71 super(mainClass);
72 }
73
74 @Override
75 public String classpath(RunMode runMode) {
76 return appJar;
77 }
78
79 @Override
80 public String[] vmArgs(RunMode runMode) {
81 return new String[] {
82 "-Xlog:cds+resolve=trace",
83 };
84 }
85
86 @Override
90 };
91 }
92
93 @Override
94 public void checkExecution(OutputAnalyzer out, RunMode runMode) {
95 if (isDumping(runMode)) {
96 out.shouldNotMatch("cds,resolve.*archived field.*TestApp.Foo => TestApp.Foo.ShouldBeExcluded.f:I");
97 }
98 }
99 }
100 }
101
102 class TestApp {
103 static volatile Object custInstance;
104 static volatile Object custArrayInstance;
105
106 public static void main(String args[]) throws Exception {
107 // In new workflow, classes from custom loaders are passed from the preimage
108 // to the final image. See ClassPrelinker::record_unregistered_klasses().
109 custInstance = initFromCustomLoader();
110 custArrayInstance = Array.newInstance(custInstance.getClass(), 0);
111 System.out.println(custArrayInstance);
112 System.out.println("Counter = " + Foo.hotSpot());
113 }
114
115 static Object initFromCustomLoader() throws Exception {
116 String path = "cust.jar";
117 URL url = new File(path).toURI().toURL();
118 URL[] urls = new URL[] {url};
119 URLClassLoader urlClassLoader =
120 new URLClassLoader("MyLoader", urls, null);
121 Class c = Class.forName("CustyWithLoop", true, urlClassLoader);
122 return c.newInstance();
123 }
124
125 static class MyInvocationHandler implements InvocationHandler {
126 volatile static int cnt;
127
128 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
129 long start = System.currentTimeMillis();
130 while (System.currentTimeMillis() - start < 20) {
|
45 import java.io.File;
46 import java.lang.reflect.Array;
47 import java.lang.reflect.InvocationHandler;
48 import java.lang.reflect.Method;
49 import java.lang.reflect.Proxy;
50 import java.net.URL;
51 import java.net.URLClassLoader;
52 import java.security.ProtectionDomain;
53 import java.util.Map;
54
55 import jdk.jfr.Event;
56 import jdk.test.lib.cds.CDSAppTester;
57 import jdk.test.lib.helpers.ClassFileInstaller;
58 import jdk.test.lib.process.OutputAnalyzer;
59
60 public class ExcludedClasses {
61 static final String appJar = ClassFileInstaller.getJarPath("app.jar");
62 static final String mainClass = "TestApp";
63
64 public static void main(String[] args) throws Exception {
65 {
66 Tester tester = new Tester();
67 tester.run(new String[] {"AOT"} );
68 }
69 {
70 Tester tester = new Tester();
71 tester.run(new String[] {"LEYDEN"} );
72 }
73 }
74
75 static class Tester extends CDSAppTester {
76 public Tester() {
77 super(mainClass);
78 }
79
80 @Override
81 public String classpath(RunMode runMode) {
82 return appJar;
83 }
84
85 @Override
86 public String[] vmArgs(RunMode runMode) {
87 return new String[] {
88 "-Xlog:cds+resolve=trace",
89 };
90 }
91
92 @Override
96 };
97 }
98
99 @Override
100 public void checkExecution(OutputAnalyzer out, RunMode runMode) {
101 if (isDumping(runMode)) {
102 out.shouldNotMatch("cds,resolve.*archived field.*TestApp.Foo => TestApp.Foo.ShouldBeExcluded.f:I");
103 }
104 }
105 }
106 }
107
108 class TestApp {
109 static volatile Object custInstance;
110 static volatile Object custArrayInstance;
111
112 public static void main(String args[]) throws Exception {
113 // In new workflow, classes from custom loaders are passed from the preimage
114 // to the final image. See ClassPrelinker::record_unregistered_klasses().
115 custInstance = initFromCustomLoader();
116 custArrayInstance = java.lang.reflect.Array.newInstance(custInstance.getClass(), 0);
117 System.out.println(custArrayInstance);
118 System.out.println("Counter = " + Foo.hotSpot());
119 }
120
121 static Object initFromCustomLoader() throws Exception {
122 String path = "cust.jar";
123 URL url = new File(path).toURI().toURL();
124 URL[] urls = new URL[] {url};
125 URLClassLoader urlClassLoader =
126 new URLClassLoader("MyLoader", urls, null);
127 Class c = Class.forName("CustyWithLoop", true, urlClassLoader);
128 return c.newInstance();
129 }
130
131 static class MyInvocationHandler implements InvocationHandler {
132 volatile static int cnt;
133
134 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
135 long start = System.currentTimeMillis();
136 while (System.currentTimeMillis() - start < 20) {
|