src/share/vm/code/exceptionHandlerTable.cpp

Mon, 25 Jun 2012 21:33:35 -0400

author
coleenp
date
Mon, 25 Jun 2012 21:33:35 -0400
changeset 3875
246d977b51f2
parent 2314
f95d63e2154a
child 6680
78bbf4d43a14
permissions
-rw-r--r--

7178670: runtime/7158800/BadUtf8.java fails in SymbolTable::rehash_table
Summary: Cannot delete _buckets and HashtableEntries in shared space (CDS)
Reviewed-by: acorn, kvn, dlong, dcubed, kamg

duke@435 1 /*
twisti@2103 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "code/exceptionHandlerTable.hpp"
stefank@2314 27 #include "code/nmethod.hpp"
stefank@2314 28 #include "memory/allocation.inline.hpp"
duke@435 29
duke@435 30 void ExceptionHandlerTable::add_entry(HandlerTableEntry entry) {
duke@435 31 _nesting.check();
duke@435 32 if (_length >= _size) {
duke@435 33 // not enough space => grow the table (amortized growth, double its size)
duke@435 34 guarantee(_size > 0, "no space allocated => cannot grow the table since it is part of nmethod");
duke@435 35 int new_size = _size * 2;
duke@435 36 _table = REALLOC_RESOURCE_ARRAY(HandlerTableEntry, _table, _size, new_size);
duke@435 37 _size = new_size;
duke@435 38 }
duke@435 39 assert(_length < _size, "sanity check");
duke@435 40 _table[_length++] = entry;
duke@435 41 }
duke@435 42
duke@435 43
duke@435 44 HandlerTableEntry* ExceptionHandlerTable::subtable_for(int catch_pco) const {
duke@435 45 int i = 0;
duke@435 46 while (i < _length) {
duke@435 47 HandlerTableEntry* t = _table + i;
duke@435 48 if (t->pco() == catch_pco) {
duke@435 49 // found subtable matching the catch_pco
duke@435 50 return t;
duke@435 51 } else {
duke@435 52 // advance to next subtable
duke@435 53 i += t->len() + 1; // +1 for header
duke@435 54 }
duke@435 55 }
duke@435 56 return NULL;
duke@435 57 }
duke@435 58
duke@435 59
duke@435 60 ExceptionHandlerTable::ExceptionHandlerTable(int initial_size) {
duke@435 61 guarantee(initial_size > 0, "initial size must be > 0");
duke@435 62 _table = NEW_RESOURCE_ARRAY(HandlerTableEntry, initial_size);
duke@435 63 _length = 0;
duke@435 64 _size = initial_size;
duke@435 65 }
duke@435 66
duke@435 67
duke@435 68 ExceptionHandlerTable::ExceptionHandlerTable(const nmethod* nm) {
duke@435 69 _table = (HandlerTableEntry*)nm->handler_table_begin();
duke@435 70 _length = nm->handler_table_size() / sizeof(HandlerTableEntry);
duke@435 71 _size = 0; // no space allocated by ExeptionHandlerTable!
duke@435 72 }
duke@435 73
duke@435 74
duke@435 75 void ExceptionHandlerTable::add_subtable(
duke@435 76 int catch_pco,
duke@435 77 GrowableArray<intptr_t>* handler_bcis,
duke@435 78 GrowableArray<intptr_t>* scope_depths_from_top_scope,
duke@435 79 GrowableArray<intptr_t>* handler_pcos
duke@435 80 ) {
duke@435 81 assert(subtable_for(catch_pco) == NULL, "catch handlers for this catch_pco added twice");
duke@435 82 assert(handler_bcis->length() == handler_pcos->length(), "bci & pc table have different length");
duke@435 83 assert(scope_depths_from_top_scope == NULL || handler_bcis->length() == scope_depths_from_top_scope->length(), "bci & scope_depths table have different length");
duke@435 84 if (handler_bcis->length() > 0) {
duke@435 85 // add subtable header
duke@435 86 add_entry(HandlerTableEntry(handler_bcis->length(), catch_pco, 0));
duke@435 87 // add individual entries
duke@435 88 for (int i = 0; i < handler_bcis->length(); i++) {
duke@435 89 intptr_t scope_depth = 0;
duke@435 90 if (scope_depths_from_top_scope != NULL) {
duke@435 91 scope_depth = scope_depths_from_top_scope->at(i);
duke@435 92 }
duke@435 93 add_entry(HandlerTableEntry(handler_bcis->at(i), handler_pcos->at(i), scope_depth));
duke@435 94 assert(entry_for(catch_pco, handler_bcis->at(i), scope_depth)->pco() == handler_pcos->at(i), "entry not added correctly (1)");
duke@435 95 assert(entry_for(catch_pco, handler_bcis->at(i), scope_depth)->scope_depth() == scope_depth, "entry not added correctly (2)");
duke@435 96 }
duke@435 97 }
duke@435 98 }
duke@435 99
duke@435 100
duke@435 101 void ExceptionHandlerTable::copy_to(nmethod* nm) {
duke@435 102 assert(size_in_bytes() == nm->handler_table_size(), "size of space allocated in nmethod incorrect");
duke@435 103 memmove(nm->handler_table_begin(), _table, size_in_bytes());
duke@435 104 }
duke@435 105
duke@435 106
duke@435 107 HandlerTableEntry* ExceptionHandlerTable::entry_for(int catch_pco, int handler_bci, int scope_depth) const {
duke@435 108 HandlerTableEntry* t = subtable_for(catch_pco);
duke@435 109 if (t != NULL) {
duke@435 110 int l = t->len();
duke@435 111 while (l-- > 0) {
duke@435 112 t++;
duke@435 113 if (t->bci() == handler_bci && t->scope_depth() == scope_depth) return t;
duke@435 114 }
duke@435 115 }
duke@435 116 return NULL;
duke@435 117 }
duke@435 118
duke@435 119
duke@435 120 void ExceptionHandlerTable::print_subtable(HandlerTableEntry* t) const {
duke@435 121 int l = t->len();
duke@435 122 tty->print_cr("catch_pco = %d (%d entries)", t->pco(), l);
duke@435 123 while (l-- > 0) {
duke@435 124 t++;
duke@435 125 tty->print_cr(" bci %d at scope depth %d -> pco %d", t->bci(), t->scope_depth(), t->pco());
duke@435 126 }
duke@435 127 }
duke@435 128
duke@435 129
duke@435 130 void ExceptionHandlerTable::print() const {
duke@435 131 tty->print_cr("ExceptionHandlerTable (size = %d bytes)", size_in_bytes());
duke@435 132 int i = 0;
duke@435 133 while (i < _length) {
duke@435 134 HandlerTableEntry* t = _table + i;
duke@435 135 print_subtable(t);
duke@435 136 // advance to next subtable
duke@435 137 i += t->len() + 1; // +1 for header
duke@435 138 }
duke@435 139 }
duke@435 140
duke@435 141 void ExceptionHandlerTable::print_subtable_for(int catch_pco) const {
duke@435 142 HandlerTableEntry* subtable = subtable_for(catch_pco);
duke@435 143
duke@435 144 if( subtable != NULL ) { print_subtable( subtable ); }
duke@435 145 }
duke@435 146
duke@435 147 // ----------------------------------------------------------------------------
duke@435 148 // Implicit null exception tables. Maps an exception PC offset to a
duke@435 149 // continuation PC offset. During construction it's a variable sized
duke@435 150 // array with a max size and current length. When stored inside an
duke@435 151 // nmethod a zero length table takes no space. This is detected by
duke@435 152 // nul_chk_table_size() == 0. Otherwise the table has a length word
duke@435 153 // followed by pairs of <excp-offset, const-offset>.
duke@435 154 void ImplicitExceptionTable::set_size( uint size ) {
duke@435 155 _size = size;
duke@435 156 _data = NEW_RESOURCE_ARRAY(implicit_null_entry, (size*2));
duke@435 157 _len = 0;
duke@435 158 }
duke@435 159
duke@435 160 void ImplicitExceptionTable::append( uint exec_off, uint cont_off ) {
duke@435 161 assert( (sizeof(implicit_null_entry) >= 4) || (exec_off < 65535), "" );
duke@435 162 assert( (sizeof(implicit_null_entry) >= 4) || (cont_off < 65535), "" );
duke@435 163 uint l = len();
duke@435 164 if (l == _size) {
duke@435 165 uint old_size_in_elements = _size*2;
duke@435 166 if (_size == 0) _size = 4;
duke@435 167 _size *= 2;
duke@435 168 uint new_size_in_elements = _size*2;
duke@435 169 _data = REALLOC_RESOURCE_ARRAY(uint, _data, old_size_in_elements, new_size_in_elements);
duke@435 170 }
duke@435 171 *(adr(l) ) = exec_off;
duke@435 172 *(adr(l)+1) = cont_off;
duke@435 173 _len = l+1;
duke@435 174 };
duke@435 175
duke@435 176 uint ImplicitExceptionTable::at( uint exec_off ) const {
duke@435 177 uint l = len();
duke@435 178 for( uint i=0; i<l; i++ )
duke@435 179 if( *adr(i) == exec_off )
duke@435 180 return *(adr(i)+1);
duke@435 181 return 0; // Failed to find any execption offset
duke@435 182 }
duke@435 183
duke@435 184 void ImplicitExceptionTable::print(address base) const {
duke@435 185 tty->print("{");
duke@435 186 for( uint i=0; i<len(); i++ )
duke@435 187 tty->print("< "INTPTR_FORMAT", "INTPTR_FORMAT" > ",base + *adr(i), base + *(adr(i)+1));
duke@435 188 tty->print_cr("}");
duke@435 189 }
duke@435 190
duke@435 191 ImplicitExceptionTable::ImplicitExceptionTable(const nmethod* nm) {
duke@435 192 if (nm->nul_chk_table_size() == 0) {
duke@435 193 _len = 0;
duke@435 194 _data = NULL;
duke@435 195 } else {
duke@435 196 // the first word is the length if non-zero, so read it out and
duke@435 197 // skip to the next word to get the table.
duke@435 198 _data = (implicit_null_entry*)nm->nul_chk_table_begin();
duke@435 199 _len = _data[0];
duke@435 200 _data++;
duke@435 201 }
duke@435 202 _size = len();
duke@435 203 assert(size_in_bytes() <= nm->nul_chk_table_size(), "size of space allocated in nmethod incorrect");
duke@435 204 }
duke@435 205
duke@435 206 void ImplicitExceptionTable::copy_to( nmethod* nm ) {
duke@435 207 assert(size_in_bytes() <= nm->nul_chk_table_size(), "size of space allocated in nmethod incorrect");
duke@435 208 if (len() != 0) {
duke@435 209 implicit_null_entry* nmdata = (implicit_null_entry*)nm->nul_chk_table_begin();
duke@435 210 // store the length in the first uint
duke@435 211 nmdata[0] = _len;
duke@435 212 nmdata++;
duke@435 213 // copy the table after the length
duke@435 214 memmove( nmdata, _data, 2 * len() * sizeof(implicit_null_entry));
duke@435 215 } else {
duke@435 216 // zero length table takes zero bytes
duke@435 217 assert(size_in_bytes() == 0, "bad size");
duke@435 218 assert(nm->nul_chk_table_size() == 0, "bad size");
duke@435 219 }
duke@435 220 }
duke@435 221
duke@435 222 void ImplicitExceptionTable::verify(nmethod *nm) const {
duke@435 223 for (uint i = 0; i < len(); i++) {
twisti@2103 224 if ((*adr(i) > (unsigned int)nm->insts_size()) ||
twisti@2103 225 (*(adr(i)+1) > (unsigned int)nm->insts_size()))
jcoomes@1845 226 fatal(err_msg("Invalid offset in ImplicitExceptionTable at " PTR_FORMAT, _data));
duke@435 227 }
duke@435 228 }

mercurial