comparison src/share/vm/graal/graalEnv.cpp @ 19782:29916dcee0b8

Verify dependencies when assertions are enabled
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 10 Mar 2015 22:18:53 -0700
parents fb38e004503c
children a560c9b81f0f
comparison
equal deleted inserted replaced
19781:ea8d6fa333ab 19782:29916dcee0b8
419 } 419 }
420 420
421 // ------------------------------------------------------------------ 421 // ------------------------------------------------------------------
422 // Check for changes to the system dictionary during compilation 422 // Check for changes to the system dictionary during compilation
423 // class loads, evolution, breakpoints 423 // class loads, evolution, breakpoints
424 bool GraalEnv::check_for_system_dictionary_modification(Dependencies* dependencies, Handle compiled_code, GraalEnv* env, char** failure_detail) { 424 GraalEnv::CodeInstallResult GraalEnv::check_for_system_dictionary_modification(Dependencies* dependencies, Handle compiled_code,
425 GraalEnv* env, char** failure_detail) {
425 // If JVMTI capabilities were enabled during compile, the compilation is invalidated. 426 // If JVMTI capabilities were enabled during compile, the compilation is invalidated.
426 if (env != NULL) { 427 if (env != NULL) {
427 if (!env->_jvmti_can_hotswap_or_post_breakpoint && JvmtiExport::can_hotswap_or_post_breakpoint()) { 428 if (!env->_jvmti_can_hotswap_or_post_breakpoint && JvmtiExport::can_hotswap_or_post_breakpoint()) {
428 *failure_detail = (char*) "Hotswapping or breakpointing was enabled during compilation"; 429 *failure_detail = (char*) "Hotswapping or breakpointing was enabled during compilation";
429 return false; 430 return GraalEnv::dependencies_failed;
430 } 431 }
431 } 432 }
432 433
433 // Dependencies must be checked when the system dictionary changes 434 // Dependencies must be checked when the system dictionary changes
434 // or if we don't know whether it has changed (i.e., env == NULL). 435 // or if we don't know whether it has changed (i.e., env == NULL).
435 // In debug mode, always check dependencies. 436 // In debug mode, always check dependencies.
436 bool counter_changed = env != NULL && env->_system_dictionary_modification_counter != SystemDictionary::number_of_modifications(); 437 bool counter_changed = env != NULL && env->_system_dictionary_modification_counter != SystemDictionary::number_of_modifications();
437 bool verify_deps = env == NULL || trueInDebug; 438 bool verify_deps = env == NULL || trueInDebug || Debug::ENABLED();
438 if (!counter_changed && !verify_deps) { 439 if (!counter_changed && !verify_deps) {
439 return true; 440 return GraalEnv::ok;
440 } 441 }
441 442
442 for (Dependencies::DepStream deps(dependencies); deps.next(); ) { 443 for (Dependencies::DepStream deps(dependencies); deps.next(); ) {
443 Klass* witness = deps.check_dependency(); 444 Klass* witness = deps.check_dependency();
444 if (witness != NULL) { 445 if (witness != NULL) {
446 // resizing in the context of an inner resource mark. 447 // resizing in the context of an inner resource mark.
447 char* buffer = NEW_RESOURCE_ARRAY(char, O_BUFLEN); 448 char* buffer = NEW_RESOURCE_ARRAY(char, O_BUFLEN);
448 stringStream st(buffer, O_BUFLEN); 449 stringStream st(buffer, O_BUFLEN);
449 deps.print_dependency(witness, true, &st); 450 deps.print_dependency(witness, true, &st);
450 *failure_detail = st.as_string(); 451 *failure_detail = st.as_string();
451 return false; 452 if (env == NULL || counter_changed) {
453 return GraalEnv::dependencies_failed;
454 } else {
455 // The dependencies were invalid at the time of installation
456 // without any intervening modification of the system
457 // dictionary. That means they were invalidly constructed.
458 return GraalEnv::dependencies_invalid;
459 }
452 } 460 }
453 if (LogCompilation) { 461 if (LogCompilation) {
454 deps.log_dependency(); 462 deps.log_dependency();
455 } 463 }
456 } 464 }
457 465
458 return true; 466 return GraalEnv::ok;
459 } 467 }
460 468
461 // ------------------------------------------------------------------ 469 // ------------------------------------------------------------------
462 GraalEnv::CodeInstallResult GraalEnv::register_method( 470 GraalEnv::CodeInstallResult GraalEnv::register_method(
463 methodHandle& method, 471 methodHandle& method,
494 502
495 // Encode the dependencies now, so we can check them right away. 503 // Encode the dependencies now, so we can check them right away.
496 dependencies->encode_content_bytes(); 504 dependencies->encode_content_bytes();
497 505
498 // Check for {class loads, evolution, breakpoints} during compilation 506 // Check for {class loads, evolution, breakpoints} during compilation
499 if (!check_for_system_dictionary_modification(dependencies, compiled_code, env, &failure_detail)) { 507 result = check_for_system_dictionary_modification(dependencies, compiled_code, env, &failure_detail);
508 if (result != GraalEnv::ok) {
500 // While not a true deoptimization, it is a preemptive decompile. 509 // While not a true deoptimization, it is a preemptive decompile.
501 MethodData* mdp = method()->method_data(); 510 MethodData* mdp = method()->method_data();
502 if (mdp != NULL) { 511 if (mdp != NULL) {
503 mdp->inc_decompile_count(); 512 mdp->inc_decompile_count();
504 if (mdp->decompile_count() > (uint)PerMethodRecompilationCutoff) { 513 if (mdp->decompile_count() > (uint)PerMethodRecompilationCutoff) {
511 520
512 // All buffers in the CodeBuffer are allocated in the CodeCache. 521 // All buffers in the CodeBuffer are allocated in the CodeCache.
513 // If the code buffer is created on each compile attempt 522 // If the code buffer is created on each compile attempt
514 // as in C2, then it must be freed. 523 // as in C2, then it must be freed.
515 //code_buffer->free_blob(); 524 //code_buffer->free_blob();
516 result = GraalEnv::dependencies_failed;
517 } else { 525 } else {
518 ImplicitExceptionTable implicit_tbl; 526 ImplicitExceptionTable implicit_tbl;
519 nm = nmethod::new_nmethod(method, 527 nm = nmethod::new_nmethod(method,
520 compile_id, 528 compile_id,
521 entry_bci, 529 entry_bci,