src/share/vm/code/debugInfoRec.cpp

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

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

mercurial