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