src/share/vm/code/debugInfoRec.cpp

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 5614
9758d9f36299
child 6876
710a3c8b516e
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

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

mercurial