Path: blob/master/src/hotspot/share/code/exceptionHandlerTable.hpp
40931 views
/*1* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_CODE_EXCEPTIONHANDLERTABLE_HPP25#define SHARE_CODE_EXCEPTIONHANDLERTABLE_HPP2627#include "memory/allocation.hpp"28#include "oops/method.hpp"29#include "utilities/align.hpp"3031// A HandlerTableEntry describes an individual entry of a subtable32// of ExceptionHandlerTable. An entry consists of a pair(bci, pco),33// where bci is the exception handler bci, and pco is the pc offset34// relative to the nmethod code start for the compiled exception35// handler corresponding to the (interpreted) exception handler36// starting at bci.37//38// The first HandlerTableEntry of each subtable holds the length39// and catch_pco for the subtable (the length is the number of40// subtable entries w/o header).4142class HandlerTableEntry {43private:44int _bci;45int _pco;46int _scope_depth;4748public:49HandlerTableEntry(int bci, int pco, int scope_depth) {50assert( 0 <= pco, "pco must be positive");51assert( 0 <= scope_depth, "scope_depth must be positive");52_bci = bci;53_pco = pco;54_scope_depth = scope_depth;55}5657int len() const { return _bci; } // for entry at subtable begin58int bci() const { return _bci; }59int pco() const { return _pco; }60int scope_depth() const { return _scope_depth; }61};626364// An ExceptionHandlerTable is an abstraction over a list of subtables65// of exception handlers for CatchNodes. Each subtable has a one-entry66// header holding length and catch_pco of the subtable, followed67// by 'length' entries for each exception handler that can be reached68// from the corresponding CatchNode. The catch_pco is the pc offset of69// the CatchNode in the corresponding nmethod. Empty subtables are dis-70// carded.71//72// Structure of the table:73//74// table = { subtable }.75// subtable = header entry { entry }.76// header = a pair (number of subtable entries, catch pc offset, [unused])77// entry = a pair (handler bci, handler pc offset, scope depth)78//79// An ExceptionHandlerTable can be created from scratch, in which case80// it is possible to add subtables. It can also be created from an81// nmethod (for lookup purposes) in which case the table cannot be82// modified.8384class nmethod;85class ExceptionHandlerTable {86private:87HandlerTableEntry* _table; // the table88int _length; // the current length of the table89int _size; // the number of allocated entries90ReallocMark _nesting; // assertion check for reallocations9192public:93// add the entry & grow the table if needed94void add_entry(HandlerTableEntry entry);95HandlerTableEntry* subtable_for(int catch_pco) const;9697// (compile-time) construction within compiler98ExceptionHandlerTable(int initial_size = 8);99100// (run-time) construction from nmethod101ExceptionHandlerTable(const CompiledMethod* nm);102103// (compile-time) add entries104void add_subtable(105int catch_pco, // the pc offset for the CatchNode106GrowableArray<intptr_t>* handler_bcis, // the exception handler entry point bcis107GrowableArray<intptr_t>* scope_depths_from_top_scope,108// if representing exception handlers in multiple109// inlined scopes, indicates which scope relative to110// the youngest/innermost one in which we are performing111// the lookup; zero (or null GrowableArray) indicates112// innermost scope113GrowableArray<intptr_t>* handler_pcos // pc offsets for the compiled handlers114);115116// nmethod support117int size_in_bytes() const { return align_up(_length * (int)sizeof(HandlerTableEntry), oopSize); }118void copy_to(CompiledMethod* nm);119void copy_bytes_to(address addr);120121// lookup122HandlerTableEntry* entry_for(int catch_pco, int handler_bci, int scope_depth) const;123124// debugging125void print_subtable(HandlerTableEntry* t, address base = NULL) const;126void print(address base = NULL) const;127void print_subtable_for(int catch_pco) const;128};129130131// ----------------------------------------------------------------------------132// Implicit null exception tables. Maps an exception PC offset to a133// continuation PC offset. During construction it's a variable sized134// array with a max size and current length. When stored inside an135// nmethod a zero length table takes no space. This is detected by136// nul_chk_table_size() == 0. Otherwise the table has a length word137// followed by pairs of <excp-offset, const-offset>.138139// Use 32-bit representation for offsets140typedef uint implicit_null_entry;141142class ImplicitExceptionTable {143uint _size;144uint _len;145implicit_null_entry *_data;146implicit_null_entry *adr( uint idx ) const { return &_data[2*idx]; }147ReallocMark _nesting; // assertion check for reallocations148149public:150ImplicitExceptionTable( ) : _size(0), _len(0), _data(0) { }151// (run-time) construction from nmethod152ImplicitExceptionTable( const CompiledMethod *nm );153154void set_size( uint size );155void append( uint exec_off, uint cont_off );156157#if INCLUDE_JVMCI158void add_deoptimize(uint exec_off) {159// Use the same offset as a marker value for deoptimization160append(exec_off, exec_off);161}162#endif163164// Returns the offset to continue execution at. If the returned165// value equals exec_off then the dispatch is expected to be a166// deoptimization instead.167uint continuation_offset( uint exec_off ) const;168169uint len() const { return _len; }170171uint get_exec_offset(uint i) { assert(i < _len, "oob"); return *adr(i); }172uint get_cont_offset(uint i) { assert(i < _len, "oob"); return *(adr(i) + 1); }173174int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * sizeof(implicit_null_entry)); }175176void copy_to(nmethod* nm);177void copy_bytes_to(address addr, int size);178void print(address base) const;179void verify(nmethod *nm) const;180};181182#endif // SHARE_CODE_EXCEPTIONHANDLERTABLE_HPP183184185