jdk/test/java/lang/StackWalker/CountLocalSlots.java
author alanb
Thu, 01 Dec 2016 08:57:53 +0000
changeset 42338 a60f280f803c
parent 40684 2e37c119dc2a
permissions -rw-r--r--
8169069: Module system implementation refresh (11/2016) Reviewed-by: plevart, chegar, psandoz, mchung, alanb, dfuchs, naoto, coffeys, weijun Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, claes.redestad@oracle.com, mark.reinhold@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38347
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
     1
/*
40684
2e37c119dc2a 8164982: Fix legal notices in java/lang, java/net, java/util tests.
shurailine
parents: 38347
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
38347
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
     4
 *
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
     8
 *
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    13
 * accompanied this code).
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    14
 *
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    18
 *
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    21
 * questions.
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    22
 */
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    23
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    24
/*
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    25
 * @test
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    26
 * @bug 8147039
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    27
 * @summary Confirm locals[] always has expected length, even for "dead" locals
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40684
diff changeset
    28
 * @modules java.base/java.lang:open
38347
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    29
 * @compile LocalsAndOperands.java
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    30
 * @run testng/othervm -Xcomp CountLocalSlots
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    31
 */
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    32
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    33
import org.testng.annotations.Test;
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    34
import java.lang.StackWalker.StackFrame;
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    35
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    36
public class CountLocalSlots {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    37
    final static boolean debug = true;
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    38
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    39
    @Test(dataProvider = "provider", dataProviderClass = LocalsAndOperands.class)
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    40
    public void countLocalSlots(StackFrame... frames) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    41
        for (StackFrame frame : frames) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    42
            if (debug) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    43
                System.out.println("Running countLocalSlots");
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    44
                LocalsAndOperands.dumpStackWithLocals(frames);
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    45
            }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    46
            // Confirm expected number of locals
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    47
            String methodName = frame.getMethodName();
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    48
            Integer expectedObj = (Integer) LocalsAndOperands.Tester.NUM_LOCALS.get(methodName);
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    49
            if (expectedObj == null) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    50
                if (!debug) { LocalsAndOperands.dumpStackWithLocals(frames); }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    51
                throw new RuntimeException("No NUM_LOCALS entry for " +
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    52
                        methodName + "().  Update test?");
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    53
            }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    54
            Object[] locals = (Object[]) LocalsAndOperands.invokeGetLocals(frame);
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    55
            if (locals.length != expectedObj) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    56
                if (!debug) { LocalsAndOperands.dumpStackWithLocals(frames); }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    57
                throw new RuntimeException(methodName + "(): number of locals (" +
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    58
                        locals.length + ") did not match expected (" + expectedObj + ")");
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    59
            }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    60
        }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    61
    }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    62
}