src/share/vm/ci/ciReplay.cpp

Thu, 24 May 2018 18:41:44 +0800

author
aoqi
date
Thu, 24 May 2018 18:41:44 +0800
changeset 8856
ac27a9c85bea
parent 6876
710a3c8b516e
child 9572
624a0741915c
permissions
-rw-r--r--

Merge

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

mercurial