10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8151486
27 * @summary Call Class.forName() on the system classloader from a class loaded
28 * from a custom classloader.
29 * @library /lib/testlibrary
30 * @build jdk.testlibrary.Utils JarUtils
31 * @build ClassForName ClassForNameLeak
32 * @run main/othervm/policy=test.policy -Djava.security.manager ClassForNameLeak
33 */
34
35 import java.io.IOException;
36 import java.lang.ref.PhantomReference;
37 import java.lang.ref.Reference;
38 import java.lang.ref.ReferenceQueue;
39 import java.net.MalformedURLException;
40 import java.net.URL;
41 import java.net.URLClassLoader;
42 import java.nio.file.Path;
43 import java.nio.file.Paths;
44 import java.util.List;
45 import java.util.concurrent.Callable;
46 import java.util.concurrent.ExecutorService;
47 import java.util.concurrent.Executors;
48 import java.util.concurrent.Future;
49 import java.util.stream.Collectors;
50 import java.util.stream.Stream;
51 import jdk.testlibrary.Utils;
52
53 /*
54 * Create .jar, load ClassForName from .jar using a URLClassLoader
55 */
56 public class ClassForNameLeak {
57 private static final long TIMEOUT = (long)(5000.0 * Utils.TIMEOUT_FACTOR);
58 private static final int THREADS = 10;
59 private static final Path jarFilePath = Paths.get("cfn.jar");
60 private static final ReferenceQueue<ClassLoader> rq = new ReferenceQueue<>();
61
62 static class TestLoader {
63 private final PhantomReference<ClassLoader> ref;
64 TestLoader() {
65 this.ref = loadAndRun();
66 }
67
68 // Use a new classloader to load the ClassForName class, then run its
69 // Runnable.
70 PhantomReference<ClassLoader> loadAndRun() {
71 try {
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8151486
27 * @summary Call Class.forName() on the system classloader from a class loaded
28 * from a custom classloader.
29 * @library /lib/testlibrary
30 * @library /test/lib
31 * @build jdk.test.lib.Utils JarUtils
32 * @build ClassForName ClassForNameLeak
33 * @run main/othervm/policy=test.policy -Djava.security.manager ClassForNameLeak
34 */
35
36 import java.io.IOException;
37 import java.lang.ref.PhantomReference;
38 import java.lang.ref.Reference;
39 import java.lang.ref.ReferenceQueue;
40 import java.net.MalformedURLException;
41 import java.net.URL;
42 import java.net.URLClassLoader;
43 import java.nio.file.Path;
44 import java.nio.file.Paths;
45 import java.util.List;
46 import java.util.concurrent.Callable;
47 import java.util.concurrent.ExecutorService;
48 import java.util.concurrent.Executors;
49 import java.util.concurrent.Future;
50 import java.util.stream.Collectors;
51 import java.util.stream.Stream;
52 import jdk.test.lib.Utils;
53
54 /*
55 * Create .jar, load ClassForName from .jar using a URLClassLoader
56 */
57 public class ClassForNameLeak {
58 private static final long TIMEOUT = (long)(5000.0 * Utils.TIMEOUT_FACTOR);
59 private static final int THREADS = 10;
60 private static final Path jarFilePath = Paths.get("cfn.jar");
61 private static final ReferenceQueue<ClassLoader> rq = new ReferenceQueue<>();
62
63 static class TestLoader {
64 private final PhantomReference<ClassLoader> ref;
65 TestLoader() {
66 this.ref = loadAndRun();
67 }
68
69 // Use a new classloader to load the ClassForName class, then run its
70 // Runnable.
71 PhantomReference<ClassLoader> loadAndRun() {
72 try {
|