src/java.base/share/classes/java/lang/LiveStackFrameInfo.java
author jlaskey
Thu, 06 Jun 2019 12:24:44 -0300
changeset 55260 cc0f117f4405
parent 47216 71c04702a3d5
permissions -rw-r--r--
8223775: String::stripIndent (Preview) Reviewed-by: abuckley, vromero, jlahoda, bchristi, rriggs, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
     1
/*
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
34362
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
final class LiveStackFrameInfo extends StackFrameInfo implements LiveStackFrame {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    28
    private static Object[] EMPTY_ARRAY = new Object[0];
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    29
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    30
    // These flags must match the values maintained in the VM
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    31
    private static final int MODE_INTERPRETED = 0x01;
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    32
    private static final int MODE_COMPILED    = 0x02;
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    33
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    34
    LiveStackFrameInfo(StackWalker walker) {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    35
        super(walker);
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
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    38
    // These fields are initialized by the VM if ExtendedOption.LOCALS_AND_OPERANDS is set
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    39
    private Object[] monitors = EMPTY_ARRAY;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    40
    private Object[] locals = EMPTY_ARRAY;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    41
    private Object[] operands = EMPTY_ARRAY;
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    42
    private int mode = 0;
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    43
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    44
    @Override
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    45
    public Object[] getMonitors() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    46
        return monitors;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    47
    }
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
    @Override
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    50
    public Object[] getLocals() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    51
        return locals;
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
    @Override
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    55
    public Object[] getStack() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    56
        return operands;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    57
    }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    58
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    59
    @Override
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    60
    public String toString() {
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    61
        StringBuilder retVal = new StringBuilder(super.toString());
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    62
        if (mode != 0) {
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    63
            retVal.append("(");
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    64
            if ((mode & MODE_INTERPRETED) == MODE_INTERPRETED) {
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    65
                retVal.append(" interpreted ");
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    66
            }
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    67
            if ((mode & MODE_COMPILED) == MODE_COMPILED) {
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    68
                retVal.append(" compiled ");
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    69
            }
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    70
            retVal.append(")");
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    71
        }
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    72
        return retVal.toString();
34362
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
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    75
    /*
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    76
     * Convert primitive value to {@code PrimitiveSlot} object to represent
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    77
     * a local variable or an element on the operand stack of primitive type.
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    78
     */
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    79
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    80
    static PrimitiveSlot asPrimitive(int value) {
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    81
        return new PrimitiveSlot32(value);
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    82
    }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    83
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    84
    static PrimitiveSlot asPrimitive(long value) {
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    85
        return new PrimitiveSlot64(value);
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    86
    }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    87
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    88
    private static class PrimitiveSlot32 extends PrimitiveSlot {
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    89
        final int value;
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    90
        PrimitiveSlot32(int value) {
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    91
            this.value = value;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    92
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    93
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    94
        @Override
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    95
        public int size() {
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
    96
            return 4;
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    97
        }
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    98
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
    99
        @Override
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   100
        public int intValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   101
            return value;
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
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   104
        @Override
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   105
        public String toString() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   106
            return String.valueOf(value);
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   107
        }
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
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
   110
    private static class PrimitiveSlot64 extends PrimitiveSlot {
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
   111
        final long value;
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
   112
        PrimitiveSlot64(long value) {
34362
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   113
            this.value = value;
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
        @Override
43715
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
   117
        public int size() {
6d72cc84759f 8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents: 34362
diff changeset
   118
            return 8;
34362
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
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   121
        @Override
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   122
        public long longValue() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   123
            return value;
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   124
        }
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
        @Override
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   127
        public String toString() {
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   128
            return String.valueOf(value);
3396ae214e7d 8140450: Implement JEP 259: Stack-Walking API
mchung
parents:
diff changeset
   129
        }
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
}