aoqi@0: /* aoqi@0: * Copyright (c) 1998, 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_CODE_EXCEPTIONHANDLERTABLE_HPP aoqi@0: #define SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP aoqi@0: aoqi@0: #include "memory/allocation.hpp" aoqi@0: #include "oops/method.hpp" aoqi@0: aoqi@0: // A HandlerTableEntry describes an individual entry of a subtable aoqi@0: // of ExceptionHandlerTable. An entry consists of a pair(bci, pco), aoqi@0: // where bci is the exception handler bci, and pco is the pc offset aoqi@0: // relative to the nmethod code start for the compiled exception aoqi@0: // handler corresponding to the (interpreted) exception handler aoqi@0: // starting at bci. aoqi@0: // aoqi@0: // The first HandlerTableEntry of each subtable holds the length aoqi@0: // and catch_pco for the subtable (the length is the number of aoqi@0: // subtable entries w/o header). aoqi@0: aoqi@0: class HandlerTableEntry { aoqi@0: private: aoqi@0: int _bci; aoqi@0: int _pco; aoqi@0: int _scope_depth; aoqi@0: aoqi@0: public: aoqi@0: HandlerTableEntry(int bci, int pco, int scope_depth) { aoqi@0: assert( 0 <= pco, "pco must be positive"); aoqi@0: assert( 0 <= scope_depth, "scope_depth must be positive"); aoqi@0: _bci = bci; aoqi@0: _pco = pco; aoqi@0: _scope_depth = scope_depth; aoqi@0: } aoqi@0: aoqi@0: int len() const { return _bci; } // for entry at subtable begin aoqi@0: int bci() const { return _bci; } aoqi@0: int pco() const { return _pco; } aoqi@0: int scope_depth() const { return _scope_depth; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // An ExceptionHandlerTable is an abstraction over a list of subtables aoqi@0: // of exception handlers for CatchNodes. Each subtable has a one-entry aoqi@0: // header holding length and catch_pco of the subtable, followed aoqi@0: // by 'length' entries for each exception handler that can be reached aoqi@0: // from the corresponding CatchNode. The catch_pco is the pc offset of aoqi@0: // the CatchNode in the corresponding nmethod. Empty subtables are dis- aoqi@0: // carded. aoqi@0: // aoqi@0: // Structure of the table: aoqi@0: // aoqi@0: // table = { subtable }. aoqi@0: // subtable = header entry { entry }. aoqi@0: // header = a pair (number of subtable entries, catch pc offset, [unused]) aoqi@0: // entry = a pair (handler bci, handler pc offset, scope depth) aoqi@0: // aoqi@0: // An ExceptionHandlerTable can be created from scratch, in which case aoqi@0: // it is possible to add subtables. It can also be created from an aoqi@0: // nmethod (for lookup purposes) in which case the table cannot be aoqi@0: // modified. aoqi@0: aoqi@0: class nmethod; aoqi@0: class ExceptionHandlerTable VALUE_OBJ_CLASS_SPEC { aoqi@0: private: aoqi@0: HandlerTableEntry* _table; // the table aoqi@0: int _length; // the current length of the table aoqi@0: int _size; // the number of allocated entries aoqi@0: ReallocMark _nesting; // assertion check for reallocations aoqi@0: aoqi@0: // add the entry & grow the table if needed aoqi@0: void add_entry(HandlerTableEntry entry); aoqi@0: HandlerTableEntry* subtable_for(int catch_pco) const; aoqi@0: aoqi@0: public: aoqi@0: // (compile-time) construction within compiler aoqi@0: ExceptionHandlerTable(int initial_size = 8); aoqi@0: aoqi@0: // (run-time) construction from nmethod aoqi@0: ExceptionHandlerTable(const nmethod* nm); aoqi@0: aoqi@0: // (compile-time) add entries aoqi@0: void add_subtable( aoqi@0: int catch_pco, // the pc offset for the CatchNode aoqi@0: GrowableArray* handler_bcis, // the exception handler entry point bcis aoqi@0: GrowableArray* scope_depths_from_top_scope, aoqi@0: // if representing exception handlers in multiple aoqi@0: // inlined scopes, indicates which scope relative to aoqi@0: // the youngest/innermost one in which we are performing aoqi@0: // the lookup; zero (or null GrowableArray) indicates aoqi@0: // innermost scope aoqi@0: GrowableArray* handler_pcos // pc offsets for the compiled handlers aoqi@0: ); aoqi@0: aoqi@0: // nmethod support aoqi@0: int size_in_bytes() const { return round_to(_length * sizeof(HandlerTableEntry), oopSize); } aoqi@0: void copy_to(nmethod* nm); aoqi@0: aoqi@0: // lookup aoqi@0: HandlerTableEntry* entry_for(int catch_pco, int handler_bci, int scope_depth) const; aoqi@0: aoqi@0: // debugging aoqi@0: void print_subtable(HandlerTableEntry* t) const; aoqi@0: void print() const; aoqi@0: void print_subtable_for(int catch_pco) const; aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: // ---------------------------------------------------------------------------- aoqi@0: // Implicit null exception tables. Maps an exception PC offset to a aoqi@0: // continuation PC offset. During construction it's a variable sized aoqi@0: // array with a max size and current length. When stored inside an aoqi@0: // nmethod a zero length table takes no space. This is detected by aoqi@0: // nul_chk_table_size() == 0. Otherwise the table has a length word aoqi@0: // followed by pairs of . aoqi@0: aoqi@0: // Use 32-bit representation for offsets aoqi@0: typedef uint implicit_null_entry; aoqi@0: aoqi@0: class ImplicitExceptionTable VALUE_OBJ_CLASS_SPEC { aoqi@0: uint _size; aoqi@0: uint _len; aoqi@0: implicit_null_entry *_data; aoqi@0: implicit_null_entry *adr( uint idx ) const { return &_data[2*idx]; } aoqi@0: ReallocMark _nesting; // assertion check for reallocations aoqi@0: public: aoqi@0: ImplicitExceptionTable( ) : _data(0), _size(0), _len(0) { } aoqi@0: // (run-time) construction from nmethod aoqi@0: ImplicitExceptionTable( const nmethod *nm ); aoqi@0: aoqi@0: void set_size( uint size ); aoqi@0: void append( uint exec_off, uint cont_off ); aoqi@0: uint at( uint exec_off ) const; aoqi@0: aoqi@0: uint len() const { return _len; } aoqi@0: int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * sizeof(implicit_null_entry)); } aoqi@0: aoqi@0: void copy_to(nmethod* nm); aoqi@0: void print(address base) const; aoqi@0: void verify(nmethod *nm) const; aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP