Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/code/exceptionHandlerTable.cpp
32285 views
/*1* Copyright (c) 1998, 2014, 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#include "precompiled.hpp"25#include "code/exceptionHandlerTable.hpp"26#include "code/nmethod.hpp"27#include "memory/allocation.inline.hpp"2829PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC3031void ExceptionHandlerTable::add_entry(HandlerTableEntry entry) {32_nesting.check();33if (_length >= _size) {34// not enough space => grow the table (amortized growth, double its size)35guarantee(_size > 0, "no space allocated => cannot grow the table since it is part of nmethod");36int new_size = _size * 2;37_table = REALLOC_RESOURCE_ARRAY(HandlerTableEntry, _table, _size, new_size);38_size = new_size;39}40assert(_length < _size, "sanity check");41_table[_length++] = entry;42}434445HandlerTableEntry* ExceptionHandlerTable::subtable_for(int catch_pco) const {46int i = 0;47while (i < _length) {48HandlerTableEntry* t = _table + i;49if (t->pco() == catch_pco) {50// found subtable matching the catch_pco51return t;52} else {53// advance to next subtable54i += t->len() + 1; // +1 for header55}56}57return NULL;58}596061ExceptionHandlerTable::ExceptionHandlerTable(int initial_size) {62guarantee(initial_size > 0, "initial size must be > 0");63_table = NEW_RESOURCE_ARRAY(HandlerTableEntry, initial_size);64_length = 0;65_size = initial_size;66}676869ExceptionHandlerTable::ExceptionHandlerTable(const nmethod* nm) {70_table = (HandlerTableEntry*)nm->handler_table_begin();71_length = nm->handler_table_size() / sizeof(HandlerTableEntry);72_size = 0; // no space allocated by ExeptionHandlerTable!73}747576void ExceptionHandlerTable::add_subtable(77int catch_pco,78GrowableArray<intptr_t>* handler_bcis,79GrowableArray<intptr_t>* scope_depths_from_top_scope,80GrowableArray<intptr_t>* handler_pcos81) {82assert(subtable_for(catch_pco) == NULL, "catch handlers for this catch_pco added twice");83assert(handler_bcis->length() == handler_pcos->length(), "bci & pc table have different length");84assert(scope_depths_from_top_scope == NULL || handler_bcis->length() == scope_depths_from_top_scope->length(), "bci & scope_depths table have different length");85if (handler_bcis->length() > 0) {86// add subtable header87add_entry(HandlerTableEntry(handler_bcis->length(), catch_pco, 0));88// add individual entries89for (int i = 0; i < handler_bcis->length(); i++) {90intptr_t scope_depth = 0;91if (scope_depths_from_top_scope != NULL) {92scope_depth = scope_depths_from_top_scope->at(i);93}94add_entry(HandlerTableEntry(handler_bcis->at(i), handler_pcos->at(i), scope_depth));95assert(entry_for(catch_pco, handler_bcis->at(i), scope_depth)->pco() == handler_pcos->at(i), "entry not added correctly (1)");96assert(entry_for(catch_pco, handler_bcis->at(i), scope_depth)->scope_depth() == scope_depth, "entry not added correctly (2)");97}98}99}100101102void ExceptionHandlerTable::copy_to(nmethod* nm) {103assert(size_in_bytes() == nm->handler_table_size(), "size of space allocated in nmethod incorrect");104memmove(nm->handler_table_begin(), _table, size_in_bytes());105}106107108HandlerTableEntry* ExceptionHandlerTable::entry_for(int catch_pco, int handler_bci, int scope_depth) const {109HandlerTableEntry* t = subtable_for(catch_pco);110if (t != NULL) {111int l = t->len();112while (l-- > 0) {113t++;114if (t->bci() == handler_bci && t->scope_depth() == scope_depth) return t;115}116}117return NULL;118}119120121void ExceptionHandlerTable::print_subtable(HandlerTableEntry* t) const {122int l = t->len();123tty->print_cr("catch_pco = %d (%d entries)", t->pco(), l);124while (l-- > 0) {125t++;126tty->print_cr(" bci %d at scope depth %d -> pco %d", t->bci(), t->scope_depth(), t->pco());127}128}129130131void ExceptionHandlerTable::print() const {132tty->print_cr("ExceptionHandlerTable (size = %d bytes)", size_in_bytes());133int i = 0;134while (i < _length) {135HandlerTableEntry* t = _table + i;136print_subtable(t);137// advance to next subtable138i += t->len() + 1; // +1 for header139}140}141142void ExceptionHandlerTable::print_subtable_for(int catch_pco) const {143HandlerTableEntry* subtable = subtable_for(catch_pco);144145if( subtable != NULL ) { print_subtable( subtable ); }146}147148// ----------------------------------------------------------------------------149// Implicit null exception tables. Maps an exception PC offset to a150// continuation PC offset. During construction it's a variable sized151// array with a max size and current length. When stored inside an152// nmethod a zero length table takes no space. This is detected by153// nul_chk_table_size() == 0. Otherwise the table has a length word154// followed by pairs of <excp-offset, const-offset>.155void ImplicitExceptionTable::set_size( uint size ) {156_size = size;157_data = NEW_RESOURCE_ARRAY(implicit_null_entry, (size*2));158_len = 0;159}160161void ImplicitExceptionTable::append( uint exec_off, uint cont_off ) {162assert( (sizeof(implicit_null_entry) >= 4) || (exec_off < 65535), "" );163assert( (sizeof(implicit_null_entry) >= 4) || (cont_off < 65535), "" );164uint l = len();165if (l == _size) {166uint old_size_in_elements = _size*2;167if (_size == 0) _size = 4;168_size *= 2;169uint new_size_in_elements = _size*2;170_data = REALLOC_RESOURCE_ARRAY(uint, _data, old_size_in_elements, new_size_in_elements);171}172*(adr(l) ) = exec_off;173*(adr(l)+1) = cont_off;174_len = l+1;175};176177uint ImplicitExceptionTable::at( uint exec_off ) const {178uint l = len();179for( uint i=0; i<l; i++ )180if( *adr(i) == exec_off )181return *(adr(i)+1);182return 0; // Failed to find any execption offset183}184185void ImplicitExceptionTable::print(address base) const {186tty->print("{");187for( uint i=0; i<len(); i++ )188tty->print("< " INTPTR_FORMAT ", " INTPTR_FORMAT " > ",base + *adr(i), base + *(adr(i)+1));189tty->print_cr("}");190}191192ImplicitExceptionTable::ImplicitExceptionTable(const nmethod* nm) {193if (nm->nul_chk_table_size() == 0) {194_len = 0;195_data = NULL;196} else {197// the first word is the length if non-zero, so read it out and198// skip to the next word to get the table.199_data = (implicit_null_entry*)nm->nul_chk_table_begin();200_len = _data[0];201_data++;202}203_size = len();204assert(size_in_bytes() <= nm->nul_chk_table_size(), "size of space allocated in nmethod incorrect");205}206207void ImplicitExceptionTable::copy_to( nmethod* nm ) {208assert(size_in_bytes() <= nm->nul_chk_table_size(), "size of space allocated in nmethod incorrect");209if (len() != 0) {210implicit_null_entry* nmdata = (implicit_null_entry*)nm->nul_chk_table_begin();211// store the length in the first uint212nmdata[0] = _len;213nmdata++;214// copy the table after the length215memmove( nmdata, _data, 2 * len() * sizeof(implicit_null_entry));216} else {217// zero length table takes zero bytes218assert(size_in_bytes() == 0, "bad size");219assert(nm->nul_chk_table_size() == 0, "bad size");220}221}222223void ImplicitExceptionTable::verify(nmethod *nm) const {224for (uint i = 0; i < len(); i++) {225if ((*adr(i) > (unsigned int)nm->insts_size()) ||226(*(adr(i)+1) > (unsigned int)nm->insts_size()))227fatal(err_msg("Invalid offset in ImplicitExceptionTable at " PTR_FORMAT, _data));228}229}230231232