annotate src/share/vm/ci/ciMethodData.cpp @ 1879:f95d63e2154a

6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
author stefank
date Tue, 23 Nov 2010 13:22:55 -0800
parents d5d065957597
children da91efe96a93
rev   line source
duke@0 1 /*
iveresov@1703 2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "ci/ciMethodData.hpp"
stefank@1879 27 #include "ci/ciUtilities.hpp"
stefank@1879 28 #include "memory/allocation.inline.hpp"
stefank@1879 29 #include "memory/resourceArea.hpp"
stefank@1879 30 #include "runtime/deoptimization.hpp"
stefank@1879 31 #include "utilities/copy.hpp"
duke@0 32
duke@0 33 // ciMethodData
duke@0 34
duke@0 35 // ------------------------------------------------------------------
duke@0 36 // ciMethodData::ciMethodData
duke@0 37 //
duke@0 38 ciMethodData::ciMethodData(methodDataHandle h_md) : ciObject(h_md) {
duke@0 39 assert(h_md() != NULL, "no null method data");
duke@0 40 Copy::zero_to_words((HeapWord*) &_orig, sizeof(_orig) / sizeof(HeapWord));
duke@0 41 _data = NULL;
duke@0 42 _data_size = 0;
duke@0 43 _extra_data_size = 0;
duke@0 44 _current_mileage = 0;
iveresov@1703 45 _invocation_counter = 0;
iveresov@1703 46 _backedge_counter = 0;
duke@0 47 _state = empty_state;
duke@0 48 _saw_free_extra_data = false;
duke@0 49 // Set an initial hint. Don't use set_hint_di() because
duke@0 50 // first_di() may be out of bounds if data_size is 0.
duke@0 51 _hint_di = first_di();
kvn@45 52 // Initialize the escape information (to "don't know.");
kvn@45 53 _eflags = _arg_local = _arg_stack = _arg_returned = 0;
duke@0 54 }
duke@0 55
duke@0 56 // ------------------------------------------------------------------
duke@0 57 // ciMethodData::ciMethodData
duke@0 58 //
duke@0 59 // No methodDataOop.
duke@0 60 ciMethodData::ciMethodData() : ciObject() {
duke@0 61 Copy::zero_to_words((HeapWord*) &_orig, sizeof(_orig) / sizeof(HeapWord));
duke@0 62 _data = NULL;
duke@0 63 _data_size = 0;
duke@0 64 _extra_data_size = 0;
duke@0 65 _current_mileage = 0;
iveresov@1703 66 _invocation_counter = 0;
iveresov@1703 67 _backedge_counter = 0;
duke@0 68 _state = empty_state;
duke@0 69 _saw_free_extra_data = false;
duke@0 70 // Set an initial hint. Don't use set_hint_di() because
duke@0 71 // first_di() may be out of bounds if data_size is 0.
duke@0 72 _hint_di = first_di();
kvn@45 73 // Initialize the escape information (to "don't know.");
kvn@45 74 _eflags = _arg_local = _arg_stack = _arg_returned = 0;
duke@0 75 }
duke@0 76
duke@0 77 void ciMethodData::load_data() {
duke@0 78 methodDataOop mdo = get_methodDataOop();
duke@0 79 if (mdo == NULL) return;
duke@0 80
duke@0 81 // To do: don't copy the data if it is not "ripe" -- require a minimum #
duke@0 82 // of invocations.
duke@0 83
duke@0 84 // Snapshot the data -- actually, take an approximate snapshot of
duke@0 85 // the data. Any concurrently executing threads may be changing the
duke@0 86 // data as we copy it.
duke@0 87 int skip_header = oopDesc::header_size();
duke@0 88 Copy::disjoint_words((HeapWord*) mdo + skip_header,
duke@0 89 (HeapWord*) &_orig + skip_header,
duke@0 90 sizeof(_orig) / HeapWordSize - skip_header);
duke@0 91 DEBUG_ONLY(*_orig.adr_method() = NULL); // no dangling oops, please
duke@0 92 Arena* arena = CURRENT_ENV->arena();
duke@0 93 _data_size = mdo->data_size();
duke@0 94 _extra_data_size = mdo->extra_data_size();
duke@0 95 int total_size = _data_size + _extra_data_size;
duke@0 96 _data = (intptr_t *) arena->Amalloc(total_size);
duke@0 97 Copy::disjoint_words((HeapWord*) mdo->data_base(), (HeapWord*) _data, total_size / HeapWordSize);
duke@0 98
duke@0 99 // Traverse the profile data, translating any oops into their
duke@0 100 // ci equivalents.
duke@0 101 ResourceMark rm;
duke@0 102 ciProfileData* ci_data = first_data();
duke@0 103 ProfileData* data = mdo->first_data();
duke@0 104 while (is_valid(ci_data)) {
duke@0 105 ci_data->translate_from(data);
duke@0 106 ci_data = next_data(ci_data);
duke@0 107 data = mdo->next_data(data);
duke@0 108 }
duke@0 109 // Note: Extra data are all BitData, and do not need translation.
duke@0 110 _current_mileage = methodDataOopDesc::mileage_of(mdo->method());
iveresov@1703 111 _invocation_counter = mdo->invocation_count();
iveresov@1703 112 _backedge_counter = mdo->backedge_count();
duke@0 113 _state = mdo->is_mature()? mature_state: immature_state;
duke@0 114
duke@0 115 _eflags = mdo->eflags();
duke@0 116 _arg_local = mdo->arg_local();
duke@0 117 _arg_stack = mdo->arg_stack();
duke@0 118 _arg_returned = mdo->arg_returned();
duke@0 119 }
duke@0 120
duke@0 121 void ciReceiverTypeData::translate_receiver_data_from(ProfileData* data) {
duke@0 122 for (uint row = 0; row < row_limit(); row++) {
duke@0 123 klassOop k = data->as_ReceiverTypeData()->receiver(row);
duke@0 124 if (k != NULL) {
duke@0 125 ciKlass* klass = CURRENT_ENV->get_object(k)->as_klass();
duke@0 126 set_receiver(row, klass);
duke@0 127 }
duke@0 128 }
duke@0 129 }
duke@0 130
duke@0 131
duke@0 132 // Get the data at an arbitrary (sort of) data index.
duke@0 133 ciProfileData* ciMethodData::data_at(int data_index) {
duke@0 134 if (out_of_bounds(data_index)) {
duke@0 135 return NULL;
duke@0 136 }
duke@0 137 DataLayout* data_layout = data_layout_at(data_index);
duke@0 138
duke@0 139 switch (data_layout->tag()) {
duke@0 140 case DataLayout::no_tag:
duke@0 141 default:
duke@0 142 ShouldNotReachHere();
duke@0 143 return NULL;
duke@0 144 case DataLayout::bit_data_tag:
duke@0 145 return new ciBitData(data_layout);
duke@0 146 case DataLayout::counter_data_tag:
duke@0 147 return new ciCounterData(data_layout);
duke@0 148 case DataLayout::jump_data_tag:
duke@0 149 return new ciJumpData(data_layout);
duke@0 150 case DataLayout::receiver_type_data_tag:
duke@0 151 return new ciReceiverTypeData(data_layout);
duke@0 152 case DataLayout::virtual_call_data_tag:
duke@0 153 return new ciVirtualCallData(data_layout);
duke@0 154 case DataLayout::ret_data_tag:
duke@0 155 return new ciRetData(data_layout);
duke@0 156 case DataLayout::branch_data_tag:
duke@0 157 return new ciBranchData(data_layout);
duke@0 158 case DataLayout::multi_branch_data_tag:
duke@0 159 return new ciMultiBranchData(data_layout);
kvn@45 160 case DataLayout::arg_info_data_tag:
kvn@45 161 return new ciArgInfoData(data_layout);
duke@0 162 };
duke@0 163 }
duke@0 164
duke@0 165 // Iteration over data.
duke@0 166 ciProfileData* ciMethodData::next_data(ciProfileData* current) {
duke@0 167 int current_index = dp_to_di(current->dp());
duke@0 168 int next_index = current_index + current->size_in_bytes();
duke@0 169 ciProfileData* next = data_at(next_index);
duke@0 170 return next;
duke@0 171 }
duke@0 172
duke@0 173 // Translate a bci to its corresponding data, or NULL.
duke@0 174 ciProfileData* ciMethodData::bci_to_data(int bci) {
duke@0 175 ciProfileData* data = data_before(bci);
duke@0 176 for ( ; is_valid(data); data = next_data(data)) {
duke@0 177 if (data->bci() == bci) {
duke@0 178 set_hint_di(dp_to_di(data->dp()));
duke@0 179 return data;
duke@0 180 } else if (data->bci() > bci) {
duke@0 181 break;
duke@0 182 }
duke@0 183 }
duke@0 184 // bci_to_extra_data(bci) ...
duke@0 185 DataLayout* dp = data_layout_at(data_size());
duke@0 186 DataLayout* end = data_layout_at(data_size() + extra_data_size());
duke@0 187 for (; dp < end; dp = methodDataOopDesc::next_extra(dp)) {
duke@0 188 if (dp->tag() == DataLayout::no_tag) {
duke@0 189 _saw_free_extra_data = true; // observed an empty slot (common case)
duke@0 190 return NULL;
duke@0 191 }
kvn@45 192 if (dp->tag() == DataLayout::arg_info_data_tag) {
kvn@45 193 break; // ArgInfoData is at the end of extra data section.
kvn@45 194 }
duke@0 195 if (dp->bci() == bci) {
duke@0 196 assert(dp->tag() == DataLayout::bit_data_tag, "sane");
duke@0 197 return new ciBitData(dp);
duke@0 198 }
duke@0 199 }
duke@0 200 return NULL;
duke@0 201 }
duke@0 202
duke@0 203 // Conservatively decode the trap_state of a ciProfileData.
duke@0 204 int ciMethodData::has_trap_at(ciProfileData* data, int reason) {
duke@0 205 typedef Deoptimization::DeoptReason DR_t;
duke@0 206 int per_bc_reason
duke@0 207 = Deoptimization::reason_recorded_per_bytecode_if_any((DR_t) reason);
duke@0 208 if (trap_count(reason) == 0) {
duke@0 209 // Impossible for this trap to have occurred, regardless of trap_state.
duke@0 210 // Note: This happens if the MDO is empty.
duke@0 211 return 0;
duke@0 212 } else if (per_bc_reason == Deoptimization::Reason_none) {
duke@0 213 // We cannot conclude anything; a trap happened somewhere, maybe here.
duke@0 214 return -1;
duke@0 215 } else if (data == NULL) {
duke@0 216 // No profile here, not even an extra_data record allocated on the fly.
duke@0 217 // If there are empty extra_data records, and there had been a trap,
duke@0 218 // there would have been a non-null data pointer. If there are no
duke@0 219 // free extra_data records, we must return a conservative -1.
duke@0 220 if (_saw_free_extra_data)
duke@0 221 return 0; // Q.E.D.
duke@0 222 else
duke@0 223 return -1; // bail with a conservative answer
duke@0 224 } else {
duke@0 225 return Deoptimization::trap_state_has_reason(data->trap_state(), per_bc_reason);
duke@0 226 }
duke@0 227 }
duke@0 228
duke@0 229 int ciMethodData::trap_recompiled_at(ciProfileData* data) {
duke@0 230 if (data == NULL) {
duke@0 231 return (_saw_free_extra_data? 0: -1); // (see previous method)
duke@0 232 } else {
duke@0 233 return Deoptimization::trap_state_is_recompiled(data->trap_state())? 1: 0;
duke@0 234 }
duke@0 235 }
duke@0 236
duke@0 237 void ciMethodData::clear_escape_info() {
duke@0 238 VM_ENTRY_MARK;
duke@0 239 methodDataOop mdo = get_methodDataOop();
kvn@45 240 if (mdo != NULL) {
duke@0 241 mdo->clear_escape_info();
kvn@45 242 ArgInfoData *aid = arg_info();
kvn@45 243 int arg_count = (aid == NULL) ? 0 : aid->number_of_args();
kvn@45 244 for (int i = 0; i < arg_count; i++) {
kvn@45 245 set_arg_modified(i, 0);
kvn@45 246 }
kvn@45 247 }
duke@0 248 _eflags = _arg_local = _arg_stack = _arg_returned = 0;
duke@0 249 }
duke@0 250
duke@0 251 // copy our escape info to the methodDataOop if it exists
duke@0 252 void ciMethodData::update_escape_info() {
duke@0 253 VM_ENTRY_MARK;
duke@0 254 methodDataOop mdo = get_methodDataOop();
duke@0 255 if ( mdo != NULL) {
duke@0 256 mdo->set_eflags(_eflags);
duke@0 257 mdo->set_arg_local(_arg_local);
duke@0 258 mdo->set_arg_stack(_arg_stack);
duke@0 259 mdo->set_arg_returned(_arg_returned);
kvn@45 260 int arg_count = mdo->method()->size_of_parameters();
kvn@45 261 for (int i = 0; i < arg_count; i++) {
kvn@45 262 mdo->set_arg_modified(i, arg_modified(i));
kvn@45 263 }
duke@0 264 }
duke@0 265 }
duke@0 266
iveresov@1703 267 void ciMethodData::set_compilation_stats(short loops, short blocks) {
iveresov@1703 268 VM_ENTRY_MARK;
iveresov@1703 269 methodDataOop mdo = get_methodDataOop();
iveresov@1703 270 if (mdo != NULL) {
iveresov@1703 271 mdo->set_num_loops(loops);
iveresov@1703 272 mdo->set_num_blocks(blocks);
iveresov@1703 273 }
iveresov@1703 274 }
iveresov@1703 275
iveresov@1703 276 void ciMethodData::set_would_profile(bool p) {
iveresov@1703 277 VM_ENTRY_MARK;
iveresov@1703 278 methodDataOop mdo = get_methodDataOop();
iveresov@1703 279 if (mdo != NULL) {
iveresov@1703 280 mdo->set_would_profile(p);
iveresov@1703 281 }
iveresov@1703 282 }
iveresov@1703 283
duke@0 284 bool ciMethodData::has_escape_info() {
duke@0 285 return eflag_set(methodDataOopDesc::estimated);
duke@0 286 }
duke@0 287
duke@0 288 void ciMethodData::set_eflag(methodDataOopDesc::EscapeFlag f) {
duke@0 289 set_bits(_eflags, f);
duke@0 290 }
duke@0 291
duke@0 292 void ciMethodData::clear_eflag(methodDataOopDesc::EscapeFlag f) {
duke@0 293 clear_bits(_eflags, f);
duke@0 294 }
duke@0 295
duke@0 296 bool ciMethodData::eflag_set(methodDataOopDesc::EscapeFlag f) const {
duke@0 297 return mask_bits(_eflags, f) != 0;
duke@0 298 }
duke@0 299
duke@0 300 void ciMethodData::set_arg_local(int i) {
duke@0 301 set_nth_bit(_arg_local, i);
duke@0 302 }
duke@0 303
duke@0 304 void ciMethodData::set_arg_stack(int i) {
duke@0 305 set_nth_bit(_arg_stack, i);
duke@0 306 }
duke@0 307
duke@0 308 void ciMethodData::set_arg_returned(int i) {
duke@0 309 set_nth_bit(_arg_returned, i);
duke@0 310 }
duke@0 311
kvn@45 312 void ciMethodData::set_arg_modified(int arg, uint val) {
kvn@45 313 ArgInfoData *aid = arg_info();
kvn@45 314 if (aid == NULL)
kvn@45 315 return;
kvn@45 316 assert(arg >= 0 && arg < aid->number_of_args(), "valid argument number");
kvn@45 317 aid->set_arg_modified(arg, val);
kvn@45 318 }
kvn@45 319
duke@0 320 bool ciMethodData::is_arg_local(int i) const {
duke@0 321 return is_set_nth_bit(_arg_local, i);
duke@0 322 }
duke@0 323
duke@0 324 bool ciMethodData::is_arg_stack(int i) const {
duke@0 325 return is_set_nth_bit(_arg_stack, i);
duke@0 326 }
duke@0 327
duke@0 328 bool ciMethodData::is_arg_returned(int i) const {
duke@0 329 return is_set_nth_bit(_arg_returned, i);
duke@0 330 }
duke@0 331
kvn@45 332 uint ciMethodData::arg_modified(int arg) const {
kvn@45 333 ArgInfoData *aid = arg_info();
kvn@45 334 if (aid == NULL)
kvn@45 335 return 0;
kvn@45 336 assert(arg >= 0 && arg < aid->number_of_args(), "valid argument number");
kvn@45 337 return aid->arg_modified(arg);
kvn@45 338 }
kvn@45 339
duke@0 340 ByteSize ciMethodData::offset_of_slot(ciProfileData* data, ByteSize slot_offset_in_data) {
duke@0 341 // Get offset within methodDataOop of the data array
duke@0 342 ByteSize data_offset = methodDataOopDesc::data_offset();
duke@0 343
duke@0 344 // Get cell offset of the ProfileData within data array
duke@0 345 int cell_offset = dp_to_di(data->dp());
duke@0 346
duke@0 347 // Add in counter_offset, the # of bytes into the ProfileData of counter or flag
duke@0 348 int offset = in_bytes(data_offset) + cell_offset + in_bytes(slot_offset_in_data);
duke@0 349
duke@0 350 return in_ByteSize(offset);
duke@0 351 }
duke@0 352
kvn@45 353 ciArgInfoData *ciMethodData::arg_info() const {
kvn@45 354 // Should be last, have to skip all traps.
kvn@45 355 DataLayout* dp = data_layout_at(data_size());
kvn@45 356 DataLayout* end = data_layout_at(data_size() + extra_data_size());
kvn@45 357 for (; dp < end; dp = methodDataOopDesc::next_extra(dp)) {
kvn@45 358 if (dp->tag() == DataLayout::arg_info_data_tag)
kvn@45 359 return new ciArgInfoData(dp);
kvn@45 360 }
kvn@45 361 return NULL;
kvn@45 362 }
kvn@45 363
kvn@45 364
duke@0 365 // Implementation of the print method.
duke@0 366 void ciMethodData::print_impl(outputStream* st) {
duke@0 367 ciObject::print_impl(st);
duke@0 368 }
duke@0 369
duke@0 370 #ifndef PRODUCT
duke@0 371 void ciMethodData::print() {
duke@0 372 print_data_on(tty);
duke@0 373 }
duke@0 374
duke@0 375 void ciMethodData::print_data_on(outputStream* st) {
duke@0 376 ResourceMark rm;
duke@0 377 ciProfileData* data;
duke@0 378 for (data = first_data(); is_valid(data); data = next_data(data)) {
duke@0 379 st->print("%d", dp_to_di(data->dp()));
duke@0 380 st->fill_to(6);
duke@0 381 data->print_data_on(st);
duke@0 382 }
kvn@45 383 st->print_cr("--- Extra data:");
kvn@45 384 DataLayout* dp = data_layout_at(data_size());
kvn@45 385 DataLayout* end = data_layout_at(data_size() + extra_data_size());
kvn@45 386 for (; dp < end; dp = methodDataOopDesc::next_extra(dp)) {
kvn@45 387 if (dp->tag() == DataLayout::no_tag) continue;
kvn@45 388 if (dp->tag() == DataLayout::bit_data_tag) {
kvn@45 389 data = new BitData(dp);
kvn@45 390 } else {
kvn@45 391 assert(dp->tag() == DataLayout::arg_info_data_tag, "must be BitData or ArgInfo");
kvn@45 392 data = new ciArgInfoData(dp);
kvn@45 393 dp = end; // ArgInfoData is at the end of extra data section.
kvn@45 394 }
kvn@45 395 st->print("%d", dp_to_di(data->dp()));
kvn@45 396 st->fill_to(6);
kvn@45 397 data->print_data_on(st);
kvn@45 398 }
duke@0 399 }
duke@0 400
duke@0 401 void ciReceiverTypeData::print_receiver_data_on(outputStream* st) {
duke@0 402 uint row;
duke@0 403 int entries = 0;
duke@0 404 for (row = 0; row < row_limit(); row++) {
duke@0 405 if (receiver(row) != NULL) entries++;
duke@0 406 }
duke@0 407 st->print_cr("count(%u) entries(%u)", count(), entries);
duke@0 408 for (row = 0; row < row_limit(); row++) {
duke@0 409 if (receiver(row) != NULL) {
duke@0 410 tab(st);
duke@0 411 receiver(row)->print_name_on(st);
duke@0 412 st->print_cr("(%u)", receiver_count(row));
duke@0 413 }
duke@0 414 }
duke@0 415 }
duke@0 416
duke@0 417 void ciReceiverTypeData::print_data_on(outputStream* st) {
duke@0 418 print_shared(st, "ciReceiverTypeData");
duke@0 419 print_receiver_data_on(st);
duke@0 420 }
duke@0 421
duke@0 422 void ciVirtualCallData::print_data_on(outputStream* st) {
duke@0 423 print_shared(st, "ciVirtualCallData");
duke@0 424 rtd_super()->print_receiver_data_on(st);
duke@0 425 }
duke@0 426 #endif