1 /*
2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
118 }
119
120 size_t size() const {
121 return calculate_size(tag());
122 }
123
124 verification_type_info* next() {
125 return (verification_type_info*)((address)this + size());
126 }
127
128 // This method is used when reading unverified data in order to ensure
129 // that we don't read past a particular memory limit. It returns false
130 // if any part of the data structure is outside the specified memory bounds.
131 bool verify(address start, address end) {
132 return ((address)this >= start &&
133 (address)this < end &&
134 (bci_addr() + sizeof(u2) <= end ||
135 !is_object() && !is_uninitialized()));
136 }
137
138 #ifdef ASSERT
139 void print_on(outputStream* st) {
140 switch (tag()) {
141 case ITEM_Top: st->print("Top"); break;
142 case ITEM_Integer: st->print("Integer"); break;
143 case ITEM_Float: st->print("Float"); break;
144 case ITEM_Double: st->print("Double"); break;
145 case ITEM_Long: st->print("Long"); break;
146 case ITEM_Null: st->print("Null"); break;
147 case ITEM_UninitializedThis:
148 st->print("UninitializedThis"); break;
149 case ITEM_Uninitialized:
150 st->print("Uninitialized[#%d]", bci()); break;
151 case ITEM_Object:
152 st->print("Object[#%d]", cpool_index()); break;
153 default:
154 assert(false, "Bad verification_type_info");
155 }
156 }
157 #endif
158 };
159
160 #define FOR_EACH_STACKMAP_FRAME_TYPE(macro, arg1, arg2) \
161 macro(same_frame, arg1, arg2) \
162 macro(same_frame_extended, arg1, arg2) \
163 macro(same_frame_1_stack_item_frame, arg1, arg2) \
164 macro(same_frame_1_stack_item_extended, arg1, arg2) \
165 macro(chop_frame, arg1, arg2) \
166 macro(append_frame, arg1, arg2) \
167 macro(full_frame, arg1, arg2)
168
169 #define SM_FORWARD_DECL(type, arg1, arg2) class type;
170 FOR_EACH_STACKMAP_FRAME_TYPE(SM_FORWARD_DECL, x, x)
171 #undef SM_FORWARD_DECL
172
173 class stack_map_frame {
174 protected:
175 address frame_type_addr() const { return (address)this; }
176
177 // No constructors - should be 'private', but GCC issues a warning if it is
178 stack_map_frame() {}
179 stack_map_frame(const stack_map_frame&) {}
180
181 public:
182
183 static stack_map_frame* at(address addr) {
184 return (stack_map_frame*)addr;
186
187 stack_map_frame* next() const {
188 return at((address)this + size());
189 }
190
191 u1 frame_type() const { return *(u1*)frame_type_addr(); }
192 void set_frame_type(u1 type) { *((u1*)frame_type_addr()) = type; }
193
194 // pseudo-virtual methods
195 inline size_t size() const;
196 inline int offset_delta() const;
197 inline void set_offset_delta(int offset_delta);
198 inline int number_of_types() const; // number of types contained in the frame
199 inline verification_type_info* types() const; // pointer to first type
200 inline bool is_valid_offset(int offset_delta) const;
201
202 // This method must be used when reading unverified data in order to ensure
203 // that we don't read past a particular memory limit. It returns false
204 // if any part of the data structure is outside the specified memory bounds.
205 inline bool verify(address start, address end) const;
206 #ifdef ASSERT
207 inline void print_on(outputStream* st) const;
208 #endif
209
210 // Create as_xxx and is_xxx methods for the subtypes
211 #define FRAME_TYPE_DECL(stackmap_frame_type, arg1, arg2) \
212 inline stackmap_frame_type* as_##stackmap_frame_type() const; \
213 bool is_##stackmap_frame_type() { \
214 return as_##stackmap_frame_type() != NULL; \
215 }
216
217 FOR_EACH_STACKMAP_FRAME_TYPE(FRAME_TYPE_DECL, x, x)
218 #undef FRAME_TYPE_DECL
219 };
220
221 class same_frame : public stack_map_frame {
222 private:
223 static int frame_type_to_offset_delta(u1 frame_type) {
224 return frame_type + 1; }
225 static u1 offset_delta_to_frame_type(int offset_delta) {
226 return (u1)(offset_delta - 1); }
227
228 public:
246
247 size_t size() const { return calculate_size(); }
248 int offset_delta() const { return frame_type_to_offset_delta(frame_type()); }
249
250 void set_offset_delta(int offset_delta) {
251 assert(offset_delta <= 64, "Offset too large for same_frame");
252 set_frame_type(offset_delta_to_frame_type(offset_delta));
253 }
254
255 int number_of_types() const { return 0; }
256 verification_type_info* types() const { return NULL; }
257
258 bool is_valid_offset(int offset_delta) const {
259 return is_frame_type(offset_delta_to_frame_type(offset_delta));
260 }
261
262 bool verify_subtype(address start, address end) const {
263 return true;
264 }
265
266 #ifdef ASSERT
267 void print_on(outputStream* st) const {
268 st->print("same_frame(%d)", offset_delta());
269 }
270 #endif
271 };
272
273 class same_frame_extended : public stack_map_frame {
274 private:
275 enum { _frame_id = 251 };
276 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
277
278 public:
279 static bool is_frame_type(u1 tag) {
280 return tag == _frame_id;
281 }
282
283 static same_frame_extended* at(address addr) {
284 assert(is_frame_type(*addr), "Wrong frame type");
285 return (same_frame_extended*)addr;
286 }
287
288 static same_frame_extended* create_at(address addr, u2 offset_delta) {
289 same_frame_extended* sm = (same_frame_extended*)addr;
290 sm->set_frame_type(_frame_id);
294
295 static size_t calculate_size() { return sizeof(u1) + sizeof(u2); }
296
297 size_t size() const { return calculate_size(); }
298 int offset_delta() const {
299 return Bytes::get_Java_u2(offset_delta_addr()) + 1;
300 }
301
302 void set_offset_delta(int offset_delta) {
303 Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
304 }
305
306 int number_of_types() const { return 0; }
307 verification_type_info* types() const { return NULL; }
308 bool is_valid_offset(int offset) const { return true; }
309
310 bool verify_subtype(address start, address end) const {
311 return frame_type_addr() + size() <= end;
312 }
313
314 #ifdef ASSERT
315 void print_on(outputStream* st) const {
316 st->print("same_frame_extended(%d)", offset_delta());
317 }
318 #endif
319 };
320
321 class same_frame_1_stack_item_frame : public stack_map_frame {
322 private:
323 address type_addr() const { return frame_type_addr() + sizeof(u1); }
324
325 static int frame_type_to_offset_delta(u1 frame_type) {
326 return frame_type - 63; }
327 static u1 offset_delta_to_frame_type(int offset_delta) {
328 return (u1)(offset_delta + 63); }
329
330 public:
331 static bool is_frame_type(u1 tag) {
332 return tag >= 64 && tag < 128;
333 }
334
335 static same_frame_1_stack_item_frame* at(address addr) {
336 assert(is_frame_type(*addr), "Wrong frame id");
337 return (same_frame_1_stack_item_frame*)addr;
338 }
339
340 static same_frame_1_stack_item_frame* create_at(
341 address addr, int offset_delta, verification_type_info* vti) {
342 same_frame_1_stack_item_frame* sm = (same_frame_1_stack_item_frame*)addr;
343 sm->set_offset_delta(offset_delta);
344 if (vti != NULL) {
345 sm->set_type(vti);
346 }
347 return sm;
348 }
349
350 static size_t calculate_size(verification_type_info* vti) {
351 return sizeof(u1) + vti->size();
352 }
353
354 static size_t max_size() {
355 return sizeof(u1) + verification_type_info::max_size();
356 }
357
358 size_t size() const { return calculate_size(types()); }
359 int offset_delta() const { return frame_type_to_offset_delta(frame_type()); }
360
361 void set_offset_delta(int offset_delta) {
362 assert(offset_delta > 0 && offset_delta <= 64,
365 }
366
367 void set_type(verification_type_info* vti) {
368 verification_type_info* cur = types();
369 cur->copy_from(vti);
370 }
371
372 int number_of_types() const { return 1; }
373 verification_type_info* types() const {
374 return verification_type_info::at(type_addr());
375 }
376
377 bool is_valid_offset(int offset_delta) const {
378 return is_frame_type(offset_delta_to_frame_type(offset_delta));
379 }
380
381 bool verify_subtype(address start, address end) const {
382 return types()->verify(start, end);
383 }
384
385 #ifdef ASSERT
386 void print_on(outputStream* st) const {
387 st->print("same_frame_1_stack_item_frame(%d,", offset_delta());
388 types()->print_on(st);
389 st->print(")");
390 }
391 #endif
392 };
393
394 class same_frame_1_stack_item_extended : public stack_map_frame {
395 private:
396 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
397 address type_addr() const { return offset_delta_addr() + sizeof(u2); }
398
399 enum { _frame_id = 247 };
400
401 public:
402 static bool is_frame_type(u1 tag) {
403 return tag == _frame_id;
404 }
405
406 static same_frame_1_stack_item_extended* at(address addr) {
407 assert(is_frame_type(*addr), "Wrong frame id");
408 return (same_frame_1_stack_item_extended*)addr;
409 }
410
411 static same_frame_1_stack_item_extended* create_at(
412 address addr, int offset_delta, verification_type_info* vti) {
413 same_frame_1_stack_item_extended* sm =
414 (same_frame_1_stack_item_extended*)addr;
415 sm->set_frame_type(_frame_id);
416 sm->set_offset_delta(offset_delta);
417 if (vti != NULL) {
418 sm->set_type(vti);
419 }
420 return sm;
421 }
422
423 static size_t calculate_size(verification_type_info* vti) {
424 return sizeof(u1) + sizeof(u2) + vti->size();
425 }
426
427 size_t size() const { return calculate_size(types()); }
428 int offset_delta() const {
429 return Bytes::get_Java_u2(offset_delta_addr()) + 1;
430 }
431
432 void set_offset_delta(int offset_delta) {
433 Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
434 }
435
436 void set_type(verification_type_info* vti) {
437 verification_type_info* cur = types();
438 cur->copy_from(vti);
439 }
440
441 int number_of_types() const { return 1; }
442 verification_type_info* types() const {
443 return verification_type_info::at(type_addr());
444 }
445 bool is_valid_offset(int offset) { return true; }
446
447 bool verify_subtype(address start, address end) const {
448 return type_addr() < end && types()->verify(start, end);
449 }
450
451 #ifdef ASSERT
452 void print_on(outputStream* st) const {
453 st->print("same_frame_1_stack_item_extended(%d,", offset_delta());
454 types()->print_on(st);
455 st->print(")");
456 }
457 #endif
458 };
459
460 class chop_frame : public stack_map_frame {
461 private:
462 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
463
464 static int frame_type_to_chops(u1 frame_type) {
465 int chop = 251 - frame_type;
466 return chop;
467 }
468
469 static u1 chops_to_frame_type(int chop) {
470 return 251 - chop;
471 }
472
473 public:
474 static bool is_frame_type(u1 tag) {
475 return frame_type_to_chops(tag) > 0 && frame_type_to_chops(tag) < 4;
476 }
477
500 }
501
502 int chops() const {
503 int chops = frame_type_to_chops(frame_type());
504 assert(chops > 0 && chops < 4, "Invalid number of chops in frame");
505 return chops;
506 }
507 void set_chops(int chops) {
508 assert(chops > 0 && chops <= 3, "Bad number of chops");
509 set_frame_type(chops_to_frame_type(chops));
510 }
511
512 int number_of_types() const { return 0; }
513 verification_type_info* types() const { return NULL; }
514 bool is_valid_offset(int offset) { return true; }
515
516 bool verify_subtype(address start, address end) const {
517 return frame_type_addr() + size() <= end;
518 }
519
520 #ifdef ASSERT
521 void print_on(outputStream* st) const {
522 st->print("chop_frame(%d,%d)", offset_delta(), chops());
523 }
524 #endif
525 };
526
527 class append_frame : public stack_map_frame {
528 private:
529 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
530 address types_addr() const { return offset_delta_addr() + sizeof(u2); }
531
532 static int frame_type_to_appends(u1 frame_type) {
533 int append = frame_type - 251;
534 return append;
535 }
536
537 static u1 appends_to_frame_type(int appends) {
538 assert(appends > 0 && appends < 4, "Invalid append amount");
539 return 251 + appends;
540 }
541
542 public:
543 static bool is_frame_type(u1 tag) {
544 return frame_type_to_appends(tag) > 0 && frame_type_to_appends(tag) < 4;
601 verification_type_info* types() const {
602 return verification_type_info::at(types_addr());
603 }
604 bool is_valid_offset(int offset) const { return true; }
605
606 bool verify_subtype(address start, address end) const {
607 verification_type_info* vti = types();
608 if ((address)vti < end && vti->verify(start, end)) {
609 int nof = number_of_types();
610 vti = vti->next();
611 if (nof < 2 || vti->verify(start, end)) {
612 vti = vti->next();
613 if (nof < 3 || vti->verify(start, end)) {
614 return true;
615 }
616 }
617 }
618 return false;
619 }
620
621 #ifdef ASSERT
622 void print_on(outputStream* st) const {
623 st->print("append_frame(%d,", offset_delta());
624 verification_type_info* vti = types();
625 for (int i = 0; i < number_of_types(); ++i) {
626 vti->print_on(st);
627 if (i != number_of_types() - 1) {
628 st->print(",");
629 }
630 vti = vti->next();
631 }
632 st->print(")");
633 }
634 #endif
635 };
636
637 class full_frame : public stack_map_frame {
638 private:
639 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
640 address num_locals_addr() const { return offset_delta_addr() + sizeof(u2); }
641 address locals_addr() const { return num_locals_addr() + sizeof(u2); }
642 address stack_slots_addr(address end_of_locals) const {
643 return end_of_locals; }
644 address stack_addr(address end_of_locals) const {
645 return stack_slots_addr(end_of_locals) + sizeof(u2); }
646
647 enum { _frame_id = 255 };
648
649 public:
650 static bool is_frame_type(u1 tag) {
651 return tag == _frame_id;
652 }
653
654 static full_frame* at(address addr) {
757 if (!vti->verify(start, end)) {
758 return false;
759 }
760 vti = vti->next();
761 }
762 address eol = (address)vti;
763 if (eol + sizeof(u2) > end) {
764 return false;
765 }
766 count = stack_slots(eol);
767 vti = stack(eol);
768 for (int i = 0; i < stack_slots(eol); ++i) {
769 if (!vti->verify(start, end)) {
770 return false;
771 }
772 vti = vti->next();
773 }
774 return true;
775 }
776
777 #ifdef ASSERT
778 void print_on(outputStream* st) const {
779 st->print("full_frame(%d,{", offset_delta());
780 verification_type_info* vti = locals();
781 for (int i = 0; i < num_locals(); ++i) {
782 vti->print_on(st);
783 if (i != num_locals() - 1) {
784 st->print(",");
785 }
786 vti = vti->next();
787 }
788 st->print("},{");
789 address end_of_locals = (address)vti;
790 vti = stack(end_of_locals);
791 int ss = stack_slots(end_of_locals);
792 for (int i = 0; i < ss; ++i) {
793 vti->print_on(st);
794 if (i != ss - 1) {
795 st->print(",");
796 }
797 vti = vti->next();
798 }
799 st->print("})");
800 }
801 #endif
802 };
803
804 #define VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \
805 stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \
806 if (item_##stack_frame_type != NULL) { \
807 return item_##stack_frame_type->func_name args; \
808 }
809
810 #define VOID_VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \
811 stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \
812 if (item_##stack_frame_type != NULL) { \
813 item_##stack_frame_type->func_name args; \
814 return; \
815 }
816
817 size_t stack_map_frame::size() const {
818 FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, size, ());
819 return 0;
820 }
821
835 }
836
837 verification_type_info* stack_map_frame::types() const {
838 FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, types, ());
839 return NULL;
840 }
841
842 bool stack_map_frame::is_valid_offset(int offset) const {
843 FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, is_valid_offset, (offset));
844 return true;
845 }
846
847 bool stack_map_frame::verify(address start, address end) const {
848 if (frame_type_addr() >= start && frame_type_addr() < end) {
849 FOR_EACH_STACKMAP_FRAME_TYPE(
850 VIRTUAL_DISPATCH, verify_subtype, (start, end));
851 }
852 return false;
853 }
854
855 #ifdef ASSERT
856 void stack_map_frame::print_on(outputStream* st) const {
857 FOR_EACH_STACKMAP_FRAME_TYPE(VOID_VIRTUAL_DISPATCH, print_on, (st));
858 }
859 #endif
860
861 #undef VIRTUAL_DISPATCH
862 #undef VOID_VIRTUAL_DISPATCH
863
864 #define AS_SUBTYPE_DEF(stack_frame_type, arg1, arg2) \
865 stack_frame_type* stack_map_frame::as_##stack_frame_type() const { \
866 if (stack_frame_type::is_frame_type(frame_type())) { \
867 return (stack_frame_type*)this; \
868 } else { \
869 return NULL; \
870 } \
871 }
872
873 FOR_EACH_STACKMAP_FRAME_TYPE(AS_SUBTYPE_DEF, x, x)
874 #undef AS_SUBTYPE_DEF
875
876 class stack_map_table_attribute {
877 private:
878 address name_index_addr() const {
879 return (address)this; }
880 address attribute_length_addr() const {
881 return name_index_addr() + sizeof(u2); }
882 address number_of_entries_addr() const {
883 return attribute_length_addr() + sizeof(u4); }
884 address entries_addr() const {
885 return number_of_entries_addr() + sizeof(u2); }
886
887 protected:
888 // No constructors - should be 'private', but GCC issues a warning if it is
889 stack_map_table_attribute() {}
890 stack_map_table_attribute(const stack_map_table_attribute&) {}
891
892 public:
893
894 static stack_map_table_attribute* at(address addr) {
895 return (stack_map_table_attribute*)addr;
896 }
897
898 u2 name_index() const {
899 return Bytes::get_Java_u2(name_index_addr()); }
900 u4 attribute_length() const {
901 return Bytes::get_Java_u4(attribute_length_addr()); }
902 u2 number_of_entries() const {
903 return Bytes::get_Java_u2(number_of_entries_addr()); }
904 stack_map_frame* entries() const {
905 return stack_map_frame::at(entries_addr());
906 }
907
908 static size_t header_size() {
909 return sizeof(u2) + sizeof(u4);
910 }
911
912 void set_name_index(u2 idx) {
913 Bytes::put_Java_u2(name_index_addr(), idx);
914 }
915 void set_attribute_length(u4 len) {
916 Bytes::put_Java_u4(attribute_length_addr(), len);
917 }
918 void set_number_of_entries(u2 num) {
919 Bytes::put_Java_u2(number_of_entries_addr(), num);
920 }
921 };
922
923 #endif // SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP
|
1 /*
2 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
118 }
119
120 size_t size() const {
121 return calculate_size(tag());
122 }
123
124 verification_type_info* next() {
125 return (verification_type_info*)((address)this + size());
126 }
127
128 // This method is used when reading unverified data in order to ensure
129 // that we don't read past a particular memory limit. It returns false
130 // if any part of the data structure is outside the specified memory bounds.
131 bool verify(address start, address end) {
132 return ((address)this >= start &&
133 (address)this < end &&
134 (bci_addr() + sizeof(u2) <= end ||
135 !is_object() && !is_uninitialized()));
136 }
137
138 void print_on(outputStream* st) {
139 switch (tag()) {
140 case ITEM_Top: st->print("Top"); break;
141 case ITEM_Integer: st->print("Integer"); break;
142 case ITEM_Float: st->print("Float"); break;
143 case ITEM_Double: st->print("Double"); break;
144 case ITEM_Long: st->print("Long"); break;
145 case ITEM_Null: st->print("Null"); break;
146 case ITEM_UninitializedThis:
147 st->print("UninitializedThis"); break;
148 case ITEM_Uninitialized:
149 st->print("Uninitialized[#%d]", bci()); break;
150 case ITEM_Object:
151 st->print("Object[#%d]", cpool_index()); break;
152 default:
153 assert(false, "Bad verification_type_info");
154 }
155 }
156 };
157
158 #define FOR_EACH_STACKMAP_FRAME_TYPE(macro, arg1, arg2) \
159 macro(same_frame, arg1, arg2) \
160 macro(same_frame_extended, arg1, arg2) \
161 macro(same_locals_1_stack_item_frame, arg1, arg2) \
162 macro(same_locals_1_stack_item_extended, arg1, arg2) \
163 macro(chop_frame, arg1, arg2) \
164 macro(append_frame, arg1, arg2) \
165 macro(full_frame, arg1, arg2)
166
167 #define SM_FORWARD_DECL(type, arg1, arg2) class type;
168 FOR_EACH_STACKMAP_FRAME_TYPE(SM_FORWARD_DECL, x, x)
169 #undef SM_FORWARD_DECL
170
171 class stack_map_frame {
172 protected:
173 address frame_type_addr() const { return (address)this; }
174
175 // No constructors - should be 'private', but GCC issues a warning if it is
176 stack_map_frame() {}
177 stack_map_frame(const stack_map_frame&) {}
178
179 public:
180
181 static stack_map_frame* at(address addr) {
182 return (stack_map_frame*)addr;
184
185 stack_map_frame* next() const {
186 return at((address)this + size());
187 }
188
189 u1 frame_type() const { return *(u1*)frame_type_addr(); }
190 void set_frame_type(u1 type) { *((u1*)frame_type_addr()) = type; }
191
192 // pseudo-virtual methods
193 inline size_t size() const;
194 inline int offset_delta() const;
195 inline void set_offset_delta(int offset_delta);
196 inline int number_of_types() const; // number of types contained in the frame
197 inline verification_type_info* types() const; // pointer to first type
198 inline bool is_valid_offset(int offset_delta) const;
199
200 // This method must be used when reading unverified data in order to ensure
201 // that we don't read past a particular memory limit. It returns false
202 // if any part of the data structure is outside the specified memory bounds.
203 inline bool verify(address start, address end) const;
204
205 inline void print_on(outputStream* st, int current_offset) const;
206 inline void print_truncated(outputStream* st, int current_offset) const;
207
208 // Create as_xxx and is_xxx methods for the subtypes
209 #define FRAME_TYPE_DECL(stackmap_frame_type, arg1, arg2) \
210 inline stackmap_frame_type* as_##stackmap_frame_type() const; \
211 bool is_##stackmap_frame_type() { \
212 return as_##stackmap_frame_type() != NULL; \
213 }
214
215 FOR_EACH_STACKMAP_FRAME_TYPE(FRAME_TYPE_DECL, x, x)
216 #undef FRAME_TYPE_DECL
217 };
218
219 class same_frame : public stack_map_frame {
220 private:
221 static int frame_type_to_offset_delta(u1 frame_type) {
222 return frame_type + 1; }
223 static u1 offset_delta_to_frame_type(int offset_delta) {
224 return (u1)(offset_delta - 1); }
225
226 public:
244
245 size_t size() const { return calculate_size(); }
246 int offset_delta() const { return frame_type_to_offset_delta(frame_type()); }
247
248 void set_offset_delta(int offset_delta) {
249 assert(offset_delta <= 64, "Offset too large for same_frame");
250 set_frame_type(offset_delta_to_frame_type(offset_delta));
251 }
252
253 int number_of_types() const { return 0; }
254 verification_type_info* types() const { return NULL; }
255
256 bool is_valid_offset(int offset_delta) const {
257 return is_frame_type(offset_delta_to_frame_type(offset_delta));
258 }
259
260 bool verify_subtype(address start, address end) const {
261 return true;
262 }
263
264 void print_on(outputStream* st, int current_offset = -1) const {
265 st->print("same_frame(@%d)", offset_delta() + current_offset);
266 }
267
268 void print_truncated(outputStream* st, int current_offset = -1) const {
269 print_on(st, current_offset);
270 }
271 };
272
273 class same_frame_extended : public stack_map_frame {
274 private:
275 enum { _frame_id = 251 };
276 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
277
278 public:
279 static bool is_frame_type(u1 tag) {
280 return tag == _frame_id;
281 }
282
283 static same_frame_extended* at(address addr) {
284 assert(is_frame_type(*addr), "Wrong frame type");
285 return (same_frame_extended*)addr;
286 }
287
288 static same_frame_extended* create_at(address addr, u2 offset_delta) {
289 same_frame_extended* sm = (same_frame_extended*)addr;
290 sm->set_frame_type(_frame_id);
294
295 static size_t calculate_size() { return sizeof(u1) + sizeof(u2); }
296
297 size_t size() const { return calculate_size(); }
298 int offset_delta() const {
299 return Bytes::get_Java_u2(offset_delta_addr()) + 1;
300 }
301
302 void set_offset_delta(int offset_delta) {
303 Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
304 }
305
306 int number_of_types() const { return 0; }
307 verification_type_info* types() const { return NULL; }
308 bool is_valid_offset(int offset) const { return true; }
309
310 bool verify_subtype(address start, address end) const {
311 return frame_type_addr() + size() <= end;
312 }
313
314 void print_on(outputStream* st, int current_offset = -1) const {
315 st->print("same_frame_extended(@%d)", offset_delta() + current_offset);
316 }
317
318 void print_truncated(outputStream* st, int current_offset = -1) const {
319 print_on(st, current_offset);
320 }
321 };
322
323 class same_locals_1_stack_item_frame : public stack_map_frame {
324 private:
325 address type_addr() const { return frame_type_addr() + sizeof(u1); }
326
327 static int frame_type_to_offset_delta(u1 frame_type) {
328 return frame_type - 63; }
329 static u1 offset_delta_to_frame_type(int offset_delta) {
330 return (u1)(offset_delta + 63); }
331
332 public:
333 static bool is_frame_type(u1 tag) {
334 return tag >= 64 && tag < 128;
335 }
336
337 static same_locals_1_stack_item_frame* at(address addr) {
338 assert(is_frame_type(*addr), "Wrong frame id");
339 return (same_locals_1_stack_item_frame*)addr;
340 }
341
342 static same_locals_1_stack_item_frame* create_at(
343 address addr, int offset_delta, verification_type_info* vti) {
344 same_locals_1_stack_item_frame* sm = (same_locals_1_stack_item_frame*)addr;
345 sm->set_offset_delta(offset_delta);
346 if (vti != NULL) {
347 sm->set_type(vti);
348 }
349 return sm;
350 }
351
352 static size_t calculate_size(verification_type_info* vti) {
353 return sizeof(u1) + vti->size();
354 }
355
356 static size_t max_size() {
357 return sizeof(u1) + verification_type_info::max_size();
358 }
359
360 size_t size() const { return calculate_size(types()); }
361 int offset_delta() const { return frame_type_to_offset_delta(frame_type()); }
362
363 void set_offset_delta(int offset_delta) {
364 assert(offset_delta > 0 && offset_delta <= 64,
367 }
368
369 void set_type(verification_type_info* vti) {
370 verification_type_info* cur = types();
371 cur->copy_from(vti);
372 }
373
374 int number_of_types() const { return 1; }
375 verification_type_info* types() const {
376 return verification_type_info::at(type_addr());
377 }
378
379 bool is_valid_offset(int offset_delta) const {
380 return is_frame_type(offset_delta_to_frame_type(offset_delta));
381 }
382
383 bool verify_subtype(address start, address end) const {
384 return types()->verify(start, end);
385 }
386
387 void print_on(outputStream* st, int current_offset = -1) const {
388 st->print("same_locals_1_stack_item_frame(@%d,",
389 offset_delta() + current_offset);
390 types()->print_on(st);
391 st->print(")");
392 }
393
394 void print_truncated(outputStream* st, int current_offset = -1) const {
395 st->print("same_locals_1_stack_item_frame(@%d), output truncated, Stackmap exceeds table size.",
396 offset_delta() + current_offset);
397 }
398 };
399
400 class same_locals_1_stack_item_extended : public stack_map_frame {
401 private:
402 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
403 address type_addr() const { return offset_delta_addr() + sizeof(u2); }
404
405 enum { _frame_id = 247 };
406
407 public:
408 static bool is_frame_type(u1 tag) {
409 return tag == _frame_id;
410 }
411
412 static same_locals_1_stack_item_extended* at(address addr) {
413 assert(is_frame_type(*addr), "Wrong frame id");
414 return (same_locals_1_stack_item_extended*)addr;
415 }
416
417 static same_locals_1_stack_item_extended* create_at(
418 address addr, int offset_delta, verification_type_info* vti) {
419 same_locals_1_stack_item_extended* sm =
420 (same_locals_1_stack_item_extended*)addr;
421 sm->set_frame_type(_frame_id);
422 sm->set_offset_delta(offset_delta);
423 if (vti != NULL) {
424 sm->set_type(vti);
425 }
426 return sm;
427 }
428
429 static size_t calculate_size(verification_type_info* vti) {
430 return sizeof(u1) + sizeof(u2) + vti->size();
431 }
432
433 size_t size() const { return calculate_size(types()); }
434 int offset_delta() const {
435 return Bytes::get_Java_u2(offset_delta_addr()) + 1;
436 }
437
438 void set_offset_delta(int offset_delta) {
439 Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1);
440 }
441
442 void set_type(verification_type_info* vti) {
443 verification_type_info* cur = types();
444 cur->copy_from(vti);
445 }
446
447 int number_of_types() const { return 1; }
448 verification_type_info* types() const {
449 return verification_type_info::at(type_addr());
450 }
451 bool is_valid_offset(int offset) { return true; }
452
453 bool verify_subtype(address start, address end) const {
454 return type_addr() < end && types()->verify(start, end);
455 }
456
457 void print_on(outputStream* st, int current_offset = -1) const {
458 st->print("same_locals_1_stack_item_extended(@%d,",
459 offset_delta() + current_offset);
460 types()->print_on(st);
461 st->print(")");
462 }
463
464 void print_truncated(outputStream* st, int current_offset = -1) const {
465 st->print("same_locals_1_stack_item_extended(@%d), output truncated, Stackmap exceeds table size.",
466 offset_delta() + current_offset);
467 }
468 };
469
470 class chop_frame : public stack_map_frame {
471 private:
472 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
473
474 static int frame_type_to_chops(u1 frame_type) {
475 int chop = 251 - frame_type;
476 return chop;
477 }
478
479 static u1 chops_to_frame_type(int chop) {
480 return 251 - chop;
481 }
482
483 public:
484 static bool is_frame_type(u1 tag) {
485 return frame_type_to_chops(tag) > 0 && frame_type_to_chops(tag) < 4;
486 }
487
510 }
511
512 int chops() const {
513 int chops = frame_type_to_chops(frame_type());
514 assert(chops > 0 && chops < 4, "Invalid number of chops in frame");
515 return chops;
516 }
517 void set_chops(int chops) {
518 assert(chops > 0 && chops <= 3, "Bad number of chops");
519 set_frame_type(chops_to_frame_type(chops));
520 }
521
522 int number_of_types() const { return 0; }
523 verification_type_info* types() const { return NULL; }
524 bool is_valid_offset(int offset) { return true; }
525
526 bool verify_subtype(address start, address end) const {
527 return frame_type_addr() + size() <= end;
528 }
529
530 void print_on(outputStream* st, int current_offset = -1) const {
531 st->print("chop_frame(@%d,%d)", offset_delta() + current_offset, chops());
532 }
533
534 void print_truncated(outputStream* st, int current_offset = -1) const {
535 print_on(st, current_offset);
536 }
537 };
538
539 class append_frame : public stack_map_frame {
540 private:
541 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
542 address types_addr() const { return offset_delta_addr() + sizeof(u2); }
543
544 static int frame_type_to_appends(u1 frame_type) {
545 int append = frame_type - 251;
546 return append;
547 }
548
549 static u1 appends_to_frame_type(int appends) {
550 assert(appends > 0 && appends < 4, "Invalid append amount");
551 return 251 + appends;
552 }
553
554 public:
555 static bool is_frame_type(u1 tag) {
556 return frame_type_to_appends(tag) > 0 && frame_type_to_appends(tag) < 4;
613 verification_type_info* types() const {
614 return verification_type_info::at(types_addr());
615 }
616 bool is_valid_offset(int offset) const { return true; }
617
618 bool verify_subtype(address start, address end) const {
619 verification_type_info* vti = types();
620 if ((address)vti < end && vti->verify(start, end)) {
621 int nof = number_of_types();
622 vti = vti->next();
623 if (nof < 2 || vti->verify(start, end)) {
624 vti = vti->next();
625 if (nof < 3 || vti->verify(start, end)) {
626 return true;
627 }
628 }
629 }
630 return false;
631 }
632
633 void print_on(outputStream* st, int current_offset = -1) const {
634 st->print("append_frame(@%d,", offset_delta() + current_offset);
635 verification_type_info* vti = types();
636 for (int i = 0; i < number_of_types(); ++i) {
637 vti->print_on(st);
638 if (i != number_of_types() - 1) {
639 st->print(",");
640 }
641 vti = vti->next();
642 }
643 st->print(")");
644 }
645
646 void print_truncated(outputStream* st, int current_offset = -1) const {
647 st->print("append_frame(@%d), output truncated, Stackmap exceeds table size.",
648 offset_delta() + current_offset);
649 }
650 };
651
652 class full_frame : public stack_map_frame {
653 private:
654 address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); }
655 address num_locals_addr() const { return offset_delta_addr() + sizeof(u2); }
656 address locals_addr() const { return num_locals_addr() + sizeof(u2); }
657 address stack_slots_addr(address end_of_locals) const {
658 return end_of_locals; }
659 address stack_addr(address end_of_locals) const {
660 return stack_slots_addr(end_of_locals) + sizeof(u2); }
661
662 enum { _frame_id = 255 };
663
664 public:
665 static bool is_frame_type(u1 tag) {
666 return tag == _frame_id;
667 }
668
669 static full_frame* at(address addr) {
772 if (!vti->verify(start, end)) {
773 return false;
774 }
775 vti = vti->next();
776 }
777 address eol = (address)vti;
778 if (eol + sizeof(u2) > end) {
779 return false;
780 }
781 count = stack_slots(eol);
782 vti = stack(eol);
783 for (int i = 0; i < stack_slots(eol); ++i) {
784 if (!vti->verify(start, end)) {
785 return false;
786 }
787 vti = vti->next();
788 }
789 return true;
790 }
791
792 void print_on(outputStream* st, int current_offset = -1) const {
793 st->print("full_frame(@%d,{", offset_delta() + current_offset);
794 verification_type_info* vti = locals();
795 for (int i = 0; i < num_locals(); ++i) {
796 vti->print_on(st);
797 if (i != num_locals() - 1) {
798 st->print(",");
799 }
800 vti = vti->next();
801 }
802 st->print("},{");
803 address end_of_locals = (address)vti;
804 vti = stack(end_of_locals);
805 int ss = stack_slots(end_of_locals);
806 for (int i = 0; i < ss; ++i) {
807 vti->print_on(st);
808 if (i != ss - 1) {
809 st->print(",");
810 }
811 vti = vti->next();
812 }
813 st->print("})");
814 }
815
816 void print_truncated(outputStream* st, int current_offset = -1) const {
817 st->print("full_frame(@%d), output truncated, Stackmap exceeds table size.",
818 offset_delta() + current_offset);
819 }
820 };
821
822 #define VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \
823 stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \
824 if (item_##stack_frame_type != NULL) { \
825 return item_##stack_frame_type->func_name args; \
826 }
827
828 #define VOID_VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \
829 stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \
830 if (item_##stack_frame_type != NULL) { \
831 item_##stack_frame_type->func_name args; \
832 return; \
833 }
834
835 size_t stack_map_frame::size() const {
836 FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, size, ());
837 return 0;
838 }
839
853 }
854
855 verification_type_info* stack_map_frame::types() const {
856 FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, types, ());
857 return NULL;
858 }
859
860 bool stack_map_frame::is_valid_offset(int offset) const {
861 FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, is_valid_offset, (offset));
862 return true;
863 }
864
865 bool stack_map_frame::verify(address start, address end) const {
866 if (frame_type_addr() >= start && frame_type_addr() < end) {
867 FOR_EACH_STACKMAP_FRAME_TYPE(
868 VIRTUAL_DISPATCH, verify_subtype, (start, end));
869 }
870 return false;
871 }
872
873 void stack_map_frame::print_on(outputStream* st, int offs = -1) const {
874 FOR_EACH_STACKMAP_FRAME_TYPE(VOID_VIRTUAL_DISPATCH, print_on, (st, offs));
875 }
876
877 void stack_map_frame::print_truncated(outputStream* st, int offs = -1) const {
878 FOR_EACH_STACKMAP_FRAME_TYPE(VOID_VIRTUAL_DISPATCH, print_truncated, (st, offs));
879 }
880
881 #undef VIRTUAL_DISPATCH
882 #undef VOID_VIRTUAL_DISPATCH
883
884 #define AS_SUBTYPE_DEF(stack_frame_type, arg1, arg2) \
885 stack_frame_type* stack_map_frame::as_##stack_frame_type() const { \
886 if (stack_frame_type::is_frame_type(frame_type())) { \
887 return (stack_frame_type*)this; \
888 } else { \
889 return NULL; \
890 } \
891 }
892
893 FOR_EACH_STACKMAP_FRAME_TYPE(AS_SUBTYPE_DEF, x, x)
894 #undef AS_SUBTYPE_DEF
895
896 class stack_map_table {
897 private:
898 address number_of_entries_addr() const {
899 return (address)this;
900 }
901 address entries_addr() const {
902 return number_of_entries_addr() + sizeof(u2);
903 }
904
905 protected:
906 // No constructors - should be 'private', but GCC issues a warning if it is
907 stack_map_table() {}
908 stack_map_table(const stack_map_table&) {}
909
910 public:
911
912 static stack_map_table* at(address addr) {
913 return (stack_map_table*)addr;
914 }
915
916 u2 number_of_entries() const {
917 return Bytes::get_Java_u2(number_of_entries_addr());
918 }
919 stack_map_frame* entries() const {
920 return stack_map_frame::at(entries_addr());
921 }
922
923 void set_number_of_entries(u2 num) {
924 Bytes::put_Java_u2(number_of_entries_addr(), num);
925 }
926 };
927
928 class stack_map_table_attribute {
929 private:
930 address name_index_addr() const {
931 return (address)this; }
932 address attribute_length_addr() const {
933 return name_index_addr() + sizeof(u2); }
934 address stack_map_table_addr() const {
935 return attribute_length_addr() + sizeof(u4); }
936
937 protected:
938 // No constructors - should be 'private', but GCC issues a warning if it is
939 stack_map_table_attribute() {}
940 stack_map_table_attribute(const stack_map_table_attribute&) {}
941
942 public:
943
944 static stack_map_table_attribute* at(address addr) {
945 return (stack_map_table_attribute*)addr;
946 }
947
948 u2 name_index() const {
949 return Bytes::get_Java_u2(name_index_addr()); }
950 u4 attribute_length() const {
951 return Bytes::get_Java_u4(attribute_length_addr()); }
952 stack_map_table* table() const {
953 return stack_map_table::at(stack_map_table_addr());
954 }
955
956 void set_name_index(u2 idx) {
957 Bytes::put_Java_u2(name_index_addr(), idx);
958 }
959 void set_attribute_length(u4 len) {
960 Bytes::put_Java_u4(attribute_length_addr(), len);
961 }
962 };
963
964 #undef FOR_EACH_STACKMAP_FRAME_TYPE
965
966 #endif // SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP
|