hotspot/test/runtime/Throwable/ThrowableIntrospectionSegfault.java
author stsmirno
Mon, 17 Oct 2016 18:54:12 -0400
changeset 41705 332239c052cc
parent 40631 ed82623d7831
child 42307 cefc81dc1d52
permissions -rw-r--r--
8165687: Fix license and copyright headers in jd9 under hotspot/test Summary: Legal notices and Oracle copyrights were updated (white and blank space, commas) in tests files for uniformity to meet Oracle requirements. Reviewed-by: dholmes, iris Contributed-by: Stanislav Smirnov <stanislav.smirnov@oracle.com>, Vassili Igouchkine <vassili.igouchkine@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
37440
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
 * @run main ThrowableIntrospectionSegfault
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    30
 */
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
import java.lang.reflect.*;
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    33
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    34
public class ThrowableIntrospectionSegfault {
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    35
    public static void main(java.lang.String[] unused) {
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    36
        // Construct a throwable object.
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    37
        Throwable throwable = new Throwable();
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    38
        throwable.fillInStackTrace();
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    39
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    40
        // Retrieve a reflection handle to the private backtrace field.
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    41
        Class class1 = throwable.getClass();
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    42
        Field field;
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    43
        try {
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    44
            field = class1.getDeclaredField("backtrace");
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    45
        }
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    46
        catch (NoSuchFieldException e) {
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    47
            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
    48
            return;
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    49
        }
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    50
        field.setAccessible(true);
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    51
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    52
        // Retrieve the value of the backtrace field.
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    53
        Object backtrace;
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    54
        try {
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    55
            backtrace = field.get(throwable);
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    56
        }
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    57
        catch (IllegalAccessException e) {
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    58
            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
    59
            return;
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    60
        }
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
        try {
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    63
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    64
            // Retrieve the class of throwable.backtrace[0][0].
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    65
            Class class2 = ((Object[]) ((Object[]) backtrace)[2])[0].getClass();
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    66
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    67
            // 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
    68
            // this class.
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    69
            String class2Name = class2.getName();
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    70
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    71
            System.err.println("class2Name=" + class2Name);
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    72
            return;  // pass!   Passes if it doesn't crash.
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    73
        } catch (ClassCastException e) {
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    74
            // 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
    75
            // ClassCastException and that's ok too.
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    76
            System.out.println("Catch exception " + e);
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    77
            return;  // pass!   Passes if it doesn't crash.
eea810d6f788 8033735: make Throwable.backtrace visible to Class.getDeclaredField again
coleenp
parents:
diff changeset
    78
        }
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
}