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