< prev index next >

src/hotspot/share/jvmci/jvmciEnv.cpp

Print this page




 393   } else if (method_holder->is_array_klass()) {
 394     return SystemDictionary::Object_klass();
 395   } else {
 396     ShouldNotReachHere();
 397   }
 398   return NULL;
 399 }
 400 
 401 
 402 // ------------------------------------------------------------------
 403 methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool,
 404                                      int index, Bytecodes::Code bc,
 405                                      InstanceKlass* accessor) {
 406   ResourceMark rm;
 407   return get_method_by_index_impl(cpool, index, bc, accessor);
 408 }
 409 
 410 // ------------------------------------------------------------------
 411 // Check for changes to the system dictionary during compilation
 412 // class loads, evolution, breakpoints
 413 JVMCIEnv::CodeInstallResult JVMCIEnv::check_for_system_dictionary_modification(Dependencies* dependencies, Handle compiled_code,
 414                                                                                JVMCIEnv* env, char** failure_detail) {
 415   // If JVMTI capabilities were enabled during compile, the compilation is invalidated.
 416   if (env != NULL) {
 417     if (!env->_jvmti_can_hotswap_or_post_breakpoint && JvmtiExport::can_hotswap_or_post_breakpoint()) {
 418       *failure_detail = (char*) "Hotswapping or breakpointing was enabled during compilation";
 419       return JVMCIEnv::dependencies_failed;
 420     }
 421   }
 422 
 423   // Dependencies must be checked when the system dictionary changes
 424   // or if we don't know whether it has changed (i.e., env == NULL).
 425   // In debug mode, always check dependencies.
 426   bool counter_changed = env != NULL && env->_system_dictionary_modification_counter != SystemDictionary::number_of_modifications();
 427   bool verify_deps = env == NULL || trueInDebug || JavaAssertions::enabled(SystemDictionary::HotSpotInstalledCode_klass()->name()->as_C_string(), true);
 428   if (!counter_changed && !verify_deps) {
 429     return JVMCIEnv::ok;
 430   }
 431 
 432   for (Dependencies::DepStream deps(dependencies); deps.next(); ) {
 433     Klass* witness = deps.check_dependency();
 434     if (witness != NULL) {
 435       // Use a fixed size buffer to prevent the string stream from
 436       // resizing in the context of an inner resource mark.
 437       char* buffer = NEW_RESOURCE_ARRAY(char, O_BUFLEN);
 438       stringStream st(buffer, O_BUFLEN);
 439       deps.print_dependency(witness, true, &st);
 440       *failure_detail = st.as_string();
 441       if (env == NULL || counter_changed || deps.type() == Dependencies::evol_method) {
 442         return JVMCIEnv::dependencies_failed;
 443       } else {
 444         // The dependencies were invalid at the time of installation
 445         // without any intervening modification of the system
 446         // dictionary.  That means they were invalidly constructed.
 447         return JVMCIEnv::dependencies_invalid;
 448       }
 449     }
 450     if (LogCompilation) {
 451       deps.log_dependency();
 452     }
 453   }
 454 
 455   return JVMCIEnv::ok;
 456 }
 457 
 458 // ------------------------------------------------------------------
 459 JVMCIEnv::CodeInstallResult JVMCIEnv::register_method(
 460                                 const methodHandle& method,
 461                                 nmethod*& nm,
 462                                 int entry_bci,
 463                                 CodeOffsets* offsets,
 464                                 int orig_pc_offset,
 465                                 CodeBuffer* code_buffer,
 466                                 int frame_words,
 467                                 OopMapSet* oop_map_set,
 468                                 ExceptionHandlerTable* handler_table,
 469                                 AbstractCompiler* compiler,
 470                                 DebugInformationRecorder* debug_info,
 471                                 Dependencies* dependencies,
 472                                 JVMCIEnv* env,
 473                                 int compile_id,
 474                                 bool has_unsafe_access,
 475                                 bool has_wide_vector,
 476                                 Handle installed_code,
 477                                 Handle compiled_code,
 478                                 Handle speculation_log) {
 479   JVMCI_EXCEPTION_CONTEXT;
 480   nm = NULL;
 481   int comp_level = CompLevel_full_optimization;
 482   char* failure_detail = NULL;
 483   JVMCIEnv::CodeInstallResult result;
 484   {
 485     // To prevent compile queue updates.
 486     MutexLocker locker(MethodCompileQueue_lock, THREAD);
 487 
 488     // Prevent SystemDictionary::add_to_hierarchy from running
 489     // and invalidating our dependencies until we install this method.
 490     MutexLocker ml(Compile_lock);
 491 
 492     // Encode the dependencies now, so we can check them right away.
 493     dependencies->encode_content_bytes();
 494 







 495     // Check for {class loads, evolution, breakpoints} during compilation
 496     result = check_for_system_dictionary_modification(dependencies, compiled_code, env, &failure_detail);
 497     if (result != JVMCIEnv::ok) {
 498       // While not a true deoptimization, it is a preemptive decompile.
 499       MethodData* mdp = method()->method_data();
 500       if (mdp != NULL) {
 501         mdp->inc_decompile_count();
 502 #ifdef ASSERT
 503         if (mdp->decompile_count() > (uint)PerMethodRecompilationCutoff) {
 504           ResourceMark m;
 505           tty->print_cr("WARN: endless recompilation of %s. Method was set to not compilable.", method()->name_and_sig_as_C_string());
 506         }
 507 #endif
 508       }
 509 
 510       // All buffers in the CodeBuffer are allocated in the CodeCache.
 511       // If the code buffer is created on each compile attempt
 512       // as in C2, then it must be freed.
 513       //code_buffer->free_blob();
 514     } else {
 515       ImplicitExceptionTable implicit_tbl;
 516       nm =  nmethod::new_nmethod(method,




 393   } else if (method_holder->is_array_klass()) {
 394     return SystemDictionary::Object_klass();
 395   } else {
 396     ShouldNotReachHere();
 397   }
 398   return NULL;
 399 }
 400 
 401 
 402 // ------------------------------------------------------------------
 403 methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool,
 404                                      int index, Bytecodes::Code bc,
 405                                      InstanceKlass* accessor) {
 406   ResourceMark rm;
 407   return get_method_by_index_impl(cpool, index, bc, accessor);
 408 }
 409 
 410 // ------------------------------------------------------------------
 411 // Check for changes to the system dictionary during compilation
 412 // class loads, evolution, breakpoints
 413 JVMCIEnv::CodeInstallResult JVMCIEnv::validate_compile_task_dependencies(Dependencies* dependencies, Handle compiled_code,
 414                                                                          JVMCIEnv* env, char** failure_detail) {
 415   // If JVMTI capabilities were enabled during compile, the compilation is invalidated.
 416   if (env != NULL) {
 417     if (!env->_jvmti_can_hotswap_or_post_breakpoint && JvmtiExport::can_hotswap_or_post_breakpoint()) {
 418       *failure_detail = (char*) "Hotswapping or breakpointing was enabled during compilation";
 419       return JVMCIEnv::dependencies_failed;
 420     }
 421   }
 422 
 423   // Dependencies must be checked when the system dictionary changes
 424   // or if we don't know whether it has changed (i.e., env == NULL).
 425   bool counter_changed = env == NULL || env->_system_dictionary_modification_counter != SystemDictionary::number_of_modifications();
 426   CompileTask* task = env == NULL ? NULL : env->task();
 427   Dependencies::DepType result = dependencies->validate_dependencies(task, counter_changed, failure_detail);
 428   if (result == Dependencies::end_marker) {
 429     return JVMCIEnv::ok;
 430   }
 431 
 432   if (!Dependencies::is_klass_type(result) || counter_changed) {









 433     return JVMCIEnv::dependencies_failed;
 434   }
 435   // The dependencies were invalid at the time of installation
 436   // without any intervening modification of the system
 437   // dictionary.  That means they were invalidly constructed.
 438   return JVMCIEnv::dependencies_invalid;








 439 }
 440 
 441 // ------------------------------------------------------------------
 442 JVMCIEnv::CodeInstallResult JVMCIEnv::register_method(
 443                                 const methodHandle& method,
 444                                 nmethod*& nm,
 445                                 int entry_bci,
 446                                 CodeOffsets* offsets,
 447                                 int orig_pc_offset,
 448                                 CodeBuffer* code_buffer,
 449                                 int frame_words,
 450                                 OopMapSet* oop_map_set,
 451                                 ExceptionHandlerTable* handler_table,
 452                                 AbstractCompiler* compiler,
 453                                 DebugInformationRecorder* debug_info,
 454                                 Dependencies* dependencies,
 455                                 JVMCIEnv* env,
 456                                 int compile_id,
 457                                 bool has_unsafe_access,
 458                                 bool has_wide_vector,
 459                                 Handle installed_code,
 460                                 Handle compiled_code,
 461                                 Handle speculation_log) {
 462   JVMCI_EXCEPTION_CONTEXT;
 463   nm = NULL;
 464   int comp_level = CompLevel_full_optimization;
 465   char* failure_detail = NULL;
 466   JVMCIEnv::CodeInstallResult result;
 467   {
 468     // To prevent compile queue updates.
 469     MutexLocker locker(MethodCompileQueue_lock, THREAD);
 470 
 471     // Prevent SystemDictionary::add_to_hierarchy from running
 472     // and invalidating our dependencies until we install this method.
 473     MutexLocker ml(Compile_lock);
 474 
 475     // Encode the dependencies now, so we can check them right away.
 476     dependencies->encode_content_bytes();
 477 
 478     // Record the dependencies for the current compile in the log
 479     if (LogCompilation) {
 480       for (Dependencies::DepStream deps(dependencies); deps.next(); ) {
 481         deps.log_dependency();
 482       }
 483     }
 484 
 485     // Check for {class loads, evolution, breakpoints} during compilation
 486     result = validate_compile_task_dependencies(dependencies, compiled_code, env, &failure_detail);
 487     if (result != JVMCIEnv::ok) {
 488       // While not a true deoptimization, it is a preemptive decompile.
 489       MethodData* mdp = method()->method_data();
 490       if (mdp != NULL) {
 491         mdp->inc_decompile_count();
 492 #ifdef ASSERT
 493         if (mdp->decompile_count() > (uint)PerMethodRecompilationCutoff) {
 494           ResourceMark m;
 495           tty->print_cr("WARN: endless recompilation of %s. Method was set to not compilable.", method()->name_and_sig_as_C_string());
 496         }
 497 #endif
 498       }
 499 
 500       // All buffers in the CodeBuffer are allocated in the CodeCache.
 501       // If the code buffer is created on each compile attempt
 502       // as in C2, then it must be freed.
 503       //code_buffer->free_blob();
 504     } else {
 505       ImplicitExceptionTable implicit_tbl;
 506       nm =  nmethod::new_nmethod(method,


< prev index next >