jdk/src/java.base/share/classes/java/lang/LiveStackFrame.java
author rriggs
Tue, 16 Feb 2016 11:36:20 -0500
changeset 35978 752d505da547
parent 34934 7fbff68dbc12
child 43715 6d72cc84759f
permissions -rw-r--r--
8148775: Spec for j.l.ProcessBuilder.Redirect.DISCARD need to be improved Reviewed-by: martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     1
/*
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     4
 *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    10
 *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    15
 * accompanied this code).
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    16
 *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    20
 *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    23
 * questions.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    24
 */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    25
package java.lang;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    26
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    27
import java.lang.StackWalker.StackFrame;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    28
import java.util.EnumSet;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    29
import java.util.Set;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    30
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    31
import static java.lang.StackWalker.ExtendedOption.LOCALS_AND_OPERANDS;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    32
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    33
/**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    34
 * <em>UNSUPPORTED</em> This interface is intended to be package-private
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    35
 * or move to an internal package.<p>
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    36
 *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    37
 * {@code LiveStackFrame} represents a frame storing data and partial results.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    38
 * Each frame has its own array of local variables (JVMS section 2.6.1),
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    39
 * its own operand stack (JVMS section 2.6.2) for a method invocation.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    40
 *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    41
 * @jvms 2.6 Frames
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    42
 */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    43
/* package-private */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    44
interface LiveStackFrame extends StackFrame {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    45
    /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    46
     * Return the monitors held by this stack frame. This method returns
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    47
     * an empty array if no monitor is held by this stack frame.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    48
     *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    49
     * @return the monitors held by this stack frames
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    50
     */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    51
    public Object[] getMonitors();
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    52
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    53
    /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    54
     * Gets the local variable array of this stack frame.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    55
     *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    56
     * <p>A single local variable can hold a value of type boolean, byte, char,
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    57
     * short, int, float, reference or returnAddress.  A pair of local variables
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    58
     * can hold a value of type long or double.  In other words,
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    59
     * a value of type long or type double occupies two consecutive local
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    60
     * variables.  For a value of primitive type, the element in the
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    61
     * local variable array is an {@link PrimitiveValue} object;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    62
     * otherwise, the element is an {@code Object}.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    63
     *
34934
7fbff68dbc12 8144552: java/lang/StackWalker/LocalsAndOperands.java fails with java.lang.NullPointerException
bchristi
parents: 34362
diff changeset
    64
     * <p>The returned array may contain null entries if a local variable is not
7fbff68dbc12 8144552: java/lang/StackWalker/LocalsAndOperands.java fails with java.lang.NullPointerException
bchristi
parents: 34362
diff changeset
    65
     * live.
7fbff68dbc12 8144552: java/lang/StackWalker/LocalsAndOperands.java fails with java.lang.NullPointerException
bchristi
parents: 34362
diff changeset
    66
     *
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    67
     * @return  the local variable array of this stack frame.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    68
     */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    69
    public Object[] getLocals();
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    70
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    71
    /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    72
     * Gets the operand stack of this stack frame.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    73
     *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    74
     * <p>
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    75
     * The 0-th element of the returned array represents the top of the operand stack.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    76
     * This method returns an empty array if the operand stack is empty.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    77
     *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    78
     * <p>Each entry on the operand stack can hold a value of any Java Virtual
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    79
     * Machine Type.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    80
     * For a value of primitive type, the element in the returned array is
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    81
     * an {@link PrimitiveValue} object; otherwise, the element is the {@code Object}
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    82
     * on the operand stack.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    83
     *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    84
     * @return the operand stack of this stack frame.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    85
     */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    86
    public Object[] getStack();
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    87
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    88
    /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    89
     * <em>UNSUPPORTED</em> This interface is intended to be package-private
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    90
     * or move to an internal package.<p>
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    91
     *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    92
     * Represents a local variable or an entry on the operand whose value is
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    93
     * of primitive type.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    94
     */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    95
    public abstract class PrimitiveValue {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    96
        /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    97
         * Returns the base type of this primitive value, one of
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    98
         * {@code B, D, C, F, I, J, S, Z}.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    99
         *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   100
         * @return Name of a base type
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   101
         * @jvms table 4.3-A
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   102
         */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   103
        abstract char type();
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   104
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   105
        /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   106
         * Returns the boolean value if this primitive value is of type boolean.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   107
         * @return the boolean value if this primitive value is of type boolean.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   108
         *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   109
         * @throws UnsupportedOperationException if this primitive value is not
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   110
         * of type boolean.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   111
         */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   112
        public boolean booleanValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   113
            throw new UnsupportedOperationException("this primitive of type " + type());
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   114
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   115
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   116
        /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   117
         * Returns the int value if this primitive value is of type int.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   118
         * @return the int value if this primitive value is of type int.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   119
         *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   120
         * @throws UnsupportedOperationException if this primitive value is not
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   121
         * of type int.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   122
         */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   123
        public int intValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   124
            throw new UnsupportedOperationException("this primitive of type " + type());
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   125
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   126
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   127
        /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   128
         * Returns the long value if this primitive value is of type long.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   129
         * @return the long value if this primitive value is of type long.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   130
         *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   131
         * @throws UnsupportedOperationException if this primitive value is not
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   132
         * of type long.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   133
         */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   134
        public long longValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   135
            throw new UnsupportedOperationException("this primitive of type " + type());
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   136
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   137
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   138
        /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   139
         * Returns the char value if this primitive value is of type char.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   140
         * @return the char value if this primitive value is of type char.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   141
         *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   142
         * @throws UnsupportedOperationException if this primitive value is not
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   143
         * of type char.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   144
         */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   145
        public char charValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   146
            throw new UnsupportedOperationException("this primitive of type " + type());
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   147
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   148
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   149
        /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   150
         * Returns the byte value if this primitive value is of type byte.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   151
         * @return the byte value if this primitive value is of type byte.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   152
         *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   153
         * @throws UnsupportedOperationException if this primitive value is not
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   154
         * of type byte.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   155
         */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   156
        public byte byteValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   157
            throw new UnsupportedOperationException("this primitive of type " + type());
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   158
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   159
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   160
        /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   161
         * Returns the short value if this primitive value is of type short.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   162
         * @return the short value if this primitive value is of type short.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   163
         *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   164
         * @throws UnsupportedOperationException if this primitive value is not
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   165
         * of type short.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   166
         */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   167
        public short shortValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   168
            throw new UnsupportedOperationException("this primitive of type " + type());
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   169
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   170
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   171
        /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   172
         * Returns the float value if this primitive value is of type float.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   173
         * @return the float value if this primitive value is of type float.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   174
         *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   175
         * @throws UnsupportedOperationException if this primitive value is not
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   176
         * of type float.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   177
         */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   178
        public float floatValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   179
            throw new UnsupportedOperationException("this primitive of type " + type());
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   180
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   181
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   182
        /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   183
         * Returns the double value if this primitive value is of type double.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   184
         * @return the double value if this primitive value is of type double.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   185
         *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   186
         * @throws UnsupportedOperationException if this primitive value is not
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   187
         * of type double.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   188
         */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   189
        public double doubleValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   190
            throw new UnsupportedOperationException("this primitive of type " + type());
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   191
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   192
    }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   193
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   194
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   195
    /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   196
     * Gets {@code StackWalker} that can get locals and operands.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   197
     *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   198
     * @throws SecurityException if the security manager is present and
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   199
     * denies access to {@code RuntimePermission("liveStackFrames")}
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   200
     */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   201
    public static StackWalker getStackWalker() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   202
        return getStackWalker(EnumSet.noneOf(StackWalker.Option.class));
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   203
    }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   204
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   205
    /**
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   206
     * Gets a {@code StackWalker} instance with the given options specifying
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   207
     * the stack frame information it can access, and which will traverse at most
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   208
     * the given {@code maxDepth} number of stack frames.  If no option is
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   209
     * specified, this {@code StackWalker} obtains the method name and
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   210
     * the class name with all
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   211
     * {@linkplain StackWalker.Option#SHOW_HIDDEN_FRAMES hidden frames} skipped.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   212
     * The returned {@code StackWalker} can get locals and operands.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   213
     *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   214
     * @param options stack walk {@link StackWalker.Option options}
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   215
     *
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   216
     * @throws SecurityException if the security manager is present and
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   217
     * it denies access to {@code RuntimePermission("liveStackFrames")}; or
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   218
     * or if the given {@code options} contains
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   219
     * {@link StackWalker.Option#RETAIN_CLASS_REFERENCE Option.RETAIN_CLASS_REFERENCE}
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   220
     * and it denies access to {@code StackFramePermission("retainClassReference")}.
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   221
     */
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   222
    public static StackWalker getStackWalker(Set<StackWalker.Option> options) {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   223
        SecurityManager sm = System.getSecurityManager();
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   224
        if (sm != null) {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   225
            sm.checkPermission(new RuntimePermission("liveStackFrames"));
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   226
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   227
        return StackWalker.newInstance(options, LOCALS_AND_OPERANDS);
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   228
    }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   229
}