author | xuelei |
Mon, 25 Jun 2018 09:48:06 -0700 | |
branch | JDK-8145252-TLS13-branch |
changeset 56807 | b9e374d0534f |
parent 47216 | 71c04702a3d5 |
child 53563 | a4b7ea85d668 |
permissions | -rw-r--r-- |
34362 | 1 |
/* |
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
34362 | 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package java.lang; |
|
26 |
||
27 |
import java.lang.StackWalker.StackFrame; |
|
28 |
import java.util.EnumSet; |
|
29 |
import java.util.Set; |
|
30 |
||
31 |
import static java.lang.StackWalker.ExtendedOption.LOCALS_AND_OPERANDS; |
|
32 |
||
33 |
/** |
|
34 |
* <em>UNSUPPORTED</em> This interface is intended to be package-private |
|
35 |
* or move to an internal package.<p> |
|
36 |
* |
|
37 |
* {@code LiveStackFrame} represents a frame storing data and partial results. |
|
38 |
* Each frame has its own array of local variables (JVMS section 2.6.1), |
|
39 |
* its own operand stack (JVMS section 2.6.2) for a method invocation. |
|
40 |
* |
|
41 |
* @jvms 2.6 Frames |
|
42 |
*/ |
|
43 |
/* package-private */ |
|
44 |
interface LiveStackFrame extends StackFrame { |
|
45 |
/** |
|
46 |
* Return the monitors held by this stack frame. This method returns |
|
47 |
* an empty array if no monitor is held by this stack frame. |
|
48 |
* |
|
49 |
* @return the monitors held by this stack frames |
|
50 |
*/ |
|
51 |
public Object[] getMonitors(); |
|
52 |
||
53 |
/** |
|
54 |
* Gets the local variable array of this stack frame. |
|
55 |
* |
|
56 |
* <p>A single local variable can hold a value of type boolean, byte, char, |
|
57 |
* short, int, float, reference or returnAddress. A pair of local variables |
|
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
58 |
* can hold a value of type long or double (JVMS section 2.6.1). Primitive |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
59 |
* locals are represented in the returned array as {@code PrimitiveSlot}s, |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
60 |
* with longs and doubles occupying a pair of consecutive |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
61 |
* {@code PrimitiveSlot}s. |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
62 |
* |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
63 |
* <p>The current VM implementation does not provide specific type |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
64 |
* information for primitive locals. This method simply returns the raw |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
65 |
* contents of the VM's primitive locals on a best-effort basis, without |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
66 |
* indicating a specific type. |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
67 |
* |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
68 |
* <p>The returned array may contain null entries for local variables that |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
69 |
* are not live. |
34362 | 70 |
* |
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
71 |
* @implNote |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
72 |
* <p> The specific subclass of {@code PrimitiveSlot} will reflect the |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
73 |
* underlying architecture, and will be either {@code PrimitiveSlot32} or |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
74 |
* {@code PrimitiveSlot64}. |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
75 |
* |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
76 |
* <p>How a long or double value is stored in the pair of |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
77 |
* {@code PrimitiveSlot}s can vary based on the underlying architecture and |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
78 |
* VM implementation. On 32-bit architectures, long/double values are split |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
79 |
* between the two {@code PrimitiveSlot32}s. |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
80 |
* On 64-bit architectures, the entire value may be stored in one of the |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
81 |
* {@code PrimitiveSlot64}s, with the other {@code PrimitiveSlot64} being |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
82 |
* unused. |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
83 |
* |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
84 |
* <p>The contents of the unused, high-order portion of a |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
85 |
* {@code PrimitiveSlot64} (when storing a primitive other than a long or |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
86 |
* double) is unspecified. In particular, the unused bits are not |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
87 |
* necessarily zeroed out. |
34934
7fbff68dbc12
8144552: java/lang/StackWalker/LocalsAndOperands.java fails with java.lang.NullPointerException
bchristi
parents:
34362
diff
changeset
|
88 |
* |
34362 | 89 |
* @return the local variable array of this stack frame. |
90 |
*/ |
|
91 |
public Object[] getLocals(); |
|
92 |
||
93 |
/** |
|
94 |
* Gets the operand stack of this stack frame. |
|
95 |
* |
|
96 |
* <p> |
|
97 |
* The 0-th element of the returned array represents the top of the operand stack. |
|
98 |
* This method returns an empty array if the operand stack is empty. |
|
99 |
* |
|
100 |
* <p>Each entry on the operand stack can hold a value of any Java Virtual |
|
101 |
* Machine Type. |
|
102 |
* For a value of primitive type, the element in the returned array is |
|
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
103 |
* a {@link PrimitiveSlot} object; otherwise, the element is the {@code Object} |
34362 | 104 |
* on the operand stack. |
105 |
* |
|
106 |
* @return the operand stack of this stack frame. |
|
107 |
*/ |
|
108 |
public Object[] getStack(); |
|
109 |
||
110 |
/** |
|
111 |
* <em>UNSUPPORTED</em> This interface is intended to be package-private |
|
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
112 |
* or moved to an internal package.<p> |
34362 | 113 |
* |
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
114 |
* Represents a local variable or an entry on the operand stack whose value is |
34362 | 115 |
* of primitive type. |
116 |
*/ |
|
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
117 |
public abstract class PrimitiveSlot { |
34362 | 118 |
/** |
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
119 |
* Returns the size, in bytes, of the slot. |
34362 | 120 |
*/ |
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
121 |
public abstract int size(); |
34362 | 122 |
|
123 |
/** |
|
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
124 |
* Returns the int value if this primitive value is of size 4 |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
125 |
* @return the int value if this primitive value is of size 4 |
34362 | 126 |
* |
127 |
* @throws UnsupportedOperationException if this primitive value is not |
|
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
128 |
* of size 4. |
34362 | 129 |
*/ |
130 |
public int intValue() { |
|
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
131 |
throw new UnsupportedOperationException("this " + size() + "-byte primitive"); |
34362 | 132 |
} |
133 |
||
134 |
/** |
|
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
135 |
* Returns the long value if this primitive value is of size 8 |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
136 |
* @return the long value if this primitive value is of size 8 |
34362 | 137 |
* |
138 |
* @throws UnsupportedOperationException if this primitive value is not |
|
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
139 |
* of size 8. |
34362 | 140 |
*/ |
43715
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
141 |
public long longValue() { |
6d72cc84759f
8156073: 2-slot LiveStackFrame locals (long and double) are incorrect
bchristi
parents:
34934
diff
changeset
|
142 |
throw new UnsupportedOperationException("this " + size() + "-byte primitive"); |
34362 | 143 |
} |
144 |
} |
|
145 |
||
146 |
||
147 |
/** |
|
148 |
* Gets {@code StackWalker} that can get locals and operands. |
|
149 |
* |
|
150 |
* @throws SecurityException if the security manager is present and |
|
151 |
* denies access to {@code RuntimePermission("liveStackFrames")} |
|
152 |
*/ |
|
153 |
public static StackWalker getStackWalker() { |
|
154 |
return getStackWalker(EnumSet.noneOf(StackWalker.Option.class)); |
|
155 |
} |
|
156 |
||
157 |
/** |
|
158 |
* Gets a {@code StackWalker} instance with the given options specifying |
|
159 |
* the stack frame information it can access, and which will traverse at most |
|
160 |
* the given {@code maxDepth} number of stack frames. If no option is |
|
161 |
* specified, this {@code StackWalker} obtains the method name and |
|
162 |
* the class name with all |
|
163 |
* {@linkplain StackWalker.Option#SHOW_HIDDEN_FRAMES hidden frames} skipped. |
|
164 |
* The returned {@code StackWalker} can get locals and operands. |
|
165 |
* |
|
166 |
* @param options stack walk {@link StackWalker.Option options} |
|
167 |
* |
|
168 |
* @throws SecurityException if the security manager is present and |
|
169 |
* it denies access to {@code RuntimePermission("liveStackFrames")}; or |
|
170 |
* or if the given {@code options} contains |
|
171 |
* {@link StackWalker.Option#RETAIN_CLASS_REFERENCE Option.RETAIN_CLASS_REFERENCE} |
|
44262
bfbb47bd118d
8176815: Remove StackFramePermission and use RuntimePermission for stack walking
mchung
parents:
43715
diff
changeset
|
172 |
* and it denies access to {@code RuntimePermission("getStackWalkerWithClassReference")}. |
34362 | 173 |
*/ |
174 |
public static StackWalker getStackWalker(Set<StackWalker.Option> options) { |
|
175 |
SecurityManager sm = System.getSecurityManager(); |
|
176 |
if (sm != null) { |
|
177 |
sm.checkPermission(new RuntimePermission("liveStackFrames")); |
|
178 |
} |
|
179 |
return StackWalker.newInstance(options, LOCALS_AND_OPERANDS); |
|
180 |
} |
|
181 |
} |