Mercurial > hg > truffle
annotate src/share/vm/classfile/stackMapFrame.hpp @ 14517:3812c088b945
Merge
author | lana |
---|---|
date | Thu, 06 Mar 2014 10:37:26 -0800 |
parents | f36e073d56a4 |
children | 2373a1f4987c b2daaf70fab2 |
rev | line source |
---|---|
0 | 1 /* |
9152 | 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_CLASSFILE_STACKMAPFRAME_HPP |
26 #define SHARE_VM_CLASSFILE_STACKMAPFRAME_HPP | |
27 | |
28 #include "classfile/verificationType.hpp" | |
29 #include "classfile/verifier.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6605
diff
changeset
|
30 #include "oops/method.hpp" |
1972 | 31 #include "runtime/handles.hpp" |
32 #include "runtime/signature.hpp" | |
33 #include "utilities/exceptions.hpp" | |
34 | |
0 | 35 // A StackMapFrame represents one frame in the stack map attribute. |
36 | |
6605 | 37 class TypeContext; |
38 | |
0 | 39 enum { |
40 FLAG_THIS_UNINIT = 0x01 | |
41 }; | |
42 | |
43 class StackMapFrame : public ResourceObj { | |
44 private: | |
45 int32_t _offset; | |
46 | |
47 // See comment in StackMapTable about _frame_count about why these | |
48 // fields are int32_t instead of u2. | |
49 int32_t _locals_size; // number of valid type elements in _locals | |
50 int32_t _stack_size; // number of valid type elements in _stack | |
51 | |
6605 | 52 int32_t _stack_mark; // Records the size of the stack prior to an |
53 // instruction modification, to allow rewinding | |
54 // when/if an error occurs. | |
55 | |
0 | 56 int32_t _max_locals; |
57 int32_t _max_stack; | |
58 | |
59 u1 _flags; | |
60 VerificationType* _locals; // local variable type array | |
61 VerificationType* _stack; // operand stack type array | |
62 | |
63 ClassVerifier* _verifier; // the verifier verifying this method | |
64 | |
6605 | 65 StackMapFrame(const StackMapFrame& cp) : |
66 _offset(cp._offset), _locals_size(cp._locals_size), | |
67 _stack_size(cp._stack_size), _stack_mark(cp._stack_mark), | |
68 _max_locals(cp._max_locals), _max_stack(cp._max_stack), | |
69 _flags(cp._flags) { | |
70 _locals = NEW_RESOURCE_ARRAY(VerificationType, _max_locals); | |
71 for (int i = 0; i < _max_locals; ++i) { | |
72 if (i < _locals_size) { | |
73 _locals[i] = cp._locals[i]; | |
74 } else { | |
75 _locals[i] = VerificationType::bogus_type(); | |
76 } | |
77 } | |
78 int ss = MAX2(_stack_size, _stack_mark); | |
79 _stack = NEW_RESOURCE_ARRAY(VerificationType, _max_stack); | |
80 for (int i = 0; i < _max_stack; ++i) { | |
81 if (i < ss) { | |
82 _stack[i] = cp._stack[i]; | |
83 } else { | |
84 _stack[i] = VerificationType::bogus_type(); | |
85 } | |
86 } | |
87 _verifier = NULL; | |
88 } | |
89 | |
0 | 90 public: |
91 // constructors | |
92 | |
93 // This constructor is used by the type checker to allocate frames | |
94 // in type state, which have _max_locals and _max_stack array elements | |
95 // in _locals and _stack. | |
96 StackMapFrame(u2 max_locals, u2 max_stack, ClassVerifier* verifier); | |
97 | |
98 // This constructor is used to initialize stackmap frames in stackmap table, | |
99 // which have _locals_size and _stack_size array elements in _locals and _stack. | |
100 StackMapFrame(int32_t offset, | |
101 u1 flags, | |
102 u2 locals_size, | |
103 u2 stack_size, | |
104 u2 max_locals, | |
105 u2 max_stack, | |
106 VerificationType* locals, | |
107 VerificationType* stack, | |
108 ClassVerifier* v) : _offset(offset), _flags(flags), | |
109 _locals_size(locals_size), | |
110 _stack_size(stack_size), | |
6605 | 111 _stack_mark(-1), |
0 | 112 _max_locals(max_locals), |
113 _max_stack(max_stack), | |
114 _locals(locals), _stack(stack), | |
115 _verifier(v) { } | |
116 | |
6605 | 117 static StackMapFrame* copy(StackMapFrame* smf) { |
118 return new StackMapFrame(*smf); | |
119 } | |
120 | |
0 | 121 inline void set_offset(int32_t offset) { _offset = offset; } |
122 inline void set_verifier(ClassVerifier* v) { _verifier = v; } | |
123 inline void set_flags(u1 flags) { _flags = flags; } | |
124 inline void set_locals_size(u2 locals_size) { _locals_size = locals_size; } | |
6605 | 125 inline void set_stack_size(u2 stack_size) { _stack_size = _stack_mark = stack_size; } |
0 | 126 inline void clear_stack() { _stack_size = 0; } |
127 inline int32_t offset() const { return _offset; } | |
128 inline ClassVerifier* verifier() const { return _verifier; } | |
129 inline u1 flags() const { return _flags; } | |
130 inline int32_t locals_size() const { return _locals_size; } | |
131 inline VerificationType* locals() const { return _locals; } | |
132 inline int32_t stack_size() const { return _stack_size; } | |
133 inline VerificationType* stack() const { return _stack; } | |
134 inline int32_t max_locals() const { return _max_locals; } | |
135 inline int32_t max_stack() const { return _max_stack; } | |
136 inline bool flag_this_uninit() const { return _flags & FLAG_THIS_UNINIT; } | |
137 | |
138 // Set locals and stack types to bogus | |
139 inline void reset() { | |
140 int32_t i; | |
141 for (i = 0; i < _max_locals; i++) { | |
142 _locals[i] = VerificationType::bogus_type(); | |
143 } | |
144 for (i = 0; i < _max_stack; i++) { | |
145 _stack[i] = VerificationType::bogus_type(); | |
146 } | |
147 } | |
148 | |
149 // Return a StackMapFrame with the same local variable array and empty stack. | |
150 // Stack array is allocate with unused one element. | |
151 StackMapFrame* frame_in_exception_handler(u1 flags); | |
152 | |
153 // Set local variable type array based on m's signature. | |
154 VerificationType set_locals_from_arg( | |
155 const methodHandle m, VerificationType thisKlass, TRAPS); | |
156 | |
157 // Search local variable type array and stack type array. | |
158 // Return true if an uninitialized object is found. | |
159 bool has_new_object() const; | |
160 | |
161 // Search local variable type array and stack type array. | |
162 // Set every element with type of old_object to new_object. | |
163 void initialize_object( | |
164 VerificationType old_object, VerificationType new_object); | |
165 | |
166 // Copy local variable type array in src into this local variable type array. | |
167 void copy_locals(const StackMapFrame* src); | |
168 | |
169 // Copy stack type array in src into this stack type array. | |
170 void copy_stack(const StackMapFrame* src); | |
171 | |
172 // Return true if this stack map frame is assignable to target. | |
6605 | 173 bool is_assignable_to( |
174 const StackMapFrame* target, bool is_exception_handler, | |
175 ErrorContext* ctx, TRAPS) const; | |
176 | |
177 inline void set_mark() { | |
9152 | 178 #ifdef ASSERT |
6605 | 179 // Put bogus type to indicate it's no longer valid. |
180 if (_stack_mark != -1) { | |
7985 | 181 for (int i = _stack_mark - 1; i >= _stack_size; --i) { |
6605 | 182 _stack[i] = VerificationType::bogus_type(); |
183 } | |
184 } | |
9152 | 185 #endif // def ASSERT |
6605 | 186 _stack_mark = _stack_size; |
187 } | |
188 | |
189 // Used when an error occurs and we want to reset the stack to the state | |
190 // it was before operands were popped off. | |
191 void restore() { | |
192 if (_stack_mark != -1) { | |
193 _stack_size = _stack_mark; | |
194 } | |
195 } | |
0 | 196 |
197 // Push type into stack type array. | |
198 inline void push_stack(VerificationType type, TRAPS) { | |
199 assert(!type.is_check(), "Must be a real type"); | |
200 if (_stack_size >= _max_stack) { | |
6605 | 201 verifier()->verify_error( |
202 ErrorContext::stack_overflow(_offset, this), | |
203 "Operand stack overflow"); | |
0 | 204 return; |
205 } | |
206 _stack[_stack_size++] = type; | |
207 } | |
208 | |
209 inline void push_stack_2( | |
210 VerificationType type1, VerificationType type2, TRAPS) { | |
211 assert(type1.is_long() || type1.is_double(), "must be long/double"); | |
212 assert(type2.is_long2() || type2.is_double2(), "must be long/double_2"); | |
213 if (_stack_size >= _max_stack - 1) { | |
6605 | 214 verifier()->verify_error( |
215 ErrorContext::stack_overflow(_offset, this), | |
216 "Operand stack overflow"); | |
0 | 217 return; |
218 } | |
219 _stack[_stack_size++] = type1; | |
220 _stack[_stack_size++] = type2; | |
221 } | |
222 | |
223 // Pop and return the top type on stack without verifying. | |
224 inline VerificationType pop_stack(TRAPS) { | |
225 if (_stack_size <= 0) { | |
6605 | 226 verifier()->verify_error( |
227 ErrorContext::stack_underflow(_offset, this), | |
228 "Operand stack underflow"); | |
0 | 229 return VerificationType::bogus_type(); |
230 } | |
231 VerificationType top = _stack[--_stack_size]; | |
232 return top; | |
233 } | |
234 | |
235 // Pop and return the top type on stack type array after verifying it | |
236 // is assignable to type. | |
237 inline VerificationType pop_stack(VerificationType type, TRAPS) { | |
238 if (_stack_size != 0) { | |
239 VerificationType top = _stack[_stack_size - 1]; | |
240 bool subtype = type.is_assignable_from( | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
241 top, verifier(), CHECK_(VerificationType::bogus_type())); |
0 | 242 if (subtype) { |
6605 | 243 --_stack_size; |
0 | 244 return top; |
245 } | |
246 } | |
247 return pop_stack_ex(type, THREAD); | |
248 } | |
249 | |
250 inline void pop_stack_2( | |
251 VerificationType type1, VerificationType type2, TRAPS) { | |
252 assert(type1.is_long2() || type1.is_double2(), "must be long/double"); | |
253 assert(type2.is_long() || type2.is_double(), "must be long/double_2"); | |
254 if (_stack_size >= 2) { | |
255 VerificationType top1 = _stack[_stack_size - 1]; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
256 bool subtype1 = type1.is_assignable_from(top1, verifier(), CHECK); |
0 | 257 VerificationType top2 = _stack[_stack_size - 2]; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
1972
diff
changeset
|
258 bool subtype2 = type2.is_assignable_from(top2, verifier(), CHECK); |
0 | 259 if (subtype1 && subtype2) { |
260 _stack_size -= 2; | |
261 return; | |
262 } | |
263 } | |
264 pop_stack_ex(type1, THREAD); | |
265 pop_stack_ex(type2, THREAD); | |
266 } | |
267 | |
6605 | 268 VerificationType local_at(int index) { |
269 return _locals[index]; | |
270 } | |
271 | |
272 VerificationType stack_at(int index) { | |
273 return _stack[index]; | |
274 } | |
275 | |
0 | 276 // Uncommon case that throws exceptions. |
277 VerificationType pop_stack_ex(VerificationType type, TRAPS); | |
278 | |
279 // Return the type at index in local variable array after verifying | |
280 // it is assignable to type. | |
281 VerificationType get_local(int32_t index, VerificationType type, TRAPS); | |
282 // For long/double. | |
283 void get_local_2( | |
284 int32_t index, VerificationType type1, VerificationType type2, TRAPS); | |
285 | |
286 // Set element at index in local variable array to type. | |
287 void set_local(int32_t index, VerificationType type, TRAPS); | |
288 // For long/double. | |
289 void set_local_2( | |
290 int32_t index, VerificationType type1, VerificationType type2, TRAPS); | |
291 | |
292 // Private auxiliary method used only in is_assignable_to(StackMapFrame). | |
293 // Returns true if src is assignable to target. | |
6605 | 294 int is_assignable_to( |
0 | 295 VerificationType* src, VerificationType* target, int32_t len, TRAPS) const; |
296 | |
2303
c1a6154012c8
7020118: Alter frame assignability to allow for exception handler coverage of invokespecial <init>
kamg
parents:
2177
diff
changeset
|
297 bool has_flag_match_exception(const StackMapFrame* target) const; |
c1a6154012c8
7020118: Alter frame assignability to allow for exception handler coverage of invokespecial <init>
kamg
parents:
2177
diff
changeset
|
298 |
6605 | 299 TypeOrigin stack_top_ctx(); |
300 | |
301 void print_on(outputStream* str) const; | |
0 | 302 }; |
1972 | 303 |
304 #endif // SHARE_VM_CLASSFILE_STACKMAPFRAME_HPP |