Mercurial > hg > truffle
annotate src/share/vm/code/debugInfoRec.cpp @ 1299:9eba43136cb5
6934494: JSR 292 MethodHandles adapters should be generated into their own CodeBlob
Summary: Passing a null pointer to an InvokeDynamic function call should lead to a NullPointerException.
Reviewed-by: kvn, never
author | twisti |
---|---|
date | Tue, 16 Mar 2010 11:52:17 +0100 |
parents | f70b0d9ab095 |
children | c18cbe5936b8 |
rev | line source |
---|---|
0 | 1 /* |
931
72088be4b386
6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents:
900
diff
changeset
|
2 * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_debugInfoRec.cpp.incl" | |
27 | |
28 // Private definition. | |
29 // There is one DIR_Chunk for each scope and values array. | |
30 // A chunk can potentially be used more than once. | |
31 // We keep track of these chunks in order to detect | |
32 // repetition and enable sharing. | |
33 class DIR_Chunk { | |
34 friend class DebugInformationRecorder; | |
35 int _offset; // location in the stream of this scope | |
36 int _length; // number of bytes in the stream | |
37 int _hash; // hash of stream bytes (for quicker reuse) | |
38 | |
39 void* operator new(size_t ignore, DebugInformationRecorder* dir) { | |
40 assert(ignore == sizeof(DIR_Chunk), ""); | |
41 if (dir->_next_chunk >= dir->_next_chunk_limit) { | |
42 const int CHUNK = 100; | |
43 dir->_next_chunk = NEW_RESOURCE_ARRAY(DIR_Chunk, CHUNK); | |
44 dir->_next_chunk_limit = dir->_next_chunk + CHUNK; | |
45 } | |
46 return dir->_next_chunk++; | |
47 } | |
48 | |
49 DIR_Chunk(int offset, int length, DebugInformationRecorder* dir) { | |
50 _offset = offset; | |
51 _length = length; | |
52 unsigned int hash = 0; | |
53 address p = dir->stream()->buffer() + _offset; | |
54 for (int i = 0; i < length; i++) { | |
55 if (i == 6) break; | |
56 hash *= 127; | |
57 hash += p[i]; | |
58 } | |
59 _hash = hash; | |
60 } | |
61 | |
62 DIR_Chunk* find_match(GrowableArray<DIR_Chunk*>* arr, | |
63 int start_index, | |
64 DebugInformationRecorder* dir) { | |
65 int end_index = arr->length(); | |
66 int hash = this->_hash, length = this->_length; | |
67 address buf = dir->stream()->buffer(); | |
68 for (int i = end_index; --i >= start_index; ) { | |
69 DIR_Chunk* that = arr->at(i); | |
70 if (hash == that->_hash && | |
71 length == that->_length && | |
72 0 == memcmp(buf + this->_offset, buf + that->_offset, length)) { | |
73 return that; | |
74 } | |
75 } | |
76 return NULL; | |
77 } | |
78 }; | |
79 | |
80 static inline bool compute_recording_non_safepoints() { | |
81 if (JvmtiExport::should_post_compiled_method_load() | |
82 && FLAG_IS_DEFAULT(DebugNonSafepoints)) { | |
83 // The default value of this flag is taken to be true, | |
84 // if JVMTI is looking at nmethod codes. | |
85 // We anticipate that JVMTI may wish to participate in profiling. | |
86 return true; | |
87 } | |
88 | |
89 // If the flag is set manually, use it, whether true or false. | |
90 // Otherwise, if JVMTI is not in the picture, use the default setting. | |
91 // (This is true in debug, just for the exercise, false in product mode.) | |
92 return DebugNonSafepoints; | |
93 } | |
94 | |
95 DebugInformationRecorder::DebugInformationRecorder(OopRecorder* oop_recorder) | |
96 : _recording_non_safepoints(compute_recording_non_safepoints()) | |
97 { | |
98 _pcs_size = 100; | |
99 _pcs = NEW_RESOURCE_ARRAY(PcDesc, _pcs_size); | |
100 _pcs_length = 0; | |
101 | |
102 _prev_safepoint_pc = PcDesc::lower_offset_limit; | |
103 | |
104 _stream = new DebugInfoWriteStream(this, 10 * K); | |
105 // make sure that there is no stream_decode_offset that is zero | |
106 _stream->write_byte((jbyte)0xFF); | |
107 | |
108 // make sure that we can distinguish the value "serialized_null" from offsets | |
109 assert(_stream->position() > serialized_null, "sanity"); | |
110 | |
111 _oop_recorder = oop_recorder; | |
112 | |
113 _all_chunks = new GrowableArray<DIR_Chunk*>(300); | |
114 _shared_chunks = new GrowableArray<DIR_Chunk*>(30); | |
115 _next_chunk = _next_chunk_limit = NULL; | |
116 | |
117 add_new_pc_offset(PcDesc::lower_offset_limit); // sentinel record | |
118 | |
119 debug_only(_recording_state = rs_null); | |
120 } | |
121 | |
122 | |
123 void DebugInformationRecorder::add_oopmap(int pc_offset, OopMap* map) { | |
124 // !!!!! Preserve old style handling of oopmaps for now | |
125 _oopmaps->add_gc_map(pc_offset, map); | |
126 } | |
127 | |
128 void DebugInformationRecorder::add_safepoint(int pc_offset, OopMap* map) { | |
129 assert(!_oop_recorder->is_complete(), "not frozen yet"); | |
130 // Store the new safepoint | |
131 | |
132 // Add the oop map | |
133 add_oopmap(pc_offset, map); | |
134 | |
135 add_new_pc_offset(pc_offset); | |
136 | |
137 assert(_recording_state == rs_null, "nesting of recording calls"); | |
138 debug_only(_recording_state = rs_safepoint); | |
139 } | |
140 | |
141 void DebugInformationRecorder::add_non_safepoint(int pc_offset) { | |
142 assert(!_oop_recorder->is_complete(), "not frozen yet"); | |
143 assert(_recording_non_safepoints, "must be recording non-safepoints"); | |
144 | |
145 add_new_pc_offset(pc_offset); | |
146 | |
147 assert(_recording_state == rs_null, "nesting of recording calls"); | |
148 debug_only(_recording_state = rs_non_safepoint); | |
149 } | |
150 | |
151 void DebugInformationRecorder::add_new_pc_offset(int pc_offset) { | |
152 assert(_pcs_length == 0 || last_pc()->pc_offset() < pc_offset, | |
153 "must specify a new, larger pc offset"); | |
154 | |
155 // add the pcdesc | |
156 if (_pcs_length == _pcs_size) { | |
157 // Expand | |
158 int new_pcs_size = _pcs_size * 2; | |
159 PcDesc* new_pcs = NEW_RESOURCE_ARRAY(PcDesc, new_pcs_size); | |
160 for (int index = 0; index < _pcs_length; index++) { | |
161 new_pcs[index] = _pcs[index]; | |
162 } | |
163 _pcs_size = new_pcs_size; | |
164 _pcs = new_pcs; | |
165 } | |
166 assert(_pcs_size > _pcs_length, "There must be room for after expanding"); | |
167 | |
168 _pcs[_pcs_length++] = PcDesc(pc_offset, DebugInformationRecorder::serialized_null, | |
169 DebugInformationRecorder::serialized_null); | |
170 } | |
171 | |
172 | |
173 int DebugInformationRecorder::serialize_monitor_values(GrowableArray<MonitorValue*>* monitors) { | |
174 if (monitors == NULL || monitors->is_empty()) return DebugInformationRecorder::serialized_null; | |
175 assert(_recording_state == rs_safepoint, "must be recording a safepoint"); | |
176 int result = stream()->position(); | |
177 stream()->write_int(monitors->length()); | |
178 for (int index = 0; index < monitors->length(); index++) { | |
179 monitors->at(index)->write_on(stream()); | |
180 } | |
181 assert(result != serialized_null, "sanity"); | |
182 | |
183 // (See comment below on DebugInformationRecorder::describe_scope.) | |
184 int shared_result = find_sharable_decode_offset(result); | |
185 if (shared_result != serialized_null) { | |
186 stream()->set_position(result); | |
187 result = shared_result; | |
188 } | |
189 | |
190 return result; | |
191 } | |
192 | |
193 | |
194 int DebugInformationRecorder::serialize_scope_values(GrowableArray<ScopeValue*>* values) { | |
195 if (values == NULL || values->is_empty()) return DebugInformationRecorder::serialized_null; | |
196 assert(_recording_state == rs_safepoint, "must be recording a safepoint"); | |
197 int result = stream()->position(); | |
198 assert(result != serialized_null, "sanity"); | |
199 stream()->write_int(values->length()); | |
200 for (int index = 0; index < values->length(); index++) { | |
201 values->at(index)->write_on(stream()); | |
202 } | |
203 | |
204 // (See comment below on DebugInformationRecorder::describe_scope.) | |
205 int shared_result = find_sharable_decode_offset(result); | |
206 if (shared_result != serialized_null) { | |
207 stream()->set_position(result); | |
208 result = shared_result; | |
209 } | |
210 | |
211 return result; | |
212 } | |
213 | |
214 | |
215 #ifndef PRODUCT | |
216 // These variables are put into one block to reduce relocations | |
217 // and make it simpler to print from the debugger. | |
218 static | |
219 struct dir_stats_struct { | |
220 int chunks_queried; | |
221 int chunks_shared; | |
222 int chunks_reshared; | |
223 int chunks_elided; | |
224 | |
225 void print() { | |
226 tty->print_cr("Debug Data Chunks: %d, shared %d+%d, non-SP's elided %d", | |
227 chunks_queried, | |
228 chunks_shared, chunks_reshared, | |
229 chunks_elided); | |
230 } | |
231 } dir_stats; | |
232 #endif //PRODUCT | |
233 | |
234 | |
235 int DebugInformationRecorder::find_sharable_decode_offset(int stream_offset) { | |
236 // Only pull this trick if non-safepoint recording | |
237 // is enabled, for now. | |
238 if (!recording_non_safepoints()) | |
239 return serialized_null; | |
240 | |
241 NOT_PRODUCT(++dir_stats.chunks_queried); | |
242 int stream_length = stream()->position() - stream_offset; | |
243 assert(stream_offset != serialized_null, "should not be null"); | |
244 assert(stream_length != 0, "should not be empty"); | |
245 | |
246 DIR_Chunk* ns = new(this) DIR_Chunk(stream_offset, stream_length, this); | |
247 | |
248 // Look in previously shared scopes first: | |
249 DIR_Chunk* ms = ns->find_match(_shared_chunks, 0, this); | |
250 if (ms != NULL) { | |
251 NOT_PRODUCT(++dir_stats.chunks_reshared); | |
252 assert(ns+1 == _next_chunk, ""); | |
253 _next_chunk = ns; | |
254 return ms->_offset; | |
255 } | |
256 | |
257 // Look in recently encountered scopes next: | |
258 const int MAX_RECENT = 50; | |
259 int start_index = _all_chunks->length() - MAX_RECENT; | |
260 if (start_index < 0) start_index = 0; | |
261 ms = ns->find_match(_all_chunks, start_index, this); | |
262 if (ms != NULL) { | |
263 NOT_PRODUCT(++dir_stats.chunks_shared); | |
264 // Searching in _all_chunks is limited to a window, | |
265 // but searching in _shared_chunks is unlimited. | |
266 _shared_chunks->append(ms); | |
267 assert(ns+1 == _next_chunk, ""); | |
268 _next_chunk = ns; | |
269 return ms->_offset; | |
270 } | |
271 | |
272 // No match. Add this guy to the list, in hopes of future shares. | |
273 _all_chunks->append(ns); | |
274 return serialized_null; | |
275 } | |
276 | |
277 | |
278 // must call add_safepoint before: it sets PcDesc and this routine uses | |
279 // the last PcDesc set | |
280 void DebugInformationRecorder::describe_scope(int pc_offset, | |
281 ciMethod* method, | |
282 int bci, | |
900
9987d9d5eb0e
6833129: specjvm98 fails with NullPointerException in the compiler with -XX:DeoptimizeALot
cfang
parents:
0
diff
changeset
|
283 bool reexecute, |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1014
diff
changeset
|
284 bool is_method_handle_invoke, |
1253
f70b0d9ab095
6910618: C2: Error: assert(d->is_oop(),"JVM_ArrayCopy: dst not an oop")
kvn
parents:
1135
diff
changeset
|
285 bool return_oop, |
0 | 286 DebugToken* locals, |
287 DebugToken* expressions, | |
288 DebugToken* monitors) { | |
289 assert(_recording_state != rs_null, "nesting of recording calls"); | |
290 PcDesc* last_pd = last_pc(); | |
291 assert(last_pd->pc_offset() == pc_offset, "must be last pc"); | |
292 int sender_stream_offset = last_pd->scope_decode_offset(); | |
293 // update the stream offset of current pc desc | |
294 int stream_offset = stream()->position(); | |
295 last_pd->set_scope_decode_offset(stream_offset); | |
296 | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1014
diff
changeset
|
297 // Record flags into pcDesc. |
931
72088be4b386
6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents:
900
diff
changeset
|
298 last_pd->set_should_reexecute(reexecute); |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
1014
diff
changeset
|
299 last_pd->set_is_method_handle_invoke(is_method_handle_invoke); |
1253
f70b0d9ab095
6910618: C2: Error: assert(d->is_oop(),"JVM_ArrayCopy: dst not an oop")
kvn
parents:
1135
diff
changeset
|
300 last_pd->set_return_oop(return_oop); |
931
72088be4b386
6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents:
900
diff
changeset
|
301 |
0 | 302 // serialize sender stream offest |
303 stream()->write_int(sender_stream_offset); | |
304 | |
305 // serialize scope | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
931
diff
changeset
|
306 jobject method_enc = (method == NULL)? NULL: method->constant_encoding(); |
0 | 307 stream()->write_int(oop_recorder()->find_index(method_enc)); |
931
72088be4b386
6873116: Modify reexecute implementation to use pcDesc to record the reexecute bit
cfang
parents:
900
diff
changeset
|
308 stream()->write_bci(bci); |
0 | 309 assert(method == NULL || |
310 (method->is_native() && bci == 0) || | |
311 (!method->is_native() && 0 <= bci && bci < method->code_size()) || | |
312 bci == -1, "illegal bci"); | |
313 | |
314 // serialize the locals/expressions/monitors | |
315 stream()->write_int((intptr_t) locals); | |
316 stream()->write_int((intptr_t) expressions); | |
317 stream()->write_int((intptr_t) monitors); | |
318 | |
319 // Here's a tricky bit. We just wrote some bytes. | |
320 // Wouldn't it be nice to find that we had already | |
321 // written those same bytes somewhere else? | |
322 // If we get lucky this way, reset the stream | |
323 // and reuse the old bytes. By the way, this | |
324 // trick not only shares parent scopes, but also | |
325 // compresses equivalent non-safepoint PcDescs. | |
326 int shared_stream_offset = find_sharable_decode_offset(stream_offset); | |
327 if (shared_stream_offset != serialized_null) { | |
328 stream()->set_position(stream_offset); | |
329 last_pd->set_scope_decode_offset(shared_stream_offset); | |
330 } | |
331 } | |
332 | |
333 void DebugInformationRecorder::dump_object_pool(GrowableArray<ScopeValue*>* objects) { | |
334 guarantee( _pcs_length > 0, "safepoint must exist before describing scopes"); | |
335 PcDesc* last_pd = &_pcs[_pcs_length-1]; | |
336 if (objects != NULL) { | |
337 for (int i = objects->length() - 1; i >= 0; i--) { | |
338 ((ObjectValue*) objects->at(i))->set_visited(false); | |
339 } | |
340 } | |
341 int offset = serialize_scope_values(objects); | |
342 last_pd->set_obj_decode_offset(offset); | |
343 } | |
344 | |
345 void DebugInformationRecorder::end_scopes(int pc_offset, bool is_safepoint) { | |
346 assert(_recording_state == (is_safepoint? rs_safepoint: rs_non_safepoint), | |
347 "nesting of recording calls"); | |
348 debug_only(_recording_state = rs_null); | |
349 | |
350 // Try to compress away an equivalent non-safepoint predecessor. | |
351 // (This only works because we have previously recognized redundant | |
352 // scope trees and made them use a common scope_decode_offset.) | |
353 if (_pcs_length >= 2 && recording_non_safepoints()) { | |
354 PcDesc* last = last_pc(); | |
355 PcDesc* prev = prev_pc(); | |
356 // If prev is (a) not a safepoint and (b) has the same | |
357 // stream pointer, then it can be coalesced into the last. | |
358 // This is valid because non-safepoints are only sought | |
359 // with pc_desc_near, which (when it misses prev) will | |
360 // search forward until it finds last. | |
361 // In addition, it does not matter if the last PcDesc | |
362 // is for a safepoint or not. | |
1014
8e954aedbb81
6889869: assert(!Interpreter::bytecode_should_reexecute(code),"should not reexecute")
never
parents:
989
diff
changeset
|
363 if (_prev_safepoint_pc < prev->pc_offset() && prev->is_same_info(last)) { |
0 | 364 assert(prev == last-1, "sane"); |
365 prev->set_pc_offset(pc_offset); | |
366 _pcs_length -= 1; | |
367 NOT_PRODUCT(++dir_stats.chunks_elided); | |
368 } | |
369 } | |
370 | |
371 // We have just recorded this safepoint. | |
372 // Remember it in case the previous paragraph needs to know. | |
373 if (is_safepoint) { | |
374 _prev_safepoint_pc = pc_offset; | |
375 } | |
376 } | |
377 | |
378 DebugToken* DebugInformationRecorder::create_scope_values(GrowableArray<ScopeValue*>* values) { | |
379 assert(!_oop_recorder->is_complete(), "not frozen yet"); | |
380 return (DebugToken*) (intptr_t) serialize_scope_values(values); | |
381 } | |
382 | |
383 | |
384 DebugToken* DebugInformationRecorder::create_monitor_values(GrowableArray<MonitorValue*>* monitors) { | |
385 assert(!_oop_recorder->is_complete(), "not frozen yet"); | |
386 return (DebugToken*) (intptr_t) serialize_monitor_values(monitors); | |
387 } | |
388 | |
389 | |
390 int DebugInformationRecorder::data_size() { | |
391 debug_only(_oop_recorder->oop_size()); // mark it "frozen" for asserts | |
392 return _stream->position(); | |
393 } | |
394 | |
395 | |
396 int DebugInformationRecorder::pcs_size() { | |
397 debug_only(_oop_recorder->oop_size()); // mark it "frozen" for asserts | |
398 if (last_pc()->pc_offset() != PcDesc::upper_offset_limit) | |
399 add_new_pc_offset(PcDesc::upper_offset_limit); | |
400 return _pcs_length * sizeof(PcDesc); | |
401 } | |
402 | |
403 | |
404 void DebugInformationRecorder::copy_to(nmethod* nm) { | |
405 nm->copy_scopes_data(stream()->buffer(), stream()->position()); | |
406 nm->copy_scopes_pcs(_pcs, _pcs_length); | |
407 } | |
408 | |
409 | |
410 void DebugInformationRecorder::verify(const nmethod* code) { | |
411 Unimplemented(); | |
412 } | |
413 | |
414 #ifndef PRODUCT | |
415 void DebugInformationRecorder::print_statistics() { | |
416 dir_stats.print(); | |
417 } | |
418 #endif //PRODUCT |