author | egahlin |
Tue, 26 Nov 2019 17:00:57 +0100 | |
changeset 59274 | eb3e2a5c2bcd |
parent 50219 | 4ab066d71956 |
permissions | -rw-r--r-- |
50219
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
1 |
/* |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
4 |
* |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
8 |
* |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
13 |
* accompanied this code). |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
14 |
* |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
18 |
* |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
21 |
* questions. |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
22 |
*/ |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
23 |
/* |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
24 |
* @test |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
25 |
* @bug 6194361 |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
26 |
* @bug 8202669 |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
27 |
* @summary Make sure the VM doesn't crash and throws a SecurityException |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
28 |
* if defineClass() is called on a byte buffer that parses into a invalid |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
29 |
* java.lang.Object class. |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
30 |
* Also, make sure the vm doesn't crash on notification for unloading an invalid |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
31 |
* java.lang.Object class. |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
32 |
* @library /runtime/testlibrary /test/lib |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
33 |
* @modules java.base/jdk.internal.misc |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
34 |
* java.compiler |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
35 |
* @run main TestUnloadClassError |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
36 |
*/ |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
37 |
|
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
38 |
import jdk.test.lib.compiler.InMemoryJavaCompiler; |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
39 |
|
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
40 |
public class TestUnloadClassError extends ClassLoader { |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
41 |
|
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
42 |
static String source = |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
43 |
" package java.lang;" + |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
44 |
" public class Object" + |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
45 |
" {" + |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
46 |
" int field;" + |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
47 |
" public boolean equals(Object o) {" + |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
48 |
" System.out.println(o.field);" + |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
49 |
" return false;" + |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
50 |
" }" + |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
51 |
" }"; |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
52 |
|
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
53 |
public static void main(String[] args) throws Exception |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
54 |
{ |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
55 |
try { |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
56 |
TestUnloadClassError loader = new TestUnloadClassError(); |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
57 |
byte[] buf = InMemoryJavaCompiler.compile("java.lang.Object", source, |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
58 |
"--patch-module=java.base"); |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
59 |
Class c = loader.defineClass(buf, 0, buf.length); |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
60 |
System.out.println("test FAILS"); |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
61 |
throw new RuntimeException("Did not get security exception"); |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
62 |
} catch(SecurityException e) { |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
63 |
System.out.println("test expects SecurityException"); |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
64 |
} |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
65 |
|
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
66 |
// Unload bad class |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
67 |
ClassUnloadCommon.triggerUnloading(); |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
68 |
System.out.println("test PASSES if it doesn't crash"); |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
69 |
} |
4ab066d71956
8202669: Intermittent crash in ClassLoadingService::compute_class_size()
coleenp
parents:
diff
changeset
|
70 |
} |