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