src/share/vm/code/exceptionHandlerTable.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial