aoqi@0: /* aoqi@0: * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP aoqi@0: #define SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP aoqi@0: aoqi@0: #include "classfile/verificationType.hpp" aoqi@0: aoqi@0: // These classes represent the stack-map substructures described in the JVMS aoqi@0: // (hence the non-conforming naming scheme). aoqi@0: aoqi@0: // These classes work with the types in their compressed form in-place (as they aoqi@0: // would appear in the classfile). No virtual methods or fields allowed. aoqi@0: aoqi@0: class verification_type_info { aoqi@0: private: aoqi@0: // u1 tag aoqi@0: // u2 cpool_index || u2 bci (for ITEM_Object & ITEM_Uninitailized only) aoqi@0: aoqi@0: address tag_addr() const { return (address)this; } aoqi@0: address cpool_index_addr() const { return tag_addr() + sizeof(u1); } aoqi@0: address bci_addr() const { return cpool_index_addr(); } aoqi@0: aoqi@0: protected: aoqi@0: // No constructors - should be 'private', but GCC issues a warning if it is aoqi@0: verification_type_info() {} aoqi@0: verification_type_info(const verification_type_info&) {} aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: static verification_type_info* at(address addr) { aoqi@0: return (verification_type_info*)addr; aoqi@0: } aoqi@0: aoqi@0: static verification_type_info* create_at(address addr, u1 tag) { aoqi@0: verification_type_info* vti = (verification_type_info*)addr; aoqi@0: vti->set_tag(tag); aoqi@0: return vti; aoqi@0: } aoqi@0: aoqi@0: static verification_type_info* create_object_at(address addr, u2 cp_idx) { aoqi@0: verification_type_info* vti = (verification_type_info*)addr; aoqi@0: vti->set_tag(ITEM_Object); aoqi@0: vti->set_cpool_index(cp_idx); aoqi@0: return vti; aoqi@0: } aoqi@0: aoqi@0: static verification_type_info* create_uninit_at(address addr, u2 bci) { aoqi@0: verification_type_info* vti = (verification_type_info*)addr; aoqi@0: vti->set_tag(ITEM_Uninitialized); aoqi@0: vti->set_bci(bci); aoqi@0: return vti; aoqi@0: } aoqi@0: aoqi@0: static size_t calculate_size(u1 tag) { aoqi@0: if (tag == ITEM_Object || tag == ITEM_Uninitialized) { aoqi@0: return sizeof(u1) + sizeof(u2); aoqi@0: } else { aoqi@0: return sizeof(u1); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: static size_t max_size() { return sizeof(u1) + sizeof(u2); } aoqi@0: aoqi@0: u1 tag() const { return *(u1*)tag_addr(); } aoqi@0: void set_tag(u1 tag) { *((u1*)tag_addr()) = tag; } aoqi@0: aoqi@0: bool is_object() const { return tag() == ITEM_Object; } aoqi@0: bool is_uninitialized() const { return tag() == ITEM_Uninitialized; } aoqi@0: aoqi@0: u2 cpool_index() const { aoqi@0: assert(is_object(), "This type has no cp_index"); aoqi@0: return Bytes::get_Java_u2(cpool_index_addr()); aoqi@0: } aoqi@0: void set_cpool_index(u2 idx) { aoqi@0: assert(is_object(), "This type has no cp_index"); aoqi@0: Bytes::put_Java_u2(cpool_index_addr(), idx); aoqi@0: } aoqi@0: aoqi@0: u2 bci() const { aoqi@0: assert(is_uninitialized(), "This type has no bci"); aoqi@0: return Bytes::get_Java_u2(bci_addr()); aoqi@0: } aoqi@0: aoqi@0: void set_bci(u2 bci) { aoqi@0: assert(is_uninitialized(), "This type has no bci"); aoqi@0: Bytes::put_Java_u2(bci_addr(), bci); aoqi@0: } aoqi@0: aoqi@0: void copy_from(verification_type_info* from) { aoqi@0: set_tag(from->tag()); aoqi@0: if (from->is_object()) { aoqi@0: set_cpool_index(from->cpool_index()); aoqi@0: } else if (from->is_uninitialized()) { aoqi@0: set_bci(from->bci()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: size_t size() const { aoqi@0: return calculate_size(tag()); aoqi@0: } aoqi@0: aoqi@0: verification_type_info* next() { aoqi@0: return (verification_type_info*)((address)this + size()); aoqi@0: } aoqi@0: aoqi@0: // This method is used when reading unverified data in order to ensure aoqi@0: // that we don't read past a particular memory limit. It returns false aoqi@0: // if any part of the data structure is outside the specified memory bounds. aoqi@0: bool verify(address start, address end) { aoqi@0: return ((address)this >= start && aoqi@0: (address)this < end && aoqi@0: (bci_addr() + sizeof(u2) <= end || aoqi@0: !is_object() && !is_uninitialized())); aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st) { aoqi@0: switch (tag()) { aoqi@0: case ITEM_Top: st->print("Top"); break; aoqi@0: case ITEM_Integer: st->print("Integer"); break; aoqi@0: case ITEM_Float: st->print("Float"); break; aoqi@0: case ITEM_Double: st->print("Double"); break; aoqi@0: case ITEM_Long: st->print("Long"); break; aoqi@0: case ITEM_Null: st->print("Null"); break; aoqi@0: case ITEM_UninitializedThis: aoqi@0: st->print("UninitializedThis"); break; aoqi@0: case ITEM_Uninitialized: aoqi@0: st->print("Uninitialized[#%d]", bci()); break; aoqi@0: case ITEM_Object: aoqi@0: st->print("Object[#%d]", cpool_index()); break; aoqi@0: default: aoqi@0: assert(false, "Bad verification_type_info"); aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: #define FOR_EACH_STACKMAP_FRAME_TYPE(macro, arg1, arg2) \ aoqi@0: macro(same_frame, arg1, arg2) \ aoqi@0: macro(same_frame_extended, arg1, arg2) \ aoqi@0: macro(same_locals_1_stack_item_frame, arg1, arg2) \ aoqi@0: macro(same_locals_1_stack_item_extended, arg1, arg2) \ aoqi@0: macro(chop_frame, arg1, arg2) \ aoqi@0: macro(append_frame, arg1, arg2) \ aoqi@0: macro(full_frame, arg1, arg2) aoqi@0: aoqi@0: #define SM_FORWARD_DECL(type, arg1, arg2) class type; aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE(SM_FORWARD_DECL, x, x) aoqi@0: #undef SM_FORWARD_DECL aoqi@0: aoqi@0: class stack_map_frame { aoqi@0: protected: aoqi@0: address frame_type_addr() const { return (address)this; } aoqi@0: aoqi@0: // No constructors - should be 'private', but GCC issues a warning if it is aoqi@0: stack_map_frame() {} aoqi@0: stack_map_frame(const stack_map_frame&) {} aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: static stack_map_frame* at(address addr) { aoqi@0: return (stack_map_frame*)addr; aoqi@0: } aoqi@0: aoqi@0: stack_map_frame* next() const { aoqi@0: return at((address)this + size()); aoqi@0: } aoqi@0: aoqi@0: u1 frame_type() const { return *(u1*)frame_type_addr(); } aoqi@0: void set_frame_type(u1 type) { *((u1*)frame_type_addr()) = type; } aoqi@0: aoqi@0: // pseudo-virtual methods aoqi@0: inline size_t size() const; aoqi@0: inline int offset_delta() const; aoqi@0: inline void set_offset_delta(int offset_delta); aoqi@0: inline int number_of_types() const; // number of types contained in the frame aoqi@0: inline verification_type_info* types() const; // pointer to first type aoqi@0: inline bool is_valid_offset(int offset_delta) const; aoqi@0: aoqi@0: // This method must be used when reading unverified data in order to ensure aoqi@0: // that we don't read past a particular memory limit. It returns false aoqi@0: // if any part of the data structure is outside the specified memory bounds. aoqi@0: inline bool verify(address start, address end) const; aoqi@0: aoqi@0: inline void print_on(outputStream* st, int current_offset) const; aoqi@0: aoqi@0: // Create as_xxx and is_xxx methods for the subtypes aoqi@0: #define FRAME_TYPE_DECL(stackmap_frame_type, arg1, arg2) \ aoqi@0: inline stackmap_frame_type* as_##stackmap_frame_type() const; \ aoqi@0: bool is_##stackmap_frame_type() { \ aoqi@0: return as_##stackmap_frame_type() != NULL; \ aoqi@0: } aoqi@0: aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE(FRAME_TYPE_DECL, x, x) aoqi@0: #undef FRAME_TYPE_DECL aoqi@0: }; aoqi@0: aoqi@0: class same_frame : public stack_map_frame { aoqi@0: private: aoqi@0: static int frame_type_to_offset_delta(u1 frame_type) { aoqi@0: return frame_type + 1; } aoqi@0: static u1 offset_delta_to_frame_type(int offset_delta) { aoqi@0: return (u1)(offset_delta - 1); } aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: static bool is_frame_type(u1 tag) { aoqi@0: return tag < 64; aoqi@0: } aoqi@0: aoqi@0: static same_frame* at(address addr) { aoqi@0: assert(is_frame_type(*addr), "Wrong frame id"); aoqi@0: return (same_frame*)addr; aoqi@0: } aoqi@0: aoqi@0: static same_frame* create_at(address addr, int offset_delta) { aoqi@0: same_frame* sm = (same_frame*)addr; aoqi@0: sm->set_offset_delta(offset_delta); aoqi@0: return sm; aoqi@0: } aoqi@0: aoqi@0: static size_t calculate_size() { return sizeof(u1); } aoqi@0: aoqi@0: size_t size() const { return calculate_size(); } aoqi@0: int offset_delta() const { return frame_type_to_offset_delta(frame_type()); } aoqi@0: aoqi@0: void set_offset_delta(int offset_delta) { aoqi@0: assert(offset_delta <= 64, "Offset too large for same_frame"); aoqi@0: set_frame_type(offset_delta_to_frame_type(offset_delta)); aoqi@0: } aoqi@0: aoqi@0: int number_of_types() const { return 0; } aoqi@0: verification_type_info* types() const { return NULL; } aoqi@0: aoqi@0: bool is_valid_offset(int offset_delta) const { aoqi@0: return is_frame_type(offset_delta_to_frame_type(offset_delta)); aoqi@0: } aoqi@0: aoqi@0: bool verify_subtype(address start, address end) const { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st, int current_offset = -1) const { aoqi@0: st->print("same_frame(@%d)", offset_delta() + current_offset); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class same_frame_extended : public stack_map_frame { aoqi@0: private: aoqi@0: enum { _frame_id = 251 }; aoqi@0: address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); } aoqi@0: aoqi@0: public: aoqi@0: static bool is_frame_type(u1 tag) { aoqi@0: return tag == _frame_id; aoqi@0: } aoqi@0: aoqi@0: static same_frame_extended* at(address addr) { aoqi@0: assert(is_frame_type(*addr), "Wrong frame type"); aoqi@0: return (same_frame_extended*)addr; aoqi@0: } aoqi@0: aoqi@0: static same_frame_extended* create_at(address addr, u2 offset_delta) { aoqi@0: same_frame_extended* sm = (same_frame_extended*)addr; aoqi@0: sm->set_frame_type(_frame_id); aoqi@0: sm->set_offset_delta(offset_delta); aoqi@0: return sm; aoqi@0: } aoqi@0: aoqi@0: static size_t calculate_size() { return sizeof(u1) + sizeof(u2); } aoqi@0: aoqi@0: size_t size() const { return calculate_size(); } aoqi@0: int offset_delta() const { aoqi@0: return Bytes::get_Java_u2(offset_delta_addr()) + 1; aoqi@0: } aoqi@0: aoqi@0: void set_offset_delta(int offset_delta) { aoqi@0: Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1); aoqi@0: } aoqi@0: aoqi@0: int number_of_types() const { return 0; } aoqi@0: verification_type_info* types() const { return NULL; } aoqi@0: bool is_valid_offset(int offset) const { return true; } aoqi@0: aoqi@0: bool verify_subtype(address start, address end) const { aoqi@0: return frame_type_addr() + size() <= end; aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st, int current_offset = -1) const { aoqi@0: st->print("same_frame_extended(@%d)", offset_delta() + current_offset); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class same_locals_1_stack_item_frame : public stack_map_frame { aoqi@0: private: aoqi@0: address type_addr() const { return frame_type_addr() + sizeof(u1); } aoqi@0: aoqi@0: static int frame_type_to_offset_delta(u1 frame_type) { aoqi@0: return frame_type - 63; } aoqi@0: static u1 offset_delta_to_frame_type(int offset_delta) { aoqi@0: return (u1)(offset_delta + 63); } aoqi@0: aoqi@0: public: aoqi@0: static bool is_frame_type(u1 tag) { aoqi@0: return tag >= 64 && tag < 128; aoqi@0: } aoqi@0: aoqi@0: static same_locals_1_stack_item_frame* at(address addr) { aoqi@0: assert(is_frame_type(*addr), "Wrong frame id"); aoqi@0: return (same_locals_1_stack_item_frame*)addr; aoqi@0: } aoqi@0: aoqi@0: static same_locals_1_stack_item_frame* create_at( aoqi@0: address addr, int offset_delta, verification_type_info* vti) { aoqi@0: same_locals_1_stack_item_frame* sm = (same_locals_1_stack_item_frame*)addr; aoqi@0: sm->set_offset_delta(offset_delta); aoqi@0: if (vti != NULL) { aoqi@0: sm->set_type(vti); aoqi@0: } aoqi@0: return sm; aoqi@0: } aoqi@0: aoqi@0: static size_t calculate_size(verification_type_info* vti) { aoqi@0: return sizeof(u1) + vti->size(); aoqi@0: } aoqi@0: aoqi@0: static size_t max_size() { aoqi@0: return sizeof(u1) + verification_type_info::max_size(); aoqi@0: } aoqi@0: aoqi@0: size_t size() const { return calculate_size(types()); } aoqi@0: int offset_delta() const { return frame_type_to_offset_delta(frame_type()); } aoqi@0: aoqi@0: void set_offset_delta(int offset_delta) { aoqi@0: assert(offset_delta > 0 && offset_delta <= 64, aoqi@0: "Offset too large for this frame type"); aoqi@0: set_frame_type(offset_delta_to_frame_type(offset_delta)); aoqi@0: } aoqi@0: aoqi@0: void set_type(verification_type_info* vti) { aoqi@0: verification_type_info* cur = types(); aoqi@0: cur->copy_from(vti); aoqi@0: } aoqi@0: aoqi@0: int number_of_types() const { return 1; } aoqi@0: verification_type_info* types() const { aoqi@0: return verification_type_info::at(type_addr()); aoqi@0: } aoqi@0: aoqi@0: bool is_valid_offset(int offset_delta) const { aoqi@0: return is_frame_type(offset_delta_to_frame_type(offset_delta)); aoqi@0: } aoqi@0: aoqi@0: bool verify_subtype(address start, address end) const { aoqi@0: return types()->verify(start, end); aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st, int current_offset = -1) const { aoqi@0: st->print("same_locals_1_stack_item_frame(@%d,", aoqi@0: offset_delta() + current_offset); aoqi@0: types()->print_on(st); aoqi@0: st->print(")"); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class same_locals_1_stack_item_extended : public stack_map_frame { aoqi@0: private: aoqi@0: address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); } aoqi@0: address type_addr() const { return offset_delta_addr() + sizeof(u2); } aoqi@0: aoqi@0: enum { _frame_id = 247 }; aoqi@0: aoqi@0: public: aoqi@0: static bool is_frame_type(u1 tag) { aoqi@0: return tag == _frame_id; aoqi@0: } aoqi@0: aoqi@0: static same_locals_1_stack_item_extended* at(address addr) { aoqi@0: assert(is_frame_type(*addr), "Wrong frame id"); aoqi@0: return (same_locals_1_stack_item_extended*)addr; aoqi@0: } aoqi@0: aoqi@0: static same_locals_1_stack_item_extended* create_at( aoqi@0: address addr, int offset_delta, verification_type_info* vti) { aoqi@0: same_locals_1_stack_item_extended* sm = aoqi@0: (same_locals_1_stack_item_extended*)addr; aoqi@0: sm->set_frame_type(_frame_id); aoqi@0: sm->set_offset_delta(offset_delta); aoqi@0: if (vti != NULL) { aoqi@0: sm->set_type(vti); aoqi@0: } aoqi@0: return sm; aoqi@0: } aoqi@0: aoqi@0: static size_t calculate_size(verification_type_info* vti) { aoqi@0: return sizeof(u1) + sizeof(u2) + vti->size(); aoqi@0: } aoqi@0: aoqi@0: size_t size() const { return calculate_size(types()); } aoqi@0: int offset_delta() const { aoqi@0: return Bytes::get_Java_u2(offset_delta_addr()) + 1; aoqi@0: } aoqi@0: aoqi@0: void set_offset_delta(int offset_delta) { aoqi@0: Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1); aoqi@0: } aoqi@0: aoqi@0: void set_type(verification_type_info* vti) { aoqi@0: verification_type_info* cur = types(); aoqi@0: cur->copy_from(vti); aoqi@0: } aoqi@0: aoqi@0: int number_of_types() const { return 1; } aoqi@0: verification_type_info* types() const { aoqi@0: return verification_type_info::at(type_addr()); aoqi@0: } aoqi@0: bool is_valid_offset(int offset) { return true; } aoqi@0: aoqi@0: bool verify_subtype(address start, address end) const { aoqi@0: return type_addr() < end && types()->verify(start, end); aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st, int current_offset = -1) const { aoqi@0: st->print("same_locals_1_stack_item_extended(@%d,", aoqi@0: offset_delta() + current_offset); aoqi@0: types()->print_on(st); aoqi@0: st->print(")"); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class chop_frame : public stack_map_frame { aoqi@0: private: aoqi@0: address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); } aoqi@0: aoqi@0: static int frame_type_to_chops(u1 frame_type) { aoqi@0: int chop = 251 - frame_type; aoqi@0: return chop; aoqi@0: } aoqi@0: aoqi@0: static u1 chops_to_frame_type(int chop) { aoqi@0: return 251 - chop; aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: static bool is_frame_type(u1 tag) { aoqi@0: return frame_type_to_chops(tag) > 0 && frame_type_to_chops(tag) < 4; aoqi@0: } aoqi@0: aoqi@0: static chop_frame* at(address addr) { aoqi@0: assert(is_frame_type(*addr), "Wrong frame id"); aoqi@0: return (chop_frame*)addr; aoqi@0: } aoqi@0: aoqi@0: static chop_frame* create_at(address addr, int offset_delta, int chops) { aoqi@0: chop_frame* sm = (chop_frame*)addr; aoqi@0: sm->set_chops(chops); aoqi@0: sm->set_offset_delta(offset_delta); aoqi@0: return sm; aoqi@0: } aoqi@0: aoqi@0: static size_t calculate_size() { aoqi@0: return sizeof(u1) + sizeof(u2); aoqi@0: } aoqi@0: aoqi@0: size_t size() const { return calculate_size(); } aoqi@0: int offset_delta() const { aoqi@0: return Bytes::get_Java_u2(offset_delta_addr()) + 1; aoqi@0: } aoqi@0: void set_offset_delta(int offset_delta) { aoqi@0: Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1); aoqi@0: } aoqi@0: aoqi@0: int chops() const { aoqi@0: int chops = frame_type_to_chops(frame_type()); aoqi@0: assert(chops > 0 && chops < 4, "Invalid number of chops in frame"); aoqi@0: return chops; aoqi@0: } aoqi@0: void set_chops(int chops) { aoqi@0: assert(chops > 0 && chops <= 3, "Bad number of chops"); aoqi@0: set_frame_type(chops_to_frame_type(chops)); aoqi@0: } aoqi@0: aoqi@0: int number_of_types() const { return 0; } aoqi@0: verification_type_info* types() const { return NULL; } aoqi@0: bool is_valid_offset(int offset) { return true; } aoqi@0: aoqi@0: bool verify_subtype(address start, address end) const { aoqi@0: return frame_type_addr() + size() <= end; aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st, int current_offset = -1) const { aoqi@0: st->print("chop_frame(@%d,%d)", offset_delta() + current_offset, chops()); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class append_frame : public stack_map_frame { aoqi@0: private: aoqi@0: address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); } aoqi@0: address types_addr() const { return offset_delta_addr() + sizeof(u2); } aoqi@0: aoqi@0: static int frame_type_to_appends(u1 frame_type) { aoqi@0: int append = frame_type - 251; aoqi@0: return append; aoqi@0: } aoqi@0: aoqi@0: static u1 appends_to_frame_type(int appends) { aoqi@0: assert(appends > 0 && appends < 4, "Invalid append amount"); aoqi@0: return 251 + appends; aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: static bool is_frame_type(u1 tag) { aoqi@0: return frame_type_to_appends(tag) > 0 && frame_type_to_appends(tag) < 4; aoqi@0: } aoqi@0: aoqi@0: static append_frame* at(address addr) { aoqi@0: assert(is_frame_type(*addr), "Wrong frame id"); aoqi@0: return (append_frame*)addr; aoqi@0: } aoqi@0: aoqi@0: static append_frame* create_at( aoqi@0: address addr, int offset_delta, int appends, aoqi@0: verification_type_info* types) { aoqi@0: append_frame* sm = (append_frame*)addr; aoqi@0: sm->set_appends(appends); aoqi@0: sm->set_offset_delta(offset_delta); aoqi@0: if (types != NULL) { aoqi@0: verification_type_info* cur = sm->types(); aoqi@0: for (int i = 0; i < appends; ++i) { aoqi@0: cur->copy_from(types); aoqi@0: cur = cur->next(); aoqi@0: types = types->next(); aoqi@0: } aoqi@0: } aoqi@0: return sm; aoqi@0: } aoqi@0: aoqi@0: static size_t calculate_size(int appends, verification_type_info* types) { aoqi@0: size_t sz = sizeof(u1) + sizeof(u2); aoqi@0: for (int i = 0; i < appends; ++i) { aoqi@0: sz += types->size(); aoqi@0: types = types->next(); aoqi@0: } aoqi@0: return sz; aoqi@0: } aoqi@0: aoqi@0: static size_t max_size() { aoqi@0: return sizeof(u1) + sizeof(u2) + 3 * verification_type_info::max_size(); aoqi@0: } aoqi@0: aoqi@0: size_t size() const { return calculate_size(number_of_types(), types()); } aoqi@0: int offset_delta() const { aoqi@0: return Bytes::get_Java_u2(offset_delta_addr()) + 1; aoqi@0: } aoqi@0: aoqi@0: void set_offset_delta(int offset_delta) { aoqi@0: Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1); aoqi@0: } aoqi@0: aoqi@0: void set_appends(int appends) { aoqi@0: assert(appends > 0 && appends < 4, "Bad number of appends"); aoqi@0: set_frame_type(appends_to_frame_type(appends)); aoqi@0: } aoqi@0: aoqi@0: int number_of_types() const { aoqi@0: int appends = frame_type_to_appends(frame_type()); aoqi@0: assert(appends > 0 && appends < 4, "Invalid number of appends in frame"); aoqi@0: return appends; aoqi@0: } aoqi@0: verification_type_info* types() const { aoqi@0: return verification_type_info::at(types_addr()); aoqi@0: } aoqi@0: bool is_valid_offset(int offset) const { return true; } aoqi@0: aoqi@0: bool verify_subtype(address start, address end) const { aoqi@0: verification_type_info* vti = types(); aoqi@0: if ((address)vti < end && vti->verify(start, end)) { aoqi@0: int nof = number_of_types(); aoqi@0: vti = vti->next(); aoqi@0: if (nof < 2 || vti->verify(start, end)) { aoqi@0: vti = vti->next(); aoqi@0: if (nof < 3 || vti->verify(start, end)) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st, int current_offset = -1) const { aoqi@0: st->print("append_frame(@%d,", offset_delta() + current_offset); aoqi@0: verification_type_info* vti = types(); aoqi@0: for (int i = 0; i < number_of_types(); ++i) { aoqi@0: vti->print_on(st); aoqi@0: if (i != number_of_types() - 1) { aoqi@0: st->print(","); aoqi@0: } aoqi@0: vti = vti->next(); aoqi@0: } aoqi@0: st->print(")"); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class full_frame : public stack_map_frame { aoqi@0: private: aoqi@0: address offset_delta_addr() const { return frame_type_addr() + sizeof(u1); } aoqi@0: address num_locals_addr() const { return offset_delta_addr() + sizeof(u2); } aoqi@0: address locals_addr() const { return num_locals_addr() + sizeof(u2); } aoqi@0: address stack_slots_addr(address end_of_locals) const { aoqi@0: return end_of_locals; } aoqi@0: address stack_addr(address end_of_locals) const { aoqi@0: return stack_slots_addr(end_of_locals) + sizeof(u2); } aoqi@0: aoqi@0: enum { _frame_id = 255 }; aoqi@0: aoqi@0: public: aoqi@0: static bool is_frame_type(u1 tag) { aoqi@0: return tag == _frame_id; aoqi@0: } aoqi@0: aoqi@0: static full_frame* at(address addr) { aoqi@0: assert(is_frame_type(*addr), "Wrong frame id"); aoqi@0: return (full_frame*)addr; aoqi@0: } aoqi@0: aoqi@0: static full_frame* create_at( aoqi@0: address addr, int offset_delta, int num_locals, aoqi@0: verification_type_info* locals, aoqi@0: int stack_slots, verification_type_info* stack) { aoqi@0: full_frame* sm = (full_frame*)addr; aoqi@0: sm->set_frame_type(_frame_id); aoqi@0: sm->set_offset_delta(offset_delta); aoqi@0: sm->set_num_locals(num_locals); aoqi@0: if (locals != NULL) { aoqi@0: verification_type_info* cur = sm->locals(); aoqi@0: for (int i = 0; i < num_locals; ++i) { aoqi@0: cur->copy_from(locals); aoqi@0: cur = cur->next(); aoqi@0: locals = locals->next(); aoqi@0: } aoqi@0: address end_of_locals = (address)cur; aoqi@0: sm->set_stack_slots(end_of_locals, stack_slots); aoqi@0: cur = sm->stack(end_of_locals); aoqi@0: for (int i = 0; i < stack_slots; ++i) { aoqi@0: cur->copy_from(stack); aoqi@0: cur = cur->next(); aoqi@0: stack = stack->next(); aoqi@0: } aoqi@0: } aoqi@0: return sm; aoqi@0: } aoqi@0: aoqi@0: static size_t calculate_size( aoqi@0: int num_locals, verification_type_info* locals, aoqi@0: int stack_slots, verification_type_info* stack) { aoqi@0: size_t sz = sizeof(u1) + sizeof(u2) + sizeof(u2) + sizeof(u2); aoqi@0: verification_type_info* vti = locals; aoqi@0: for (int i = 0; i < num_locals; ++i) { aoqi@0: sz += vti->size(); aoqi@0: vti = vti->next(); aoqi@0: } aoqi@0: vti = stack; aoqi@0: for (int i = 0; i < stack_slots; ++i) { aoqi@0: sz += vti->size(); aoqi@0: vti = vti->next(); aoqi@0: } aoqi@0: return sz; aoqi@0: } aoqi@0: aoqi@0: static size_t max_size(int locals, int stack) { aoqi@0: return sizeof(u1) + 3 * sizeof(u2) + aoqi@0: (locals + stack) * verification_type_info::max_size(); aoqi@0: } aoqi@0: aoqi@0: size_t size() const { aoqi@0: address eol = end_of_locals(); aoqi@0: return calculate_size(num_locals(), locals(), stack_slots(eol), stack(eol)); aoqi@0: } aoqi@0: aoqi@0: int offset_delta() const { aoqi@0: return Bytes::get_Java_u2(offset_delta_addr()) + 1; aoqi@0: } aoqi@0: int num_locals() const { return Bytes::get_Java_u2(num_locals_addr()); } aoqi@0: verification_type_info* locals() const { aoqi@0: return verification_type_info::at(locals_addr()); aoqi@0: } aoqi@0: address end_of_locals() const { aoqi@0: verification_type_info* vti = locals(); aoqi@0: for (int i = 0; i < num_locals(); ++i) { aoqi@0: vti = vti->next(); aoqi@0: } aoqi@0: return (address)vti; aoqi@0: } aoqi@0: int stack_slots(address end_of_locals) const { aoqi@0: return Bytes::get_Java_u2(stack_slots_addr(end_of_locals)); aoqi@0: } aoqi@0: verification_type_info* stack(address end_of_locals) const { aoqi@0: return verification_type_info::at(stack_addr(end_of_locals)); aoqi@0: } aoqi@0: aoqi@0: void set_offset_delta(int offset_delta) { aoqi@0: Bytes::put_Java_u2(offset_delta_addr(), offset_delta - 1); aoqi@0: } aoqi@0: void set_num_locals(int num_locals) { aoqi@0: Bytes::put_Java_u2(num_locals_addr(), num_locals); aoqi@0: } aoqi@0: void set_stack_slots(address end_of_locals, int stack_slots) { aoqi@0: Bytes::put_Java_u2(stack_slots_addr(end_of_locals), stack_slots); aoqi@0: } aoqi@0: aoqi@0: // These return only the locals. Extra processing is required for stack aoqi@0: // types of full frames. aoqi@0: int number_of_types() const { return num_locals(); } aoqi@0: verification_type_info* types() const { return locals(); } aoqi@0: bool is_valid_offset(int offset) { return true; } aoqi@0: aoqi@0: bool verify_subtype(address start, address end) const { aoqi@0: verification_type_info* vti = types(); aoqi@0: if ((address)vti >= end) { aoqi@0: return false; aoqi@0: } aoqi@0: int count = number_of_types(); aoqi@0: for (int i = 0; i < count; ++i) { aoqi@0: if (!vti->verify(start, end)) { aoqi@0: return false; aoqi@0: } aoqi@0: vti = vti->next(); aoqi@0: } aoqi@0: address eol = (address)vti; aoqi@0: if (eol + sizeof(u2) > end) { aoqi@0: return false; aoqi@0: } aoqi@0: count = stack_slots(eol); aoqi@0: vti = stack(eol); aoqi@0: for (int i = 0; i < stack_slots(eol); ++i) { aoqi@0: if (!vti->verify(start, end)) { aoqi@0: return false; aoqi@0: } aoqi@0: vti = vti->next(); aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: void print_on(outputStream* st, int current_offset = -1) const { aoqi@0: st->print("full_frame(@%d,{", offset_delta() + current_offset); aoqi@0: verification_type_info* vti = locals(); aoqi@0: for (int i = 0; i < num_locals(); ++i) { aoqi@0: vti->print_on(st); aoqi@0: if (i != num_locals() - 1) { aoqi@0: st->print(","); aoqi@0: } aoqi@0: vti = vti->next(); aoqi@0: } aoqi@0: st->print("},{"); aoqi@0: address end_of_locals = (address)vti; aoqi@0: vti = stack(end_of_locals); aoqi@0: int ss = stack_slots(end_of_locals); aoqi@0: for (int i = 0; i < ss; ++i) { aoqi@0: vti->print_on(st); aoqi@0: if (i != ss - 1) { aoqi@0: st->print(","); aoqi@0: } aoqi@0: vti = vti->next(); aoqi@0: } aoqi@0: st->print("})"); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: #define VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \ aoqi@0: stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \ aoqi@0: if (item_##stack_frame_type != NULL) { \ aoqi@0: return item_##stack_frame_type->func_name args; \ aoqi@0: } aoqi@0: aoqi@0: #define VOID_VIRTUAL_DISPATCH(stack_frame_type, func_name, args) \ aoqi@0: stack_frame_type* item_##stack_frame_type = as_##stack_frame_type(); \ aoqi@0: if (item_##stack_frame_type != NULL) { \ aoqi@0: item_##stack_frame_type->func_name args; \ aoqi@0: return; \ aoqi@0: } aoqi@0: aoqi@0: size_t stack_map_frame::size() const { aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, size, ()); aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: int stack_map_frame::offset_delta() const { aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, offset_delta, ()); aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: void stack_map_frame::set_offset_delta(int offset_delta) { aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE( aoqi@0: VOID_VIRTUAL_DISPATCH, set_offset_delta, (offset_delta)); aoqi@0: } aoqi@0: aoqi@0: int stack_map_frame::number_of_types() const { aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, number_of_types, ()); aoqi@0: return 0; aoqi@0: } aoqi@0: aoqi@0: verification_type_info* stack_map_frame::types() const { aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, types, ()); aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: bool stack_map_frame::is_valid_offset(int offset) const { aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE(VIRTUAL_DISPATCH, is_valid_offset, (offset)); aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: bool stack_map_frame::verify(address start, address end) const { aoqi@0: if (frame_type_addr() >= start && frame_type_addr() < end) { aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE( aoqi@0: VIRTUAL_DISPATCH, verify_subtype, (start, end)); aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: void stack_map_frame::print_on(outputStream* st, int offs = -1) const { aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE(VOID_VIRTUAL_DISPATCH, print_on, (st, offs)); aoqi@0: } aoqi@0: aoqi@0: #undef VIRTUAL_DISPATCH aoqi@0: #undef VOID_VIRTUAL_DISPATCH aoqi@0: aoqi@0: #define AS_SUBTYPE_DEF(stack_frame_type, arg1, arg2) \ aoqi@0: stack_frame_type* stack_map_frame::as_##stack_frame_type() const { \ aoqi@0: if (stack_frame_type::is_frame_type(frame_type())) { \ aoqi@0: return (stack_frame_type*)this; \ aoqi@0: } else { \ aoqi@0: return NULL; \ aoqi@0: } \ aoqi@0: } aoqi@0: aoqi@0: FOR_EACH_STACKMAP_FRAME_TYPE(AS_SUBTYPE_DEF, x, x) aoqi@0: #undef AS_SUBTYPE_DEF aoqi@0: aoqi@0: class stack_map_table { aoqi@0: private: aoqi@0: address number_of_entries_addr() const { aoqi@0: return (address)this; aoqi@0: } aoqi@0: address entries_addr() const { aoqi@0: return number_of_entries_addr() + sizeof(u2); aoqi@0: } aoqi@0: aoqi@0: protected: aoqi@0: // No constructors - should be 'private', but GCC issues a warning if it is aoqi@0: stack_map_table() {} aoqi@0: stack_map_table(const stack_map_table&) {} aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: static stack_map_table* at(address addr) { aoqi@0: return (stack_map_table*)addr; aoqi@0: } aoqi@0: aoqi@0: u2 number_of_entries() const { aoqi@0: return Bytes::get_Java_u2(number_of_entries_addr()); aoqi@0: } aoqi@0: stack_map_frame* entries() const { aoqi@0: return stack_map_frame::at(entries_addr()); aoqi@0: } aoqi@0: aoqi@0: void set_number_of_entries(u2 num) { aoqi@0: Bytes::put_Java_u2(number_of_entries_addr(), num); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: class stack_map_table_attribute { aoqi@0: private: aoqi@0: address name_index_addr() const { aoqi@0: return (address)this; } aoqi@0: address attribute_length_addr() const { aoqi@0: return name_index_addr() + sizeof(u2); } aoqi@0: address stack_map_table_addr() const { aoqi@0: return attribute_length_addr() + sizeof(u4); } aoqi@0: aoqi@0: protected: aoqi@0: // No constructors - should be 'private', but GCC issues a warning if it is aoqi@0: stack_map_table_attribute() {} aoqi@0: stack_map_table_attribute(const stack_map_table_attribute&) {} aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: static stack_map_table_attribute* at(address addr) { aoqi@0: return (stack_map_table_attribute*)addr; aoqi@0: } aoqi@0: aoqi@0: u2 name_index() const { aoqi@0: return Bytes::get_Java_u2(name_index_addr()); } aoqi@0: u4 attribute_length() const { aoqi@0: return Bytes::get_Java_u4(attribute_length_addr()); } aoqi@0: stack_map_table* table() const { aoqi@0: return stack_map_table::at(stack_map_table_addr()); aoqi@0: } aoqi@0: aoqi@0: void set_name_index(u2 idx) { aoqi@0: Bytes::put_Java_u2(name_index_addr(), idx); aoqi@0: } aoqi@0: void set_attribute_length(u4 len) { aoqi@0: Bytes::put_Java_u4(attribute_length_addr(), len); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: #undef FOR_EACH_STACKMAP_FRAME_TYPE aoqi@0: aoqi@0: #endif // SHARE_VM_CLASSFILE_STACKMAPTABLEFORMAT_HPP