annotate test/runtime/testlibrary/ClassUnloadCommon.java @ 18781:941761f6b736

Truffle-DSL: fixed thrown exception messages should provide more contextual information. (reported by Benoit Daloze)
author Christian Humer <christian.humer@gmail.com>
date Mon, 05 Jan 2015 20:23:22 +0100
parents 33bcd9ead1d5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10230
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
1 /*
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
4 *
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
7 * published by the Free Software Foundation.
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
8 *
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
13 * accompanied this code).
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
14 *
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
18 *
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
21 * questions.
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
22 */
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
23
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
24 import java.io.File;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
25 import java.net.MalformedURLException;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
26 import java.net.URL;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
27 import java.net.URLClassLoader;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
28 import java.nio.file.Paths;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
29 import java.util.ArrayList;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
30
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
31 public class ClassUnloadCommon {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
32 public static class TestFailure extends RuntimeException {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
33 TestFailure(String msg) {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
34 super(msg);
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
35 }
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
36 }
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
37
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
38 public static void failIf(boolean value, String msg) {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
39 if (value) throw new TestFailure("Test failed: " + msg);
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
40 }
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
41
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
42 private static volatile Object dummy = null;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
43 private static void allocateMemory(int kilobytes) {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
44 ArrayList<byte[]> l = new ArrayList<>();
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
45 dummy = l;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
46 for (int i = kilobytes; i > 0; i -= 1) {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
47 l.add(new byte[1024]);
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
48 }
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
49 l = null;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
50 dummy = null;
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
51 }
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
52
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
53 public static void triggerUnloading() {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
54 allocateMemory(16 * 1024); // yg size is 8m with cms, force young collection
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
55 System.gc();
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
56 }
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
57
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
58 public static ClassLoader newClassLoader() {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
59 try {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
60 return new URLClassLoader(new URL[] {
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
61 Paths.get(System.getProperty("test.classes",".") + File.separatorChar + "classes").toUri().toURL(),
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
62 }, null);
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
63 } catch (MalformedURLException e){
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
64 throw new RuntimeException("Unexpected URL conversion failure", e);
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
65 }
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
66 }
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
67
33bcd9ead1d5 8009577: Test test/closed/runtime/classunload broken
ctornqvi
parents:
diff changeset
68 }