src/hotspot/share/code/dependencies.cpp
changeset 48299 e8f5fc8f5f67
parent 47216 71c04702a3d5
child 49192 6734eeef4283
equal deleted inserted replaced
48298:40b9faefb496 48299:e8f5fc8f5f67
    28 #include "ci/ciKlass.hpp"
    28 #include "ci/ciKlass.hpp"
    29 #include "ci/ciMethod.hpp"
    29 #include "ci/ciMethod.hpp"
    30 #include "classfile/javaClasses.inline.hpp"
    30 #include "classfile/javaClasses.inline.hpp"
    31 #include "code/dependencies.hpp"
    31 #include "code/dependencies.hpp"
    32 #include "compiler/compileLog.hpp"
    32 #include "compiler/compileLog.hpp"
       
    33 #include "compiler/compileBroker.hpp"
       
    34 #include "compiler/compileTask.hpp"
    33 #include "memory/resourceArea.hpp"
    35 #include "memory/resourceArea.hpp"
    34 #include "oops/oop.inline.hpp"
    36 #include "oops/oop.inline.hpp"
    35 #include "oops/objArrayKlass.hpp"
    37 #include "oops/objArrayKlass.hpp"
    36 #include "runtime/handles.hpp"
    38 #include "runtime/handles.hpp"
    37 #include "runtime/handles.inline.hpp"
    39 #include "runtime/handles.inline.hpp"
   616   return _dep_args[dept];
   618   return _dep_args[dept];
   617 }
   619 }
   618 
   620 
   619 void Dependencies::check_valid_dependency_type(DepType dept) {
   621 void Dependencies::check_valid_dependency_type(DepType dept) {
   620   guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, "invalid dependency type: %d", (int) dept);
   622   guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, "invalid dependency type: %d", (int) dept);
       
   623 }
       
   624 
       
   625 Dependencies::DepType Dependencies::validate_dependencies(CompileTask* task, bool counter_changed, char** failure_detail) {
       
   626   // First, check non-klass dependencies as we might return early and
       
   627   // not check klass dependencies if the system dictionary
       
   628   // modification counter hasn't changed (see below).
       
   629   for (Dependencies::DepStream deps(this); deps.next(); ) {
       
   630     if (deps.is_klass_type())  continue;  // skip klass dependencies
       
   631     Klass* witness = deps.check_dependency();
       
   632     if (witness != NULL) {
       
   633       return deps.type();
       
   634     }
       
   635   }
       
   636 
       
   637   // Klass dependencies must be checked when the system dictionary
       
   638   // changes.  If logging is enabled all violated dependences will be
       
   639   // recorded in the log.  In debug mode check dependencies even if
       
   640   // the system dictionary hasn't changed to verify that no invalid
       
   641   // dependencies were inserted.  Any violated dependences in this
       
   642   // case are dumped to the tty.
       
   643   if (!counter_changed && !trueInDebug) {
       
   644     return end_marker;
       
   645   }
       
   646 
       
   647   int klass_violations = 0;
       
   648   DepType result = end_marker;
       
   649   for (Dependencies::DepStream deps(this); deps.next(); ) {
       
   650     if (!deps.is_klass_type())  continue;  // skip non-klass dependencies
       
   651     Klass* witness = deps.check_dependency();
       
   652     if (witness != NULL) {
       
   653       if (klass_violations == 0) {
       
   654         result = deps.type();
       
   655         if (failure_detail != NULL && klass_violations == 0) {
       
   656           // Use a fixed size buffer to prevent the string stream from
       
   657           // resizing in the context of an inner resource mark.
       
   658           char* buffer = NEW_RESOURCE_ARRAY(char, O_BUFLEN);
       
   659           stringStream st(buffer, O_BUFLEN);
       
   660           deps.print_dependency(witness, true, &st);
       
   661           *failure_detail = st.as_string();
       
   662         }
       
   663       }
       
   664       klass_violations++;
       
   665       if (!counter_changed) {
       
   666         // Dependence failed but counter didn't change.  Log a message
       
   667         // describing what failed and allow the assert at the end to
       
   668         // trigger.
       
   669         deps.print_dependency(witness);
       
   670       } else if (xtty == NULL) {
       
   671         // If we're not logging then a single violation is sufficient,
       
   672         // otherwise we want to log all the dependences which were
       
   673         // violated.
       
   674         break;
       
   675       }
       
   676     }
       
   677   }
       
   678 
       
   679   if (klass_violations != 0) {
       
   680 #ifdef ASSERT
       
   681     if (task != NULL && !counter_changed && !PrintCompilation) {
       
   682       // Print out the compile task that failed
       
   683       task->print_tty();
       
   684     }
       
   685 #endif
       
   686     assert(counter_changed, "failed dependencies, but counter didn't change");
       
   687   }
       
   688   return result;
   621 }
   689 }
   622 
   690 
   623 // for the sake of the compiler log, print out current dependencies:
   691 // for the sake of the compiler log, print out current dependencies:
   624 void Dependencies::log_all_dependencies() {
   692 void Dependencies::log_all_dependencies() {
   625   if (log() == NULL)  return;
   693   if (log() == NULL)  return;