jdk/test/java/lang/StackWalker/CountLocalSlots.java
changeset 43840 499bdc13c435
parent 43839 b002a92940ff
parent 43838 d696d6394a37
child 43842 ce5b78554c67
equal deleted inserted replaced
43839:b002a92940ff 43840:499bdc13c435
     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 Confirm locals[] always has expected length, even for "dead" locals
       
    28  * @modules java.base/java.lang:open
       
    29  * @compile LocalsAndOperands.java
       
    30  * @run testng/othervm -Xcomp CountLocalSlots
       
    31  */
       
    32 
       
    33 import org.testng.annotations.Test;
       
    34 import java.lang.StackWalker.StackFrame;
       
    35 
       
    36 public class CountLocalSlots {
       
    37     final static boolean debug = true;
       
    38 
       
    39     @Test(dataProvider = "provider", dataProviderClass = LocalsAndOperands.class)
       
    40     public void countLocalSlots(StackFrame... frames) {
       
    41         for (StackFrame frame : frames) {
       
    42             if (debug) {
       
    43                 System.out.println("Running countLocalSlots");
       
    44                 LocalsAndOperands.dumpStackWithLocals(frames);
       
    45             }
       
    46             // Confirm expected number of locals
       
    47             String methodName = frame.getMethodName();
       
    48             Integer expectedObj = (Integer) LocalsAndOperands.Tester.NUM_LOCALS.get(methodName);
       
    49             if (expectedObj == null) {
       
    50                 if (!debug) { LocalsAndOperands.dumpStackWithLocals(frames); }
       
    51                 throw new RuntimeException("No NUM_LOCALS entry for " +
       
    52                         methodName + "().  Update test?");
       
    53             }
       
    54             Object[] locals = (Object[]) LocalsAndOperands.invokeGetLocals(frame);
       
    55             if (locals.length != expectedObj) {
       
    56                 if (!debug) { LocalsAndOperands.dumpStackWithLocals(frames); }
       
    57                 throw new RuntimeException(methodName + "(): number of locals (" +
       
    58                         locals.length + ") did not match expected (" + expectedObj + ")");
       
    59             }
       
    60         }
       
    61     }
       
    62 }