src/share/vm/code/exceptionHandlerTable.hpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/code/exceptionHandlerTable.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,156 @@
     1.4 +/*
     1.5 + * Copyright 1998-2005 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +// A HandlerTableEntry describes an individual entry of a subtable
    1.29 +// of ExceptionHandlerTable. An entry consists of a pair(bci, pco),
    1.30 +// where bci is the exception handler bci, and pco is the pc offset
    1.31 +// relative to the nmethod code start for the compiled exception
    1.32 +// handler corresponding to the (interpreted) exception handler
    1.33 +// starting at bci.
    1.34 +//
    1.35 +// The first HandlerTableEntry of each subtable holds the length
    1.36 +// and catch_pco for the subtable (the length is the number of
    1.37 +// subtable entries w/o header).
    1.38 +
    1.39 +class HandlerTableEntry {
    1.40 + private:
    1.41 +  int _bci;
    1.42 +  int _pco;
    1.43 +  int _scope_depth;
    1.44 +
    1.45 + public:
    1.46 +  HandlerTableEntry(int bci, int pco, int scope_depth) {
    1.47 +    assert( 0 <= pco, "pco must be positive");
    1.48 +    assert( 0 <= scope_depth, "scope_depth must be positive");
    1.49 +    _bci = bci;
    1.50 +    _pco = pco;
    1.51 +    _scope_depth = scope_depth;
    1.52 +  }
    1.53 +
    1.54 +  int len() const { return _bci; } // for entry at subtable begin
    1.55 +  int bci() const { return _bci; }
    1.56 +  int pco() const { return _pco; }
    1.57 +  int scope_depth() const { return _scope_depth; }
    1.58 +};
    1.59 +
    1.60 +
    1.61 +// An ExceptionHandlerTable is an abstraction over a list of subtables
    1.62 +// of exception handlers for CatchNodes. Each subtable has a one-entry
    1.63 +// header holding length and catch_pco of the subtable, followed
    1.64 +// by 'length' entries for each exception handler that can be reached
    1.65 +// from the corresponding CatchNode. The catch_pco is the pc offset of
    1.66 +// the CatchNode in the corresponding nmethod. Empty subtables are dis-
    1.67 +// carded.
    1.68 +//
    1.69 +// Structure of the table:
    1.70 +//
    1.71 +// table    = { subtable }.
    1.72 +// subtable = header entry { entry }.
    1.73 +// header   = a pair (number of subtable entries, catch pc offset, [unused])
    1.74 +// entry    = a pair (handler bci, handler pc offset, scope depth)
    1.75 +//
    1.76 +// An ExceptionHandlerTable can be created from scratch, in which case
    1.77 +// it is possible to add subtables. It can also be created from an
    1.78 +// nmethod (for lookup purposes) in which case the table cannot be
    1.79 +// modified.
    1.80 +
    1.81 +class nmethod;
    1.82 +class ExceptionHandlerTable VALUE_OBJ_CLASS_SPEC {
    1.83 + private:
    1.84 +  HandlerTableEntry* _table;    // the table
    1.85 +  int                _length;   // the current length of the table
    1.86 +  int                _size;     // the number of allocated entries
    1.87 +  ReallocMark        _nesting;  // assertion check for reallocations
    1.88 +
    1.89 +  // add the entry & grow the table if needed
    1.90 +  void add_entry(HandlerTableEntry entry);
    1.91 +  HandlerTableEntry* subtable_for(int catch_pco) const;
    1.92 +
    1.93 + public:
    1.94 +  // (compile-time) construction within compiler
    1.95 +  ExceptionHandlerTable(int initial_size = 8);
    1.96 +
    1.97 +  // (run-time) construction from nmethod
    1.98 +  ExceptionHandlerTable(const nmethod* nm);
    1.99 +
   1.100 +  // (compile-time) add entries
   1.101 +  void add_subtable(
   1.102 +    int                 catch_pco, // the pc offset for the CatchNode
   1.103 +    GrowableArray<intptr_t>* handler_bcis, // the exception handler entry point bcis
   1.104 +    GrowableArray<intptr_t>* scope_depths_from_top_scope,
   1.105 +                                           // if representing exception handlers in multiple
   1.106 +                                           // inlined scopes, indicates which scope relative to
   1.107 +                                           // the youngest/innermost one in which we are performing
   1.108 +                                           // the lookup; zero (or null GrowableArray) indicates
   1.109 +                                           // innermost scope
   1.110 +    GrowableArray<intptr_t>* handler_pcos  // pc offsets for the compiled handlers
   1.111 +  );
   1.112 +
   1.113 +  // nmethod support
   1.114 +  int  size_in_bytes() const { return round_to(_length * sizeof(HandlerTableEntry), oopSize); }
   1.115 +  void copy_to(nmethod* nm);
   1.116 +
   1.117 +  // lookup
   1.118 +  HandlerTableEntry* entry_for(int catch_pco, int handler_bci, int scope_depth) const;
   1.119 +
   1.120 +  // debugging
   1.121 +  void print_subtable(HandlerTableEntry* t) const;
   1.122 +  void print() const;
   1.123 +  void print_subtable_for(int catch_pco) const;
   1.124 +};
   1.125 +
   1.126 +
   1.127 +// ----------------------------------------------------------------------------
   1.128 +// Implicit null exception tables.  Maps an exception PC offset to a
   1.129 +// continuation PC offset.  During construction it's a variable sized
   1.130 +// array with a max size and current length.  When stored inside an
   1.131 +// nmethod a zero length table takes no space.  This is detected by
   1.132 +// nul_chk_table_size() == 0.  Otherwise the table has a length word
   1.133 +// followed by pairs of <excp-offset, const-offset>.
   1.134 +
   1.135 +// Use 32-bit representation for offsets
   1.136 +typedef  uint              implicit_null_entry;
   1.137 +
   1.138 +class ImplicitExceptionTable VALUE_OBJ_CLASS_SPEC {
   1.139 +  uint _size;
   1.140 +  uint _len;
   1.141 +  implicit_null_entry *_data;
   1.142 +  implicit_null_entry *adr( uint idx ) const { return &_data[2*idx]; }
   1.143 +  ReallocMark          _nesting;  // assertion check for reallocations
   1.144 +public:
   1.145 +  ImplicitExceptionTable( ) :  _data(0), _size(0), _len(0) { }
   1.146 +  // (run-time) construction from nmethod
   1.147 +  ImplicitExceptionTable( const nmethod *nm );
   1.148 +
   1.149 +  void set_size( uint size );
   1.150 +  void append( uint exec_off, uint cont_off );
   1.151 +  uint at( uint exec_off ) const;
   1.152 +
   1.153 +  uint len() const { return _len; }
   1.154 +  int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * sizeof(implicit_null_entry)); }
   1.155 +
   1.156 +  void copy_to(nmethod* nm);
   1.157 +  void print(address base) const;
   1.158 +  void verify(nmethod *nm) const;
   1.159 +};

mercurial