src/share/vm/ci/ciReplay.cpp

Mon, 07 Oct 2013 10:41:56 -0700

author
twisti
date
Mon, 07 Oct 2013 10:41:56 -0700
changeset 5907
c775af091fe9
parent 5449
1b6395189726
child 6217
849eb7bfceac
permissions
-rw-r--r--

8025566: EXCEPTION_ACCESS_VIOLATION in compiled by C1 String.valueOf method
Reviewed-by: kvn

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

mercurial