src/share/vm/runtime/objectMonitor.cpp

changeset 8729
402618d5afc9
parent 8067
c1374141598c
child 8856
ac27a9c85bea
child 8887
b55756ea22d8
     1.1 --- a/src/share/vm/runtime/objectMonitor.cpp	Wed Aug 13 10:44:50 2014 +0200
     1.2 +++ b/src/share/vm/runtime/objectMonitor.cpp	Fri Mar 17 03:39:23 2017 -0700
     1.3 @@ -2529,6 +2529,10 @@
     1.4    SETKNOB(FastHSSEC) ;
     1.5    #undef SETKNOB
     1.6  
     1.7 +  if (Knob_Verbose) {
     1.8 +    sanity_checks();
     1.9 +  }
    1.10 +
    1.11    if (os::is_MP()) {
    1.12       BackOffMask = (1 << Knob_SpinBackOff) - 1 ;
    1.13       if (Knob_ReportSettings) ::printf ("BackOffMask=%X\n", BackOffMask) ;
    1.14 @@ -2549,6 +2553,66 @@
    1.15    InitDone = 1 ;
    1.16  }
    1.17  
    1.18 +void ObjectMonitor::sanity_checks() {
    1.19 +  int error_cnt = 0;
    1.20 +  int warning_cnt = 0;
    1.21 +  bool verbose = Knob_Verbose != 0 NOT_PRODUCT(|| VerboseInternalVMTests);
    1.22 +
    1.23 +  if (verbose) {
    1.24 +    tty->print_cr("INFO: sizeof(ObjectMonitor)=" SIZE_FORMAT,
    1.25 +                  sizeof(ObjectMonitor));
    1.26 +  }
    1.27 +
    1.28 +  uint cache_line_size = VM_Version::L1_data_cache_line_size();
    1.29 +  if (verbose) {
    1.30 +    tty->print_cr("INFO: L1_data_cache_line_size=%u", cache_line_size);
    1.31 +  }
    1.32 +
    1.33 +  ObjectMonitor dummy;
    1.34 +  u_char *addr_begin  = (u_char*)&dummy;
    1.35 +  u_char *addr_header = (u_char*)&dummy._header;
    1.36 +  u_char *addr_owner  = (u_char*)&dummy._owner;
    1.37 +
    1.38 +  uint offset_header = (uint)(addr_header - addr_begin);
    1.39 +  if (verbose) tty->print_cr("INFO: offset(_header)=%u", offset_header);
    1.40 +
    1.41 +  uint offset_owner = (uint)(addr_owner - addr_begin);
    1.42 +  if (verbose) tty->print_cr("INFO: offset(_owner)=%u", offset_owner);
    1.43 +
    1.44 +  if ((uint)(addr_header - addr_begin) != 0) {
    1.45 +    tty->print_cr("ERROR: offset(_header) must be zero (0).");
    1.46 +    error_cnt++;
    1.47 +  }
    1.48 +
    1.49 +  if (cache_line_size != 0) {
    1.50 +    // We were able to determine the L1 data cache line size so
    1.51 +    // do some cache line specific sanity checks
    1.52 +
    1.53 +    if ((offset_owner - offset_header) < cache_line_size) {
    1.54 +      tty->print_cr("WARNING: the _header and _owner fields are closer "
    1.55 +                    "than a cache line which permits false sharing.");
    1.56 +      warning_cnt++;
    1.57 +    }
    1.58 +
    1.59 +    if ((sizeof(ObjectMonitor) % cache_line_size) != 0) {
    1.60 +      tty->print_cr("WARNING: ObjectMonitor size is not a multiple of "
    1.61 +                    "a cache line which permits false sharing.");
    1.62 +      warning_cnt++;
    1.63 +    }
    1.64 +  }
    1.65 +
    1.66 +  ObjectSynchronizer::sanity_checks(verbose, cache_line_size, &error_cnt,
    1.67 +                                    &warning_cnt);
    1.68 +
    1.69 +  if (verbose || error_cnt != 0 || warning_cnt != 0) {
    1.70 +    tty->print_cr("INFO: error_cnt=%d", error_cnt);
    1.71 +    tty->print_cr("INFO: warning_cnt=%d", warning_cnt);
    1.72 +  }
    1.73 +
    1.74 +  guarantee(error_cnt == 0,
    1.75 +            "Fatal error(s) found in ObjectMonitor::sanity_checks()");
    1.76 +}
    1.77 +
    1.78  #ifndef PRODUCT
    1.79  void ObjectMonitor::verify() {
    1.80  }

mercurial