Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/instrument/DaemonThread/TestDaemonThread.java
38828 views
1
/*
2
* Copyright 2014 Goldman Sachs.
3
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*/
24
/* @test
25
* @bug 7142035
26
* @summary Assert in java.lang.instrument agents during shutdown when classloading occurs after shutdown
27
* @library /lib/testlibrary
28
*
29
* @build jdk.testlibrary.* DummyAgent DummyClass TestDaemonThreadLauncher TestDaemonThread
30
* @run shell ../MakeJAR3.sh DummyAgent
31
* @run main/timeout=240 TestDaemonThreadLauncher
32
*
33
*/
34
import java.io.File;
35
import java.net.URL;
36
import java.net.URLClassLoader;
37
38
public class TestDaemonThread implements Runnable{
39
File classpath;
40
41
public TestDaemonThread(File classpath) {
42
this.classpath = classpath;
43
}
44
45
@Override
46
public void run() {
47
48
49
try {
50
URL u = this.getClass().getClassLoader().getResource("DummyClass.class");
51
String path = u.getPath();
52
String parent = u.getPath().substring(0, path.lastIndexOf('/')+1);
53
URL parentURL = new URL(u, parent);
54
System.out.println(parentURL);
55
/* Load lots of class by creating multiple classloaders */
56
for(;;) {
57
ClassLoader cl = new URLClassLoader(new URL[] {parentURL}, null);
58
cl.loadClass("DummyClass");
59
}
60
} catch (Exception e) {
61
e.printStackTrace();
62
}
63
}
64
65
public static void main(String[] args) throws Exception {
66
Thread t = new Thread(new TestDaemonThread(new File(args[0])));
67
/* The important part of the bug is that a Daemon thread can continue to load classes after shutdown */
68
t.setDaemon(true);
69
t.start();
70
Thread.sleep(200);
71
}
72
}
73
74