src/share/vm/ci/ciReplay.cpp

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

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 9572
624a0741915c
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

phh@9507 1 /*
phh@9507 2 * Copyright (c) 2013, 2018, 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 "ci/ciMethodData.hpp"
aoqi@0 27 #include "ci/ciReplay.hpp"
aoqi@0 28 #include "ci/ciSymbol.hpp"
aoqi@0 29 #include "ci/ciKlass.hpp"
aoqi@0 30 #include "ci/ciUtilities.hpp"
aoqi@0 31 #include "compiler/compileBroker.hpp"
aoqi@0 32 #include "memory/allocation.inline.hpp"
aoqi@0 33 #include "memory/oopFactory.hpp"
aoqi@0 34 #include "memory/resourceArea.hpp"
aoqi@0 35 #include "utilities/copy.hpp"
aoqi@0 36 #include "utilities/macros.hpp"
aoqi@0 37
aoqi@0 38 #ifndef PRODUCT
aoqi@0 39
aoqi@0 40 // ciReplay
aoqi@0 41
aoqi@0 42 typedef struct _ciMethodDataRecord {
aoqi@0 43 const char* _klass_name;
aoqi@0 44 const char* _method_name;
aoqi@0 45 const char* _signature;
aoqi@0 46
aoqi@0 47 int _state;
aoqi@0 48 int _current_mileage;
aoqi@0 49
aoqi@0 50 intptr_t* _data;
aoqi@0 51 char* _orig_data;
aoqi@0 52 jobject* _oops_handles;
aoqi@0 53 int* _oops_offsets;
aoqi@0 54 int _data_length;
aoqi@0 55 int _orig_data_length;
aoqi@0 56 int _oops_length;
aoqi@0 57 } ciMethodDataRecord;
aoqi@0 58
aoqi@0 59 typedef struct _ciMethodRecord {
aoqi@0 60 const char* _klass_name;
aoqi@0 61 const char* _method_name;
aoqi@0 62 const char* _signature;
aoqi@0 63
aoqi@0 64 int _instructions_size;
aoqi@0 65 int _interpreter_invocation_count;
aoqi@0 66 int _interpreter_throwout_count;
aoqi@0 67 int _invocation_counter;
aoqi@0 68 int _backedge_counter;
aoqi@0 69 } ciMethodRecord;
aoqi@0 70
aoqi@0 71 typedef struct _ciInlineRecord {
aoqi@0 72 const char* _klass_name;
aoqi@0 73 const char* _method_name;
aoqi@0 74 const char* _signature;
aoqi@0 75
aoqi@0 76 int _inline_depth;
aoqi@0 77 int _inline_bci;
aoqi@0 78 } ciInlineRecord;
aoqi@0 79
aoqi@0 80 class CompileReplay;
aoqi@0 81 static CompileReplay* replay_state;
aoqi@0 82
aoqi@0 83 class CompileReplay : public StackObj {
aoqi@0 84 private:
aoqi@0 85 FILE* _stream;
aoqi@0 86 Thread* _thread;
aoqi@0 87 Handle _protection_domain;
aoqi@0 88 Handle _loader;
aoqi@0 89
aoqi@0 90 GrowableArray<ciMethodRecord*> _ci_method_records;
aoqi@0 91 GrowableArray<ciMethodDataRecord*> _ci_method_data_records;
aoqi@0 92
aoqi@0 93 // Use pointer because we may need to return inline records
aoqi@0 94 // without destroying them.
aoqi@0 95 GrowableArray<ciInlineRecord*>* _ci_inline_records;
aoqi@0 96
aoqi@0 97 const char* _error_message;
aoqi@0 98
aoqi@0 99 char* _bufptr;
aoqi@0 100 char* _buffer;
aoqi@0 101 int _buffer_length;
aoqi@0 102 int _buffer_pos;
aoqi@0 103
aoqi@0 104 // "compile" data
aoqi@0 105 ciKlass* _iklass;
aoqi@0 106 Method* _imethod;
aoqi@0 107 int _entry_bci;
aoqi@0 108 int _comp_level;
aoqi@0 109
aoqi@0 110 public:
aoqi@0 111 CompileReplay(const char* filename, TRAPS) {
aoqi@0 112 _thread = THREAD;
aoqi@0 113 _loader = Handle(_thread, SystemDictionary::java_system_loader());
aoqi@0 114 _protection_domain = Handle();
aoqi@0 115
aoqi@0 116 _stream = fopen(filename, "rt");
aoqi@0 117 if (_stream == NULL) {
aoqi@0 118 fprintf(stderr, "ERROR: Can't open replay file %s\n", filename);
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 _ci_inline_records = NULL;
aoqi@0 122 _error_message = NULL;
aoqi@0 123
aoqi@0 124 _buffer_length = 32;
aoqi@0 125 _buffer = NEW_RESOURCE_ARRAY(char, _buffer_length);
aoqi@0 126 _bufptr = _buffer;
aoqi@0 127 _buffer_pos = 0;
aoqi@0 128
aoqi@0 129 _imethod = NULL;
aoqi@0 130 _iklass = NULL;
aoqi@0 131 _entry_bci = 0;
aoqi@0 132 _comp_level = 0;
aoqi@0 133
aoqi@0 134 test();
aoqi@0 135 }
aoqi@0 136
aoqi@0 137 ~CompileReplay() {
aoqi@0 138 if (_stream != NULL) fclose(_stream);
aoqi@0 139 }
aoqi@0 140
aoqi@0 141 void test() {
aoqi@0 142 strcpy(_buffer, "1 2 foo 4 bar 0x9 \"this is it\"");
aoqi@0 143 _bufptr = _buffer;
aoqi@0 144 assert(parse_int("test") == 1, "what");
aoqi@0 145 assert(parse_int("test") == 2, "what");
aoqi@0 146 assert(strcmp(parse_string(), "foo") == 0, "what");
aoqi@0 147 assert(parse_int("test") == 4, "what");
aoqi@0 148 assert(strcmp(parse_string(), "bar") == 0, "what");
aoqi@0 149 assert(parse_intptr_t("test") == 9, "what");
aoqi@0 150 assert(strcmp(parse_quoted_string(), "this is it") == 0, "what");
aoqi@0 151 }
aoqi@0 152
aoqi@0 153 bool had_error() {
aoqi@0 154 return _error_message != NULL || _thread->has_pending_exception();
aoqi@0 155 }
aoqi@0 156
aoqi@0 157 bool can_replay() {
aoqi@0 158 return !(_stream == NULL || had_error());
aoqi@0 159 }
aoqi@0 160
aoqi@0 161 void report_error(const char* msg) {
aoqi@0 162 _error_message = msg;
aoqi@0 163 // Restore the _buffer contents for error reporting
aoqi@0 164 for (int i = 0; i < _buffer_pos; i++) {
aoqi@0 165 if (_buffer[i] == '\0') _buffer[i] = ' ';
aoqi@0 166 }
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 int parse_int(const char* label) {
aoqi@0 170 if (had_error()) {
aoqi@0 171 return 0;
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 int v = 0;
aoqi@0 175 int read;
aoqi@0 176 if (sscanf(_bufptr, "%i%n", &v, &read) != 1) {
aoqi@0 177 report_error(label);
aoqi@0 178 } else {
aoqi@0 179 _bufptr += read;
aoqi@0 180 }
aoqi@0 181 return v;
aoqi@0 182 }
aoqi@0 183
aoqi@0 184 intptr_t parse_intptr_t(const char* label) {
aoqi@0 185 if (had_error()) {
aoqi@0 186 return 0;
aoqi@0 187 }
aoqi@0 188
aoqi@0 189 intptr_t v = 0;
aoqi@0 190 int read;
aoqi@0 191 if (sscanf(_bufptr, INTPTR_FORMAT "%n", &v, &read) != 1) {
aoqi@0 192 report_error(label);
aoqi@0 193 } else {
aoqi@0 194 _bufptr += read;
aoqi@0 195 }
aoqi@0 196 return v;
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 void skip_ws() {
aoqi@0 200 // Skip any leading whitespace
aoqi@0 201 while (*_bufptr == ' ' || *_bufptr == '\t') {
aoqi@0 202 _bufptr++;
aoqi@0 203 }
aoqi@0 204 }
aoqi@0 205
aoqi@0 206
aoqi@0 207 char* scan_and_terminate(char delim) {
aoqi@0 208 char* str = _bufptr;
aoqi@0 209 while (*_bufptr != delim && *_bufptr != '\0') {
aoqi@0 210 _bufptr++;
aoqi@0 211 }
aoqi@0 212 if (*_bufptr != '\0') {
aoqi@0 213 *_bufptr++ = '\0';
aoqi@0 214 }
aoqi@0 215 if (_bufptr == str) {
aoqi@0 216 // nothing here
aoqi@0 217 return NULL;
aoqi@0 218 }
aoqi@0 219 return str;
aoqi@0 220 }
aoqi@0 221
aoqi@0 222 char* parse_string() {
aoqi@0 223 if (had_error()) return NULL;
aoqi@0 224
aoqi@0 225 skip_ws();
aoqi@0 226 return scan_and_terminate(' ');
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 char* parse_quoted_string() {
aoqi@0 230 if (had_error()) return NULL;
aoqi@0 231
aoqi@0 232 skip_ws();
aoqi@0 233
aoqi@0 234 if (*_bufptr == '"') {
aoqi@0 235 _bufptr++;
aoqi@0 236 return scan_and_terminate('"');
aoqi@0 237 } else {
aoqi@0 238 return scan_and_terminate(' ');
aoqi@0 239 }
aoqi@0 240 }
aoqi@0 241
aoqi@0 242 const char* parse_escaped_string() {
aoqi@0 243 char* result = parse_quoted_string();
aoqi@0 244 if (result != NULL) {
aoqi@0 245 unescape_string(result);
aoqi@0 246 }
aoqi@0 247 return result;
aoqi@0 248 }
aoqi@0 249
aoqi@0 250 // Look for the tag 'tag' followed by an
aoqi@0 251 bool parse_tag_and_count(const char* tag, int& length) {
aoqi@0 252 const char* t = parse_string();
aoqi@0 253 if (t == NULL) {
aoqi@0 254 return false;
aoqi@0 255 }
aoqi@0 256
aoqi@0 257 if (strcmp(tag, t) != 0) {
aoqi@0 258 report_error(tag);
aoqi@0 259 return false;
aoqi@0 260 }
aoqi@0 261 length = parse_int("parse_tag_and_count");
aoqi@0 262 return !had_error();
aoqi@0 263 }
aoqi@0 264
aoqi@0 265 // Parse a sequence of raw data encoded as bytes and return the
aoqi@0 266 // resulting data.
aoqi@0 267 char* parse_data(const char* tag, int& length) {
aoqi@0 268 if (!parse_tag_and_count(tag, length)) {
aoqi@0 269 return NULL;
aoqi@0 270 }
aoqi@0 271
aoqi@0 272 char * result = NEW_RESOURCE_ARRAY(char, length);
aoqi@0 273 for (int i = 0; i < length; i++) {
aoqi@0 274 int val = parse_int("data");
aoqi@0 275 result[i] = val;
aoqi@0 276 }
aoqi@0 277 return result;
aoqi@0 278 }
aoqi@0 279
aoqi@0 280 // Parse a standard chunk of data emitted as:
aoqi@0 281 // 'tag' <length> # # ...
aoqi@0 282 // Where each # is an intptr_t item
aoqi@0 283 intptr_t* parse_intptr_data(const char* tag, int& length) {
aoqi@0 284 if (!parse_tag_and_count(tag, length)) {
aoqi@0 285 return NULL;
aoqi@0 286 }
aoqi@0 287
aoqi@0 288 intptr_t* result = NEW_RESOURCE_ARRAY(intptr_t, length);
aoqi@0 289 for (int i = 0; i < length; i++) {
aoqi@0 290 skip_ws();
aoqi@0 291 intptr_t val = parse_intptr_t("data");
aoqi@0 292 result[i] = val;
aoqi@0 293 }
aoqi@0 294 return result;
aoqi@0 295 }
aoqi@0 296
aoqi@0 297 // Parse a possibly quoted version of a symbol into a symbolOop
aoqi@0 298 Symbol* parse_symbol(TRAPS) {
aoqi@0 299 const char* str = parse_escaped_string();
aoqi@0 300 if (str != NULL) {
aoqi@0 301 Symbol* sym = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
aoqi@0 302 return sym;
aoqi@0 303 }
aoqi@0 304 return NULL;
aoqi@0 305 }
aoqi@0 306
aoqi@0 307 // Parse a valid klass name and look it up
aoqi@0 308 Klass* parse_klass(TRAPS) {
aoqi@0 309 const char* str = parse_escaped_string();
aoqi@0 310 Symbol* klass_name = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
aoqi@0 311 if (klass_name != NULL) {
aoqi@0 312 Klass* k = NULL;
aoqi@0 313 if (_iklass != NULL) {
aoqi@0 314 k = (Klass*)_iklass->find_klass(ciSymbol::make(klass_name->as_C_string()))->constant_encoding();
aoqi@0 315 } else {
aoqi@0 316 k = SystemDictionary::resolve_or_fail(klass_name, _loader, _protection_domain, true, THREAD);
aoqi@0 317 }
aoqi@0 318 if (HAS_PENDING_EXCEPTION) {
aoqi@0 319 oop throwable = PENDING_EXCEPTION;
aoqi@0 320 java_lang_Throwable::print(throwable, tty);
aoqi@0 321 tty->cr();
aoqi@0 322 report_error(str);
aoqi@0 323 return NULL;
aoqi@0 324 }
aoqi@0 325 return k;
aoqi@0 326 }
aoqi@0 327 return NULL;
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 // Lookup a klass
aoqi@0 331 Klass* resolve_klass(const char* klass, TRAPS) {
aoqi@0 332 Symbol* klass_name = SymbolTable::lookup(klass, (int)strlen(klass), CHECK_NULL);
phh@9507 333 return SystemDictionary::resolve_or_fail(klass_name, _loader, _protection_domain, true, THREAD);
aoqi@0 334 }
aoqi@0 335
aoqi@0 336 // Parse the standard tuple of <klass> <name> <signature>
aoqi@0 337 Method* parse_method(TRAPS) {
aoqi@0 338 InstanceKlass* k = (InstanceKlass*)parse_klass(CHECK_NULL);
aoqi@0 339 Symbol* method_name = parse_symbol(CHECK_NULL);
aoqi@0 340 Symbol* method_signature = parse_symbol(CHECK_NULL);
aoqi@0 341 Method* m = k->find_method(method_name, method_signature);
aoqi@0 342 if (m == NULL) {
aoqi@0 343 report_error("Can't find method");
aoqi@0 344 }
aoqi@0 345 return m;
aoqi@0 346 }
aoqi@0 347
aoqi@0 348 int get_line(int c) {
aoqi@0 349 while(c != EOF) {
aoqi@0 350 if (_buffer_pos + 1 >= _buffer_length) {
aoqi@0 351 int new_length = _buffer_length * 2;
aoqi@0 352 // Next call will throw error in case of OOM.
aoqi@0 353 _buffer = REALLOC_RESOURCE_ARRAY(char, _buffer, _buffer_length, new_length);
aoqi@0 354 _buffer_length = new_length;
aoqi@0 355 }
aoqi@0 356 if (c == '\n') {
aoqi@0 357 c = getc(_stream); // get next char
aoqi@0 358 break;
aoqi@0 359 } else if (c == '\r') {
aoqi@0 360 // skip LF
aoqi@0 361 } else {
aoqi@0 362 _buffer[_buffer_pos++] = c;
aoqi@0 363 }
aoqi@0 364 c = getc(_stream);
aoqi@0 365 }
aoqi@0 366 // null terminate it, reset the pointer
aoqi@0 367 _buffer[_buffer_pos] = '\0'; // NL or EOF
aoqi@0 368 _buffer_pos = 0;
aoqi@0 369 _bufptr = _buffer;
aoqi@0 370 return c;
aoqi@0 371 }
aoqi@0 372
aoqi@0 373 // Process each line of the replay file executing each command until
aoqi@0 374 // the file ends.
aoqi@0 375 void process(TRAPS) {
aoqi@0 376 int line_no = 1;
aoqi@0 377 int c = getc(_stream);
aoqi@0 378 while(c != EOF) {
aoqi@0 379 c = get_line(c);
aoqi@0 380 process_command(THREAD);
aoqi@0 381 if (had_error()) {
aoqi@0 382 tty->print_cr("Error while parsing line %d: %s\n", line_no, _error_message);
aoqi@0 383 if (ReplayIgnoreInitErrors) {
aoqi@0 384 CLEAR_PENDING_EXCEPTION;
aoqi@0 385 _error_message = NULL;
aoqi@0 386 } else {
aoqi@0 387 return;
aoqi@0 388 }
aoqi@0 389 }
aoqi@0 390 line_no++;
aoqi@0 391 }
aoqi@0 392 }
aoqi@0 393
aoqi@0 394 void process_command(TRAPS) {
aoqi@0 395 char* cmd = parse_string();
aoqi@0 396 if (cmd == NULL) {
aoqi@0 397 return;
aoqi@0 398 }
aoqi@0 399 if (strcmp("#", cmd) == 0) {
aoqi@0 400 // ignore
aoqi@0 401 } else if (strcmp("compile", cmd) == 0) {
aoqi@0 402 process_compile(CHECK);
aoqi@0 403 } else if (strcmp("ciMethod", cmd) == 0) {
aoqi@0 404 process_ciMethod(CHECK);
aoqi@0 405 } else if (strcmp("ciMethodData", cmd) == 0) {
aoqi@0 406 process_ciMethodData(CHECK);
aoqi@0 407 } else if (strcmp("staticfield", cmd) == 0) {
aoqi@0 408 process_staticfield(CHECK);
aoqi@0 409 } else if (strcmp("ciInstanceKlass", cmd) == 0) {
aoqi@0 410 process_ciInstanceKlass(CHECK);
aoqi@0 411 } else if (strcmp("instanceKlass", cmd) == 0) {
aoqi@0 412 process_instanceKlass(CHECK);
aoqi@0 413 #if INCLUDE_JVMTI
aoqi@0 414 } else if (strcmp("JvmtiExport", cmd) == 0) {
aoqi@0 415 process_JvmtiExport(CHECK);
aoqi@0 416 #endif // INCLUDE_JVMTI
aoqi@0 417 } else {
aoqi@0 418 report_error("unknown command");
aoqi@0 419 }
aoqi@0 420 }
aoqi@0 421
aoqi@0 422 // validation of comp_level
aoqi@0 423 bool is_valid_comp_level(int comp_level) {
aoqi@0 424 const int msg_len = 256;
aoqi@0 425 char* msg = NULL;
aoqi@0 426 if (!is_compile(comp_level)) {
aoqi@0 427 msg = NEW_RESOURCE_ARRAY(char, msg_len);
aoqi@0 428 jio_snprintf(msg, msg_len, "%d isn't compilation level", comp_level);
aoqi@0 429 } else if (!TieredCompilation && (comp_level != CompLevel_highest_tier)) {
aoqi@0 430 msg = NEW_RESOURCE_ARRAY(char, msg_len);
aoqi@0 431 switch (comp_level) {
aoqi@0 432 case CompLevel_simple:
aoqi@0 433 jio_snprintf(msg, msg_len, "compilation level %d requires Client VM or TieredCompilation", comp_level);
aoqi@0 434 break;
aoqi@0 435 case CompLevel_full_optimization:
aoqi@0 436 jio_snprintf(msg, msg_len, "compilation level %d requires Server VM", comp_level);
aoqi@0 437 break;
aoqi@0 438 default:
aoqi@0 439 jio_snprintf(msg, msg_len, "compilation level %d requires TieredCompilation", comp_level);
aoqi@0 440 }
aoqi@0 441 }
aoqi@0 442 if (msg != NULL) {
aoqi@0 443 report_error(msg);
aoqi@0 444 return false;
aoqi@0 445 }
aoqi@0 446 return true;
aoqi@0 447 }
aoqi@0 448
aoqi@0 449 // compile <klass> <name> <signature> <entry_bci> <comp_level> inline <count> <depth> <bci> <klass> <name> <signature> ...
aoqi@0 450 void* process_inline(ciMethod* imethod, Method* m, int entry_bci, int comp_level, TRAPS) {
aoqi@0 451 _imethod = m;
aoqi@0 452 _iklass = imethod->holder();
aoqi@0 453 _entry_bci = entry_bci;
aoqi@0 454 _comp_level = comp_level;
aoqi@0 455 int line_no = 1;
aoqi@0 456 int c = getc(_stream);
aoqi@0 457 while(c != EOF) {
aoqi@0 458 c = get_line(c);
aoqi@0 459 // Expecting only lines with "compile" command in inline replay file.
aoqi@0 460 char* cmd = parse_string();
aoqi@0 461 if (cmd == NULL || strcmp("compile", cmd) != 0) {
aoqi@0 462 return NULL;
aoqi@0 463 }
aoqi@0 464 process_compile(CHECK_NULL);
aoqi@0 465 if (had_error()) {
aoqi@0 466 tty->print_cr("Error while parsing line %d: %s\n", line_no, _error_message);
aoqi@0 467 tty->print_cr("%s", _buffer);
aoqi@0 468 return NULL;
aoqi@0 469 }
aoqi@0 470 if (_ci_inline_records != NULL && _ci_inline_records->length() > 0) {
aoqi@0 471 // Found inlining record for the requested method.
aoqi@0 472 return _ci_inline_records;
aoqi@0 473 }
aoqi@0 474 line_no++;
aoqi@0 475 }
aoqi@0 476 return NULL;
aoqi@0 477 }
aoqi@0 478
aoqi@0 479 // compile <klass> <name> <signature> <entry_bci> <comp_level> inline <count> <depth> <bci> <klass> <name> <signature> ...
aoqi@0 480 void process_compile(TRAPS) {
aoqi@0 481 Method* method = parse_method(CHECK);
aoqi@0 482 if (had_error()) return;
aoqi@0 483 int entry_bci = parse_int("entry_bci");
aoqi@0 484 const char* comp_level_label = "comp_level";
aoqi@0 485 int comp_level = parse_int(comp_level_label);
aoqi@0 486 // old version w/o comp_level
aoqi@0 487 if (had_error() && (error_message() == comp_level_label)) {
aoqi@0 488 comp_level = CompLevel_full_optimization;
aoqi@0 489 }
aoqi@0 490 if (!is_valid_comp_level(comp_level)) {
aoqi@0 491 return;
aoqi@0 492 }
aoqi@0 493 if (_imethod != NULL) {
aoqi@0 494 // Replay Inlining
aoqi@0 495 if (entry_bci != _entry_bci || comp_level != _comp_level) {
aoqi@0 496 return;
aoqi@0 497 }
aoqi@0 498 const char* iklass_name = _imethod->method_holder()->name()->as_utf8();
aoqi@0 499 const char* imethod_name = _imethod->name()->as_utf8();
aoqi@0 500 const char* isignature = _imethod->signature()->as_utf8();
aoqi@0 501 const char* klass_name = method->method_holder()->name()->as_utf8();
aoqi@0 502 const char* method_name = method->name()->as_utf8();
aoqi@0 503 const char* signature = method->signature()->as_utf8();
aoqi@0 504 if (strcmp(iklass_name, klass_name) != 0 ||
aoqi@0 505 strcmp(imethod_name, method_name) != 0 ||
aoqi@0 506 strcmp(isignature, signature) != 0) {
aoqi@0 507 return;
aoqi@0 508 }
aoqi@0 509 }
aoqi@0 510 int inline_count = 0;
aoqi@0 511 if (parse_tag_and_count("inline", inline_count)) {
aoqi@0 512 // Record inlining data
aoqi@0 513 _ci_inline_records = new GrowableArray<ciInlineRecord*>();
aoqi@0 514 for (int i = 0; i < inline_count; i++) {
aoqi@0 515 int depth = parse_int("inline_depth");
aoqi@0 516 int bci = parse_int("inline_bci");
aoqi@0 517 if (had_error()) {
aoqi@0 518 break;
aoqi@0 519 }
aoqi@0 520 Method* inl_method = parse_method(CHECK);
aoqi@0 521 if (had_error()) {
aoqi@0 522 break;
aoqi@0 523 }
aoqi@0 524 new_ciInlineRecord(inl_method, bci, depth);
aoqi@0 525 }
aoqi@0 526 }
aoqi@0 527 if (_imethod != NULL) {
aoqi@0 528 return; // Replay Inlining
aoqi@0 529 }
aoqi@0 530 Klass* k = method->method_holder();
aoqi@0 531 ((InstanceKlass*)k)->initialize(THREAD);
aoqi@0 532 if (HAS_PENDING_EXCEPTION) {
aoqi@0 533 oop throwable = PENDING_EXCEPTION;
aoqi@0 534 java_lang_Throwable::print(throwable, tty);
aoqi@0 535 tty->cr();
aoqi@0 536 if (ReplayIgnoreInitErrors) {
aoqi@0 537 CLEAR_PENDING_EXCEPTION;
aoqi@0 538 ((InstanceKlass*)k)->set_init_state(InstanceKlass::fully_initialized);
aoqi@0 539 } else {
aoqi@0 540 return;
aoqi@0 541 }
aoqi@0 542 }
aoqi@0 543 // Make sure the existence of a prior compile doesn't stop this one
aoqi@0 544 nmethod* nm = (entry_bci != InvocationEntryBci) ? method->lookup_osr_nmethod_for(entry_bci, comp_level, true) : method->code();
aoqi@0 545 if (nm != NULL) {
aoqi@0 546 nm->make_not_entrant();
aoqi@0 547 }
aoqi@0 548 replay_state = this;
aoqi@0 549 CompileBroker::compile_method(method, entry_bci, comp_level,
aoqi@0 550 methodHandle(), 0, "replay", THREAD);
aoqi@0 551 replay_state = NULL;
aoqi@0 552 reset();
aoqi@0 553 }
aoqi@0 554
aoqi@0 555 // ciMethod <klass> <name> <signature> <invocation_counter> <backedge_counter> <interpreter_invocation_count> <interpreter_throwout_count> <instructions_size>
aoqi@0 556 //
aoqi@0 557 //
aoqi@0 558 void process_ciMethod(TRAPS) {
aoqi@0 559 Method* method = parse_method(CHECK);
aoqi@0 560 if (had_error()) return;
aoqi@0 561 ciMethodRecord* rec = new_ciMethod(method);
aoqi@0 562 rec->_invocation_counter = parse_int("invocation_counter");
aoqi@0 563 rec->_backedge_counter = parse_int("backedge_counter");
aoqi@0 564 rec->_interpreter_invocation_count = parse_int("interpreter_invocation_count");
aoqi@0 565 rec->_interpreter_throwout_count = parse_int("interpreter_throwout_count");
aoqi@0 566 rec->_instructions_size = parse_int("instructions_size");
aoqi@0 567 }
aoqi@0 568
aoqi@0 569 // ciMethodData <klass> <name> <signature> <state> <current mileage> orig <length> # # ... data <length> # # ... oops <length>
aoqi@0 570 void process_ciMethodData(TRAPS) {
aoqi@0 571 Method* method = parse_method(CHECK);
aoqi@0 572 if (had_error()) return;
aoqi@0 573 /* just copied from Method, to build interpret data*/
aoqi@0 574 if (InstanceRefKlass::owns_pending_list_lock((JavaThread*)THREAD)) {
aoqi@0 575 return;
aoqi@0 576 }
aoqi@0 577 // To be properly initialized, some profiling in the MDO needs the
aoqi@0 578 // method to be rewritten (number of arguments at a call for
aoqi@0 579 // instance)
aoqi@0 580 method->method_holder()->link_class(CHECK);
aoqi@0 581 // methodOopDesc::build_interpreter_method_data(method, CHECK);
aoqi@0 582 {
aoqi@0 583 // Grab a lock here to prevent multiple
aoqi@0 584 // MethodData*s from being created.
aoqi@0 585 MutexLocker ml(MethodData_lock, THREAD);
aoqi@0 586 if (method->method_data() == NULL) {
aoqi@0 587 ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
aoqi@0 588 MethodData* method_data = MethodData::allocate(loader_data, method, CHECK);
aoqi@0 589 method->set_method_data(method_data);
aoqi@0 590 }
aoqi@0 591 }
aoqi@0 592
aoqi@0 593 // collect and record all the needed information for later
aoqi@0 594 ciMethodDataRecord* rec = new_ciMethodData(method);
aoqi@0 595 rec->_state = parse_int("state");
aoqi@0 596 rec->_current_mileage = parse_int("current_mileage");
aoqi@0 597
aoqi@0 598 rec->_orig_data = parse_data("orig", rec->_orig_data_length);
aoqi@0 599 if (rec->_orig_data == NULL) {
aoqi@0 600 return;
aoqi@0 601 }
aoqi@0 602 rec->_data = parse_intptr_data("data", rec->_data_length);
aoqi@0 603 if (rec->_data == NULL) {
aoqi@0 604 return;
aoqi@0 605 }
aoqi@0 606 if (!parse_tag_and_count("oops", rec->_oops_length)) {
aoqi@0 607 return;
aoqi@0 608 }
aoqi@0 609 rec->_oops_handles = NEW_RESOURCE_ARRAY(jobject, rec->_oops_length);
aoqi@0 610 rec->_oops_offsets = NEW_RESOURCE_ARRAY(int, rec->_oops_length);
aoqi@0 611 for (int i = 0; i < rec->_oops_length; i++) {
aoqi@0 612 int offset = parse_int("offset");
aoqi@0 613 if (had_error()) {
aoqi@0 614 return;
aoqi@0 615 }
aoqi@0 616 Klass* k = parse_klass(CHECK);
aoqi@0 617 rec->_oops_offsets[i] = offset;
aoqi@0 618 KlassHandle *kh = NEW_C_HEAP_OBJ(KlassHandle, mtCompiler);
aoqi@0 619 ::new ((void*)kh) KlassHandle(THREAD, k);
aoqi@0 620 rec->_oops_handles[i] = (jobject)kh;
aoqi@0 621 }
aoqi@0 622 }
aoqi@0 623
aoqi@0 624 // instanceKlass <name>
aoqi@0 625 //
aoqi@0 626 // Loads and initializes the klass 'name'. This can be used to
aoqi@0 627 // create particular class loading environments
aoqi@0 628 void process_instanceKlass(TRAPS) {
aoqi@0 629 // just load the referenced class
aoqi@0 630 Klass* k = parse_klass(CHECK);
aoqi@0 631 }
aoqi@0 632
aoqi@0 633 // ciInstanceKlass <name> <is_linked> <is_initialized> <length> tag # # # ...
aoqi@0 634 //
aoqi@0 635 // Load the klass 'name' and link or initialize it. Verify that the
aoqi@0 636 // constant pool is the same length as 'length' and make sure the
aoqi@0 637 // constant pool tags are in the same state.
aoqi@0 638 void process_ciInstanceKlass(TRAPS) {
aoqi@0 639 InstanceKlass* k = (InstanceKlass *)parse_klass(CHECK);
aoqi@0 640 int is_linked = parse_int("is_linked");
aoqi@0 641 int is_initialized = parse_int("is_initialized");
aoqi@0 642 int length = parse_int("length");
aoqi@0 643 if (is_initialized) {
aoqi@0 644 k->initialize(THREAD);
aoqi@0 645 if (HAS_PENDING_EXCEPTION) {
aoqi@0 646 oop throwable = PENDING_EXCEPTION;
aoqi@0 647 java_lang_Throwable::print(throwable, tty);
aoqi@0 648 tty->cr();
aoqi@0 649 if (ReplayIgnoreInitErrors) {
aoqi@0 650 CLEAR_PENDING_EXCEPTION;
aoqi@0 651 k->set_init_state(InstanceKlass::fully_initialized);
aoqi@0 652 } else {
aoqi@0 653 return;
aoqi@0 654 }
aoqi@0 655 }
aoqi@0 656 } else if (is_linked) {
aoqi@0 657 k->link_class(CHECK);
aoqi@0 658 }
aoqi@0 659 ConstantPool* cp = k->constants();
aoqi@0 660 if (length != cp->length()) {
aoqi@0 661 report_error("constant pool length mismatch: wrong class files?");
aoqi@0 662 return;
aoqi@0 663 }
aoqi@0 664
aoqi@0 665 int parsed_two_word = 0;
aoqi@0 666 for (int i = 1; i < length; i++) {
aoqi@0 667 int tag = parse_int("tag");
aoqi@0 668 if (had_error()) {
aoqi@0 669 return;
aoqi@0 670 }
aoqi@0 671 switch (cp->tag_at(i).value()) {
aoqi@0 672 case JVM_CONSTANT_UnresolvedClass: {
aoqi@0 673 if (tag == JVM_CONSTANT_Class) {
aoqi@0 674 tty->print_cr("Resolving klass %s at %d", cp->unresolved_klass_at(i)->as_utf8(), i);
aoqi@0 675 Klass* k = cp->klass_at(i, CHECK);
aoqi@0 676 }
aoqi@0 677 break;
aoqi@0 678 }
aoqi@0 679 case JVM_CONSTANT_Long:
aoqi@0 680 case JVM_CONSTANT_Double:
aoqi@0 681 parsed_two_word = i + 1;
aoqi@0 682
aoqi@0 683 case JVM_CONSTANT_ClassIndex:
aoqi@0 684 case JVM_CONSTANT_StringIndex:
aoqi@0 685 case JVM_CONSTANT_String:
aoqi@0 686 case JVM_CONSTANT_UnresolvedClassInError:
aoqi@0 687 case JVM_CONSTANT_Fieldref:
aoqi@0 688 case JVM_CONSTANT_Methodref:
aoqi@0 689 case JVM_CONSTANT_InterfaceMethodref:
aoqi@0 690 case JVM_CONSTANT_NameAndType:
aoqi@0 691 case JVM_CONSTANT_Utf8:
aoqi@0 692 case JVM_CONSTANT_Integer:
aoqi@0 693 case JVM_CONSTANT_Float:
aoqi@0 694 case JVM_CONSTANT_MethodHandle:
aoqi@0 695 case JVM_CONSTANT_MethodType:
aoqi@0 696 case JVM_CONSTANT_InvokeDynamic:
aoqi@0 697 if (tag != cp->tag_at(i).value()) {
aoqi@0 698 report_error("tag mismatch: wrong class files?");
aoqi@0 699 return;
aoqi@0 700 }
aoqi@0 701 break;
aoqi@0 702
aoqi@0 703 case JVM_CONSTANT_Class:
aoqi@0 704 if (tag == JVM_CONSTANT_Class) {
aoqi@0 705 } else if (tag == JVM_CONSTANT_UnresolvedClass) {
aoqi@0 706 tty->print_cr("Warning: entry was unresolved in the replay data");
aoqi@0 707 } else {
aoqi@0 708 report_error("Unexpected tag");
aoqi@0 709 return;
aoqi@0 710 }
aoqi@0 711 break;
aoqi@0 712
aoqi@0 713 case 0:
aoqi@0 714 if (parsed_two_word == i) continue;
aoqi@0 715
aoqi@0 716 default:
aoqi@0 717 fatal(err_msg_res("Unexpected tag: %d", cp->tag_at(i).value()));
aoqi@0 718 break;
aoqi@0 719 }
aoqi@0 720
aoqi@0 721 }
aoqi@0 722 }
aoqi@0 723
aoqi@0 724 // Initialize a class and fill in the value for a static field.
aoqi@0 725 // This is useful when the compile was dependent on the value of
aoqi@0 726 // static fields but it's impossible to properly rerun the static
aoqi@0 727 // initiailizer.
aoqi@0 728 void process_staticfield(TRAPS) {
aoqi@0 729 InstanceKlass* k = (InstanceKlass *)parse_klass(CHECK);
aoqi@0 730
aoqi@0 731 if (ReplaySuppressInitializers == 0 ||
aoqi@0 732 ReplaySuppressInitializers == 2 && k->class_loader() == NULL) {
aoqi@0 733 return;
aoqi@0 734 }
aoqi@0 735
aoqi@0 736 assert(k->is_initialized(), "must be");
aoqi@0 737
aoqi@0 738 const char* field_name = parse_escaped_string();;
aoqi@0 739 const char* field_signature = parse_string();
aoqi@0 740 fieldDescriptor fd;
aoqi@0 741 Symbol* name = SymbolTable::lookup(field_name, (int)strlen(field_name), CHECK);
aoqi@0 742 Symbol* sig = SymbolTable::lookup(field_signature, (int)strlen(field_signature), CHECK);
aoqi@0 743 if (!k->find_local_field(name, sig, &fd) ||
aoqi@0 744 !fd.is_static() ||
aoqi@0 745 fd.has_initial_value()) {
aoqi@0 746 report_error(field_name);
aoqi@0 747 return;
aoqi@0 748 }
aoqi@0 749
aoqi@0 750 oop java_mirror = k->java_mirror();
aoqi@0 751 if (field_signature[0] == '[') {
aoqi@0 752 int length = parse_int("array length");
aoqi@0 753 oop value = NULL;
aoqi@0 754
aoqi@0 755 if (field_signature[1] == '[') {
aoqi@0 756 // multi dimensional array
aoqi@0 757 ArrayKlass* kelem = (ArrayKlass *)parse_klass(CHECK);
aoqi@0 758 int rank = 0;
aoqi@0 759 while (field_signature[rank] == '[') {
aoqi@0 760 rank++;
aoqi@0 761 }
aoqi@0 762 int* dims = NEW_RESOURCE_ARRAY(int, rank);
aoqi@0 763 dims[0] = length;
aoqi@0 764 for (int i = 1; i < rank; i++) {
aoqi@0 765 dims[i] = 1; // These aren't relevant to the compiler
aoqi@0 766 }
aoqi@0 767 value = kelem->multi_allocate(rank, dims, CHECK);
aoqi@0 768 } else {
aoqi@0 769 if (strcmp(field_signature, "[B") == 0) {
aoqi@0 770 value = oopFactory::new_byteArray(length, CHECK);
aoqi@0 771 } else if (strcmp(field_signature, "[Z") == 0) {
aoqi@0 772 value = oopFactory::new_boolArray(length, CHECK);
aoqi@0 773 } else if (strcmp(field_signature, "[C") == 0) {
aoqi@0 774 value = oopFactory::new_charArray(length, CHECK);
aoqi@0 775 } else if (strcmp(field_signature, "[S") == 0) {
aoqi@0 776 value = oopFactory::new_shortArray(length, CHECK);
aoqi@0 777 } else if (strcmp(field_signature, "[F") == 0) {
aoqi@0 778 value = oopFactory::new_singleArray(length, CHECK);
aoqi@0 779 } else if (strcmp(field_signature, "[D") == 0) {
aoqi@0 780 value = oopFactory::new_doubleArray(length, CHECK);
aoqi@0 781 } else if (strcmp(field_signature, "[I") == 0) {
aoqi@0 782 value = oopFactory::new_intArray(length, CHECK);
aoqi@0 783 } else if (strcmp(field_signature, "[J") == 0) {
aoqi@0 784 value = oopFactory::new_longArray(length, CHECK);
aoqi@0 785 } else if (field_signature[0] == '[' && field_signature[1] == 'L') {
aoqi@0 786 KlassHandle kelem = resolve_klass(field_signature + 1, CHECK);
aoqi@0 787 value = oopFactory::new_objArray(kelem(), length, CHECK);
aoqi@0 788 } else {
aoqi@0 789 report_error("unhandled array staticfield");
aoqi@0 790 }
aoqi@0 791 }
aoqi@0 792 java_mirror->obj_field_put(fd.offset(), value);
aoqi@0 793 } else {
aoqi@0 794 const char* string_value = parse_escaped_string();
aoqi@0 795 if (strcmp(field_signature, "I") == 0) {
aoqi@0 796 int value = atoi(string_value);
aoqi@0 797 java_mirror->int_field_put(fd.offset(), value);
aoqi@0 798 } else if (strcmp(field_signature, "B") == 0) {
aoqi@0 799 int value = atoi(string_value);
aoqi@0 800 java_mirror->byte_field_put(fd.offset(), value);
aoqi@0 801 } else if (strcmp(field_signature, "C") == 0) {
aoqi@0 802 int value = atoi(string_value);
aoqi@0 803 java_mirror->char_field_put(fd.offset(), value);
aoqi@0 804 } else if (strcmp(field_signature, "S") == 0) {
aoqi@0 805 int value = atoi(string_value);
aoqi@0 806 java_mirror->short_field_put(fd.offset(), value);
aoqi@0 807 } else if (strcmp(field_signature, "Z") == 0) {
aoqi@0 808 int value = atol(string_value);
aoqi@0 809 java_mirror->bool_field_put(fd.offset(), value);
aoqi@0 810 } else if (strcmp(field_signature, "J") == 0) {
aoqi@0 811 jlong value;
aoqi@0 812 if (sscanf(string_value, JLONG_FORMAT, &value) != 1) {
aoqi@0 813 fprintf(stderr, "Error parsing long: %s\n", string_value);
aoqi@0 814 return;
aoqi@0 815 }
aoqi@0 816 java_mirror->long_field_put(fd.offset(), value);
aoqi@0 817 } else if (strcmp(field_signature, "F") == 0) {
aoqi@0 818 float value = atof(string_value);
aoqi@0 819 java_mirror->float_field_put(fd.offset(), value);
aoqi@0 820 } else if (strcmp(field_signature, "D") == 0) {
aoqi@0 821 double value = atof(string_value);
aoqi@0 822 java_mirror->double_field_put(fd.offset(), value);
aoqi@0 823 } else if (strcmp(field_signature, "Ljava/lang/String;") == 0) {
aoqi@0 824 Handle value = java_lang_String::create_from_str(string_value, CHECK);
aoqi@0 825 java_mirror->obj_field_put(fd.offset(), value());
aoqi@0 826 } else if (field_signature[0] == 'L') {
aoqi@0 827 Symbol* klass_name = SymbolTable::lookup(field_signature, (int)strlen(field_signature), CHECK);
aoqi@0 828 KlassHandle kelem = resolve_klass(field_signature, CHECK);
aoqi@0 829 oop value = ((InstanceKlass*)kelem())->allocate_instance(CHECK);
aoqi@0 830 java_mirror->obj_field_put(fd.offset(), value);
aoqi@0 831 } else {
aoqi@0 832 report_error("unhandled staticfield");
aoqi@0 833 }
aoqi@0 834 }
aoqi@0 835 }
aoqi@0 836
aoqi@0 837 #if INCLUDE_JVMTI
aoqi@0 838 void process_JvmtiExport(TRAPS) {
aoqi@0 839 const char* field = parse_string();
aoqi@0 840 bool value = parse_int("JvmtiExport flag") != 0;
aoqi@0 841 if (strcmp(field, "can_access_local_variables") == 0) {
aoqi@0 842 JvmtiExport::set_can_access_local_variables(value);
aoqi@0 843 } else if (strcmp(field, "can_hotswap_or_post_breakpoint") == 0) {
aoqi@0 844 JvmtiExport::set_can_hotswap_or_post_breakpoint(value);
aoqi@0 845 } else if (strcmp(field, "can_post_on_exceptions") == 0) {
aoqi@0 846 JvmtiExport::set_can_post_on_exceptions(value);
aoqi@0 847 } else {
aoqi@0 848 report_error("Unrecognized JvmtiExport directive");
aoqi@0 849 }
aoqi@0 850 }
aoqi@0 851 #endif // INCLUDE_JVMTI
aoqi@0 852
aoqi@0 853 // Create and initialize a record for a ciMethod
aoqi@0 854 ciMethodRecord* new_ciMethod(Method* method) {
aoqi@0 855 ciMethodRecord* rec = NEW_RESOURCE_OBJ(ciMethodRecord);
aoqi@0 856 rec->_klass_name = method->method_holder()->name()->as_utf8();
aoqi@0 857 rec->_method_name = method->name()->as_utf8();
aoqi@0 858 rec->_signature = method->signature()->as_utf8();
aoqi@0 859 _ci_method_records.append(rec);
aoqi@0 860 return rec;
aoqi@0 861 }
aoqi@0 862
aoqi@0 863 // Lookup data for a ciMethod
aoqi@0 864 ciMethodRecord* find_ciMethodRecord(Method* method) {
aoqi@0 865 const char* klass_name = method->method_holder()->name()->as_utf8();
aoqi@0 866 const char* method_name = method->name()->as_utf8();
aoqi@0 867 const char* signature = method->signature()->as_utf8();
aoqi@0 868 for (int i = 0; i < _ci_method_records.length(); i++) {
aoqi@0 869 ciMethodRecord* rec = _ci_method_records.at(i);
aoqi@0 870 if (strcmp(rec->_klass_name, klass_name) == 0 &&
aoqi@0 871 strcmp(rec->_method_name, method_name) == 0 &&
aoqi@0 872 strcmp(rec->_signature, signature) == 0) {
aoqi@0 873 return rec;
aoqi@0 874 }
aoqi@0 875 }
aoqi@0 876 return NULL;
aoqi@0 877 }
aoqi@0 878
aoqi@0 879 // Create and initialize a record for a ciMethodData
aoqi@0 880 ciMethodDataRecord* new_ciMethodData(Method* method) {
aoqi@0 881 ciMethodDataRecord* rec = NEW_RESOURCE_OBJ(ciMethodDataRecord);
aoqi@0 882 rec->_klass_name = method->method_holder()->name()->as_utf8();
aoqi@0 883 rec->_method_name = method->name()->as_utf8();
aoqi@0 884 rec->_signature = method->signature()->as_utf8();
aoqi@0 885 _ci_method_data_records.append(rec);
aoqi@0 886 return rec;
aoqi@0 887 }
aoqi@0 888
aoqi@0 889 // Lookup data for a ciMethodData
aoqi@0 890 ciMethodDataRecord* find_ciMethodDataRecord(Method* method) {
aoqi@0 891 const char* klass_name = method->method_holder()->name()->as_utf8();
aoqi@0 892 const char* method_name = method->name()->as_utf8();
aoqi@0 893 const char* signature = method->signature()->as_utf8();
aoqi@0 894 for (int i = 0; i < _ci_method_data_records.length(); i++) {
aoqi@0 895 ciMethodDataRecord* rec = _ci_method_data_records.at(i);
aoqi@0 896 if (strcmp(rec->_klass_name, klass_name) == 0 &&
aoqi@0 897 strcmp(rec->_method_name, method_name) == 0 &&
aoqi@0 898 strcmp(rec->_signature, signature) == 0) {
aoqi@0 899 return rec;
aoqi@0 900 }
aoqi@0 901 }
aoqi@0 902 return NULL;
aoqi@0 903 }
aoqi@0 904
aoqi@0 905 // Create and initialize a record for a ciInlineRecord
aoqi@0 906 ciInlineRecord* new_ciInlineRecord(Method* method, int bci, int depth) {
aoqi@0 907 ciInlineRecord* rec = NEW_RESOURCE_OBJ(ciInlineRecord);
aoqi@0 908 rec->_klass_name = method->method_holder()->name()->as_utf8();
aoqi@0 909 rec->_method_name = method->name()->as_utf8();
aoqi@0 910 rec->_signature = method->signature()->as_utf8();
aoqi@0 911 rec->_inline_bci = bci;
aoqi@0 912 rec->_inline_depth = depth;
aoqi@0 913 _ci_inline_records->append(rec);
aoqi@0 914 return rec;
aoqi@0 915 }
aoqi@0 916
aoqi@0 917 // Lookup inlining data for a ciMethod
aoqi@0 918 ciInlineRecord* find_ciInlineRecord(Method* method, int bci, int depth) {
aoqi@0 919 if (_ci_inline_records != NULL) {
aoqi@0 920 return find_ciInlineRecord(_ci_inline_records, method, bci, depth);
aoqi@0 921 }
aoqi@0 922 return NULL;
aoqi@0 923 }
aoqi@0 924
aoqi@0 925 static ciInlineRecord* find_ciInlineRecord(GrowableArray<ciInlineRecord*>* records,
aoqi@0 926 Method* method, int bci, int depth) {
aoqi@0 927 if (records != NULL) {
aoqi@0 928 const char* klass_name = method->method_holder()->name()->as_utf8();
aoqi@0 929 const char* method_name = method->name()->as_utf8();
aoqi@0 930 const char* signature = method->signature()->as_utf8();
aoqi@0 931 for (int i = 0; i < records->length(); i++) {
aoqi@0 932 ciInlineRecord* rec = records->at(i);
aoqi@0 933 if ((rec->_inline_bci == bci) &&
aoqi@0 934 (rec->_inline_depth == depth) &&
aoqi@0 935 (strcmp(rec->_klass_name, klass_name) == 0) &&
aoqi@0 936 (strcmp(rec->_method_name, method_name) == 0) &&
aoqi@0 937 (strcmp(rec->_signature, signature) == 0)) {
aoqi@0 938 return rec;
aoqi@0 939 }
aoqi@0 940 }
aoqi@0 941 }
aoqi@0 942 return NULL;
aoqi@0 943 }
aoqi@0 944
aoqi@0 945 const char* error_message() {
aoqi@0 946 return _error_message;
aoqi@0 947 }
aoqi@0 948
aoqi@0 949 void reset() {
aoqi@0 950 _error_message = NULL;
aoqi@0 951 _ci_method_records.clear();
aoqi@0 952 _ci_method_data_records.clear();
aoqi@0 953 }
aoqi@0 954
aoqi@0 955 // Take an ascii string contain \u#### escapes and convert it to utf8
aoqi@0 956 // in place.
aoqi@0 957 static void unescape_string(char* value) {
aoqi@0 958 char* from = value;
aoqi@0 959 char* to = value;
aoqi@0 960 while (*from != '\0') {
aoqi@0 961 if (*from != '\\') {
aoqi@0 962 *from++ = *to++;
aoqi@0 963 } else {
aoqi@0 964 switch (from[1]) {
aoqi@0 965 case 'u': {
aoqi@0 966 from += 2;
aoqi@0 967 jchar value=0;
aoqi@0 968 for (int i=0; i<4; i++) {
aoqi@0 969 char c = *from++;
aoqi@0 970 switch (c) {
aoqi@0 971 case '0': case '1': case '2': case '3': case '4':
aoqi@0 972 case '5': case '6': case '7': case '8': case '9':
aoqi@0 973 value = (value << 4) + c - '0';
aoqi@0 974 break;
aoqi@0 975 case 'a': case 'b': case 'c':
aoqi@0 976 case 'd': case 'e': case 'f':
aoqi@0 977 value = (value << 4) + 10 + c - 'a';
aoqi@0 978 break;
aoqi@0 979 case 'A': case 'B': case 'C':
aoqi@0 980 case 'D': case 'E': case 'F':
aoqi@0 981 value = (value << 4) + 10 + c - 'A';
aoqi@0 982 break;
aoqi@0 983 default:
aoqi@0 984 ShouldNotReachHere();
aoqi@0 985 }
aoqi@0 986 }
aoqi@0 987 UNICODE::convert_to_utf8(&value, 1, to);
aoqi@0 988 to++;
aoqi@0 989 break;
aoqi@0 990 }
aoqi@0 991 case 't': *to++ = '\t'; from += 2; break;
aoqi@0 992 case 'n': *to++ = '\n'; from += 2; break;
aoqi@0 993 case 'r': *to++ = '\r'; from += 2; break;
aoqi@0 994 case 'f': *to++ = '\f'; from += 2; break;
aoqi@0 995 default:
aoqi@0 996 ShouldNotReachHere();
aoqi@0 997 }
aoqi@0 998 }
aoqi@0 999 }
aoqi@0 1000 *from = *to;
aoqi@0 1001 }
aoqi@0 1002 };
aoqi@0 1003
aoqi@0 1004 void ciReplay::replay(TRAPS) {
aoqi@0 1005 int exit_code = replay_impl(THREAD);
aoqi@0 1006
aoqi@0 1007 Threads::destroy_vm();
aoqi@0 1008
aoqi@0 1009 vm_exit(exit_code);
aoqi@0 1010 }
aoqi@0 1011
aoqi@0 1012 void* ciReplay::load_inline_data(ciMethod* method, int entry_bci, int comp_level) {
aoqi@0 1013 if (FLAG_IS_DEFAULT(InlineDataFile)) {
aoqi@0 1014 tty->print_cr("ERROR: no inline replay data file specified (use -XX:InlineDataFile=inline_pid12345.txt).");
aoqi@0 1015 return NULL;
aoqi@0 1016 }
aoqi@0 1017
aoqi@0 1018 VM_ENTRY_MARK;
aoqi@0 1019 // Load and parse the replay data
aoqi@0 1020 CompileReplay rp(InlineDataFile, THREAD);
aoqi@0 1021 if (!rp.can_replay()) {
aoqi@0 1022 tty->print_cr("ciReplay: !rp.can_replay()");
aoqi@0 1023 return NULL;
aoqi@0 1024 }
aoqi@0 1025 void* data = rp.process_inline(method, method->get_Method(), entry_bci, comp_level, THREAD);
aoqi@0 1026 if (HAS_PENDING_EXCEPTION) {
aoqi@0 1027 oop throwable = PENDING_EXCEPTION;
aoqi@0 1028 CLEAR_PENDING_EXCEPTION;
aoqi@0 1029 java_lang_Throwable::print(throwable, tty);
aoqi@0 1030 tty->cr();
aoqi@0 1031 java_lang_Throwable::print_stack_trace(throwable, tty);
aoqi@0 1032 tty->cr();
aoqi@0 1033 return NULL;
aoqi@0 1034 }
aoqi@0 1035
aoqi@0 1036 if (rp.had_error()) {
aoqi@0 1037 tty->print_cr("ciReplay: Failed on %s", rp.error_message());
aoqi@0 1038 return NULL;
aoqi@0 1039 }
aoqi@0 1040 return data;
aoqi@0 1041 }
aoqi@0 1042
aoqi@0 1043 int ciReplay::replay_impl(TRAPS) {
aoqi@0 1044 HandleMark hm;
aoqi@0 1045 ResourceMark rm;
aoqi@0 1046 // Make sure we don't run with background compilation
aoqi@0 1047 BackgroundCompilation = false;
aoqi@0 1048
aoqi@0 1049 if (ReplaySuppressInitializers > 2) {
aoqi@0 1050 // ReplaySuppressInitializers > 2 means that we want to allow
aoqi@0 1051 // normal VM bootstrap but once we get into the replay itself
aoqi@0 1052 // don't allow any intializers to be run.
aoqi@0 1053 ReplaySuppressInitializers = 1;
aoqi@0 1054 }
aoqi@0 1055
aoqi@0 1056 if (FLAG_IS_DEFAULT(ReplayDataFile)) {
aoqi@0 1057 tty->print_cr("ERROR: no compiler replay data file specified (use -XX:ReplayDataFile=replay_pid12345.txt).");
aoqi@0 1058 return 1;
aoqi@0 1059 }
aoqi@0 1060
aoqi@0 1061 // Load and parse the replay data
aoqi@0 1062 CompileReplay rp(ReplayDataFile, THREAD);
aoqi@0 1063 int exit_code = 0;
aoqi@0 1064 if (rp.can_replay()) {
aoqi@0 1065 rp.process(THREAD);
aoqi@0 1066 } else {
aoqi@0 1067 exit_code = 1;
aoqi@0 1068 return exit_code;
aoqi@0 1069 }
aoqi@0 1070
aoqi@0 1071 if (HAS_PENDING_EXCEPTION) {
aoqi@0 1072 oop throwable = PENDING_EXCEPTION;
aoqi@0 1073 CLEAR_PENDING_EXCEPTION;
aoqi@0 1074 java_lang_Throwable::print(throwable, tty);
aoqi@0 1075 tty->cr();
aoqi@0 1076 java_lang_Throwable::print_stack_trace(throwable, tty);
aoqi@0 1077 tty->cr();
aoqi@0 1078 exit_code = 2;
aoqi@0 1079 }
aoqi@0 1080
aoqi@0 1081 if (rp.had_error()) {
aoqi@0 1082 tty->print_cr("Failed on %s", rp.error_message());
aoqi@0 1083 exit_code = 1;
aoqi@0 1084 }
aoqi@0 1085 return exit_code;
aoqi@0 1086 }
aoqi@0 1087
aoqi@0 1088 void ciReplay::initialize(ciMethodData* m) {
aoqi@0 1089 if (replay_state == NULL) {
aoqi@0 1090 return;
aoqi@0 1091 }
aoqi@0 1092
aoqi@0 1093 ASSERT_IN_VM;
aoqi@0 1094 ResourceMark rm;
aoqi@0 1095
aoqi@0 1096 Method* method = m->get_MethodData()->method();
aoqi@0 1097 ciMethodDataRecord* rec = replay_state->find_ciMethodDataRecord(method);
aoqi@0 1098 if (rec == NULL) {
aoqi@0 1099 // This indicates some mismatch with the original environment and
aoqi@0 1100 // the replay environment though it's not always enough to
aoqi@0 1101 // interfere with reproducing a bug
aoqi@0 1102 tty->print_cr("Warning: requesting ciMethodData record for method with no data: ");
aoqi@0 1103 method->print_name(tty);
aoqi@0 1104 tty->cr();
aoqi@0 1105 } else {
aoqi@0 1106 m->_state = rec->_state;
aoqi@0 1107 m->_current_mileage = rec->_current_mileage;
aoqi@0 1108 if (rec->_data_length != 0) {
aoqi@0 1109 assert(m->_data_size == rec->_data_length * (int)sizeof(rec->_data[0]), "must agree");
aoqi@0 1110
aoqi@0 1111 // Write the correct ciObjects back into the profile data
aoqi@0 1112 ciEnv* env = ciEnv::current();
aoqi@0 1113 for (int i = 0; i < rec->_oops_length; i++) {
aoqi@0 1114 KlassHandle *h = (KlassHandle *)rec->_oops_handles[i];
aoqi@0 1115 *(ciMetadata**)(rec->_data + rec->_oops_offsets[i]) =
aoqi@0 1116 env->get_metadata((*h)());
aoqi@0 1117 }
aoqi@0 1118 // Copy the updated profile data into place as intptr_ts
aoqi@0 1119 #ifdef _LP64
aoqi@0 1120 Copy::conjoint_jlongs_atomic((jlong *)rec->_data, (jlong *)m->_data, rec->_data_length);
aoqi@0 1121 #else
aoqi@0 1122 Copy::conjoint_jints_atomic((jint *)rec->_data, (jint *)m->_data, rec->_data_length);
aoqi@0 1123 #endif
aoqi@0 1124 }
aoqi@0 1125
aoqi@0 1126 // copy in the original header
aoqi@0 1127 Copy::conjoint_jbytes(rec->_orig_data, (char*)&m->_orig, rec->_orig_data_length);
aoqi@0 1128 }
aoqi@0 1129 }
aoqi@0 1130
aoqi@0 1131
aoqi@0 1132 bool ciReplay::should_not_inline(ciMethod* method) {
aoqi@0 1133 if (replay_state == NULL) {
aoqi@0 1134 return false;
aoqi@0 1135 }
aoqi@0 1136 VM_ENTRY_MARK;
aoqi@0 1137 // ciMethod without a record shouldn't be inlined.
aoqi@0 1138 return replay_state->find_ciMethodRecord(method->get_Method()) == NULL;
aoqi@0 1139 }
aoqi@0 1140
aoqi@0 1141 bool ciReplay::should_inline(void* data, ciMethod* method, int bci, int inline_depth) {
aoqi@0 1142 if (data != NULL) {
aoqi@0 1143 GrowableArray<ciInlineRecord*>* records = (GrowableArray<ciInlineRecord*>*)data;
aoqi@0 1144 VM_ENTRY_MARK;
aoqi@0 1145 // Inline record are ordered by bci and depth.
aoqi@0 1146 return CompileReplay::find_ciInlineRecord(records, method->get_Method(), bci, inline_depth) != NULL;
aoqi@0 1147 } else if (replay_state != NULL) {
aoqi@0 1148 VM_ENTRY_MARK;
aoqi@0 1149 // Inline record are ordered by bci and depth.
aoqi@0 1150 return replay_state->find_ciInlineRecord(method->get_Method(), bci, inline_depth) != NULL;
aoqi@0 1151 }
aoqi@0 1152 return false;
aoqi@0 1153 }
aoqi@0 1154
aoqi@0 1155 bool ciReplay::should_not_inline(void* data, ciMethod* method, int bci, int inline_depth) {
aoqi@0 1156 if (data != NULL) {
aoqi@0 1157 GrowableArray<ciInlineRecord*>* records = (GrowableArray<ciInlineRecord*>*)data;
aoqi@0 1158 VM_ENTRY_MARK;
aoqi@0 1159 // Inline record are ordered by bci and depth.
aoqi@0 1160 return CompileReplay::find_ciInlineRecord(records, method->get_Method(), bci, inline_depth) == NULL;
aoqi@0 1161 } else if (replay_state != NULL) {
aoqi@0 1162 VM_ENTRY_MARK;
aoqi@0 1163 // Inline record are ordered by bci and depth.
aoqi@0 1164 return replay_state->find_ciInlineRecord(method->get_Method(), bci, inline_depth) == NULL;
aoqi@0 1165 }
aoqi@0 1166 return false;
aoqi@0 1167 }
aoqi@0 1168
aoqi@0 1169 void ciReplay::initialize(ciMethod* m) {
aoqi@0 1170 if (replay_state == NULL) {
aoqi@0 1171 return;
aoqi@0 1172 }
aoqi@0 1173
aoqi@0 1174 ASSERT_IN_VM;
aoqi@0 1175 ResourceMark rm;
aoqi@0 1176
aoqi@0 1177 Method* method = m->get_Method();
aoqi@0 1178 ciMethodRecord* rec = replay_state->find_ciMethodRecord(method);
aoqi@0 1179 if (rec == NULL) {
aoqi@0 1180 // This indicates some mismatch with the original environment and
aoqi@0 1181 // the replay environment though it's not always enough to
aoqi@0 1182 // interfere with reproducing a bug
aoqi@0 1183 tty->print_cr("Warning: requesting ciMethod record for method with no data: ");
aoqi@0 1184 method->print_name(tty);
aoqi@0 1185 tty->cr();
aoqi@0 1186 } else {
aoqi@0 1187 EXCEPTION_CONTEXT;
aoqi@0 1188 // m->_instructions_size = rec->_instructions_size;
aoqi@0 1189 m->_instructions_size = -1;
aoqi@0 1190 m->_interpreter_invocation_count = rec->_interpreter_invocation_count;
aoqi@0 1191 m->_interpreter_throwout_count = rec->_interpreter_throwout_count;
aoqi@0 1192 MethodCounters* mcs = method->get_method_counters(CHECK_AND_CLEAR);
aoqi@0 1193 guarantee(mcs != NULL, "method counters allocation failed");
aoqi@0 1194 mcs->invocation_counter()->_counter = rec->_invocation_counter;
aoqi@0 1195 mcs->backedge_counter()->_counter = rec->_backedge_counter;
aoqi@0 1196 }
aoqi@0 1197 }
aoqi@0 1198
aoqi@0 1199 bool ciReplay::is_loaded(Method* method) {
aoqi@0 1200 if (replay_state == NULL) {
aoqi@0 1201 return true;
aoqi@0 1202 }
aoqi@0 1203
aoqi@0 1204 ASSERT_IN_VM;
aoqi@0 1205 ResourceMark rm;
aoqi@0 1206
aoqi@0 1207 ciMethodRecord* rec = replay_state->find_ciMethodRecord(method);
aoqi@0 1208 return rec != NULL;
aoqi@0 1209 }
aoqi@0 1210 #endif // PRODUCT

mercurial