0N/A/*
1879N/A * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP
1879N/A#define SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP
1879N/A
1879N/A#include "memory/allocation.hpp"
1879N/A#include "oops/methodOop.hpp"
1879N/A
0N/A// A HandlerTableEntry describes an individual entry of a subtable
0N/A// of ExceptionHandlerTable. An entry consists of a pair(bci, pco),
0N/A// where bci is the exception handler bci, and pco is the pc offset
0N/A// relative to the nmethod code start for the compiled exception
0N/A// handler corresponding to the (interpreted) exception handler
0N/A// starting at bci.
0N/A//
0N/A// The first HandlerTableEntry of each subtable holds the length
0N/A// and catch_pco for the subtable (the length is the number of
0N/A// subtable entries w/o header).
0N/A
0N/Aclass HandlerTableEntry {
0N/A private:
0N/A int _bci;
0N/A int _pco;
0N/A int _scope_depth;
0N/A
0N/A public:
0N/A HandlerTableEntry(int bci, int pco, int scope_depth) {
0N/A assert( 0 <= pco, "pco must be positive");
0N/A assert( 0 <= scope_depth, "scope_depth must be positive");
0N/A _bci = bci;
0N/A _pco = pco;
0N/A _scope_depth = scope_depth;
0N/A }
0N/A
0N/A int len() const { return _bci; } // for entry at subtable begin
0N/A int bci() const { return _bci; }
0N/A int pco() const { return _pco; }
0N/A int scope_depth() const { return _scope_depth; }
0N/A};
0N/A
0N/A
0N/A// An ExceptionHandlerTable is an abstraction over a list of subtables
0N/A// of exception handlers for CatchNodes. Each subtable has a one-entry
0N/A// header holding length and catch_pco of the subtable, followed
0N/A// by 'length' entries for each exception handler that can be reached
0N/A// from the corresponding CatchNode. The catch_pco is the pc offset of
0N/A// the CatchNode in the corresponding nmethod. Empty subtables are dis-
0N/A// carded.
0N/A//
0N/A// Structure of the table:
0N/A//
0N/A// table = { subtable }.
0N/A// subtable = header entry { entry }.
0N/A// header = a pair (number of subtable entries, catch pc offset, [unused])
0N/A// entry = a pair (handler bci, handler pc offset, scope depth)
0N/A//
0N/A// An ExceptionHandlerTable can be created from scratch, in which case
0N/A// it is possible to add subtables. It can also be created from an
0N/A// nmethod (for lookup purposes) in which case the table cannot be
0N/A// modified.
0N/A
0N/Aclass nmethod;
0N/Aclass ExceptionHandlerTable VALUE_OBJ_CLASS_SPEC {
0N/A private:
0N/A HandlerTableEntry* _table; // the table
0N/A int _length; // the current length of the table
0N/A int _size; // the number of allocated entries
0N/A ReallocMark _nesting; // assertion check for reallocations
0N/A
0N/A // add the entry & grow the table if needed
0N/A void add_entry(HandlerTableEntry entry);
0N/A HandlerTableEntry* subtable_for(int catch_pco) const;
0N/A
0N/A public:
0N/A // (compile-time) construction within compiler
0N/A ExceptionHandlerTable(int initial_size = 8);
0N/A
0N/A // (run-time) construction from nmethod
0N/A ExceptionHandlerTable(const nmethod* nm);
0N/A
0N/A // (compile-time) add entries
0N/A void add_subtable(
0N/A int catch_pco, // the pc offset for the CatchNode
0N/A GrowableArray<intptr_t>* handler_bcis, // the exception handler entry point bcis
0N/A GrowableArray<intptr_t>* scope_depths_from_top_scope,
0N/A // if representing exception handlers in multiple
0N/A // inlined scopes, indicates which scope relative to
0N/A // the youngest/innermost one in which we are performing
0N/A // the lookup; zero (or null GrowableArray) indicates
0N/A // innermost scope
0N/A GrowableArray<intptr_t>* handler_pcos // pc offsets for the compiled handlers
0N/A );
0N/A
0N/A // nmethod support
0N/A int size_in_bytes() const { return round_to(_length * sizeof(HandlerTableEntry), oopSize); }
0N/A void copy_to(nmethod* nm);
0N/A
0N/A // lookup
0N/A HandlerTableEntry* entry_for(int catch_pco, int handler_bci, int scope_depth) const;
0N/A
0N/A // debugging
0N/A void print_subtable(HandlerTableEntry* t) const;
0N/A void print() const;
0N/A void print_subtable_for(int catch_pco) const;
0N/A};
0N/A
0N/A
0N/A// ----------------------------------------------------------------------------
0N/A// Implicit null exception tables. Maps an exception PC offset to a
0N/A// continuation PC offset. During construction it's a variable sized
0N/A// array with a max size and current length. When stored inside an
0N/A// nmethod a zero length table takes no space. This is detected by
0N/A// nul_chk_table_size() == 0. Otherwise the table has a length word
0N/A// followed by pairs of <excp-offset, const-offset>.
0N/A
0N/A// Use 32-bit representation for offsets
0N/Atypedef uint implicit_null_entry;
0N/A
0N/Aclass ImplicitExceptionTable VALUE_OBJ_CLASS_SPEC {
0N/A uint _size;
0N/A uint _len;
0N/A implicit_null_entry *_data;
0N/A implicit_null_entry *adr( uint idx ) const { return &_data[2*idx]; }
0N/A ReallocMark _nesting; // assertion check for reallocations
0N/Apublic:
0N/A ImplicitExceptionTable( ) : _data(0), _size(0), _len(0) { }
0N/A // (run-time) construction from nmethod
0N/A ImplicitExceptionTable( const nmethod *nm );
0N/A
0N/A void set_size( uint size );
0N/A void append( uint exec_off, uint cont_off );
0N/A uint at( uint exec_off ) const;
0N/A
0N/A uint len() const { return _len; }
0N/A int size_in_bytes() const { return len() == 0 ? 0 : ((2 * len() + 1) * sizeof(implicit_null_entry)); }
0N/A
0N/A void copy_to(nmethod* nm);
0N/A void print(address base) const;
0N/A void verify(nmethod *nm) const;
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_CODE_EXCEPTIONHANDLERTABLE_HPP