src/share/vm/ci/ciReplay.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 8028468 Sdiff src/share/vm/ci

src/share/vm/ci/ciReplay.cpp

Print this page




   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "ci/ciMethodData.hpp"
  26 #include "ci/ciReplay.hpp"


  27 #include "ci/ciUtilities.hpp"
  28 #include "compiler/compileBroker.hpp"
  29 #include "memory/allocation.inline.hpp"
  30 #include "memory/oopFactory.hpp"
  31 #include "memory/resourceArea.hpp"
  32 #include "utilities/copy.hpp"
  33 #include "utilities/macros.hpp"
  34 
  35 #ifndef PRODUCT
  36 
  37 // ciReplay
  38 
  39 typedef struct _ciMethodDataRecord {
  40   const char* klass;
  41   const char* method;
  42   const char* signature;
  43   int state;
  44   int current_mileage;
  45   intptr_t* data;
  46   int data_length;
  47   char* orig_data;
  48   int orig_data_length;
  49   int oops_length;
  50   jobject* oops_handles;
  51   int* oops_offsets;
  52 } ciMethodDataRecord;
  53 
  54 typedef struct _ciMethodRecord {
  55   const char* klass;
  56   const char* method;
  57   const char* signature;
  58   int instructions_size;
  59   int interpreter_invocation_count;
  60   int interpreter_throwout_count;
  61   int invocation_counter;
  62   int backedge_counter;
  63 } ciMethodRecord;
  64 








  65 class CompileReplay;
  66 static CompileReplay* replay_state;
  67 
  68 class CompileReplay : public StackObj {
  69  private:
  70   FILE*   stream;
  71   Thread* thread;
  72   Handle  protection_domain;
  73   Handle  loader;
  74 
  75   GrowableArray<ciMethodRecord*>     ci_method_records;
  76   GrowableArray<ciMethodDataRecord*> ci_method_data_records;



  77 
  78   const char* _error_message;
  79 
  80   char* bufptr;
  81   char* buffer;
  82   int   buffer_length;
  83   int   buffer_end;
  84   int   line_no;
  85 
  86  public:
  87   CompileReplay(const char* filename, TRAPS) {
  88     thread = THREAD;
  89     loader = Handle(thread, SystemDictionary::java_system_loader());
  90     stream = fopen(filename, "rt");
  91     if (stream == NULL) {
  92       fprintf(stderr, "ERROR: Can't open replay file %s\n", filename);
  93     }
  94     buffer_length = 32;
  95     buffer = NEW_RESOURCE_ARRAY(char, buffer_length);
  96     _error_message = NULL;


 256       result[i] = val;
 257     }
 258     return result;
 259   }
 260 
 261   // Parse a possibly quoted version of a symbol into a symbolOop
 262   Symbol* parse_symbol(TRAPS) {
 263     const char* str = parse_escaped_string();
 264     if (str != NULL) {
 265       Symbol* sym = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
 266       return sym;
 267     }
 268     return NULL;
 269   }
 270 
 271   // Parse a valid klass name and look it up
 272   Klass* parse_klass(TRAPS) {
 273     const char* str = parse_escaped_string();
 274     Symbol* klass_name = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
 275     if (klass_name != NULL) {
 276       Klass* k = SystemDictionary::resolve_or_fail(klass_name, loader, protection_domain, true, THREAD);





 277       if (HAS_PENDING_EXCEPTION) {
 278         oop throwable = PENDING_EXCEPTION;
 279         java_lang_Throwable::print(throwable, tty);
 280         tty->cr();
 281         report_error(str);
 282         return NULL;
 283       }
 284       return k;
 285     }
 286     return NULL;
 287   }
 288 
 289   // Lookup a klass
 290   Klass* resolve_klass(const char* klass, TRAPS) {
 291     Symbol* klass_name = SymbolTable::lookup(klass, (int)strlen(klass), CHECK_NULL);
 292     return SystemDictionary::resolve_or_fail(klass_name, loader, protection_domain, true, CHECK_NULL);
 293   }
 294 
 295   // Parse the standard tuple of <klass> <name> <signature>
 296   Method* parse_method(TRAPS) {
 297     InstanceKlass* k = (InstanceKlass*)parse_klass(CHECK_NULL);
 298     Symbol* method_name = parse_symbol(CHECK_NULL);
 299     Symbol* method_signature = parse_symbol(CHECK_NULL);
 300     Method* m = k->find_method(method_name, method_signature);
 301     if (m == NULL) {
 302       report_error("Can't find method");
 303     }
 304     return m;
 305   }
 306 
 307   // Process each line of the replay file executing each command until
 308   // the file ends.
 309   void process(TRAPS) {





 310     line_no = 1;
 311     int pos = 0;
 312     int c = getc(stream);
 313     while(c != EOF) {
 314       if (pos + 1 >= buffer_length) {
 315         int newl = buffer_length * 2;
 316         char* newb = NEW_RESOURCE_ARRAY(char, newl);
 317         memcpy(newb, buffer, pos);
 318         buffer = newb;
 319         buffer_length = newl;
 320       }
 321       if (c == '\n') {
 322         // null terminate it, reset the pointer and process the line
 323         buffer[pos] = '\0';
 324         buffer_end = pos++;
 325         bufptr = buffer;
 326         process_command(CHECK);
 327         if (had_error()) {
 328           tty->print_cr("Error while parsing line %d: %s\n", line_no, _error_message);
 329           tty->print_cr("%s", buffer);


 379     } else if (!TieredCompilation && (comp_level != CompLevel_highest_tier)) {
 380       msg = NEW_RESOURCE_ARRAY(char, msg_len);
 381       switch (comp_level) {
 382         case CompLevel_simple:
 383           jio_snprintf(msg, msg_len, "compilation level %d requires Client VM or TieredCompilation", comp_level);
 384           break;
 385         case CompLevel_full_optimization:
 386           jio_snprintf(msg, msg_len, "compilation level %d requires Server VM", comp_level);
 387           break;
 388         default:
 389           jio_snprintf(msg, msg_len, "compilation level %d requires TieredCompilation", comp_level);
 390       }
 391     }
 392     if (msg != NULL) {
 393       report_error(msg);
 394       return false;
 395     }
 396     return true;
 397   }
 398 
 399   // compile <klass> <name> <signature> <entry_bci> <comp_level>























































 400   void process_compile(TRAPS) {
 401     Method* method = parse_method(CHECK);
 402     if (had_error()) return;
 403     int entry_bci = parse_int("entry_bci");
 404     const char* comp_level_label = "comp_level";
 405     int comp_level = parse_int(comp_level_label);
 406     // old version w/o comp_level
 407     if (had_error() && (error_message() == comp_level_label)) {
 408       comp_level = CompLevel_full_optimization;
 409     }
 410     if (!is_valid_comp_level(comp_level)) {
 411       return;
 412     }





































 413     Klass* k = method->method_holder();
 414     ((InstanceKlass*)k)->initialize(THREAD);
 415     if (HAS_PENDING_EXCEPTION) {
 416       oop throwable = PENDING_EXCEPTION;
 417       java_lang_Throwable::print(throwable, tty);
 418       tty->cr();
 419       if (ReplayIgnoreInitErrors) {
 420         CLEAR_PENDING_EXCEPTION;
 421         ((InstanceKlass*)k)->set_init_state(InstanceKlass::fully_initialized);
 422       } else {
 423         return;
 424       }
 425     }
 426     // Make sure the existence of a prior compile doesn't stop this one
 427     nmethod* nm = (entry_bci != InvocationEntryBci) ? method->lookup_osr_nmethod_for(entry_bci, comp_level, true) : method->code();
 428     if (nm != NULL) {
 429       nm->make_not_entrant();
 430     }
 431     replay_state = this;
 432     CompileBroker::compile_method(method, entry_bci, comp_level,


 553             tty->print_cr("Resolving klass %s at %d", cp->unresolved_klass_at(i)->as_utf8(), i);
 554             Klass* k = cp->klass_at(i, CHECK);
 555           }
 556           break;
 557         }
 558         case JVM_CONSTANT_Long:
 559         case JVM_CONSTANT_Double:
 560           parsed_two_word = i + 1;
 561 
 562         case JVM_CONSTANT_ClassIndex:
 563         case JVM_CONSTANT_StringIndex:
 564         case JVM_CONSTANT_String:
 565         case JVM_CONSTANT_UnresolvedClassInError:
 566         case JVM_CONSTANT_Fieldref:
 567         case JVM_CONSTANT_Methodref:
 568         case JVM_CONSTANT_InterfaceMethodref:
 569         case JVM_CONSTANT_NameAndType:
 570         case JVM_CONSTANT_Utf8:
 571         case JVM_CONSTANT_Integer:
 572         case JVM_CONSTANT_Float:



 573           if (tag != cp->tag_at(i).value()) {
 574             report_error("tag mismatch: wrong class files?");
 575             return;
 576           }
 577           break;
 578 
 579         case JVM_CONSTANT_Class:
 580           if (tag == JVM_CONSTANT_Class) {
 581           } else if (tag == JVM_CONSTANT_UnresolvedClass) {
 582             tty->print_cr("Warning: entry was unresolved in the replay data");
 583           } else {
 584             report_error("Unexpected tag");
 585             return;
 586           }
 587           break;
 588 
 589         case 0:
 590           if (parsed_two_word == i) continue;
 591 
 592         default:


 761     ci_method_data_records.append(rec);
 762     return rec;
 763   }
 764 
 765   // Lookup data for a ciMethodData
 766   ciMethodDataRecord* find_ciMethodDataRecord(Method* method) {
 767     const char* klass_name =  method->method_holder()->name()->as_utf8();
 768     const char* method_name = method->name()->as_utf8();
 769     const char* signature = method->signature()->as_utf8();
 770     for (int i = 0; i < ci_method_data_records.length(); i++) {
 771       ciMethodDataRecord* rec = ci_method_data_records.at(i);
 772       if (strcmp(rec->klass, klass_name) == 0 &&
 773           strcmp(rec->method, method_name) == 0 &&
 774           strcmp(rec->signature, signature) == 0) {
 775         return rec;
 776       }
 777     }
 778     return NULL;
 779   }
 780 




















































 781   const char* error_message() {
 782     return _error_message;
 783   }
 784 
 785   void reset() {
 786     _error_message = NULL;
 787     ci_method_records.clear();
 788     ci_method_data_records.clear();
 789   }
 790 
 791   // Take an ascii string contain \u#### escapes and convert it to utf8
 792   // in place.
 793   static void unescape_string(char* value) {
 794     char* from = value;
 795     char* to = value;
 796     while (*from != '\0') {
 797       if (*from != '\\') {
 798         *from++ = *to++;
 799       } else {
 800         switch (from[1]) {


 828           case 'n': *to++ = '\n'; from += 2; break;
 829           case 'r': *to++ = '\r'; from += 2; break;
 830           case 'f': *to++ = '\f'; from += 2; break;
 831           default:
 832             ShouldNotReachHere();
 833         }
 834       }
 835     }
 836     *from = *to;
 837   }
 838 };
 839 
 840 void ciReplay::replay(TRAPS) {
 841   int exit_code = replay_impl(THREAD);
 842 
 843   Threads::destroy_vm();
 844 
 845   vm_exit(exit_code);
 846 }
 847 































 848 int ciReplay::replay_impl(TRAPS) {
 849   HandleMark hm;
 850   ResourceMark rm;
 851   // Make sure we don't run with background compilation
 852   BackgroundCompilation = false;
 853 
 854   if (ReplaySuppressInitializers > 2) {
 855     // ReplaySuppressInitializers > 2 means that we want to allow
 856     // normal VM bootstrap but once we get into the replay itself
 857     // don't allow any intializers to be run.
 858     ReplaySuppressInitializers = 1;
 859   }
 860 
 861   if (FLAG_IS_DEFAULT(ReplayDataFile)) {
 862     tty->print_cr("ERROR: no compiler replay data file specified (use -XX:ReplayDataFile=replay_pid12345.txt).");
 863     return 1;
 864   }
 865 
 866   // Load and parse the replay data
 867   CompileReplay rp(ReplayDataFile, THREAD);
 868   int exit_code = 0;
 869   if (rp.can_replay()) {
 870     rp.process(THREAD);
 871   } else {
 872     exit_code = 1;
 873     return exit_code;
 874   }
 875 
 876   if (HAS_PENDING_EXCEPTION) {
 877     oop throwable = PENDING_EXCEPTION;
 878     CLEAR_PENDING_EXCEPTION;
 879     java_lang_Throwable::print(throwable, tty);
 880     tty->cr();
 881     java_lang_Throwable::print_stack_trace(throwable, tty);
 882     tty->cr();
 883     exit_code = 2;
 884   }
 885 
 886   if (rp.had_error()) {
 887     tty->print_cr("Failed on %s", rp.error_message());
 888     exit_code = 1;
 889   }
 890   return exit_code;
 891 }
 892 
 893 
 894 void ciReplay::initialize(ciMethodData* m) {
 895   if (replay_state == NULL) {
 896     return;
 897   }
 898 
 899   ASSERT_IN_VM;
 900   ResourceMark rm;
 901 
 902   Method* method = m->get_MethodData()->method();
 903   ciMethodDataRecord* rec = replay_state->find_ciMethodDataRecord(method);
 904   if (rec == NULL) {
 905     // This indicates some mismatch with the original environment and
 906     // the replay environment though it's not always enough to
 907     // interfere with reproducing a bug
 908     tty->print_cr("Warning: requesting ciMethodData record for method with no data: ");
 909     method->print_name(tty);
 910     tty->cr();
 911   } else {
 912     m->_state = rec->state;
 913     m->_current_mileage = rec->current_mileage;


 922           env->get_metadata((*h)());
 923       }
 924       // Copy the updated profile data into place as intptr_ts
 925 #ifdef _LP64
 926       Copy::conjoint_jlongs_atomic((jlong *)rec->data, (jlong *)m->_data, rec->data_length);
 927 #else
 928       Copy::conjoint_jints_atomic((jint *)rec->data, (jint *)m->_data, rec->data_length);
 929 #endif
 930     }
 931 
 932     // copy in the original header
 933     Copy::conjoint_jbytes(rec->orig_data, (char*)&m->_orig, rec->orig_data_length);
 934   }
 935 }
 936 
 937 
 938 bool ciReplay::should_not_inline(ciMethod* method) {
 939   if (replay_state == NULL) {
 940     return false;
 941   }
 942 
 943   VM_ENTRY_MARK;
 944   // ciMethod without a record shouldn't be inlined.
 945   return replay_state->find_ciMethodRecord(method->get_Method()) == NULL;
 946 }
 947 



























 948 
 949 void ciReplay::initialize(ciMethod* m) {
 950   if (replay_state == NULL) {
 951     return;
 952   }
 953 
 954   ASSERT_IN_VM;
 955   ResourceMark rm;
 956 
 957   Method* method = m->get_Method();
 958   ciMethodRecord* rec = replay_state->find_ciMethodRecord(method);
 959   if (rec == NULL) {
 960     // This indicates some mismatch with the original environment and
 961     // the replay environment though it's not always enough to
 962     // interfere with reproducing a bug
 963     tty->print_cr("Warning: requesting ciMethod record for method with no data: ");
 964     method->print_name(tty);
 965     tty->cr();
 966   } else {
 967     EXCEPTION_CONTEXT;




   7  *
   8  * This code is distributed in the hope that it will be useful, but WITHOUT
   9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  11  * version 2 for more details (a copy is included in the LICENSE file that
  12  * accompanied this code).
  13  *
  14  * You should have received a copy of the GNU General Public License version
  15  * 2 along with this work; if not, write to the Free Software Foundation,
  16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  17  *
  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  19  * or visit www.oracle.com if you need additional information or have any
  20  * questions.
  21  *
  22  */
  23 
  24 #include "precompiled.hpp"
  25 #include "ci/ciMethodData.hpp"
  26 #include "ci/ciReplay.hpp"
  27 #include "ci/ciSymbol.hpp"
  28 #include "ci/ciKlass.hpp"
  29 #include "ci/ciUtilities.hpp"
  30 #include "compiler/compileBroker.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "memory/oopFactory.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "utilities/copy.hpp"
  35 #include "utilities/macros.hpp"
  36 
  37 #ifndef PRODUCT
  38 
  39 // ciReplay
  40 
  41 typedef struct _ciMethodDataRecord {
  42   const char* klass;
  43   const char* method;
  44   const char* signature;
  45   int state;
  46   int current_mileage;
  47   intptr_t* data;
  48   int data_length;
  49   char* orig_data;
  50   int orig_data_length;
  51   int oops_length;
  52   jobject* oops_handles;
  53   int* oops_offsets;
  54 } ciMethodDataRecord;
  55 
  56 typedef struct _ciMethodRecord {
  57   const char* klass;
  58   const char* method;
  59   const char* signature;
  60   int instructions_size;
  61   int interpreter_invocation_count;
  62   int interpreter_throwout_count;
  63   int invocation_counter;
  64   int backedge_counter;
  65 } ciMethodRecord;
  66 
  67 typedef struct _ciInlineRecord {
  68   const char* klass;
  69   const char* method;
  70   const char* signature;
  71   int inline_depth;
  72   int bci;
  73 } ciInlineRecord;
  74 
  75 class CompileReplay;
  76 static CompileReplay* replay_state;
  77 
  78 class CompileReplay : public StackObj {
  79  private:
  80   FILE*   stream;
  81   Thread* thread;
  82   Handle  protection_domain;
  83   Handle  loader;
  84 
  85   GrowableArray<ciMethodRecord*>     ci_method_records;
  86   GrowableArray<ciMethodDataRecord*> ci_method_data_records;
  87   // Use pointer because we may need to retirn inline records
  88   // without destroying.
  89   GrowableArray<ciInlineRecord*>*    ci_inline_records;
  90 
  91   const char* _error_message;
  92 
  93   char* bufptr;
  94   char* buffer;
  95   int   buffer_length;
  96   int   buffer_end;
  97   int   line_no;
  98 
  99  public:
 100   CompileReplay(const char* filename, TRAPS) {
 101     thread = THREAD;
 102     loader = Handle(thread, SystemDictionary::java_system_loader());
 103     stream = fopen(filename, "rt");
 104     if (stream == NULL) {
 105       fprintf(stderr, "ERROR: Can't open replay file %s\n", filename);
 106     }
 107     buffer_length = 32;
 108     buffer = NEW_RESOURCE_ARRAY(char, buffer_length);
 109     _error_message = NULL;


 269       result[i] = val;
 270     }
 271     return result;
 272   }
 273 
 274   // Parse a possibly quoted version of a symbol into a symbolOop
 275   Symbol* parse_symbol(TRAPS) {
 276     const char* str = parse_escaped_string();
 277     if (str != NULL) {
 278       Symbol* sym = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
 279       return sym;
 280     }
 281     return NULL;
 282   }
 283 
 284   // Parse a valid klass name and look it up
 285   Klass* parse_klass(TRAPS) {
 286     const char* str = parse_escaped_string();
 287     Symbol* klass_name = SymbolTable::lookup(str, (int)strlen(str), CHECK_NULL);
 288     if (klass_name != NULL) {
 289       Klass* k = NULL;
 290       if (_iklass != NULL) {
 291         k = (Klass*)_iklass->find_klass(ciSymbol::make(klass_name->as_C_string()))->constant_encoding();
 292       } else {
 293         k = SystemDictionary::resolve_or_fail(klass_name, loader, protection_domain, true, THREAD);
 294       }
 295       if (HAS_PENDING_EXCEPTION) {
 296         oop throwable = PENDING_EXCEPTION;
 297         java_lang_Throwable::print(throwable, tty);
 298         tty->cr();
 299         report_error(str);
 300         return NULL;
 301       }
 302       return k;
 303     }
 304     return NULL;
 305   }
 306 
 307   // Lookup a klass
 308   Klass* resolve_klass(const char* klass, TRAPS) {
 309     Symbol* klass_name = SymbolTable::lookup(klass, (int)strlen(klass), CHECK_NULL);
 310     return SystemDictionary::resolve_or_fail(klass_name, loader, protection_domain, true, CHECK_NULL);
 311   }
 312 
 313   // Parse the standard tuple of <klass> <name> <signature>
 314   Method* parse_method(TRAPS) {
 315     InstanceKlass* k = (InstanceKlass*)parse_klass(CHECK_NULL);
 316     Symbol* method_name = parse_symbol(CHECK_NULL);
 317     Symbol* method_signature = parse_symbol(CHECK_NULL);
 318     Method* m = k->find_method(method_name, method_signature);
 319     if (m == NULL) {
 320       report_error("Can't find method");
 321     }
 322     return m;
 323   }
 324 
 325   // Process each line of the replay file executing each command until
 326   // the file ends.
 327   void process(TRAPS) {
 328     _imethod = NULL;
 329     _iklass  = NULL;
 330     _entry_bci  = 0;
 331     _comp_level = 0;
 332 
 333     line_no = 1;
 334     int pos = 0;
 335     int c = getc(stream);
 336     while(c != EOF) {
 337       if (pos + 1 >= buffer_length) {
 338         int newl = buffer_length * 2;
 339         char* newb = NEW_RESOURCE_ARRAY(char, newl);
 340         memcpy(newb, buffer, pos);
 341         buffer = newb;
 342         buffer_length = newl;
 343       }
 344       if (c == '\n') {
 345         // null terminate it, reset the pointer and process the line
 346         buffer[pos] = '\0';
 347         buffer_end = pos++;
 348         bufptr = buffer;
 349         process_command(CHECK);
 350         if (had_error()) {
 351           tty->print_cr("Error while parsing line %d: %s\n", line_no, _error_message);
 352           tty->print_cr("%s", buffer);


 402     } else if (!TieredCompilation && (comp_level != CompLevel_highest_tier)) {
 403       msg = NEW_RESOURCE_ARRAY(char, msg_len);
 404       switch (comp_level) {
 405         case CompLevel_simple:
 406           jio_snprintf(msg, msg_len, "compilation level %d requires Client VM or TieredCompilation", comp_level);
 407           break;
 408         case CompLevel_full_optimization:
 409           jio_snprintf(msg, msg_len, "compilation level %d requires Server VM", comp_level);
 410           break;
 411         default:
 412           jio_snprintf(msg, msg_len, "compilation level %d requires TieredCompilation", comp_level);
 413       }
 414     }
 415     if (msg != NULL) {
 416       report_error(msg);
 417       return false;
 418     }
 419     return true;
 420   }
 421 
 422   ciKlass* _iklass;
 423   Method* _imethod;
 424   int _entry_bci;
 425   int _comp_level;
 426 
 427   // compile <klass> <name> <signature> <entry_bci> <comp_level> inline <count> <depth> <bci> <klass> <name> <signature> ...
 428   void* process_inline(ciMethod* imethod, Method* m, int entry_bci, int comp_level, TRAPS) {
 429     _imethod = m;
 430     _iklass  = imethod->holder();
 431     _entry_bci  = entry_bci;
 432     _comp_level = comp_level;
 433     line_no = 1;
 434     int pos = 0;
 435     int c = getc(stream);
 436     while(c != EOF) {
 437       if (pos + 1 >= buffer_length) {
 438         int newl = buffer_length * 2;
 439         char* newb = NEW_RESOURCE_ARRAY(char, newl);
 440         memcpy(newb, buffer, pos);
 441         buffer = newb;
 442         buffer_length = newl;
 443       }
 444       if (c == '\n') {
 445         // null terminate it, reset the pointer and process the line
 446         buffer[pos] = '\0';
 447         buffer_end = pos++;
 448         bufptr = buffer;
 449         {
 450           char* cmd = parse_string();
 451           if (cmd == NULL || strcmp("compile", cmd) != 0) {
 452             return NULL;
 453           }
 454           process_compile(CHECK_NULL);
 455           if (ci_inline_records != NULL && ci_inline_records->length() > 0) {
 456             return ci_inline_records;
 457           }
 458         }
 459         if (had_error()) {
 460           tty->print_cr("Error while parsing line %d: %s\n", line_no, _error_message);
 461           tty->print_cr("%s", buffer);
 462           return NULL;
 463         }
 464         pos = 0;
 465         buffer_end = 0;
 466         line_no++;
 467       } else if (c == '\r') {
 468         // skip LF
 469       } else {
 470         buffer[pos++] = c;
 471       }
 472       c = getc(stream);
 473     }
 474     return NULL;
 475   }
 476 
 477   // compile <klass> <name> <signature> <entry_bci> <comp_level> inline <count> <depth> <bci> <klass> <name> <signature> ...
 478   void process_compile(TRAPS) {
 479     Method* method = parse_method(CHECK);
 480     if (had_error()) return;
 481     int entry_bci = parse_int("entry_bci");
 482     const char* comp_level_label = "comp_level";
 483     int comp_level = parse_int(comp_level_label);
 484     // old version w/o comp_level
 485     if (had_error() && (error_message() == comp_level_label)) {
 486       comp_level = CompLevel_full_optimization;
 487     }
 488     if (!is_valid_comp_level(comp_level)) {
 489       return;
 490     }
 491     if (_imethod != NULL) {
 492       // Replay Inlinig
 493       if (entry_bci != _entry_bci || comp_level != _comp_level) {
 494         return;
 495       }
 496       const char* iklass_name  = _imethod->method_holder()->name()->as_utf8();
 497       const char* imethod_name = _imethod->name()->as_utf8();
 498       const char* isignature   = _imethod->signature()->as_utf8();
 499       const char* klass_name   = method->method_holder()->name()->as_utf8();
 500       const char* method_name  = method->name()->as_utf8();
 501       const char* signature    = method->signature()->as_utf8();
 502       if (strcmp(iklass_name,  klass_name)  != 0 ||
 503           strcmp(imethod_name, method_name) != 0 ||
 504           strcmp(isignature,   signature)   != 0) {
 505         return;
 506       }
 507     }
 508     int inline_count = 0;
 509     if (parse_tag_and_count("inline", inline_count)) {
 510       // Record inlining data
 511       ci_inline_records = new GrowableArray<ciInlineRecord*>();
 512       for (int i = 0; i < inline_count; i++) {
 513         int depth = parse_int("inline_depth");
 514         int bci = parse_int("inline_bci");
 515         if (had_error()) {
 516           break;
 517         }
 518         Method* inl_method = parse_method(CHECK);
 519         if (had_error()) {
 520           break;
 521         }
 522         new_ciInlineRecord(inl_method, bci, depth);
 523       }
 524     }
 525     if (_imethod != NULL) {
 526       return; // Replay Inlining
 527     }
 528     Klass* k = method->method_holder();
 529     ((InstanceKlass*)k)->initialize(THREAD);
 530     if (HAS_PENDING_EXCEPTION) {
 531       oop throwable = PENDING_EXCEPTION;
 532       java_lang_Throwable::print(throwable, tty);
 533       tty->cr();
 534       if (ReplayIgnoreInitErrors) {
 535         CLEAR_PENDING_EXCEPTION;
 536         ((InstanceKlass*)k)->set_init_state(InstanceKlass::fully_initialized);
 537       } else {
 538         return;
 539       }
 540     }
 541     // Make sure the existence of a prior compile doesn't stop this one
 542     nmethod* nm = (entry_bci != InvocationEntryBci) ? method->lookup_osr_nmethod_for(entry_bci, comp_level, true) : method->code();
 543     if (nm != NULL) {
 544       nm->make_not_entrant();
 545     }
 546     replay_state = this;
 547     CompileBroker::compile_method(method, entry_bci, comp_level,


 668             tty->print_cr("Resolving klass %s at %d", cp->unresolved_klass_at(i)->as_utf8(), i);
 669             Klass* k = cp->klass_at(i, CHECK);
 670           }
 671           break;
 672         }
 673         case JVM_CONSTANT_Long:
 674         case JVM_CONSTANT_Double:
 675           parsed_two_word = i + 1;
 676 
 677         case JVM_CONSTANT_ClassIndex:
 678         case JVM_CONSTANT_StringIndex:
 679         case JVM_CONSTANT_String:
 680         case JVM_CONSTANT_UnresolvedClassInError:
 681         case JVM_CONSTANT_Fieldref:
 682         case JVM_CONSTANT_Methodref:
 683         case JVM_CONSTANT_InterfaceMethodref:
 684         case JVM_CONSTANT_NameAndType:
 685         case JVM_CONSTANT_Utf8:
 686         case JVM_CONSTANT_Integer:
 687         case JVM_CONSTANT_Float:
 688         case JVM_CONSTANT_MethodHandle:
 689         case JVM_CONSTANT_MethodType:
 690         case JVM_CONSTANT_InvokeDynamic:
 691           if (tag != cp->tag_at(i).value()) {
 692             report_error("tag mismatch: wrong class files?");
 693             return;
 694           }
 695           break;
 696 
 697         case JVM_CONSTANT_Class:
 698           if (tag == JVM_CONSTANT_Class) {
 699           } else if (tag == JVM_CONSTANT_UnresolvedClass) {
 700             tty->print_cr("Warning: entry was unresolved in the replay data");
 701           } else {
 702             report_error("Unexpected tag");
 703             return;
 704           }
 705           break;
 706 
 707         case 0:
 708           if (parsed_two_word == i) continue;
 709 
 710         default:


 879     ci_method_data_records.append(rec);
 880     return rec;
 881   }
 882 
 883   // Lookup data for a ciMethodData
 884   ciMethodDataRecord* find_ciMethodDataRecord(Method* method) {
 885     const char* klass_name =  method->method_holder()->name()->as_utf8();
 886     const char* method_name = method->name()->as_utf8();
 887     const char* signature = method->signature()->as_utf8();
 888     for (int i = 0; i < ci_method_data_records.length(); i++) {
 889       ciMethodDataRecord* rec = ci_method_data_records.at(i);
 890       if (strcmp(rec->klass, klass_name) == 0 &&
 891           strcmp(rec->method, method_name) == 0 &&
 892           strcmp(rec->signature, signature) == 0) {
 893         return rec;
 894       }
 895     }
 896     return NULL;
 897   }
 898 
 899   // Create and initialize a record for a ciInlineRecord
 900   ciInlineRecord* new_ciInlineRecord(Method* method, int bci, int depth) {
 901     ciInlineRecord* rec = NEW_RESOURCE_OBJ(ciInlineRecord);
 902     rec->klass =  method->method_holder()->name()->as_utf8();
 903     rec->method = method->name()->as_utf8();
 904     rec->signature = method->signature()->as_utf8();
 905     rec->bci = bci;
 906     rec->inline_depth = depth;
 907     ci_inline_records->append(rec);
 908     return rec;
 909   }
 910 
 911   // Lookup inlining data for a ciMethod
 912   ciInlineRecord* find_ciInlineRecord(Method* method, int bci, int inline_depth) {
 913     if (ci_inline_records != NULL) {
 914       const char* klass_name =  method->method_holder()->name()->as_utf8();
 915       const char* method_name = method->name()->as_utf8();
 916       const char* signature = method->signature()->as_utf8();
 917       for (int i = 0; i < ci_inline_records->length(); i++) {
 918         ciInlineRecord* rec = ci_inline_records->at(i);
 919         if ((rec->bci == bci) &&
 920             (rec->inline_depth == inline_depth) &&
 921             (strcmp(rec->klass, klass_name) == 0) &&
 922             (strcmp(rec->method, method_name) == 0) &&
 923             (strcmp(rec->signature, signature) == 0)) {
 924           return rec;
 925         }
 926       }
 927     }
 928     return NULL;
 929   }
 930 
 931   static ciInlineRecord* find_ciInlineRecord(GrowableArray<ciInlineRecord*>*  records,
 932                                       Method* method, int bci, int inline_depth) {
 933     if (records != NULL) {
 934       const char* klass_name =  method->method_holder()->name()->as_utf8();
 935       const char* method_name = method->name()->as_utf8();
 936       const char* signature = method->signature()->as_utf8();
 937       for (int i = 0; i < records->length(); i++) {
 938         ciInlineRecord* rec = records->at(i);
 939         if ((rec->bci == bci) &&
 940             (rec->inline_depth == inline_depth) &&
 941             (strcmp(rec->klass, klass_name) == 0) &&
 942             (strcmp(rec->method, method_name) == 0) &&
 943             (strcmp(rec->signature, signature) == 0)) {
 944           return rec;
 945         }
 946       }
 947     }
 948     return NULL;
 949   }
 950 
 951   const char* error_message() {
 952     return _error_message;
 953   }
 954 
 955   void reset() {
 956     _error_message = NULL;
 957     ci_method_records.clear();
 958     ci_method_data_records.clear();
 959   }
 960 
 961   // Take an ascii string contain \u#### escapes and convert it to utf8
 962   // in place.
 963   static void unescape_string(char* value) {
 964     char* from = value;
 965     char* to = value;
 966     while (*from != '\0') {
 967       if (*from != '\\') {
 968         *from++ = *to++;
 969       } else {
 970         switch (from[1]) {


 998           case 'n': *to++ = '\n'; from += 2; break;
 999           case 'r': *to++ = '\r'; from += 2; break;
1000           case 'f': *to++ = '\f'; from += 2; break;
1001           default:
1002             ShouldNotReachHere();
1003         }
1004       }
1005     }
1006     *from = *to;
1007   }
1008 };
1009 
1010 void ciReplay::replay(TRAPS) {
1011   int exit_code = replay_impl(THREAD);
1012 
1013   Threads::destroy_vm();
1014 
1015   vm_exit(exit_code);
1016 }
1017 
1018 void* ciReplay::load_inline_data(ciMethod* method, int entry_bci, int comp_level) {
1019   if (FLAG_IS_DEFAULT(InlineDataFile)) {
1020     tty->print_cr("ERROR: no inline replay data file specified (use -XX:InlineDataFile=inline_pid12345.txt).");
1021     return NULL;
1022   }
1023 
1024   VM_ENTRY_MARK;
1025   // Load and parse the replay data
1026   CompileReplay rp(InlineDataFile, THREAD);
1027   if (!rp.can_replay()) {
1028     tty->print_cr("ciReplay: !rp.can_replay()");
1029     return NULL;
1030   }
1031   void* data = rp.process_inline(method, method->get_Method(), entry_bci, comp_level, THREAD);
1032   if (HAS_PENDING_EXCEPTION) {
1033     oop throwable = PENDING_EXCEPTION;
1034     CLEAR_PENDING_EXCEPTION;
1035     java_lang_Throwable::print(throwable, tty);
1036     tty->cr();
1037     java_lang_Throwable::print_stack_trace(throwable, tty);
1038     tty->cr();
1039     return NULL;
1040   }
1041 
1042   if (rp.had_error()) {
1043     tty->print_cr("ciReplay: Failed on %s", rp.error_message());
1044     return NULL;
1045   }
1046   return data;
1047 }
1048 
1049 int ciReplay::replay_impl(TRAPS) {
1050   HandleMark hm;
1051   ResourceMark rm;
1052   // Make sure we don't run with background compilation
1053   //  BackgroundCompilation = false;
1054 
1055   if (ReplaySuppressInitializers > 2) {
1056     // ReplaySuppressInitializers > 2 means that we want to allow
1057     // normal VM bootstrap but once we get into the replay itself
1058     // don't allow any intializers to be run.
1059     ReplaySuppressInitializers = 1;
1060   }
1061 
1062   if (FLAG_IS_DEFAULT(ReplayDataFile)) {
1063     tty->print_cr("ERROR: no compiler replay data file specified (use -XX:ReplayDataFile=replay_pid12345.txt).");
1064     return 1;
1065   }
1066 
1067   // Load and parse the replay data
1068   CompileReplay rp(ReplayDataFile, THREAD);
1069   int exit_code = 0;
1070   if (rp.can_replay()) {
1071     rp.process(THREAD);
1072   } else {
1073     exit_code = 1;
1074     return exit_code;
1075   }
1076 
1077   if (HAS_PENDING_EXCEPTION) {
1078     oop throwable = PENDING_EXCEPTION;
1079     CLEAR_PENDING_EXCEPTION;
1080     java_lang_Throwable::print(throwable, tty);
1081     tty->cr();
1082     java_lang_Throwable::print_stack_trace(throwable, tty);
1083     tty->cr();
1084     exit_code = 2;
1085   }
1086 
1087   if (rp.had_error()) {
1088     tty->print_cr("Failed on %s", rp.error_message());
1089     exit_code = 1;
1090   }
1091   return exit_code;
1092 }
1093 

1094 void ciReplay::initialize(ciMethodData* m) {
1095   if (replay_state == NULL) {
1096     return;
1097   }
1098 
1099   ASSERT_IN_VM;
1100   ResourceMark rm;
1101 
1102   Method* method = m->get_MethodData()->method();
1103   ciMethodDataRecord* rec = replay_state->find_ciMethodDataRecord(method);
1104   if (rec == NULL) {
1105     // This indicates some mismatch with the original environment and
1106     // the replay environment though it's not always enough to
1107     // interfere with reproducing a bug
1108     tty->print_cr("Warning: requesting ciMethodData record for method with no data: ");
1109     method->print_name(tty);
1110     tty->cr();
1111   } else {
1112     m->_state = rec->state;
1113     m->_current_mileage = rec->current_mileage;


1122           env->get_metadata((*h)());
1123       }
1124       // Copy the updated profile data into place as intptr_ts
1125 #ifdef _LP64
1126       Copy::conjoint_jlongs_atomic((jlong *)rec->data, (jlong *)m->_data, rec->data_length);
1127 #else
1128       Copy::conjoint_jints_atomic((jint *)rec->data, (jint *)m->_data, rec->data_length);
1129 #endif
1130     }
1131 
1132     // copy in the original header
1133     Copy::conjoint_jbytes(rec->orig_data, (char*)&m->_orig, rec->orig_data_length);
1134   }
1135 }
1136 
1137 
1138 bool ciReplay::should_not_inline(ciMethod* method) {
1139   if (replay_state == NULL) {
1140     return false;
1141   }

1142   VM_ENTRY_MARK;
1143   // ciMethod without a record shouldn't be inlined.
1144   return replay_state->find_ciMethodRecord(method->get_Method()) == NULL;
1145 }
1146 
1147 bool ciReplay::should_inline(void* data, ciMethod* method, int bci, int inline_depth) {
1148   if (data != NULL) {
1149     GrowableArray<ciInlineRecord*>*  records = (GrowableArray<ciInlineRecord*>*)data;
1150     VM_ENTRY_MARK;
1151     // Inline record are ordered by bci and depth.
1152     return CompileReplay::find_ciInlineRecord(records, method->get_Method(), bci, inline_depth) != NULL;
1153   } else if (replay_state != NULL) {
1154     VM_ENTRY_MARK;
1155     // Inline record are ordered by bci and depth.
1156     return replay_state->find_ciInlineRecord(method->get_Method(), bci, inline_depth) != NULL;
1157   }
1158   return false;
1159 }
1160 
1161 bool ciReplay::should_not_inline(void* data, ciMethod* method, int bci, int inline_depth) {
1162   if (data != NULL) {
1163     GrowableArray<ciInlineRecord*>*  records = (GrowableArray<ciInlineRecord*>*)data;
1164     VM_ENTRY_MARK;
1165     // Inline record are ordered by bci and depth.
1166     return CompileReplay::find_ciInlineRecord(records, method->get_Method(), bci, inline_depth) == NULL;
1167   } else if (replay_state != NULL) {
1168     VM_ENTRY_MARK;
1169     // Inline record are ordered by bci and depth.
1170     return replay_state->find_ciInlineRecord(method->get_Method(), bci, inline_depth) == NULL;
1171   }
1172   return false;
1173 }
1174 
1175 void ciReplay::initialize(ciMethod* m) {
1176   if (replay_state == NULL) {
1177     return;
1178   }
1179 
1180   ASSERT_IN_VM;
1181   ResourceMark rm;
1182 
1183   Method* method = m->get_Method();
1184   ciMethodRecord* rec = replay_state->find_ciMethodRecord(method);
1185   if (rec == NULL) {
1186     // This indicates some mismatch with the original environment and
1187     // the replay environment though it's not always enough to
1188     // interfere with reproducing a bug
1189     tty->print_cr("Warning: requesting ciMethod record for method with no data: ");
1190     method->print_name(tty);
1191     tty->cr();
1192   } else {
1193     EXCEPTION_CONTEXT;


src/share/vm/ci/ciReplay.cpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File