src/share/vm/code/exceptionHandlerTable.hpp

Wed, 02 Jun 2010 22:45:42 -0700

author
jrose
date
Wed, 02 Jun 2010 22:45:42 -0700
changeset 1934
e9ff18c4ace7
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

Merge

duke@435 1 /*
trims@1907 2 * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // A HandlerTableEntry describes an individual entry of a subtable
duke@435 26 // of ExceptionHandlerTable. An entry consists of a pair(bci, pco),
duke@435 27 // where bci is the exception handler bci, and pco is the pc offset
duke@435 28 // relative to the nmethod code start for the compiled exception
duke@435 29 // handler corresponding to the (interpreted) exception handler
duke@435 30 // starting at bci.
duke@435 31 //
duke@435 32 // The first HandlerTableEntry of each subtable holds the length
duke@435 33 // and catch_pco for the subtable (the length is the number of
duke@435 34 // subtable entries w/o header).
duke@435 35
duke@435 36 class HandlerTableEntry {
duke@435 37 private:
duke@435 38 int _bci;
duke@435 39 int _pco;
duke@435 40 int _scope_depth;
duke@435 41
duke@435 42 public:
duke@435 43 HandlerTableEntry(int bci, int pco, int scope_depth) {
duke@435 44 assert( 0 <= pco, "pco must be positive");
duke@435 45 assert( 0 <= scope_depth, "scope_depth must be positive");
duke@435 46 _bci = bci;
duke@435 47 _pco = pco;
duke@435 48 _scope_depth = scope_depth;
duke@435 49 }
duke@435 50
duke@435 51 int len() const { return _bci; } // for entry at subtable begin
duke@435 52 int bci() const { return _bci; }
duke@435 53 int pco() const { return _pco; }
duke@435 54 int scope_depth() const { return _scope_depth; }
duke@435 55 };
duke@435 56
duke@435 57
duke@435 58 // An ExceptionHandlerTable is an abstraction over a list of subtables
duke@435 59 // of exception handlers for CatchNodes. Each subtable has a one-entry
duke@435 60 // header holding length and catch_pco of the subtable, followed
duke@435 61 // by 'length' entries for each exception handler that can be reached
duke@435 62 // from the corresponding CatchNode. The catch_pco is the pc offset of
duke@435 63 // the CatchNode in the corresponding nmethod. Empty subtables are dis-
duke@435 64 // carded.
duke@435 65 //
duke@435 66 // Structure of the table:
duke@435 67 //
duke@435 68 // table = { subtable }.
duke@435 69 // subtable = header entry { entry }.
duke@435 70 // header = a pair (number of subtable entries, catch pc offset, [unused])
duke@435 71 // entry = a pair (handler bci, handler pc offset, scope depth)
duke@435 72 //
duke@435 73 // An ExceptionHandlerTable can be created from scratch, in which case
duke@435 74 // it is possible to add subtables. It can also be created from an
duke@435 75 // nmethod (for lookup purposes) in which case the table cannot be
duke@435 76 // modified.
duke@435 77
duke@435 78 class nmethod;
duke@435 79 class ExceptionHandlerTable VALUE_OBJ_CLASS_SPEC {
duke@435 80 private:
duke@435 81 HandlerTableEntry* _table; // the table
duke@435 82 int _length; // the current length of the table
duke@435 83 int _size; // the number of allocated entries
duke@435 84 ReallocMark _nesting; // assertion check for reallocations
duke@435 85
duke@435 86 // add the entry & grow the table if needed
duke@435 87 void add_entry(HandlerTableEntry entry);
duke@435 88 HandlerTableEntry* subtable_for(int catch_pco) const;
duke@435 89
duke@435 90 public:
duke@435 91 // (compile-time) construction within compiler
duke@435 92 ExceptionHandlerTable(int initial_size = 8);
duke@435 93
duke@435 94 // (run-time) construction from nmethod
duke@435 95 ExceptionHandlerTable(const nmethod* nm);
duke@435 96
duke@435 97 // (compile-time) add entries
duke@435 98 void add_subtable(
duke@435 99 int catch_pco, // the pc offset for the CatchNode
duke@435 100 GrowableArray<intptr_t>* handler_bcis, // the exception handler entry point bcis
duke@435 101 GrowableArray<intptr_t>* scope_depths_from_top_scope,
duke@435 102 // if representing exception handlers in multiple
duke@435 103 // inlined scopes, indicates which scope relative to
duke@435 104 // the youngest/innermost one in which we are performing
duke@435 105 // the lookup; zero (or null GrowableArray) indicates
duke@435 106 // innermost scope
duke@435 107 GrowableArray<intptr_t>* handler_pcos // pc offsets for the compiled handlers
duke@435 108 );
duke@435 109
duke@435 110 // nmethod support
duke@435 111 int size_in_bytes() const { return round_to(_length * sizeof(HandlerTableEntry), oopSize); }
duke@435 112 void copy_to(nmethod* nm);
duke@435 113
duke@435 114 // lookup
duke@435 115 HandlerTableEntry* entry_for(int catch_pco, int handler_bci, int scope_depth) const;
duke@435 116
duke@435 117 // debugging
duke@435 118 void print_subtable(HandlerTableEntry* t) const;
duke@435 119 void print() const;
duke@435 120 void print_subtable_for(int catch_pco) const;
duke@435 121 };
duke@435 122
duke@435 123
duke@435 124 // ----------------------------------------------------------------------------
duke@435 125 // Implicit null exception tables. Maps an exception PC offset to a
duke@435 126 // continuation PC offset. During construction it's a variable sized
duke@435 127 // array with a max size and current length. When stored inside an
duke@435 128 // nmethod a zero length table takes no space. This is detected by
duke@435 129 // nul_chk_table_size() == 0. Otherwise the table has a length word
duke@435 130 // followed by pairs of <excp-offset, const-offset>.
duke@435 131
duke@435 132 // Use 32-bit representation for offsets
duke@435 133 typedef uint implicit_null_entry;
duke@435 134
duke@435 135 class ImplicitExceptionTable VALUE_OBJ_CLASS_SPEC {
duke@435 136 uint _size;
duke@435 137 uint _len;
duke@435 138 implicit_null_entry *_data;
duke@435 139 implicit_null_entry *adr( uint idx ) const { return &_data[2*idx]; }
duke@435 140 ReallocMark _nesting; // assertion check for reallocations
duke@435 141 public:
duke@435 142 ImplicitExceptionTable( ) : _data(0), _size(0), _len(0) { }
duke@435 143 // (run-time) construction from nmethod
duke@435 144 ImplicitExceptionTable( const nmethod *nm );
duke@435 145
duke@435 146 void set_size( uint size );
duke@435 147 void append( uint exec_off, uint cont_off );
duke@435 148 uint at( uint exec_off ) const;
duke@435 149
duke@435 150 uint len() const { return _len; }
duke@435 151 int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * sizeof(implicit_null_entry)); }
duke@435 152
duke@435 153 void copy_to(nmethod* nm);
duke@435 154 void print(address base) const;
duke@435 155 void verify(nmethod *nm) const;
duke@435 156 };

mercurial