jdk/test/java/lang/StackWalker/CountLocalSlots.java
author bchristi
Thu, 05 May 2016 11:44:01 -0700
changeset 38347 a3fdbd11148f
child 40684 2e37c119dc2a
permissions -rw-r--r--
8147039: Incorrect locals and operands in compiled frames Summary: Implement stack walking using javaVFrame instead of vframeStream Reviewed-by: mchung, vlivanov
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
/*
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
     2
 * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
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
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    28
 * @compile LocalsAndOperands.java
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    29
 * @run testng/othervm -Xcomp CountLocalSlots
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    30
 */
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
import org.testng.annotations.Test;
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    33
import java.lang.StackWalker.StackFrame;
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    34
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    35
public class CountLocalSlots {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    36
    final static boolean debug = true;
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    37
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    38
    @Test(dataProvider = "provider", dataProviderClass = LocalsAndOperands.class)
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    39
    public void countLocalSlots(StackFrame... frames) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    40
        for (StackFrame frame : frames) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    41
            if (debug) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    42
                System.out.println("Running countLocalSlots");
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    43
                LocalsAndOperands.dumpStackWithLocals(frames);
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    44
            }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    45
            // Confirm expected number of locals
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    46
            String methodName = frame.getMethodName();
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    47
            Integer expectedObj = (Integer) LocalsAndOperands.Tester.NUM_LOCALS.get(methodName);
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    48
            if (expectedObj == null) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    49
                if (!debug) { LocalsAndOperands.dumpStackWithLocals(frames); }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    50
                throw new RuntimeException("No NUM_LOCALS entry for " +
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    51
                        methodName + "().  Update test?");
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    52
            }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    53
            Object[] locals = (Object[]) LocalsAndOperands.invokeGetLocals(frame);
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    54
            if (locals.length != expectedObj) {
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    55
                if (!debug) { LocalsAndOperands.dumpStackWithLocals(frames); }
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    56
                throw new RuntimeException(methodName + "(): number of locals (" +
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    57
                        locals.length + ") did not match expected (" + expectedObj + ")");
a3fdbd11148f 8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
diff changeset
    58
            }
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
}