jdk/test/java/lang/StackWalker/LocalsCrash.java
changeset 43774 fa3e76b47782
parent 43773 8d8593871575
parent 43753 acab82802f8a
child 43775 73a0b9362c98
equal deleted inserted replaced
43773:8d8593871575 43774:fa3e76b47782
     1 /*
       
     2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8147039
       
    27  * @summary Test for -Xcomp crash that happened before 8147039 fix
       
    28  * @modules java.base/java.lang:open
       
    29  * @run testng/othervm -Xcomp LocalsCrash
       
    30  */
       
    31 
       
    32 import org.testng.annotations.*;
       
    33 import java.lang.reflect.*;
       
    34 import java.util.List;
       
    35 import java.util.stream.Collectors;
       
    36 
       
    37 public class LocalsCrash {
       
    38     static Class<?> liveStackFrameClass;
       
    39     static Method getStackWalker;
       
    40 
       
    41     static {
       
    42         try {
       
    43             liveStackFrameClass = Class.forName("java.lang.LiveStackFrame");
       
    44             getStackWalker = liveStackFrameClass.getMethod("getStackWalker");
       
    45             getStackWalker.setAccessible(true);
       
    46         } catch (Throwable t) { throw new RuntimeException(t); }
       
    47     }
       
    48 
       
    49     private StackWalker walker;
       
    50 
       
    51     LocalsCrash() {
       
    52         try {
       
    53             walker = (StackWalker) getStackWalker.invoke(null);
       
    54         } catch (Exception e) { throw new RuntimeException(e); }
       
    55     }
       
    56 
       
    57     @Test
       
    58     public void test00() { doStackWalk(); }
       
    59 
       
    60     @Test
       
    61     public void test01() { doStackWalk(); }
       
    62 
       
    63     private synchronized List<StackWalker.StackFrame> doStackWalk() {
       
    64         try {
       
    65             // Unused local variables will become dead
       
    66             int x = 10;
       
    67             char c = 'z';
       
    68             String hi = "himom";
       
    69             long l = 1000000L;
       
    70             double d =  3.1415926;
       
    71 
       
    72             return walker.walk(s -> s.collect(Collectors.toList()));
       
    73         } catch (Exception e) { throw new RuntimeException(e); }
       
    74     }
       
    75 }