src/share/vm/oops/methodData.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7365
600c44255e5f
parent 6876
710a3c8b516e
child 9203
53eec13fbaa5
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2000, 2014, 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 "classfile/systemDictionary.hpp"
aoqi@0 27 #include "compiler/compilerOracle.hpp"
aoqi@0 28 #include "interpreter/bytecode.hpp"
aoqi@0 29 #include "interpreter/bytecodeStream.hpp"
aoqi@0 30 #include "interpreter/linkResolver.hpp"
aoqi@0 31 #include "memory/heapInspection.hpp"
aoqi@0 32 #include "oops/methodData.hpp"
aoqi@0 33 #include "prims/jvmtiRedefineClasses.hpp"
aoqi@0 34 #include "runtime/compilationPolicy.hpp"
aoqi@0 35 #include "runtime/deoptimization.hpp"
aoqi@0 36 #include "runtime/handles.inline.hpp"
goetz@6911 37 #include "runtime/orderAccess.inline.hpp"
aoqi@0 38
aoqi@0 39 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 40
aoqi@0 41 // ==================================================================
aoqi@0 42 // DataLayout
aoqi@0 43 //
aoqi@0 44 // Overlay for generic profiling data.
aoqi@0 45
aoqi@0 46 // Some types of data layouts need a length field.
aoqi@0 47 bool DataLayout::needs_array_len(u1 tag) {
aoqi@0 48 return (tag == multi_branch_data_tag) || (tag == arg_info_data_tag) || (tag == parameters_type_data_tag);
aoqi@0 49 }
aoqi@0 50
aoqi@0 51 // Perform generic initialization of the data. More specific
aoqi@0 52 // initialization occurs in overrides of ProfileData::post_initialize.
aoqi@0 53 void DataLayout::initialize(u1 tag, u2 bci, int cell_count) {
aoqi@0 54 _header._bits = (intptr_t)0;
aoqi@0 55 _header._struct._tag = tag;
aoqi@0 56 _header._struct._bci = bci;
aoqi@0 57 for (int i = 0; i < cell_count; i++) {
aoqi@0 58 set_cell_at(i, (intptr_t)0);
aoqi@0 59 }
aoqi@0 60 if (needs_array_len(tag)) {
aoqi@0 61 set_cell_at(ArrayData::array_len_off_set, cell_count - 1); // -1 for header.
aoqi@0 62 }
aoqi@0 63 if (tag == call_type_data_tag) {
aoqi@0 64 CallTypeData::initialize(this, cell_count);
aoqi@0 65 } else if (tag == virtual_call_type_data_tag) {
aoqi@0 66 VirtualCallTypeData::initialize(this, cell_count);
aoqi@0 67 }
aoqi@0 68 }
aoqi@0 69
aoqi@0 70 void DataLayout::clean_weak_klass_links(BoolObjectClosure* cl) {
aoqi@0 71 ResourceMark m;
aoqi@0 72 data_in()->clean_weak_klass_links(cl);
aoqi@0 73 }
aoqi@0 74
aoqi@0 75
aoqi@0 76 // ==================================================================
aoqi@0 77 // ProfileData
aoqi@0 78 //
aoqi@0 79 // A ProfileData object is created to refer to a section of profiling
aoqi@0 80 // data in a structured way.
aoqi@0 81
aoqi@0 82 // Constructor for invalid ProfileData.
aoqi@0 83 ProfileData::ProfileData() {
aoqi@0 84 _data = NULL;
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 char* ProfileData::print_data_on_helper(const MethodData* md) const {
aoqi@0 88 DataLayout* dp = md->extra_data_base();
aoqi@0 89 DataLayout* end = md->extra_data_limit();
aoqi@0 90 stringStream ss;
aoqi@0 91 for (;; dp = MethodData::next_extra(dp)) {
aoqi@0 92 assert(dp < end, "moved past end of extra data");
aoqi@0 93 switch(dp->tag()) {
aoqi@0 94 case DataLayout::speculative_trap_data_tag:
aoqi@0 95 if (dp->bci() == bci()) {
aoqi@0 96 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
aoqi@0 97 int trap = data->trap_state();
aoqi@0 98 char buf[100];
aoqi@0 99 ss.print("trap/");
aoqi@0 100 data->method()->print_short_name(&ss);
aoqi@0 101 ss.print("(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
aoqi@0 102 }
aoqi@0 103 break;
aoqi@0 104 case DataLayout::bit_data_tag:
aoqi@0 105 break;
aoqi@0 106 case DataLayout::no_tag:
aoqi@0 107 case DataLayout::arg_info_data_tag:
aoqi@0 108 return ss.as_string();
aoqi@0 109 break;
aoqi@0 110 default:
aoqi@0 111 fatal(err_msg("unexpected tag %d", dp->tag()));
aoqi@0 112 }
aoqi@0 113 }
aoqi@0 114 return NULL;
aoqi@0 115 }
aoqi@0 116
aoqi@0 117 void ProfileData::print_data_on(outputStream* st, const MethodData* md) const {
aoqi@0 118 print_data_on(st, print_data_on_helper(md));
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 #ifndef PRODUCT
aoqi@0 122 void ProfileData::print_shared(outputStream* st, const char* name, const char* extra) const {
aoqi@0 123 st->print("bci: %d", bci());
aoqi@0 124 st->fill_to(tab_width_one);
aoqi@0 125 st->print("%s", name);
aoqi@0 126 tab(st);
aoqi@0 127 int trap = trap_state();
aoqi@0 128 if (trap != 0) {
aoqi@0 129 char buf[100];
aoqi@0 130 st->print("trap(%s) ", Deoptimization::format_trap_state(buf, sizeof(buf), trap));
aoqi@0 131 }
aoqi@0 132 if (extra != NULL) {
aoqi@0 133 st->print("%s", extra);
aoqi@0 134 }
aoqi@0 135 int flags = data()->flags();
aoqi@0 136 if (flags != 0) {
aoqi@0 137 st->print("flags(%d) ", flags);
aoqi@0 138 }
aoqi@0 139 }
aoqi@0 140
aoqi@0 141 void ProfileData::tab(outputStream* st, bool first) const {
aoqi@0 142 st->fill_to(first ? tab_width_one : tab_width_two);
aoqi@0 143 }
aoqi@0 144 #endif // !PRODUCT
aoqi@0 145
aoqi@0 146 // ==================================================================
aoqi@0 147 // BitData
aoqi@0 148 //
aoqi@0 149 // A BitData corresponds to a one-bit flag. This is used to indicate
aoqi@0 150 // whether a checkcast bytecode has seen a null value.
aoqi@0 151
aoqi@0 152
aoqi@0 153 #ifndef PRODUCT
aoqi@0 154 void BitData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 155 print_shared(st, "BitData", extra);
aoqi@0 156 }
aoqi@0 157 #endif // !PRODUCT
aoqi@0 158
aoqi@0 159 // ==================================================================
aoqi@0 160 // CounterData
aoqi@0 161 //
aoqi@0 162 // A CounterData corresponds to a simple counter.
aoqi@0 163
aoqi@0 164 #ifndef PRODUCT
aoqi@0 165 void CounterData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 166 print_shared(st, "CounterData", extra);
aoqi@0 167 st->print_cr("count(%u)", count());
aoqi@0 168 }
aoqi@0 169 #endif // !PRODUCT
aoqi@0 170
aoqi@0 171 // ==================================================================
aoqi@0 172 // JumpData
aoqi@0 173 //
aoqi@0 174 // A JumpData is used to access profiling information for a direct
aoqi@0 175 // branch. It is a counter, used for counting the number of branches,
aoqi@0 176 // plus a data displacement, used for realigning the data pointer to
aoqi@0 177 // the corresponding target bci.
aoqi@0 178
aoqi@0 179 void JumpData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
aoqi@0 180 assert(stream->bci() == bci(), "wrong pos");
aoqi@0 181 int target;
aoqi@0 182 Bytecodes::Code c = stream->code();
aoqi@0 183 if (c == Bytecodes::_goto_w || c == Bytecodes::_jsr_w) {
aoqi@0 184 target = stream->dest_w();
aoqi@0 185 } else {
aoqi@0 186 target = stream->dest();
aoqi@0 187 }
aoqi@0 188 int my_di = mdo->dp_to_di(dp());
aoqi@0 189 int target_di = mdo->bci_to_di(target);
aoqi@0 190 int offset = target_di - my_di;
aoqi@0 191 set_displacement(offset);
aoqi@0 192 }
aoqi@0 193
aoqi@0 194 #ifndef PRODUCT
aoqi@0 195 void JumpData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 196 print_shared(st, "JumpData", extra);
aoqi@0 197 st->print_cr("taken(%u) displacement(%d)", taken(), displacement());
aoqi@0 198 }
aoqi@0 199 #endif // !PRODUCT
aoqi@0 200
aoqi@0 201 int TypeStackSlotEntries::compute_cell_count(Symbol* signature, bool include_receiver, int max) {
aoqi@0 202 // Parameter profiling include the receiver
aoqi@0 203 int args_count = include_receiver ? 1 : 0;
aoqi@0 204 ResourceMark rm;
aoqi@0 205 SignatureStream ss(signature);
aoqi@0 206 args_count += ss.reference_parameter_count();
aoqi@0 207 args_count = MIN2(args_count, max);
aoqi@0 208 return args_count * per_arg_cell_count;
aoqi@0 209 }
aoqi@0 210
aoqi@0 211 int TypeEntriesAtCall::compute_cell_count(BytecodeStream* stream) {
aoqi@0 212 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
aoqi@0 213 assert(TypeStackSlotEntries::per_arg_count() > ReturnTypeEntry::static_cell_count(), "code to test for arguments/results broken");
aoqi@0 214 Bytecode_invoke inv(stream->method(), stream->bci());
aoqi@0 215 int args_cell = 0;
aoqi@0 216 if (arguments_profiling_enabled()) {
aoqi@0 217 args_cell = TypeStackSlotEntries::compute_cell_count(inv.signature(), false, TypeProfileArgsLimit);
aoqi@0 218 }
aoqi@0 219 int ret_cell = 0;
aoqi@0 220 if (return_profiling_enabled() && (inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY)) {
aoqi@0 221 ret_cell = ReturnTypeEntry::static_cell_count();
aoqi@0 222 }
aoqi@0 223 int header_cell = 0;
aoqi@0 224 if (args_cell + ret_cell > 0) {
aoqi@0 225 header_cell = header_cell_count();
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 return header_cell + args_cell + ret_cell;
aoqi@0 229 }
aoqi@0 230
aoqi@0 231 class ArgumentOffsetComputer : public SignatureInfo {
aoqi@0 232 private:
aoqi@0 233 int _max;
aoqi@0 234 GrowableArray<int> _offsets;
aoqi@0 235
aoqi@0 236 void set(int size, BasicType type) { _size += size; }
aoqi@0 237 void do_object(int begin, int end) {
aoqi@0 238 if (_offsets.length() < _max) {
aoqi@0 239 _offsets.push(_size);
aoqi@0 240 }
aoqi@0 241 SignatureInfo::do_object(begin, end);
aoqi@0 242 }
aoqi@0 243 void do_array (int begin, int end) {
aoqi@0 244 if (_offsets.length() < _max) {
aoqi@0 245 _offsets.push(_size);
aoqi@0 246 }
aoqi@0 247 SignatureInfo::do_array(begin, end);
aoqi@0 248 }
aoqi@0 249
aoqi@0 250 public:
aoqi@0 251 ArgumentOffsetComputer(Symbol* signature, int max)
aoqi@0 252 : SignatureInfo(signature), _max(max), _offsets(Thread::current(), max) {
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 int total() { lazy_iterate_parameters(); return _size; }
aoqi@0 256
aoqi@0 257 int off_at(int i) const { return _offsets.at(i); }
aoqi@0 258 };
aoqi@0 259
aoqi@0 260 void TypeStackSlotEntries::post_initialize(Symbol* signature, bool has_receiver, bool include_receiver) {
aoqi@0 261 ResourceMark rm;
aoqi@0 262 int start = 0;
aoqi@0 263 // Parameter profiling include the receiver
aoqi@0 264 if (include_receiver && has_receiver) {
aoqi@0 265 set_stack_slot(0, 0);
aoqi@0 266 set_type(0, type_none());
aoqi@0 267 start += 1;
aoqi@0 268 }
aoqi@0 269 ArgumentOffsetComputer aos(signature, _number_of_entries-start);
aoqi@0 270 aos.total();
aoqi@0 271 for (int i = start; i < _number_of_entries; i++) {
aoqi@0 272 set_stack_slot(i, aos.off_at(i-start) + (has_receiver ? 1 : 0));
aoqi@0 273 set_type(i, type_none());
aoqi@0 274 }
aoqi@0 275 }
aoqi@0 276
aoqi@0 277 void CallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
aoqi@0 278 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
aoqi@0 279 Bytecode_invoke inv(stream->method(), stream->bci());
aoqi@0 280
aoqi@0 281 SignatureStream ss(inv.signature());
aoqi@0 282 if (has_arguments()) {
aoqi@0 283 #ifdef ASSERT
aoqi@0 284 ResourceMark rm;
aoqi@0 285 int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
aoqi@0 286 assert(count > 0, "room for args type but none found?");
aoqi@0 287 check_number_of_arguments(count);
aoqi@0 288 #endif
aoqi@0 289 _args.post_initialize(inv.signature(), inv.has_receiver(), false);
aoqi@0 290 }
aoqi@0 291
aoqi@0 292 if (has_return()) {
aoqi@0 293 assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
aoqi@0 294 _ret.post_initialize();
aoqi@0 295 }
aoqi@0 296 }
aoqi@0 297
aoqi@0 298 void VirtualCallTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
aoqi@0 299 assert(Bytecodes::is_invoke(stream->code()), "should be invoke");
aoqi@0 300 Bytecode_invoke inv(stream->method(), stream->bci());
aoqi@0 301
aoqi@0 302 if (has_arguments()) {
aoqi@0 303 #ifdef ASSERT
aoqi@0 304 ResourceMark rm;
aoqi@0 305 SignatureStream ss(inv.signature());
aoqi@0 306 int count = MIN2(ss.reference_parameter_count(), (int)TypeProfileArgsLimit);
aoqi@0 307 assert(count > 0, "room for args type but none found?");
aoqi@0 308 check_number_of_arguments(count);
aoqi@0 309 #endif
aoqi@0 310 _args.post_initialize(inv.signature(), inv.has_receiver(), false);
aoqi@0 311 }
aoqi@0 312
aoqi@0 313 if (has_return()) {
aoqi@0 314 assert(inv.result_type() == T_OBJECT || inv.result_type() == T_ARRAY, "room for a ret type but doesn't return obj?");
aoqi@0 315 _ret.post_initialize();
aoqi@0 316 }
aoqi@0 317 }
aoqi@0 318
aoqi@0 319 bool TypeEntries::is_loader_alive(BoolObjectClosure* is_alive_cl, intptr_t p) {
aoqi@0 320 Klass* k = (Klass*)klass_part(p);
aoqi@0 321 return k != NULL && k->is_loader_alive(is_alive_cl);
aoqi@0 322 }
aoqi@0 323
aoqi@0 324 void TypeStackSlotEntries::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
aoqi@0 325 for (int i = 0; i < _number_of_entries; i++) {
aoqi@0 326 intptr_t p = type(i);
aoqi@0 327 if (!is_loader_alive(is_alive_cl, p)) {
aoqi@0 328 set_type(i, with_status((Klass*)NULL, p));
aoqi@0 329 }
aoqi@0 330 }
aoqi@0 331 }
aoqi@0 332
aoqi@0 333 void ReturnTypeEntry::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
aoqi@0 334 intptr_t p = type();
aoqi@0 335 if (!is_loader_alive(is_alive_cl, p)) {
aoqi@0 336 set_type(with_status((Klass*)NULL, p));
aoqi@0 337 }
aoqi@0 338 }
aoqi@0 339
aoqi@0 340 bool TypeEntriesAtCall::return_profiling_enabled() {
aoqi@0 341 return MethodData::profile_return();
aoqi@0 342 }
aoqi@0 343
aoqi@0 344 bool TypeEntriesAtCall::arguments_profiling_enabled() {
aoqi@0 345 return MethodData::profile_arguments();
aoqi@0 346 }
aoqi@0 347
aoqi@0 348 #ifndef PRODUCT
aoqi@0 349 void TypeEntries::print_klass(outputStream* st, intptr_t k) {
aoqi@0 350 if (is_type_none(k)) {
aoqi@0 351 st->print("none");
aoqi@0 352 } else if (is_type_unknown(k)) {
aoqi@0 353 st->print("unknown");
aoqi@0 354 } else {
aoqi@0 355 valid_klass(k)->print_value_on(st);
aoqi@0 356 }
aoqi@0 357 if (was_null_seen(k)) {
aoqi@0 358 st->print(" (null seen)");
aoqi@0 359 }
aoqi@0 360 }
aoqi@0 361
aoqi@0 362 void TypeStackSlotEntries::print_data_on(outputStream* st) const {
aoqi@0 363 for (int i = 0; i < _number_of_entries; i++) {
aoqi@0 364 _pd->tab(st);
aoqi@0 365 st->print("%d: stack(%u) ", i, stack_slot(i));
aoqi@0 366 print_klass(st, type(i));
aoqi@0 367 st->cr();
aoqi@0 368 }
aoqi@0 369 }
aoqi@0 370
aoqi@0 371 void ReturnTypeEntry::print_data_on(outputStream* st) const {
aoqi@0 372 _pd->tab(st);
aoqi@0 373 print_klass(st, type());
aoqi@0 374 st->cr();
aoqi@0 375 }
aoqi@0 376
aoqi@0 377 void CallTypeData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 378 CounterData::print_data_on(st, extra);
aoqi@0 379 if (has_arguments()) {
aoqi@0 380 tab(st, true);
aoqi@0 381 st->print("argument types");
aoqi@0 382 _args.print_data_on(st);
aoqi@0 383 }
aoqi@0 384 if (has_return()) {
aoqi@0 385 tab(st, true);
aoqi@0 386 st->print("return type");
aoqi@0 387 _ret.print_data_on(st);
aoqi@0 388 }
aoqi@0 389 }
aoqi@0 390
aoqi@0 391 void VirtualCallTypeData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 392 VirtualCallData::print_data_on(st, extra);
aoqi@0 393 if (has_arguments()) {
aoqi@0 394 tab(st, true);
aoqi@0 395 st->print("argument types");
aoqi@0 396 _args.print_data_on(st);
aoqi@0 397 }
aoqi@0 398 if (has_return()) {
aoqi@0 399 tab(st, true);
aoqi@0 400 st->print("return type");
aoqi@0 401 _ret.print_data_on(st);
aoqi@0 402 }
aoqi@0 403 }
aoqi@0 404 #endif
aoqi@0 405
aoqi@0 406 // ==================================================================
aoqi@0 407 // ReceiverTypeData
aoqi@0 408 //
aoqi@0 409 // A ReceiverTypeData is used to access profiling information about a
aoqi@0 410 // dynamic type check. It consists of a counter which counts the total times
aoqi@0 411 // that the check is reached, and a series of (Klass*, count) pairs
aoqi@0 412 // which are used to store a type profile for the receiver of the check.
aoqi@0 413
aoqi@0 414 void ReceiverTypeData::clean_weak_klass_links(BoolObjectClosure* is_alive_cl) {
aoqi@0 415 for (uint row = 0; row < row_limit(); row++) {
aoqi@0 416 Klass* p = receiver(row);
aoqi@0 417 if (p != NULL && !p->is_loader_alive(is_alive_cl)) {
aoqi@0 418 clear_row(row);
aoqi@0 419 }
aoqi@0 420 }
aoqi@0 421 }
aoqi@0 422
aoqi@0 423 #ifndef PRODUCT
aoqi@0 424 void ReceiverTypeData::print_receiver_data_on(outputStream* st) const {
aoqi@0 425 uint row;
aoqi@0 426 int entries = 0;
aoqi@0 427 for (row = 0; row < row_limit(); row++) {
aoqi@0 428 if (receiver(row) != NULL) entries++;
aoqi@0 429 }
aoqi@0 430 st->print_cr("count(%u) entries(%u)", count(), entries);
aoqi@0 431 int total = count();
aoqi@0 432 for (row = 0; row < row_limit(); row++) {
aoqi@0 433 if (receiver(row) != NULL) {
aoqi@0 434 total += receiver_count(row);
aoqi@0 435 }
aoqi@0 436 }
aoqi@0 437 for (row = 0; row < row_limit(); row++) {
aoqi@0 438 if (receiver(row) != NULL) {
aoqi@0 439 tab(st);
aoqi@0 440 receiver(row)->print_value_on(st);
aoqi@0 441 st->print_cr("(%u %4.2f)", receiver_count(row), (float) receiver_count(row) / (float) total);
aoqi@0 442 }
aoqi@0 443 }
aoqi@0 444 }
aoqi@0 445 void ReceiverTypeData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 446 print_shared(st, "ReceiverTypeData", extra);
aoqi@0 447 print_receiver_data_on(st);
aoqi@0 448 }
aoqi@0 449 void VirtualCallData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 450 print_shared(st, "VirtualCallData", extra);
aoqi@0 451 print_receiver_data_on(st);
aoqi@0 452 }
aoqi@0 453 #endif // !PRODUCT
aoqi@0 454
aoqi@0 455 // ==================================================================
aoqi@0 456 // RetData
aoqi@0 457 //
aoqi@0 458 // A RetData is used to access profiling information for a ret bytecode.
aoqi@0 459 // It is composed of a count of the number of times that the ret has
aoqi@0 460 // been executed, followed by a series of triples of the form
aoqi@0 461 // (bci, count, di) which count the number of times that some bci was the
aoqi@0 462 // target of the ret and cache a corresponding displacement.
aoqi@0 463
aoqi@0 464 void RetData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
aoqi@0 465 for (uint row = 0; row < row_limit(); row++) {
aoqi@0 466 set_bci_displacement(row, -1);
aoqi@0 467 set_bci(row, no_bci);
aoqi@0 468 }
aoqi@0 469 // release so other threads see a consistent state. bci is used as
aoqi@0 470 // a valid flag for bci_displacement.
aoqi@0 471 OrderAccess::release();
aoqi@0 472 }
aoqi@0 473
aoqi@0 474 // This routine needs to atomically update the RetData structure, so the
aoqi@0 475 // caller needs to hold the RetData_lock before it gets here. Since taking
aoqi@0 476 // the lock can block (and allow GC) and since RetData is a ProfileData is a
aoqi@0 477 // wrapper around a derived oop, taking the lock in _this_ method will
aoqi@0 478 // basically cause the 'this' pointer's _data field to contain junk after the
aoqi@0 479 // lock. We require the caller to take the lock before making the ProfileData
aoqi@0 480 // structure. Currently the only caller is InterpreterRuntime::update_mdp_for_ret
aoqi@0 481 address RetData::fixup_ret(int return_bci, MethodData* h_mdo) {
aoqi@0 482 // First find the mdp which corresponds to the return bci.
aoqi@0 483 address mdp = h_mdo->bci_to_dp(return_bci);
aoqi@0 484
aoqi@0 485 // Now check to see if any of the cache slots are open.
aoqi@0 486 for (uint row = 0; row < row_limit(); row++) {
aoqi@0 487 if (bci(row) == no_bci) {
aoqi@0 488 set_bci_displacement(row, mdp - dp());
aoqi@0 489 set_bci_count(row, DataLayout::counter_increment);
aoqi@0 490 // Barrier to ensure displacement is written before the bci; allows
aoqi@0 491 // the interpreter to read displacement without fear of race condition.
aoqi@0 492 release_set_bci(row, return_bci);
aoqi@0 493 break;
aoqi@0 494 }
aoqi@0 495 }
aoqi@0 496 return mdp;
aoqi@0 497 }
aoqi@0 498
aoqi@0 499 #ifdef CC_INTERP
aoqi@0 500 DataLayout* RetData::advance(MethodData *md, int bci) {
aoqi@0 501 return (DataLayout*) md->bci_to_dp(bci);
aoqi@0 502 }
aoqi@0 503 #endif // CC_INTERP
aoqi@0 504
aoqi@0 505 #ifndef PRODUCT
aoqi@0 506 void RetData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 507 print_shared(st, "RetData", extra);
aoqi@0 508 uint row;
aoqi@0 509 int entries = 0;
aoqi@0 510 for (row = 0; row < row_limit(); row++) {
aoqi@0 511 if (bci(row) != no_bci) entries++;
aoqi@0 512 }
aoqi@0 513 st->print_cr("count(%u) entries(%u)", count(), entries);
aoqi@0 514 for (row = 0; row < row_limit(); row++) {
aoqi@0 515 if (bci(row) != no_bci) {
aoqi@0 516 tab(st);
aoqi@0 517 st->print_cr("bci(%d: count(%u) displacement(%d))",
aoqi@0 518 bci(row), bci_count(row), bci_displacement(row));
aoqi@0 519 }
aoqi@0 520 }
aoqi@0 521 }
aoqi@0 522 #endif // !PRODUCT
aoqi@0 523
aoqi@0 524 // ==================================================================
aoqi@0 525 // BranchData
aoqi@0 526 //
aoqi@0 527 // A BranchData is used to access profiling data for a two-way branch.
aoqi@0 528 // It consists of taken and not_taken counts as well as a data displacement
aoqi@0 529 // for the taken case.
aoqi@0 530
aoqi@0 531 void BranchData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
aoqi@0 532 assert(stream->bci() == bci(), "wrong pos");
aoqi@0 533 int target = stream->dest();
aoqi@0 534 int my_di = mdo->dp_to_di(dp());
aoqi@0 535 int target_di = mdo->bci_to_di(target);
aoqi@0 536 int offset = target_di - my_di;
aoqi@0 537 set_displacement(offset);
aoqi@0 538 }
aoqi@0 539
aoqi@0 540 #ifndef PRODUCT
aoqi@0 541 void BranchData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 542 print_shared(st, "BranchData", extra);
aoqi@0 543 st->print_cr("taken(%u) displacement(%d)",
aoqi@0 544 taken(), displacement());
aoqi@0 545 tab(st);
aoqi@0 546 st->print_cr("not taken(%u)", not_taken());
aoqi@0 547 }
aoqi@0 548 #endif
aoqi@0 549
aoqi@0 550 // ==================================================================
aoqi@0 551 // MultiBranchData
aoqi@0 552 //
aoqi@0 553 // A MultiBranchData is used to access profiling information for
aoqi@0 554 // a multi-way branch (*switch bytecodes). It consists of a series
aoqi@0 555 // of (count, displacement) pairs, which count the number of times each
aoqi@0 556 // case was taken and specify the data displacment for each branch target.
aoqi@0 557
aoqi@0 558 int MultiBranchData::compute_cell_count(BytecodeStream* stream) {
aoqi@0 559 int cell_count = 0;
aoqi@0 560 if (stream->code() == Bytecodes::_tableswitch) {
aoqi@0 561 Bytecode_tableswitch sw(stream->method()(), stream->bcp());
aoqi@0 562 cell_count = 1 + per_case_cell_count * (1 + sw.length()); // 1 for default
aoqi@0 563 } else {
aoqi@0 564 Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
aoqi@0 565 cell_count = 1 + per_case_cell_count * (sw.number_of_pairs() + 1); // 1 for default
aoqi@0 566 }
aoqi@0 567 return cell_count;
aoqi@0 568 }
aoqi@0 569
aoqi@0 570 void MultiBranchData::post_initialize(BytecodeStream* stream,
aoqi@0 571 MethodData* mdo) {
aoqi@0 572 assert(stream->bci() == bci(), "wrong pos");
aoqi@0 573 int target;
aoqi@0 574 int my_di;
aoqi@0 575 int target_di;
aoqi@0 576 int offset;
aoqi@0 577 if (stream->code() == Bytecodes::_tableswitch) {
aoqi@0 578 Bytecode_tableswitch sw(stream->method()(), stream->bcp());
aoqi@0 579 int len = sw.length();
aoqi@0 580 assert(array_len() == per_case_cell_count * (len + 1), "wrong len");
aoqi@0 581 for (int count = 0; count < len; count++) {
aoqi@0 582 target = sw.dest_offset_at(count) + bci();
aoqi@0 583 my_di = mdo->dp_to_di(dp());
aoqi@0 584 target_di = mdo->bci_to_di(target);
aoqi@0 585 offset = target_di - my_di;
aoqi@0 586 set_displacement_at(count, offset);
aoqi@0 587 }
aoqi@0 588 target = sw.default_offset() + bci();
aoqi@0 589 my_di = mdo->dp_to_di(dp());
aoqi@0 590 target_di = mdo->bci_to_di(target);
aoqi@0 591 offset = target_di - my_di;
aoqi@0 592 set_default_displacement(offset);
aoqi@0 593
aoqi@0 594 } else {
aoqi@0 595 Bytecode_lookupswitch sw(stream->method()(), stream->bcp());
aoqi@0 596 int npairs = sw.number_of_pairs();
aoqi@0 597 assert(array_len() == per_case_cell_count * (npairs + 1), "wrong len");
aoqi@0 598 for (int count = 0; count < npairs; count++) {
aoqi@0 599 LookupswitchPair pair = sw.pair_at(count);
aoqi@0 600 target = pair.offset() + bci();
aoqi@0 601 my_di = mdo->dp_to_di(dp());
aoqi@0 602 target_di = mdo->bci_to_di(target);
aoqi@0 603 offset = target_di - my_di;
aoqi@0 604 set_displacement_at(count, offset);
aoqi@0 605 }
aoqi@0 606 target = sw.default_offset() + bci();
aoqi@0 607 my_di = mdo->dp_to_di(dp());
aoqi@0 608 target_di = mdo->bci_to_di(target);
aoqi@0 609 offset = target_di - my_di;
aoqi@0 610 set_default_displacement(offset);
aoqi@0 611 }
aoqi@0 612 }
aoqi@0 613
aoqi@0 614 #ifndef PRODUCT
aoqi@0 615 void MultiBranchData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 616 print_shared(st, "MultiBranchData", extra);
aoqi@0 617 st->print_cr("default_count(%u) displacement(%d)",
aoqi@0 618 default_count(), default_displacement());
aoqi@0 619 int cases = number_of_cases();
aoqi@0 620 for (int i = 0; i < cases; i++) {
aoqi@0 621 tab(st);
aoqi@0 622 st->print_cr("count(%u) displacement(%d)",
aoqi@0 623 count_at(i), displacement_at(i));
aoqi@0 624 }
aoqi@0 625 }
aoqi@0 626 #endif
aoqi@0 627
aoqi@0 628 #ifndef PRODUCT
aoqi@0 629 void ArgInfoData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 630 print_shared(st, "ArgInfoData", extra);
aoqi@0 631 int nargs = number_of_args();
aoqi@0 632 for (int i = 0; i < nargs; i++) {
aoqi@0 633 st->print(" 0x%x", arg_modified(i));
aoqi@0 634 }
aoqi@0 635 st->cr();
aoqi@0 636 }
aoqi@0 637
aoqi@0 638 #endif
aoqi@0 639
aoqi@0 640 int ParametersTypeData::compute_cell_count(Method* m) {
aoqi@0 641 if (!MethodData::profile_parameters_for_method(m)) {
aoqi@0 642 return 0;
aoqi@0 643 }
aoqi@0 644 int max = TypeProfileParmsLimit == -1 ? INT_MAX : TypeProfileParmsLimit;
aoqi@0 645 int obj_args = TypeStackSlotEntries::compute_cell_count(m->signature(), !m->is_static(), max);
aoqi@0 646 if (obj_args > 0) {
aoqi@0 647 return obj_args + 1; // 1 cell for array len
aoqi@0 648 }
aoqi@0 649 return 0;
aoqi@0 650 }
aoqi@0 651
aoqi@0 652 void ParametersTypeData::post_initialize(BytecodeStream* stream, MethodData* mdo) {
aoqi@0 653 _parameters.post_initialize(mdo->method()->signature(), !mdo->method()->is_static(), true);
aoqi@0 654 }
aoqi@0 655
aoqi@0 656 bool ParametersTypeData::profiling_enabled() {
aoqi@0 657 return MethodData::profile_parameters();
aoqi@0 658 }
aoqi@0 659
aoqi@0 660 #ifndef PRODUCT
aoqi@0 661 void ParametersTypeData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 662 st->print("parameter types"); // FIXME extra ignored?
aoqi@0 663 _parameters.print_data_on(st);
aoqi@0 664 }
aoqi@0 665
aoqi@0 666 void SpeculativeTrapData::print_data_on(outputStream* st, const char* extra) const {
aoqi@0 667 print_shared(st, "SpeculativeTrapData", extra);
aoqi@0 668 tab(st);
aoqi@0 669 method()->print_short_name(st);
aoqi@0 670 st->cr();
aoqi@0 671 }
aoqi@0 672 #endif
aoqi@0 673
aoqi@0 674 // ==================================================================
aoqi@0 675 // MethodData*
aoqi@0 676 //
aoqi@0 677 // A MethodData* holds information which has been collected about
aoqi@0 678 // a method.
aoqi@0 679
aoqi@0 680 MethodData* MethodData::allocate(ClassLoaderData* loader_data, methodHandle method, TRAPS) {
aoqi@0 681 int size = MethodData::compute_allocation_size_in_words(method);
aoqi@0 682
aoqi@0 683 return new (loader_data, size, false, MetaspaceObj::MethodDataType, THREAD)
aoqi@0 684 MethodData(method(), size, CHECK_NULL);
aoqi@0 685 }
aoqi@0 686
aoqi@0 687 int MethodData::bytecode_cell_count(Bytecodes::Code code) {
aoqi@0 688 #if defined(COMPILER1) && !defined(COMPILER2)
aoqi@0 689 return no_profile_data;
aoqi@0 690 #else
aoqi@0 691 switch (code) {
aoqi@0 692 case Bytecodes::_checkcast:
aoqi@0 693 case Bytecodes::_instanceof:
aoqi@0 694 case Bytecodes::_aastore:
aoqi@0 695 if (TypeProfileCasts) {
aoqi@0 696 return ReceiverTypeData::static_cell_count();
aoqi@0 697 } else {
aoqi@0 698 return BitData::static_cell_count();
aoqi@0 699 }
aoqi@0 700 case Bytecodes::_invokespecial:
aoqi@0 701 case Bytecodes::_invokestatic:
aoqi@0 702 if (MethodData::profile_arguments() || MethodData::profile_return()) {
aoqi@0 703 return variable_cell_count;
aoqi@0 704 } else {
aoqi@0 705 return CounterData::static_cell_count();
aoqi@0 706 }
aoqi@0 707 case Bytecodes::_goto:
aoqi@0 708 case Bytecodes::_goto_w:
aoqi@0 709 case Bytecodes::_jsr:
aoqi@0 710 case Bytecodes::_jsr_w:
aoqi@0 711 return JumpData::static_cell_count();
aoqi@0 712 case Bytecodes::_invokevirtual:
aoqi@0 713 case Bytecodes::_invokeinterface:
aoqi@0 714 if (MethodData::profile_arguments() || MethodData::profile_return()) {
aoqi@0 715 return variable_cell_count;
aoqi@0 716 } else {
aoqi@0 717 return VirtualCallData::static_cell_count();
aoqi@0 718 }
aoqi@0 719 case Bytecodes::_invokedynamic:
aoqi@0 720 if (MethodData::profile_arguments() || MethodData::profile_return()) {
aoqi@0 721 return variable_cell_count;
aoqi@0 722 } else {
aoqi@0 723 return CounterData::static_cell_count();
aoqi@0 724 }
aoqi@0 725 case Bytecodes::_ret:
aoqi@0 726 return RetData::static_cell_count();
aoqi@0 727 case Bytecodes::_ifeq:
aoqi@0 728 case Bytecodes::_ifne:
aoqi@0 729 case Bytecodes::_iflt:
aoqi@0 730 case Bytecodes::_ifge:
aoqi@0 731 case Bytecodes::_ifgt:
aoqi@0 732 case Bytecodes::_ifle:
aoqi@0 733 case Bytecodes::_if_icmpeq:
aoqi@0 734 case Bytecodes::_if_icmpne:
aoqi@0 735 case Bytecodes::_if_icmplt:
aoqi@0 736 case Bytecodes::_if_icmpge:
aoqi@0 737 case Bytecodes::_if_icmpgt:
aoqi@0 738 case Bytecodes::_if_icmple:
aoqi@0 739 case Bytecodes::_if_acmpeq:
aoqi@0 740 case Bytecodes::_if_acmpne:
aoqi@0 741 case Bytecodes::_ifnull:
aoqi@0 742 case Bytecodes::_ifnonnull:
aoqi@0 743 return BranchData::static_cell_count();
aoqi@0 744 case Bytecodes::_lookupswitch:
aoqi@0 745 case Bytecodes::_tableswitch:
aoqi@0 746 return variable_cell_count;
aoqi@0 747 }
aoqi@0 748 return no_profile_data;
aoqi@0 749 #endif
aoqi@0 750 }
aoqi@0 751
aoqi@0 752 // Compute the size of the profiling information corresponding to
aoqi@0 753 // the current bytecode.
aoqi@0 754 int MethodData::compute_data_size(BytecodeStream* stream) {
aoqi@0 755 int cell_count = bytecode_cell_count(stream->code());
aoqi@0 756 if (cell_count == no_profile_data) {
aoqi@0 757 return 0;
aoqi@0 758 }
aoqi@0 759 if (cell_count == variable_cell_count) {
aoqi@0 760 switch (stream->code()) {
aoqi@0 761 case Bytecodes::_lookupswitch:
aoqi@0 762 case Bytecodes::_tableswitch:
aoqi@0 763 cell_count = MultiBranchData::compute_cell_count(stream);
aoqi@0 764 break;
aoqi@0 765 case Bytecodes::_invokespecial:
aoqi@0 766 case Bytecodes::_invokestatic:
aoqi@0 767 case Bytecodes::_invokedynamic:
aoqi@0 768 assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");
aoqi@0 769 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
aoqi@0 770 profile_return_for_invoke(stream->method(), stream->bci())) {
aoqi@0 771 cell_count = CallTypeData::compute_cell_count(stream);
aoqi@0 772 } else {
aoqi@0 773 cell_count = CounterData::static_cell_count();
aoqi@0 774 }
aoqi@0 775 break;
aoqi@0 776 case Bytecodes::_invokevirtual:
aoqi@0 777 case Bytecodes::_invokeinterface: {
aoqi@0 778 assert(MethodData::profile_arguments() || MethodData::profile_return(), "should be collecting args profile");
aoqi@0 779 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
aoqi@0 780 profile_return_for_invoke(stream->method(), stream->bci())) {
aoqi@0 781 cell_count = VirtualCallTypeData::compute_cell_count(stream);
aoqi@0 782 } else {
aoqi@0 783 cell_count = VirtualCallData::static_cell_count();
aoqi@0 784 }
aoqi@0 785 break;
aoqi@0 786 }
aoqi@0 787 default:
aoqi@0 788 fatal("unexpected bytecode for var length profile data");
aoqi@0 789 }
aoqi@0 790 }
aoqi@0 791 // Note: cell_count might be zero, meaning that there is just
aoqi@0 792 // a DataLayout header, with no extra cells.
aoqi@0 793 assert(cell_count >= 0, "sanity");
aoqi@0 794 return DataLayout::compute_size_in_bytes(cell_count);
aoqi@0 795 }
aoqi@0 796
aoqi@0 797 bool MethodData::is_speculative_trap_bytecode(Bytecodes::Code code) {
aoqi@0 798 // Bytecodes for which we may use speculation
aoqi@0 799 switch (code) {
aoqi@0 800 case Bytecodes::_checkcast:
aoqi@0 801 case Bytecodes::_instanceof:
aoqi@0 802 case Bytecodes::_aastore:
aoqi@0 803 case Bytecodes::_invokevirtual:
aoqi@0 804 case Bytecodes::_invokeinterface:
aoqi@0 805 case Bytecodes::_if_acmpeq:
aoqi@0 806 case Bytecodes::_if_acmpne:
aoqi@0 807 case Bytecodes::_invokestatic:
aoqi@0 808 #ifdef COMPILER2
aoqi@0 809 return UseTypeSpeculation;
aoqi@0 810 #endif
aoqi@0 811 default:
aoqi@0 812 return false;
aoqi@0 813 }
aoqi@0 814 return false;
aoqi@0 815 }
aoqi@0 816
aoqi@0 817 int MethodData::compute_extra_data_count(int data_size, int empty_bc_count, bool needs_speculative_traps) {
aoqi@0 818 if (ProfileTraps) {
aoqi@0 819 // Assume that up to 3% of BCIs with no MDP will need to allocate one.
aoqi@0 820 int extra_data_count = (uint)(empty_bc_count * 3) / 128 + 1;
aoqi@0 821 // If the method is large, let the extra BCIs grow numerous (to ~1%).
aoqi@0 822 int one_percent_of_data
aoqi@0 823 = (uint)data_size / (DataLayout::header_size_in_bytes()*128);
aoqi@0 824 if (extra_data_count < one_percent_of_data)
aoqi@0 825 extra_data_count = one_percent_of_data;
aoqi@0 826 if (extra_data_count > empty_bc_count)
aoqi@0 827 extra_data_count = empty_bc_count; // no need for more
aoqi@0 828
aoqi@0 829 // Make sure we have a minimum number of extra data slots to
aoqi@0 830 // allocate SpeculativeTrapData entries. We would want to have one
aoqi@0 831 // entry per compilation that inlines this method and for which
aoqi@0 832 // some type speculation assumption fails. So the room we need for
aoqi@0 833 // the SpeculativeTrapData entries doesn't directly depend on the
aoqi@0 834 // size of the method. Because it's hard to estimate, we reserve
aoqi@0 835 // space for an arbitrary number of entries.
aoqi@0 836 int spec_data_count = (needs_speculative_traps ? SpecTrapLimitExtraEntries : 0) *
aoqi@0 837 (SpeculativeTrapData::static_cell_count() + DataLayout::header_size_in_cells());
aoqi@0 838
aoqi@0 839 return MAX2(extra_data_count, spec_data_count);
aoqi@0 840 } else {
aoqi@0 841 return 0;
aoqi@0 842 }
aoqi@0 843 }
aoqi@0 844
aoqi@0 845 // Compute the size of the MethodData* necessary to store
aoqi@0 846 // profiling information about a given method. Size is in bytes.
aoqi@0 847 int MethodData::compute_allocation_size_in_bytes(methodHandle method) {
aoqi@0 848 int data_size = 0;
aoqi@0 849 BytecodeStream stream(method);
aoqi@0 850 Bytecodes::Code c;
aoqi@0 851 int empty_bc_count = 0; // number of bytecodes lacking data
aoqi@0 852 bool needs_speculative_traps = false;
aoqi@0 853 while ((c = stream.next()) >= 0) {
aoqi@0 854 int size_in_bytes = compute_data_size(&stream);
aoqi@0 855 data_size += size_in_bytes;
aoqi@0 856 if (size_in_bytes == 0) empty_bc_count += 1;
aoqi@0 857 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
aoqi@0 858 }
aoqi@0 859 int object_size = in_bytes(data_offset()) + data_size;
aoqi@0 860
aoqi@0 861 // Add some extra DataLayout cells (at least one) to track stray traps.
aoqi@0 862 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
aoqi@0 863 object_size += extra_data_count * DataLayout::compute_size_in_bytes(0);
aoqi@0 864
aoqi@0 865 // Add a cell to record information about modified arguments.
aoqi@0 866 int arg_size = method->size_of_parameters();
aoqi@0 867 object_size += DataLayout::compute_size_in_bytes(arg_size+1);
aoqi@0 868
aoqi@0 869 // Reserve room for an area of the MDO dedicated to profiling of
aoqi@0 870 // parameters
aoqi@0 871 int args_cell = ParametersTypeData::compute_cell_count(method());
aoqi@0 872 if (args_cell > 0) {
aoqi@0 873 object_size += DataLayout::compute_size_in_bytes(args_cell);
aoqi@0 874 }
aoqi@0 875 return object_size;
aoqi@0 876 }
aoqi@0 877
aoqi@0 878 // Compute the size of the MethodData* necessary to store
aoqi@0 879 // profiling information about a given method. Size is in words
aoqi@0 880 int MethodData::compute_allocation_size_in_words(methodHandle method) {
aoqi@0 881 int byte_size = compute_allocation_size_in_bytes(method);
aoqi@0 882 int word_size = align_size_up(byte_size, BytesPerWord) / BytesPerWord;
aoqi@0 883 return align_object_size(word_size);
aoqi@0 884 }
aoqi@0 885
aoqi@0 886 // Initialize an individual data segment. Returns the size of
aoqi@0 887 // the segment in bytes.
aoqi@0 888 int MethodData::initialize_data(BytecodeStream* stream,
aoqi@0 889 int data_index) {
aoqi@0 890 #if defined(COMPILER1) && !defined(COMPILER2)
aoqi@0 891 return 0;
aoqi@0 892 #else
aoqi@0 893 int cell_count = -1;
aoqi@0 894 int tag = DataLayout::no_tag;
aoqi@0 895 DataLayout* data_layout = data_layout_at(data_index);
aoqi@0 896 Bytecodes::Code c = stream->code();
aoqi@0 897 switch (c) {
aoqi@0 898 case Bytecodes::_checkcast:
aoqi@0 899 case Bytecodes::_instanceof:
aoqi@0 900 case Bytecodes::_aastore:
aoqi@0 901 if (TypeProfileCasts) {
aoqi@0 902 cell_count = ReceiverTypeData::static_cell_count();
aoqi@0 903 tag = DataLayout::receiver_type_data_tag;
aoqi@0 904 } else {
aoqi@0 905 cell_count = BitData::static_cell_count();
aoqi@0 906 tag = DataLayout::bit_data_tag;
aoqi@0 907 }
aoqi@0 908 break;
aoqi@0 909 case Bytecodes::_invokespecial:
aoqi@0 910 case Bytecodes::_invokestatic: {
aoqi@0 911 int counter_data_cell_count = CounterData::static_cell_count();
aoqi@0 912 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
aoqi@0 913 profile_return_for_invoke(stream->method(), stream->bci())) {
aoqi@0 914 cell_count = CallTypeData::compute_cell_count(stream);
aoqi@0 915 } else {
aoqi@0 916 cell_count = counter_data_cell_count;
aoqi@0 917 }
aoqi@0 918 if (cell_count > counter_data_cell_count) {
aoqi@0 919 tag = DataLayout::call_type_data_tag;
aoqi@0 920 } else {
aoqi@0 921 tag = DataLayout::counter_data_tag;
aoqi@0 922 }
aoqi@0 923 break;
aoqi@0 924 }
aoqi@0 925 case Bytecodes::_goto:
aoqi@0 926 case Bytecodes::_goto_w:
aoqi@0 927 case Bytecodes::_jsr:
aoqi@0 928 case Bytecodes::_jsr_w:
aoqi@0 929 cell_count = JumpData::static_cell_count();
aoqi@0 930 tag = DataLayout::jump_data_tag;
aoqi@0 931 break;
aoqi@0 932 case Bytecodes::_invokevirtual:
aoqi@0 933 case Bytecodes::_invokeinterface: {
aoqi@0 934 int virtual_call_data_cell_count = VirtualCallData::static_cell_count();
aoqi@0 935 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
aoqi@0 936 profile_return_for_invoke(stream->method(), stream->bci())) {
aoqi@0 937 cell_count = VirtualCallTypeData::compute_cell_count(stream);
aoqi@0 938 } else {
aoqi@0 939 cell_count = virtual_call_data_cell_count;
aoqi@0 940 }
aoqi@0 941 if (cell_count > virtual_call_data_cell_count) {
aoqi@0 942 tag = DataLayout::virtual_call_type_data_tag;
aoqi@0 943 } else {
aoqi@0 944 tag = DataLayout::virtual_call_data_tag;
aoqi@0 945 }
aoqi@0 946 break;
aoqi@0 947 }
aoqi@0 948 case Bytecodes::_invokedynamic: {
aoqi@0 949 // %%% should make a type profile for any invokedynamic that takes a ref argument
aoqi@0 950 int counter_data_cell_count = CounterData::static_cell_count();
aoqi@0 951 if (profile_arguments_for_invoke(stream->method(), stream->bci()) ||
aoqi@0 952 profile_return_for_invoke(stream->method(), stream->bci())) {
aoqi@0 953 cell_count = CallTypeData::compute_cell_count(stream);
aoqi@0 954 } else {
aoqi@0 955 cell_count = counter_data_cell_count;
aoqi@0 956 }
aoqi@0 957 if (cell_count > counter_data_cell_count) {
aoqi@0 958 tag = DataLayout::call_type_data_tag;
aoqi@0 959 } else {
aoqi@0 960 tag = DataLayout::counter_data_tag;
aoqi@0 961 }
aoqi@0 962 break;
aoqi@0 963 }
aoqi@0 964 case Bytecodes::_ret:
aoqi@0 965 cell_count = RetData::static_cell_count();
aoqi@0 966 tag = DataLayout::ret_data_tag;
aoqi@0 967 break;
aoqi@0 968 case Bytecodes::_ifeq:
aoqi@0 969 case Bytecodes::_ifne:
aoqi@0 970 case Bytecodes::_iflt:
aoqi@0 971 case Bytecodes::_ifge:
aoqi@0 972 case Bytecodes::_ifgt:
aoqi@0 973 case Bytecodes::_ifle:
aoqi@0 974 case Bytecodes::_if_icmpeq:
aoqi@0 975 case Bytecodes::_if_icmpne:
aoqi@0 976 case Bytecodes::_if_icmplt:
aoqi@0 977 case Bytecodes::_if_icmpge:
aoqi@0 978 case Bytecodes::_if_icmpgt:
aoqi@0 979 case Bytecodes::_if_icmple:
aoqi@0 980 case Bytecodes::_if_acmpeq:
aoqi@0 981 case Bytecodes::_if_acmpne:
aoqi@0 982 case Bytecodes::_ifnull:
aoqi@0 983 case Bytecodes::_ifnonnull:
aoqi@0 984 cell_count = BranchData::static_cell_count();
aoqi@0 985 tag = DataLayout::branch_data_tag;
aoqi@0 986 break;
aoqi@0 987 case Bytecodes::_lookupswitch:
aoqi@0 988 case Bytecodes::_tableswitch:
aoqi@0 989 cell_count = MultiBranchData::compute_cell_count(stream);
aoqi@0 990 tag = DataLayout::multi_branch_data_tag;
aoqi@0 991 break;
aoqi@0 992 }
aoqi@0 993 assert(tag == DataLayout::multi_branch_data_tag ||
aoqi@0 994 ((MethodData::profile_arguments() || MethodData::profile_return()) &&
aoqi@0 995 (tag == DataLayout::call_type_data_tag ||
aoqi@0 996 tag == DataLayout::counter_data_tag ||
aoqi@0 997 tag == DataLayout::virtual_call_type_data_tag ||
aoqi@0 998 tag == DataLayout::virtual_call_data_tag)) ||
aoqi@0 999 cell_count == bytecode_cell_count(c), "cell counts must agree");
aoqi@0 1000 if (cell_count >= 0) {
aoqi@0 1001 assert(tag != DataLayout::no_tag, "bad tag");
aoqi@0 1002 assert(bytecode_has_profile(c), "agree w/ BHP");
aoqi@0 1003 data_layout->initialize(tag, stream->bci(), cell_count);
aoqi@0 1004 return DataLayout::compute_size_in_bytes(cell_count);
aoqi@0 1005 } else {
aoqi@0 1006 assert(!bytecode_has_profile(c), "agree w/ !BHP");
aoqi@0 1007 return 0;
aoqi@0 1008 }
aoqi@0 1009 #endif
aoqi@0 1010 }
aoqi@0 1011
aoqi@0 1012 // Get the data at an arbitrary (sort of) data index.
aoqi@0 1013 ProfileData* MethodData::data_at(int data_index) const {
aoqi@0 1014 if (out_of_bounds(data_index)) {
aoqi@0 1015 return NULL;
aoqi@0 1016 }
aoqi@0 1017 DataLayout* data_layout = data_layout_at(data_index);
aoqi@0 1018 return data_layout->data_in();
aoqi@0 1019 }
aoqi@0 1020
aoqi@0 1021 ProfileData* DataLayout::data_in() {
aoqi@0 1022 switch (tag()) {
aoqi@0 1023 case DataLayout::no_tag:
aoqi@0 1024 default:
aoqi@0 1025 ShouldNotReachHere();
aoqi@0 1026 return NULL;
aoqi@0 1027 case DataLayout::bit_data_tag:
aoqi@0 1028 return new BitData(this);
aoqi@0 1029 case DataLayout::counter_data_tag:
aoqi@0 1030 return new CounterData(this);
aoqi@0 1031 case DataLayout::jump_data_tag:
aoqi@0 1032 return new JumpData(this);
aoqi@0 1033 case DataLayout::receiver_type_data_tag:
aoqi@0 1034 return new ReceiverTypeData(this);
aoqi@0 1035 case DataLayout::virtual_call_data_tag:
aoqi@0 1036 return new VirtualCallData(this);
aoqi@0 1037 case DataLayout::ret_data_tag:
aoqi@0 1038 return new RetData(this);
aoqi@0 1039 case DataLayout::branch_data_tag:
aoqi@0 1040 return new BranchData(this);
aoqi@0 1041 case DataLayout::multi_branch_data_tag:
aoqi@0 1042 return new MultiBranchData(this);
aoqi@0 1043 case DataLayout::arg_info_data_tag:
aoqi@0 1044 return new ArgInfoData(this);
aoqi@0 1045 case DataLayout::call_type_data_tag:
aoqi@0 1046 return new CallTypeData(this);
aoqi@0 1047 case DataLayout::virtual_call_type_data_tag:
aoqi@0 1048 return new VirtualCallTypeData(this);
aoqi@0 1049 case DataLayout::parameters_type_data_tag:
aoqi@0 1050 return new ParametersTypeData(this);
aoqi@0 1051 };
aoqi@0 1052 }
aoqi@0 1053
aoqi@0 1054 // Iteration over data.
aoqi@0 1055 ProfileData* MethodData::next_data(ProfileData* current) const {
aoqi@0 1056 int current_index = dp_to_di(current->dp());
aoqi@0 1057 int next_index = current_index + current->size_in_bytes();
aoqi@0 1058 ProfileData* next = data_at(next_index);
aoqi@0 1059 return next;
aoqi@0 1060 }
aoqi@0 1061
aoqi@0 1062 // Give each of the data entries a chance to perform specific
aoqi@0 1063 // data initialization.
aoqi@0 1064 void MethodData::post_initialize(BytecodeStream* stream) {
aoqi@0 1065 ResourceMark rm;
aoqi@0 1066 ProfileData* data;
aoqi@0 1067 for (data = first_data(); is_valid(data); data = next_data(data)) {
aoqi@0 1068 stream->set_start(data->bci());
aoqi@0 1069 stream->next();
aoqi@0 1070 data->post_initialize(stream, this);
aoqi@0 1071 }
aoqi@0 1072 if (_parameters_type_data_di != -1) {
aoqi@0 1073 parameters_type_data()->post_initialize(NULL, this);
aoqi@0 1074 }
aoqi@0 1075 }
aoqi@0 1076
aoqi@0 1077 // Initialize the MethodData* corresponding to a given method.
aoqi@0 1078 MethodData::MethodData(methodHandle method, int size, TRAPS)
aoqi@0 1079 : _extra_data_lock(Monitor::leaf, "MDO extra data lock") {
aoqi@0 1080 No_Safepoint_Verifier no_safepoint; // init function atomic wrt GC
aoqi@0 1081 ResourceMark rm;
aoqi@0 1082 // Set the method back-pointer.
aoqi@0 1083 _method = method();
aoqi@0 1084
aoqi@0 1085 init();
aoqi@0 1086 set_creation_mileage(mileage_of(method()));
aoqi@0 1087
aoqi@0 1088 // Go through the bytecodes and allocate and initialize the
aoqi@0 1089 // corresponding data cells.
aoqi@0 1090 int data_size = 0;
aoqi@0 1091 int empty_bc_count = 0; // number of bytecodes lacking data
aoqi@0 1092 _data[0] = 0; // apparently not set below.
aoqi@0 1093 BytecodeStream stream(method);
aoqi@0 1094 Bytecodes::Code c;
aoqi@0 1095 bool needs_speculative_traps = false;
aoqi@0 1096 while ((c = stream.next()) >= 0) {
aoqi@0 1097 int size_in_bytes = initialize_data(&stream, data_size);
aoqi@0 1098 data_size += size_in_bytes;
aoqi@0 1099 if (size_in_bytes == 0) empty_bc_count += 1;
aoqi@0 1100 needs_speculative_traps = needs_speculative_traps || is_speculative_trap_bytecode(c);
aoqi@0 1101 }
aoqi@0 1102 _data_size = data_size;
aoqi@0 1103 int object_size = in_bytes(data_offset()) + data_size;
aoqi@0 1104
aoqi@0 1105 // Add some extra DataLayout cells (at least one) to track stray traps.
aoqi@0 1106 int extra_data_count = compute_extra_data_count(data_size, empty_bc_count, needs_speculative_traps);
aoqi@0 1107 int extra_size = extra_data_count * DataLayout::compute_size_in_bytes(0);
aoqi@0 1108
aoqi@0 1109 // Let's zero the space for the extra data
aoqi@0 1110 Copy::zero_to_bytes(((address)_data) + data_size, extra_size);
aoqi@0 1111
aoqi@0 1112 // Add a cell to record information about modified arguments.
aoqi@0 1113 // Set up _args_modified array after traps cells so that
aoqi@0 1114 // the code for traps cells works.
aoqi@0 1115 DataLayout *dp = data_layout_at(data_size + extra_size);
aoqi@0 1116
aoqi@0 1117 int arg_size = method->size_of_parameters();
aoqi@0 1118 dp->initialize(DataLayout::arg_info_data_tag, 0, arg_size+1);
aoqi@0 1119
aoqi@0 1120 int arg_data_size = DataLayout::compute_size_in_bytes(arg_size+1);
aoqi@0 1121 object_size += extra_size + arg_data_size;
aoqi@0 1122
aoqi@0 1123 int parms_cell = ParametersTypeData::compute_cell_count(method());
aoqi@0 1124 // If we are profiling parameters, we reserver an area near the end
aoqi@0 1125 // of the MDO after the slots for bytecodes (because there's no bci
aoqi@0 1126 // for method entry so they don't fit with the framework for the
aoqi@0 1127 // profiling of bytecodes). We store the offset within the MDO of
aoqi@0 1128 // this area (or -1 if no parameter is profiled)
aoqi@0 1129 if (parms_cell > 0) {
aoqi@0 1130 object_size += DataLayout::compute_size_in_bytes(parms_cell);
aoqi@0 1131 _parameters_type_data_di = data_size + extra_size + arg_data_size;
aoqi@0 1132 DataLayout *dp = data_layout_at(data_size + extra_size + arg_data_size);
aoqi@0 1133 dp->initialize(DataLayout::parameters_type_data_tag, 0, parms_cell);
aoqi@0 1134 } else {
aoqi@0 1135 _parameters_type_data_di = -1;
aoqi@0 1136 }
aoqi@0 1137
aoqi@0 1138 // Set an initial hint. Don't use set_hint_di() because
aoqi@0 1139 // first_di() may be out of bounds if data_size is 0.
aoqi@0 1140 // In that situation, _hint_di is never used, but at
aoqi@0 1141 // least well-defined.
aoqi@0 1142 _hint_di = first_di();
aoqi@0 1143
aoqi@0 1144 post_initialize(&stream);
aoqi@0 1145
aoqi@0 1146 set_size(object_size);
aoqi@0 1147 }
aoqi@0 1148
aoqi@0 1149 void MethodData::init() {
aoqi@0 1150 _invocation_counter.init();
aoqi@0 1151 _backedge_counter.init();
aoqi@0 1152 _invocation_counter_start = 0;
aoqi@0 1153 _backedge_counter_start = 0;
aoqi@0 1154 _num_loops = 0;
aoqi@0 1155 _num_blocks = 0;
thartmann@7365 1156 _would_profile = unknown;
aoqi@0 1157
aoqi@0 1158 #if INCLUDE_RTM_OPT
aoqi@0 1159 _rtm_state = NoRTM; // No RTM lock eliding by default
aoqi@0 1160 if (UseRTMLocking &&
aoqi@0 1161 !CompilerOracle::has_option_string(_method, "NoRTMLockEliding")) {
aoqi@0 1162 if (CompilerOracle::has_option_string(_method, "UseRTMLockEliding") || !UseRTMDeopt) {
aoqi@0 1163 // Generate RTM lock eliding code without abort ratio calculation code.
aoqi@0 1164 _rtm_state = UseRTM;
aoqi@0 1165 } else if (UseRTMDeopt) {
aoqi@0 1166 // Generate RTM lock eliding code and include abort ratio calculation
aoqi@0 1167 // code if UseRTMDeopt is on.
aoqi@0 1168 _rtm_state = ProfileRTM;
aoqi@0 1169 }
aoqi@0 1170 }
aoqi@0 1171 #endif
aoqi@0 1172
aoqi@0 1173 // Initialize flags and trap history.
aoqi@0 1174 _nof_decompiles = 0;
aoqi@0 1175 _nof_overflow_recompiles = 0;
aoqi@0 1176 _nof_overflow_traps = 0;
aoqi@0 1177 clear_escape_info();
aoqi@0 1178 assert(sizeof(_trap_hist) % sizeof(HeapWord) == 0, "align");
aoqi@0 1179 Copy::zero_to_words((HeapWord*) &_trap_hist,
aoqi@0 1180 sizeof(_trap_hist) / sizeof(HeapWord));
aoqi@0 1181 }
aoqi@0 1182
aoqi@0 1183 // Get a measure of how much mileage the method has on it.
aoqi@0 1184 int MethodData::mileage_of(Method* method) {
aoqi@0 1185 int mileage = 0;
aoqi@0 1186 if (TieredCompilation) {
aoqi@0 1187 mileage = MAX2(method->invocation_count(), method->backedge_count());
aoqi@0 1188 } else {
aoqi@0 1189 int iic = method->interpreter_invocation_count();
aoqi@0 1190 if (mileage < iic) mileage = iic;
aoqi@0 1191 MethodCounters* mcs = method->method_counters();
aoqi@0 1192 if (mcs != NULL) {
aoqi@0 1193 InvocationCounter* ic = mcs->invocation_counter();
aoqi@0 1194 InvocationCounter* bc = mcs->backedge_counter();
aoqi@0 1195 int icval = ic->count();
aoqi@0 1196 if (ic->carry()) icval += CompileThreshold;
aoqi@0 1197 if (mileage < icval) mileage = icval;
aoqi@0 1198 int bcval = bc->count();
aoqi@0 1199 if (bc->carry()) bcval += CompileThreshold;
aoqi@0 1200 if (mileage < bcval) mileage = bcval;
aoqi@0 1201 }
aoqi@0 1202 }
aoqi@0 1203 return mileage;
aoqi@0 1204 }
aoqi@0 1205
aoqi@0 1206 bool MethodData::is_mature() const {
aoqi@0 1207 return CompilationPolicy::policy()->is_mature(_method);
aoqi@0 1208 }
aoqi@0 1209
aoqi@0 1210 // Translate a bci to its corresponding data index (di).
aoqi@0 1211 address MethodData::bci_to_dp(int bci) {
aoqi@0 1212 ResourceMark rm;
aoqi@0 1213 ProfileData* data = data_before(bci);
aoqi@0 1214 ProfileData* prev = NULL;
aoqi@0 1215 for ( ; is_valid(data); data = next_data(data)) {
aoqi@0 1216 if (data->bci() >= bci) {
aoqi@0 1217 if (data->bci() == bci) set_hint_di(dp_to_di(data->dp()));
aoqi@0 1218 else if (prev != NULL) set_hint_di(dp_to_di(prev->dp()));
aoqi@0 1219 return data->dp();
aoqi@0 1220 }
aoqi@0 1221 prev = data;
aoqi@0 1222 }
aoqi@0 1223 return (address)limit_data_position();
aoqi@0 1224 }
aoqi@0 1225
aoqi@0 1226 // Translate a bci to its corresponding data, or NULL.
aoqi@0 1227 ProfileData* MethodData::bci_to_data(int bci) {
aoqi@0 1228 ProfileData* data = data_before(bci);
aoqi@0 1229 for ( ; is_valid(data); data = next_data(data)) {
aoqi@0 1230 if (data->bci() == bci) {
aoqi@0 1231 set_hint_di(dp_to_di(data->dp()));
aoqi@0 1232 return data;
aoqi@0 1233 } else if (data->bci() > bci) {
aoqi@0 1234 break;
aoqi@0 1235 }
aoqi@0 1236 }
aoqi@0 1237 return bci_to_extra_data(bci, NULL, false);
aoqi@0 1238 }
aoqi@0 1239
aoqi@0 1240 DataLayout* MethodData::next_extra(DataLayout* dp) {
aoqi@0 1241 int nb_cells = 0;
aoqi@0 1242 switch(dp->tag()) {
aoqi@0 1243 case DataLayout::bit_data_tag:
aoqi@0 1244 case DataLayout::no_tag:
aoqi@0 1245 nb_cells = BitData::static_cell_count();
aoqi@0 1246 break;
aoqi@0 1247 case DataLayout::speculative_trap_data_tag:
aoqi@0 1248 nb_cells = SpeculativeTrapData::static_cell_count();
aoqi@0 1249 break;
aoqi@0 1250 default:
aoqi@0 1251 fatal(err_msg("unexpected tag %d", dp->tag()));
aoqi@0 1252 }
aoqi@0 1253 return (DataLayout*)((address)dp + DataLayout::compute_size_in_bytes(nb_cells));
aoqi@0 1254 }
aoqi@0 1255
aoqi@0 1256 ProfileData* MethodData::bci_to_extra_data_helper(int bci, Method* m, DataLayout*& dp, bool concurrent) {
aoqi@0 1257 DataLayout* end = extra_data_limit();
aoqi@0 1258
aoqi@0 1259 for (;; dp = next_extra(dp)) {
aoqi@0 1260 assert(dp < end, "moved past end of extra data");
aoqi@0 1261 // No need for "OrderAccess::load_acquire" ops,
aoqi@0 1262 // since the data structure is monotonic.
aoqi@0 1263 switch(dp->tag()) {
aoqi@0 1264 case DataLayout::no_tag:
aoqi@0 1265 return NULL;
aoqi@0 1266 case DataLayout::arg_info_data_tag:
aoqi@0 1267 dp = end;
aoqi@0 1268 return NULL; // ArgInfoData is at the end of extra data section.
aoqi@0 1269 case DataLayout::bit_data_tag:
aoqi@0 1270 if (m == NULL && dp->bci() == bci) {
aoqi@0 1271 return new BitData(dp);
aoqi@0 1272 }
aoqi@0 1273 break;
aoqi@0 1274 case DataLayout::speculative_trap_data_tag:
aoqi@0 1275 if (m != NULL) {
aoqi@0 1276 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
aoqi@0 1277 // data->method() may be null in case of a concurrent
aoqi@0 1278 // allocation. Maybe it's for the same method. Try to use that
aoqi@0 1279 // entry in that case.
aoqi@0 1280 if (dp->bci() == bci) {
aoqi@0 1281 if (data->method() == NULL) {
aoqi@0 1282 assert(concurrent, "impossible because no concurrent allocation");
aoqi@0 1283 return NULL;
aoqi@0 1284 } else if (data->method() == m) {
aoqi@0 1285 return data;
aoqi@0 1286 }
aoqi@0 1287 }
aoqi@0 1288 }
aoqi@0 1289 break;
aoqi@0 1290 default:
aoqi@0 1291 fatal(err_msg("unexpected tag %d", dp->tag()));
aoqi@0 1292 }
aoqi@0 1293 }
aoqi@0 1294 return NULL;
aoqi@0 1295 }
aoqi@0 1296
aoqi@0 1297
aoqi@0 1298 // Translate a bci to its corresponding extra data, or NULL.
aoqi@0 1299 ProfileData* MethodData::bci_to_extra_data(int bci, Method* m, bool create_if_missing) {
aoqi@0 1300 // This code assumes an entry for a SpeculativeTrapData is 2 cells
aoqi@0 1301 assert(2*DataLayout::compute_size_in_bytes(BitData::static_cell_count()) ==
aoqi@0 1302 DataLayout::compute_size_in_bytes(SpeculativeTrapData::static_cell_count()),
aoqi@0 1303 "code needs to be adjusted");
aoqi@0 1304
aoqi@0 1305 DataLayout* dp = extra_data_base();
aoqi@0 1306 DataLayout* end = extra_data_limit();
aoqi@0 1307
aoqi@0 1308 // Allocation in the extra data space has to be atomic because not
aoqi@0 1309 // all entries have the same size and non atomic concurrent
aoqi@0 1310 // allocation would result in a corrupted extra data space.
aoqi@0 1311 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, true);
aoqi@0 1312 if (result != NULL) {
aoqi@0 1313 return result;
aoqi@0 1314 }
aoqi@0 1315
aoqi@0 1316 if (create_if_missing && dp < end) {
aoqi@0 1317 MutexLocker ml(&_extra_data_lock);
aoqi@0 1318 // Check again now that we have the lock. Another thread may
aoqi@0 1319 // have added extra data entries.
aoqi@0 1320 ProfileData* result = bci_to_extra_data_helper(bci, m, dp, false);
aoqi@0 1321 if (result != NULL || dp >= end) {
aoqi@0 1322 return result;
aoqi@0 1323 }
aoqi@0 1324
aoqi@0 1325 assert(dp->tag() == DataLayout::no_tag || (dp->tag() == DataLayout::speculative_trap_data_tag && m != NULL), "should be free");
aoqi@0 1326 assert(next_extra(dp)->tag() == DataLayout::no_tag || next_extra(dp)->tag() == DataLayout::arg_info_data_tag, "should be free or arg info");
aoqi@0 1327 u1 tag = m == NULL ? DataLayout::bit_data_tag : DataLayout::speculative_trap_data_tag;
aoqi@0 1328 // SpeculativeTrapData is 2 slots. Make sure we have room.
aoqi@0 1329 if (m != NULL && next_extra(dp)->tag() != DataLayout::no_tag) {
aoqi@0 1330 return NULL;
aoqi@0 1331 }
aoqi@0 1332 DataLayout temp;
aoqi@0 1333 temp.initialize(tag, bci, 0);
aoqi@0 1334
aoqi@0 1335 dp->set_header(temp.header());
aoqi@0 1336 assert(dp->tag() == tag, "sane");
aoqi@0 1337 assert(dp->bci() == bci, "no concurrent allocation");
aoqi@0 1338 if (tag == DataLayout::bit_data_tag) {
aoqi@0 1339 return new BitData(dp);
aoqi@0 1340 } else {
aoqi@0 1341 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
aoqi@0 1342 data->set_method(m);
aoqi@0 1343 return data;
aoqi@0 1344 }
aoqi@0 1345 }
aoqi@0 1346 return NULL;
aoqi@0 1347 }
aoqi@0 1348
aoqi@0 1349 ArgInfoData *MethodData::arg_info() {
aoqi@0 1350 DataLayout* dp = extra_data_base();
aoqi@0 1351 DataLayout* end = extra_data_limit();
aoqi@0 1352 for (; dp < end; dp = next_extra(dp)) {
aoqi@0 1353 if (dp->tag() == DataLayout::arg_info_data_tag)
aoqi@0 1354 return new ArgInfoData(dp);
aoqi@0 1355 }
aoqi@0 1356 return NULL;
aoqi@0 1357 }
aoqi@0 1358
aoqi@0 1359 // Printing
aoqi@0 1360
aoqi@0 1361 #ifndef PRODUCT
aoqi@0 1362
aoqi@0 1363 void MethodData::print_on(outputStream* st) const {
aoqi@0 1364 assert(is_methodData(), "should be method data");
aoqi@0 1365 st->print("method data for ");
aoqi@0 1366 method()->print_value_on(st);
aoqi@0 1367 st->cr();
aoqi@0 1368 print_data_on(st);
aoqi@0 1369 }
aoqi@0 1370
aoqi@0 1371 #endif //PRODUCT
aoqi@0 1372
aoqi@0 1373 void MethodData::print_value_on(outputStream* st) const {
aoqi@0 1374 assert(is_methodData(), "should be method data");
aoqi@0 1375 st->print("method data for ");
aoqi@0 1376 method()->print_value_on(st);
aoqi@0 1377 }
aoqi@0 1378
aoqi@0 1379 #ifndef PRODUCT
aoqi@0 1380 void MethodData::print_data_on(outputStream* st) const {
aoqi@0 1381 ResourceMark rm;
aoqi@0 1382 ProfileData* data = first_data();
aoqi@0 1383 if (_parameters_type_data_di != -1) {
aoqi@0 1384 parameters_type_data()->print_data_on(st);
aoqi@0 1385 }
aoqi@0 1386 for ( ; is_valid(data); data = next_data(data)) {
aoqi@0 1387 st->print("%d", dp_to_di(data->dp()));
aoqi@0 1388 st->fill_to(6);
aoqi@0 1389 data->print_data_on(st, this);
aoqi@0 1390 }
aoqi@0 1391 st->print_cr("--- Extra data:");
aoqi@0 1392 DataLayout* dp = extra_data_base();
aoqi@0 1393 DataLayout* end = extra_data_limit();
aoqi@0 1394 for (;; dp = next_extra(dp)) {
aoqi@0 1395 assert(dp < end, "moved past end of extra data");
aoqi@0 1396 // No need for "OrderAccess::load_acquire" ops,
aoqi@0 1397 // since the data structure is monotonic.
aoqi@0 1398 switch(dp->tag()) {
aoqi@0 1399 case DataLayout::no_tag:
aoqi@0 1400 continue;
aoqi@0 1401 case DataLayout::bit_data_tag:
aoqi@0 1402 data = new BitData(dp);
aoqi@0 1403 break;
aoqi@0 1404 case DataLayout::speculative_trap_data_tag:
aoqi@0 1405 data = new SpeculativeTrapData(dp);
aoqi@0 1406 break;
aoqi@0 1407 case DataLayout::arg_info_data_tag:
aoqi@0 1408 data = new ArgInfoData(dp);
aoqi@0 1409 dp = end; // ArgInfoData is at the end of extra data section.
aoqi@0 1410 break;
aoqi@0 1411 default:
aoqi@0 1412 fatal(err_msg("unexpected tag %d", dp->tag()));
aoqi@0 1413 }
aoqi@0 1414 st->print("%d", dp_to_di(data->dp()));
aoqi@0 1415 st->fill_to(6);
aoqi@0 1416 data->print_data_on(st);
aoqi@0 1417 if (dp >= end) return;
aoqi@0 1418 }
aoqi@0 1419 }
aoqi@0 1420 #endif
aoqi@0 1421
aoqi@0 1422 #if INCLUDE_SERVICES
aoqi@0 1423 // Size Statistics
aoqi@0 1424 void MethodData::collect_statistics(KlassSizeStats *sz) const {
aoqi@0 1425 int n = sz->count(this);
aoqi@0 1426 sz->_method_data_bytes += n;
aoqi@0 1427 sz->_method_all_bytes += n;
aoqi@0 1428 sz->_rw_bytes += n;
aoqi@0 1429 }
aoqi@0 1430 #endif // INCLUDE_SERVICES
aoqi@0 1431
aoqi@0 1432 // Verification
aoqi@0 1433
aoqi@0 1434 void MethodData::verify_on(outputStream* st) {
aoqi@0 1435 guarantee(is_methodData(), "object must be method data");
aoqi@0 1436 // guarantee(m->is_perm(), "should be in permspace");
aoqi@0 1437 this->verify_data_on(st);
aoqi@0 1438 }
aoqi@0 1439
aoqi@0 1440 void MethodData::verify_data_on(outputStream* st) {
aoqi@0 1441 NEEDS_CLEANUP;
aoqi@0 1442 // not yet implemented.
aoqi@0 1443 }
aoqi@0 1444
aoqi@0 1445 bool MethodData::profile_jsr292(methodHandle m, int bci) {
aoqi@0 1446 if (m->is_compiled_lambda_form()) {
aoqi@0 1447 return true;
aoqi@0 1448 }
aoqi@0 1449
aoqi@0 1450 Bytecode_invoke inv(m , bci);
aoqi@0 1451 return inv.is_invokedynamic() || inv.is_invokehandle();
aoqi@0 1452 }
aoqi@0 1453
aoqi@0 1454 int MethodData::profile_arguments_flag() {
aoqi@0 1455 return TypeProfileLevel % 10;
aoqi@0 1456 }
aoqi@0 1457
aoqi@0 1458 bool MethodData::profile_arguments() {
aoqi@0 1459 return profile_arguments_flag() > no_type_profile && profile_arguments_flag() <= type_profile_all;
aoqi@0 1460 }
aoqi@0 1461
aoqi@0 1462 bool MethodData::profile_arguments_jsr292_only() {
aoqi@0 1463 return profile_arguments_flag() == type_profile_jsr292;
aoqi@0 1464 }
aoqi@0 1465
aoqi@0 1466 bool MethodData::profile_all_arguments() {
aoqi@0 1467 return profile_arguments_flag() == type_profile_all;
aoqi@0 1468 }
aoqi@0 1469
aoqi@0 1470 bool MethodData::profile_arguments_for_invoke(methodHandle m, int bci) {
aoqi@0 1471 if (!profile_arguments()) {
aoqi@0 1472 return false;
aoqi@0 1473 }
aoqi@0 1474
aoqi@0 1475 if (profile_all_arguments()) {
aoqi@0 1476 return true;
aoqi@0 1477 }
aoqi@0 1478
aoqi@0 1479 assert(profile_arguments_jsr292_only(), "inconsistent");
aoqi@0 1480 return profile_jsr292(m, bci);
aoqi@0 1481 }
aoqi@0 1482
aoqi@0 1483 int MethodData::profile_return_flag() {
aoqi@0 1484 return (TypeProfileLevel % 100) / 10;
aoqi@0 1485 }
aoqi@0 1486
aoqi@0 1487 bool MethodData::profile_return() {
aoqi@0 1488 return profile_return_flag() > no_type_profile && profile_return_flag() <= type_profile_all;
aoqi@0 1489 }
aoqi@0 1490
aoqi@0 1491 bool MethodData::profile_return_jsr292_only() {
aoqi@0 1492 return profile_return_flag() == type_profile_jsr292;
aoqi@0 1493 }
aoqi@0 1494
aoqi@0 1495 bool MethodData::profile_all_return() {
aoqi@0 1496 return profile_return_flag() == type_profile_all;
aoqi@0 1497 }
aoqi@0 1498
aoqi@0 1499 bool MethodData::profile_return_for_invoke(methodHandle m, int bci) {
aoqi@0 1500 if (!profile_return()) {
aoqi@0 1501 return false;
aoqi@0 1502 }
aoqi@0 1503
aoqi@0 1504 if (profile_all_return()) {
aoqi@0 1505 return true;
aoqi@0 1506 }
aoqi@0 1507
aoqi@0 1508 assert(profile_return_jsr292_only(), "inconsistent");
aoqi@0 1509 return profile_jsr292(m, bci);
aoqi@0 1510 }
aoqi@0 1511
aoqi@0 1512 int MethodData::profile_parameters_flag() {
aoqi@0 1513 return TypeProfileLevel / 100;
aoqi@0 1514 }
aoqi@0 1515
aoqi@0 1516 bool MethodData::profile_parameters() {
aoqi@0 1517 return profile_parameters_flag() > no_type_profile && profile_parameters_flag() <= type_profile_all;
aoqi@0 1518 }
aoqi@0 1519
aoqi@0 1520 bool MethodData::profile_parameters_jsr292_only() {
aoqi@0 1521 return profile_parameters_flag() == type_profile_jsr292;
aoqi@0 1522 }
aoqi@0 1523
aoqi@0 1524 bool MethodData::profile_all_parameters() {
aoqi@0 1525 return profile_parameters_flag() == type_profile_all;
aoqi@0 1526 }
aoqi@0 1527
aoqi@0 1528 bool MethodData::profile_parameters_for_method(methodHandle m) {
aoqi@0 1529 if (!profile_parameters()) {
aoqi@0 1530 return false;
aoqi@0 1531 }
aoqi@0 1532
aoqi@0 1533 if (profile_all_parameters()) {
aoqi@0 1534 return true;
aoqi@0 1535 }
aoqi@0 1536
aoqi@0 1537 assert(profile_parameters_jsr292_only(), "inconsistent");
aoqi@0 1538 return m->is_compiled_lambda_form();
aoqi@0 1539 }
aoqi@0 1540
aoqi@0 1541 void MethodData::clean_extra_data_helper(DataLayout* dp, int shift, bool reset) {
aoqi@0 1542 if (shift == 0) {
aoqi@0 1543 return;
aoqi@0 1544 }
aoqi@0 1545 if (!reset) {
aoqi@0 1546 // Move all cells of trap entry at dp left by "shift" cells
aoqi@0 1547 intptr_t* start = (intptr_t*)dp;
aoqi@0 1548 intptr_t* end = (intptr_t*)next_extra(dp);
aoqi@0 1549 for (intptr_t* ptr = start; ptr < end; ptr++) {
aoqi@0 1550 *(ptr-shift) = *ptr;
aoqi@0 1551 }
aoqi@0 1552 } else {
aoqi@0 1553 // Reset "shift" cells stopping at dp
aoqi@0 1554 intptr_t* start = ((intptr_t*)dp) - shift;
aoqi@0 1555 intptr_t* end = (intptr_t*)dp;
aoqi@0 1556 for (intptr_t* ptr = start; ptr < end; ptr++) {
aoqi@0 1557 *ptr = 0;
aoqi@0 1558 }
aoqi@0 1559 }
aoqi@0 1560 }
aoqi@0 1561
aoqi@0 1562 // Remove SpeculativeTrapData entries that reference an unloaded
aoqi@0 1563 // method
aoqi@0 1564 void MethodData::clean_extra_data(BoolObjectClosure* is_alive) {
aoqi@0 1565 DataLayout* dp = extra_data_base();
aoqi@0 1566 DataLayout* end = extra_data_limit();
aoqi@0 1567
aoqi@0 1568 int shift = 0;
aoqi@0 1569 for (; dp < end; dp = next_extra(dp)) {
aoqi@0 1570 switch(dp->tag()) {
aoqi@0 1571 case DataLayout::speculative_trap_data_tag: {
aoqi@0 1572 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
aoqi@0 1573 Method* m = data->method();
aoqi@0 1574 assert(m != NULL, "should have a method");
aoqi@0 1575 if (!m->method_holder()->is_loader_alive(is_alive)) {
aoqi@0 1576 // "shift" accumulates the number of cells for dead
aoqi@0 1577 // SpeculativeTrapData entries that have been seen so
aoqi@0 1578 // far. Following entries must be shifted left by that many
aoqi@0 1579 // cells to remove the dead SpeculativeTrapData entries.
aoqi@0 1580 shift += (int)((intptr_t*)next_extra(dp) - (intptr_t*)dp);
aoqi@0 1581 } else {
aoqi@0 1582 // Shift this entry left if it follows dead
aoqi@0 1583 // SpeculativeTrapData entries
aoqi@0 1584 clean_extra_data_helper(dp, shift);
aoqi@0 1585 }
aoqi@0 1586 break;
aoqi@0 1587 }
aoqi@0 1588 case DataLayout::bit_data_tag:
aoqi@0 1589 // Shift this entry left if it follows dead SpeculativeTrapData
aoqi@0 1590 // entries
aoqi@0 1591 clean_extra_data_helper(dp, shift);
aoqi@0 1592 continue;
aoqi@0 1593 case DataLayout::no_tag:
aoqi@0 1594 case DataLayout::arg_info_data_tag:
aoqi@0 1595 // We are at end of the live trap entries. The previous "shift"
aoqi@0 1596 // cells contain entries that are either dead or were shifted
aoqi@0 1597 // left. They need to be reset to no_tag
aoqi@0 1598 clean_extra_data_helper(dp, shift, true);
aoqi@0 1599 return;
aoqi@0 1600 default:
aoqi@0 1601 fatal(err_msg("unexpected tag %d", dp->tag()));
aoqi@0 1602 }
aoqi@0 1603 }
aoqi@0 1604 }
aoqi@0 1605
aoqi@0 1606 // Verify there's no unloaded method referenced by a
aoqi@0 1607 // SpeculativeTrapData entry
aoqi@0 1608 void MethodData::verify_extra_data_clean(BoolObjectClosure* is_alive) {
aoqi@0 1609 #ifdef ASSERT
aoqi@0 1610 DataLayout* dp = extra_data_base();
aoqi@0 1611 DataLayout* end = extra_data_limit();
aoqi@0 1612
aoqi@0 1613 for (; dp < end; dp = next_extra(dp)) {
aoqi@0 1614 switch(dp->tag()) {
aoqi@0 1615 case DataLayout::speculative_trap_data_tag: {
aoqi@0 1616 SpeculativeTrapData* data = new SpeculativeTrapData(dp);
aoqi@0 1617 Method* m = data->method();
aoqi@0 1618 assert(m != NULL && m->method_holder()->is_loader_alive(is_alive), "Method should exist");
aoqi@0 1619 break;
aoqi@0 1620 }
aoqi@0 1621 case DataLayout::bit_data_tag:
aoqi@0 1622 continue;
aoqi@0 1623 case DataLayout::no_tag:
aoqi@0 1624 case DataLayout::arg_info_data_tag:
aoqi@0 1625 return;
aoqi@0 1626 default:
aoqi@0 1627 fatal(err_msg("unexpected tag %d", dp->tag()));
aoqi@0 1628 }
aoqi@0 1629 }
aoqi@0 1630 #endif
aoqi@0 1631 }
aoqi@0 1632
aoqi@0 1633 void MethodData::clean_method_data(BoolObjectClosure* is_alive) {
aoqi@0 1634 for (ProfileData* data = first_data();
aoqi@0 1635 is_valid(data);
aoqi@0 1636 data = next_data(data)) {
aoqi@0 1637 data->clean_weak_klass_links(is_alive);
aoqi@0 1638 }
aoqi@0 1639 ParametersTypeData* parameters = parameters_type_data();
aoqi@0 1640 if (parameters != NULL) {
aoqi@0 1641 parameters->clean_weak_klass_links(is_alive);
aoqi@0 1642 }
aoqi@0 1643
aoqi@0 1644 clean_extra_data(is_alive);
aoqi@0 1645 verify_extra_data_clean(is_alive);
aoqi@0 1646 }

mercurial