9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23
24 /*
25 * To use ClassUnloadCommon from a sub-process, see hotspot/test/runtime/logging/ClassLoadUnloadTest.java
26 * for an example.
27 */
28
29 import java.io.File;
30 import java.net.MalformedURLException;
31 import java.net.URL;
32 import java.net.URLClassLoader;
33 import java.nio.file.Path;
34 import java.nio.file.Paths;
35 import java.util.ArrayList;
36 import java.util.stream.Stream;
37
38 public class ClassUnloadCommon {
39 public static class TestFailure extends RuntimeException {
40 TestFailure(String msg) {
41 super(msg);
42 }
43 }
44
45 public static void failIf(boolean value, String msg) {
46 if (value) throw new TestFailure("Test failed: " + msg);
47 }
48
|
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23
24 /*
25 * To use ClassUnloadCommon from a sub-process, see hotspot/test/runtime/logging/ClassLoadUnloadTest.java
26 * for an example.
27 */
28
29
30 import java.io.File;
31 import java.io.FileInputStream;
32 import java.io.IOException;
33 import java.net.MalformedURLException;
34 import java.net.URL;
35 import java.net.URLClassLoader;
36 import java.nio.file.Path;
37 import java.nio.file.Paths;
38 import java.util.ArrayList;
39 import java.util.stream.Stream;
40
41 public class ClassUnloadCommon {
42 public static class TestFailure extends RuntimeException {
43 TestFailure(String msg) {
44 super(msg);
45 }
46 }
47
48 public static void failIf(boolean value, String msg) {
49 if (value) throw new TestFailure("Test failed: " + msg);
50 }
51
|
84 c = findClass(cn);
85 } catch (ClassNotFoundException e) {
86 c = getParent().loadClass(cn);
87 }
88
89 }
90 if (resolve) {
91 resolveClass(c);
92 }
93 return c;
94 }
95 }
96 };
97 }
98
99 static URL toURL(Path path) {
100 try {
101 return path.toUri().toURL();
102 } catch (MalformedURLException e) {
103 throw new RuntimeException(e);
104 }
105 }
106 }
|
87 c = findClass(cn);
88 } catch (ClassNotFoundException e) {
89 c = getParent().loadClass(cn);
90 }
91
92 }
93 if (resolve) {
94 resolveClass(c);
95 }
96 return c;
97 }
98 }
99 };
100 }
101
102 static URL toURL(Path path) {
103 try {
104 return path.toUri().toURL();
105 } catch (MalformedURLException e) {
106 throw new RuntimeException(e);
107 }
108 }
109
110 // Get data for pre-compiled class file to load.
111 public static byte[] getClassData(String name) {
112 try {
113 String TempName = name.replaceAll("\\.", "/");
114 String currentDir = System.getProperty("test.classes");
115 String filename = currentDir + File.separator + TempName + ".class";
116 System.out.println("filename is " + filename);
117 FileInputStream fis = new FileInputStream(filename);
118 byte[] b = new byte[5000];
119 int cnt = fis.read(b, 0, 5000);
120 byte[] c = new byte[cnt];
121 for (int i=0; i<cnt; i++) c[i] = b[i];
122 return c;
123 } catch (IOException e) {
124 return null;
125 }
126 }
127 }
|