author | amurillo |
Fri, 06 May 2016 06:23:29 -0700 | |
changeset 38208 | ff63d43b0480 |
parent 38152 | 80e5da81fb2c |
child 40631 | ed82623d7831 |
permissions | -rw-r--r-- |
37440
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
1 |
/* |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
4 |
* |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
8 |
* |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
13 |
* accompanied this code). |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
14 |
* |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
18 |
* |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
21 |
* questions. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
22 |
*/ |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
23 |
|
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
24 |
/* |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
25 |
* @test |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
26 |
* @bug 8033735 |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
27 |
* @summary check backtrace field introspection |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
37440
diff
changeset
|
28 |
* @modules java.base/jdk.internal.misc |
37440
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
29 |
* @library /testlibrary |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
30 |
* @run main ThrowableIntrospectionSegfault |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
31 |
*/ |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
32 |
|
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
33 |
import java.lang.reflect.*; |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
34 |
|
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
35 |
public class ThrowableIntrospectionSegfault { |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
36 |
public static void main(java.lang.String[] unused) { |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
37 |
// Construct a throwable object. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
38 |
Throwable throwable = new Throwable(); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
39 |
throwable.fillInStackTrace(); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
40 |
|
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
41 |
// Retrieve a reflection handle to the private backtrace field. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
42 |
Class class1 = throwable.getClass(); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
43 |
Field field; |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
44 |
try { |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
45 |
field = class1.getDeclaredField("backtrace"); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
46 |
} |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
47 |
catch (NoSuchFieldException e) { |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
48 |
System.err.println("Can't retrieve field handle Throwable.backtrace: " + e.toString()); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
49 |
return; |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
50 |
} |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
51 |
field.setAccessible(true); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
52 |
|
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
53 |
// Retrieve the value of the backtrace field. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
54 |
Object backtrace; |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
55 |
try { |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
56 |
backtrace = field.get(throwable); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
57 |
} |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
58 |
catch (IllegalAccessException e) { |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
59 |
System.err.println( "Can't retrieve field value for Throwable.backtrace: " + e.toString()); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
60 |
return; |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
61 |
} |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
62 |
|
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
63 |
try { |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
64 |
|
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
65 |
// Retrieve the class of throwable.backtrace[0][0]. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
66 |
Class class2 = ((Object[]) ((Object[]) backtrace)[2])[0].getClass(); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
67 |
|
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
68 |
// Segfault occurs while executing this line, to retrieve the name of |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
69 |
// this class. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
70 |
String class2Name = class2.getName(); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
71 |
|
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
72 |
System.err.println("class2Name=" + class2Name); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
73 |
return; // pass! Passes if it doesn't crash. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
74 |
} catch (ClassCastException e) { |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
75 |
// Passes if it doesn't crash. Also if the backtrace changes this test might get |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
76 |
// ClassCastException and that's ok too. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
77 |
System.out.println("Catch exception " + e); |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
78 |
return; // pass! Passes if it doesn't crash. |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
79 |
} |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
80 |
} |
eea810d6f788
8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff
changeset
|
81 |
} |