duke@435: /* coleenp@4037: * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP stefank@2314: #define SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP stefank@2314: stefank@2314: #include "memory/allocation.hpp" coleenp@4037: #include "oops/method.hpp" stefank@2314: duke@435: // A HandlerTableEntry describes an individual entry of a subtable duke@435: // of ExceptionHandlerTable. An entry consists of a pair(bci, pco), duke@435: // where bci is the exception handler bci, and pco is the pc offset duke@435: // relative to the nmethod code start for the compiled exception duke@435: // handler corresponding to the (interpreted) exception handler duke@435: // starting at bci. duke@435: // duke@435: // The first HandlerTableEntry of each subtable holds the length duke@435: // and catch_pco for the subtable (the length is the number of duke@435: // subtable entries w/o header). duke@435: duke@435: class HandlerTableEntry { duke@435: private: duke@435: int _bci; duke@435: int _pco; duke@435: int _scope_depth; duke@435: duke@435: public: duke@435: HandlerTableEntry(int bci, int pco, int scope_depth) { duke@435: assert( 0 <= pco, "pco must be positive"); duke@435: assert( 0 <= scope_depth, "scope_depth must be positive"); duke@435: _bci = bci; duke@435: _pco = pco; duke@435: _scope_depth = scope_depth; duke@435: } duke@435: duke@435: int len() const { return _bci; } // for entry at subtable begin duke@435: int bci() const { return _bci; } duke@435: int pco() const { return _pco; } duke@435: int scope_depth() const { return _scope_depth; } duke@435: }; duke@435: duke@435: duke@435: // An ExceptionHandlerTable is an abstraction over a list of subtables duke@435: // of exception handlers for CatchNodes. Each subtable has a one-entry duke@435: // header holding length and catch_pco of the subtable, followed duke@435: // by 'length' entries for each exception handler that can be reached duke@435: // from the corresponding CatchNode. The catch_pco is the pc offset of duke@435: // the CatchNode in the corresponding nmethod. Empty subtables are dis- duke@435: // carded. duke@435: // duke@435: // Structure of the table: duke@435: // duke@435: // table = { subtable }. duke@435: // subtable = header entry { entry }. duke@435: // header = a pair (number of subtable entries, catch pc offset, [unused]) duke@435: // entry = a pair (handler bci, handler pc offset, scope depth) duke@435: // duke@435: // An ExceptionHandlerTable can be created from scratch, in which case duke@435: // it is possible to add subtables. It can also be created from an duke@435: // nmethod (for lookup purposes) in which case the table cannot be duke@435: // modified. duke@435: duke@435: class nmethod; duke@435: class ExceptionHandlerTable VALUE_OBJ_CLASS_SPEC { duke@435: private: duke@435: HandlerTableEntry* _table; // the table duke@435: int _length; // the current length of the table duke@435: int _size; // the number of allocated entries duke@435: ReallocMark _nesting; // assertion check for reallocations duke@435: duke@435: // add the entry & grow the table if needed duke@435: void add_entry(HandlerTableEntry entry); duke@435: HandlerTableEntry* subtable_for(int catch_pco) const; duke@435: duke@435: public: duke@435: // (compile-time) construction within compiler duke@435: ExceptionHandlerTable(int initial_size = 8); duke@435: duke@435: // (run-time) construction from nmethod duke@435: ExceptionHandlerTable(const nmethod* nm); duke@435: duke@435: // (compile-time) add entries duke@435: void add_subtable( duke@435: int catch_pco, // the pc offset for the CatchNode duke@435: GrowableArray* handler_bcis, // the exception handler entry point bcis duke@435: GrowableArray* scope_depths_from_top_scope, duke@435: // if representing exception handlers in multiple duke@435: // inlined scopes, indicates which scope relative to duke@435: // the youngest/innermost one in which we are performing duke@435: // the lookup; zero (or null GrowableArray) indicates duke@435: // innermost scope duke@435: GrowableArray* handler_pcos // pc offsets for the compiled handlers duke@435: ); duke@435: duke@435: // nmethod support duke@435: int size_in_bytes() const { return round_to(_length * sizeof(HandlerTableEntry), oopSize); } duke@435: void copy_to(nmethod* nm); duke@435: duke@435: // lookup duke@435: HandlerTableEntry* entry_for(int catch_pco, int handler_bci, int scope_depth) const; duke@435: duke@435: // debugging duke@435: void print_subtable(HandlerTableEntry* t) const; duke@435: void print() const; duke@435: void print_subtable_for(int catch_pco) const; duke@435: }; duke@435: duke@435: duke@435: // ---------------------------------------------------------------------------- duke@435: // Implicit null exception tables. Maps an exception PC offset to a duke@435: // continuation PC offset. During construction it's a variable sized duke@435: // array with a max size and current length. When stored inside an duke@435: // nmethod a zero length table takes no space. This is detected by duke@435: // nul_chk_table_size() == 0. Otherwise the table has a length word duke@435: // followed by pairs of . duke@435: duke@435: // Use 32-bit representation for offsets duke@435: typedef uint implicit_null_entry; duke@435: duke@435: class ImplicitExceptionTable VALUE_OBJ_CLASS_SPEC { duke@435: uint _size; duke@435: uint _len; duke@435: implicit_null_entry *_data; duke@435: implicit_null_entry *adr( uint idx ) const { return &_data[2*idx]; } duke@435: ReallocMark _nesting; // assertion check for reallocations duke@435: public: duke@435: ImplicitExceptionTable( ) : _data(0), _size(0), _len(0) { } duke@435: // (run-time) construction from nmethod duke@435: ImplicitExceptionTable( const nmethod *nm ); duke@435: duke@435: void set_size( uint size ); duke@435: void append( uint exec_off, uint cont_off ); duke@435: uint at( uint exec_off ) const; duke@435: duke@435: uint len() const { return _len; } duke@435: int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * sizeof(implicit_null_entry)); } duke@435: duke@435: void copy_to(nmethod* nm); duke@435: void print(address base) const; duke@435: void verify(nmethod *nm) const; duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP