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