1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/code/exceptionHandlerTable.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,164 @@ 1.4 +/* 1.5 + * Copyright (c) 1998, 2012, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP 1.29 +#define SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 +#include "oops/method.hpp" 1.33 + 1.34 +// A HandlerTableEntry describes an individual entry of a subtable 1.35 +// of ExceptionHandlerTable. An entry consists of a pair(bci, pco), 1.36 +// where bci is the exception handler bci, and pco is the pc offset 1.37 +// relative to the nmethod code start for the compiled exception 1.38 +// handler corresponding to the (interpreted) exception handler 1.39 +// starting at bci. 1.40 +// 1.41 +// The first HandlerTableEntry of each subtable holds the length 1.42 +// and catch_pco for the subtable (the length is the number of 1.43 +// subtable entries w/o header). 1.44 + 1.45 +class HandlerTableEntry { 1.46 + private: 1.47 + int _bci; 1.48 + int _pco; 1.49 + int _scope_depth; 1.50 + 1.51 + public: 1.52 + HandlerTableEntry(int bci, int pco, int scope_depth) { 1.53 + assert( 0 <= pco, "pco must be positive"); 1.54 + assert( 0 <= scope_depth, "scope_depth must be positive"); 1.55 + _bci = bci; 1.56 + _pco = pco; 1.57 + _scope_depth = scope_depth; 1.58 + } 1.59 + 1.60 + int len() const { return _bci; } // for entry at subtable begin 1.61 + int bci() const { return _bci; } 1.62 + int pco() const { return _pco; } 1.63 + int scope_depth() const { return _scope_depth; } 1.64 +}; 1.65 + 1.66 + 1.67 +// An ExceptionHandlerTable is an abstraction over a list of subtables 1.68 +// of exception handlers for CatchNodes. Each subtable has a one-entry 1.69 +// header holding length and catch_pco of the subtable, followed 1.70 +// by 'length' entries for each exception handler that can be reached 1.71 +// from the corresponding CatchNode. The catch_pco is the pc offset of 1.72 +// the CatchNode in the corresponding nmethod. Empty subtables are dis- 1.73 +// carded. 1.74 +// 1.75 +// Structure of the table: 1.76 +// 1.77 +// table = { subtable }. 1.78 +// subtable = header entry { entry }. 1.79 +// header = a pair (number of subtable entries, catch pc offset, [unused]) 1.80 +// entry = a pair (handler bci, handler pc offset, scope depth) 1.81 +// 1.82 +// An ExceptionHandlerTable can be created from scratch, in which case 1.83 +// it is possible to add subtables. It can also be created from an 1.84 +// nmethod (for lookup purposes) in which case the table cannot be 1.85 +// modified. 1.86 + 1.87 +class nmethod; 1.88 +class ExceptionHandlerTable VALUE_OBJ_CLASS_SPEC { 1.89 + private: 1.90 + HandlerTableEntry* _table; // the table 1.91 + int _length; // the current length of the table 1.92 + int _size; // the number of allocated entries 1.93 + ReallocMark _nesting; // assertion check for reallocations 1.94 + 1.95 + // add the entry & grow the table if needed 1.96 + void add_entry(HandlerTableEntry entry); 1.97 + HandlerTableEntry* subtable_for(int catch_pco) const; 1.98 + 1.99 + public: 1.100 + // (compile-time) construction within compiler 1.101 + ExceptionHandlerTable(int initial_size = 8); 1.102 + 1.103 + // (run-time) construction from nmethod 1.104 + ExceptionHandlerTable(const nmethod* nm); 1.105 + 1.106 + // (compile-time) add entries 1.107 + void add_subtable( 1.108 + int catch_pco, // the pc offset for the CatchNode 1.109 + GrowableArray<intptr_t>* handler_bcis, // the exception handler entry point bcis 1.110 + GrowableArray<intptr_t>* scope_depths_from_top_scope, 1.111 + // if representing exception handlers in multiple 1.112 + // inlined scopes, indicates which scope relative to 1.113 + // the youngest/innermost one in which we are performing 1.114 + // the lookup; zero (or null GrowableArray) indicates 1.115 + // innermost scope 1.116 + GrowableArray<intptr_t>* handler_pcos // pc offsets for the compiled handlers 1.117 + ); 1.118 + 1.119 + // nmethod support 1.120 + int size_in_bytes() const { return round_to(_length * sizeof(HandlerTableEntry), oopSize); } 1.121 + void copy_to(nmethod* nm); 1.122 + 1.123 + // lookup 1.124 + HandlerTableEntry* entry_for(int catch_pco, int handler_bci, int scope_depth) const; 1.125 + 1.126 + // debugging 1.127 + void print_subtable(HandlerTableEntry* t) const; 1.128 + void print() const; 1.129 + void print_subtable_for(int catch_pco) const; 1.130 +}; 1.131 + 1.132 + 1.133 +// ---------------------------------------------------------------------------- 1.134 +// Implicit null exception tables. Maps an exception PC offset to a 1.135 +// continuation PC offset. During construction it's a variable sized 1.136 +// array with a max size and current length. When stored inside an 1.137 +// nmethod a zero length table takes no space. This is detected by 1.138 +// nul_chk_table_size() == 0. Otherwise the table has a length word 1.139 +// followed by pairs of <excp-offset, const-offset>. 1.140 + 1.141 +// Use 32-bit representation for offsets 1.142 +typedef uint implicit_null_entry; 1.143 + 1.144 +class ImplicitExceptionTable VALUE_OBJ_CLASS_SPEC { 1.145 + uint _size; 1.146 + uint _len; 1.147 + implicit_null_entry *_data; 1.148 + implicit_null_entry *adr( uint idx ) const { return &_data[2*idx]; } 1.149 + ReallocMark _nesting; // assertion check for reallocations 1.150 +public: 1.151 + ImplicitExceptionTable( ) : _data(0), _size(0), _len(0) { } 1.152 + // (run-time) construction from nmethod 1.153 + ImplicitExceptionTable( const nmethod *nm ); 1.154 + 1.155 + void set_size( uint size ); 1.156 + void append( uint exec_off, uint cont_off ); 1.157 + uint at( uint exec_off ) const; 1.158 + 1.159 + uint len() const { return _len; } 1.160 + int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * sizeof(implicit_null_entry)); } 1.161 + 1.162 + void copy_to(nmethod* nm); 1.163 + void print(address base) const; 1.164 + void verify(nmethod *nm) const; 1.165 +}; 1.166 + 1.167 +#endif // SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP