< prev index next >

src/hotspot/share/code/dependencies.cpp

Print this page




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciArrayKlass.hpp"
  27 #include "ci/ciEnv.hpp"
  28 #include "ci/ciKlass.hpp"
  29 #include "ci/ciMethod.hpp"
  30 #include "classfile/javaClasses.inline.hpp"
  31 #include "code/dependencies.hpp"
  32 #include "compiler/compileLog.hpp"


  33 #include "memory/resourceArea.hpp"
  34 #include "oops/oop.inline.hpp"
  35 #include "oops/objArrayKlass.hpp"
  36 #include "runtime/handles.hpp"
  37 #include "runtime/handles.inline.hpp"
  38 #include "runtime/thread.inline.hpp"
  39 #include "utilities/copy.hpp"
  40 
  41 
  42 #ifdef ASSERT
  43 static bool must_be_in_vm() {
  44   Thread* thread = Thread::current();
  45   if (thread->is_Java_thread())
  46     return ((JavaThread*)thread)->thread_state() == _thread_in_vm;
  47   else
  48     return true;  //something like this: thread->is_VM_thread();
  49 }
  50 #endif //ASSERT
  51 
  52 void Dependencies::initialize(ciEnv* env) {


 603   3, // unique_concrete_subtypes_2 ctxk, k1, k2
 604   3, // unique_concrete_methods_2 ctxk, m1, m2
 605   1, // no_finalizable_subclasses ctxk
 606   2  // call_site_target_value call_site, method_handle
 607 };
 608 
 609 const char* Dependencies::dep_name(Dependencies::DepType dept) {
 610   if (!dept_in_mask(dept, all_types))  return "?bad-dep?";
 611   return _dep_name[dept];
 612 }
 613 
 614 int Dependencies::dep_args(Dependencies::DepType dept) {
 615   if (!dept_in_mask(dept, all_types))  return -1;
 616   return _dep_args[dept];
 617 }
 618 
 619 void Dependencies::check_valid_dependency_type(DepType dept) {
 620   guarantee(FIRST_TYPE <= dept && dept < TYPE_LIMIT, "invalid dependency type: %d", (int) dept);
 621 }
 622 


































































 623 // for the sake of the compiler log, print out current dependencies:
 624 void Dependencies::log_all_dependencies() {
 625   if (log() == NULL)  return;
 626   ResourceMark rm;
 627   for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
 628     DepType dept = (DepType)deptv;
 629     GrowableArray<ciBaseObject*>* deps = _deps[dept];
 630     int deplen = deps->length();
 631     if (deplen == 0) {
 632       continue;
 633     }
 634     int stride = dep_args(dept);
 635     GrowableArray<ciBaseObject*>* ciargs = new GrowableArray<ciBaseObject*>(stride);
 636     for (int i = 0; i < deps->length(); i += stride) {
 637       for (int j = 0; j < stride; j++) {
 638         // flush out the identities before printing
 639         ciargs->push(deps->at(i+j));
 640       }
 641       write_dependency_to(log(), dept, ciargs);
 642       ciargs->clear();




  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "ci/ciArrayKlass.hpp"
  27 #include "ci/ciEnv.hpp"
  28 #include "ci/ciKlass.hpp"
  29 #include "ci/ciMethod.hpp"
  30 #include "classfile/javaClasses.inline.hpp"
  31 #include "code/dependencies.hpp"
  32 #include "compiler/compileLog.hpp"
  33 #include "compiler/compileBroker.hpp"
  34 #include "compiler/compileTask.hpp"
  35 #include "memory/resourceArea.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "oops/objArrayKlass.hpp"
  38 #include "runtime/handles.hpp"
  39 #include "runtime/handles.inline.hpp"
  40 #include "runtime/thread.inline.hpp"
  41 #include "utilities/copy.hpp"
  42 
  43 
  44 #ifdef ASSERT
  45 static bool must_be_in_vm() {
  46   Thread* thread = Thread::current();
  47   if (thread->is_Java_thread())
  48     return ((JavaThread*)thread)->thread_state() == _thread_in_vm;
  49   else
  50     return true;  //something like this: thread->is_VM_thread();
  51 }
  52 #endif //ASSERT
  53 
  54 void Dependencies::initialize(ciEnv* env) {


 605   3, // unique_concrete_subtypes_2 ctxk, k1, k2
 606   3, // unique_concrete_methods_2 ctxk, m1, m2
 607   1, // no_finalizable_subclasses ctxk
 608   2  // call_site_target_value call_site, method_handle
 609 };
 610 
 611 const char* Dependencies::dep_name(Dependencies::DepType dept) {
 612   if (!dept_in_mask(dept, all_types))  return "?bad-dep?";
 613   return _dep_name[dept];
 614 }
 615 
 616 int Dependencies::dep_args(Dependencies::DepType dept) {
 617   if (!dept_in_mask(dept, all_types))  return -1;
 618   return _dep_args[dept];
 619 }
 620 
 621 void Dependencies::check_valid_dependency_type(DepType 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;
 689 }
 690 
 691 // for the sake of the compiler log, print out current dependencies:
 692 void Dependencies::log_all_dependencies() {
 693   if (log() == NULL)  return;
 694   ResourceMark rm;
 695   for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) {
 696     DepType dept = (DepType)deptv;
 697     GrowableArray<ciBaseObject*>* deps = _deps[dept];
 698     int deplen = deps->length();
 699     if (deplen == 0) {
 700       continue;
 701     }
 702     int stride = dep_args(dept);
 703     GrowableArray<ciBaseObject*>* ciargs = new GrowableArray<ciBaseObject*>(stride);
 704     for (int i = 0; i < deps->length(); i += stride) {
 705       for (int j = 0; j < stride; j++) {
 706         // flush out the identities before printing
 707         ciargs->push(deps->at(i+j));
 708       }
 709       write_dependency_to(log(), dept, ciargs);
 710       ciargs->clear();


< prev index next >