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