annotate src/share/vm/ci/ciMethodData.cpp @ 3602:da91efe96a93

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