Print this page


Split Close
Expand all
Collapse all
          --- old/src/share/vm/memory/referenceProcessor.cpp
          +++ new/src/share/vm/memory/referenceProcessor.cpp
↓ open down ↓ 94 lines elided ↑ open up ↑
  95   95    _default_soft_ref_policy      = new COMPILER2_PRESENT(LRUMaxHeapPolicy())
  96   96                                        NOT_COMPILER2(LRUCurrentHeapPolicy());
  97   97    if (_always_clear_soft_ref_policy == NULL || _default_soft_ref_policy == NULL) {
  98   98      vm_exit_during_initialization("Could not allocate reference policy object");
  99   99    }
 100  100    guarantee(RefDiscoveryPolicy == ReferenceBasedDiscovery ||
 101  101              RefDiscoveryPolicy == ReferentBasedDiscovery,
 102  102              "Unrecongnized RefDiscoveryPolicy");
 103  103  }
 104  104  
 105      -ReferenceProcessor*
 106      -ReferenceProcessor::create_ref_processor(MemRegion          span,
 107      -                                         bool               atomic_discovery,
 108      -                                         bool               mt_discovery,
 109      -                                         BoolObjectClosure* is_alive_non_header,
 110      -                                         int                parallel_gc_threads,
 111      -                                         bool               mt_processing,
 112      -                                         bool               dl_needs_barrier) {
 113      -  int mt_degree = 1;
 114      -  if (parallel_gc_threads > 1) {
 115      -    mt_degree = parallel_gc_threads;
 116      -  }
 117      -  ReferenceProcessor* rp =
 118      -    new ReferenceProcessor(span, atomic_discovery,
 119      -                           mt_discovery, mt_degree,
 120      -                           mt_processing && (parallel_gc_threads > 0),
 121      -                           dl_needs_barrier);
 122      -  if (rp == NULL) {
 123      -    vm_exit_during_initialization("Could not allocate ReferenceProcessor object");
 124      -  }
 125      -  rp->set_is_alive_non_header(is_alive_non_header);
 126      -  rp->setup_policy(false /* default soft ref policy */);
 127      -  return rp;
 128      -}
 129      -
 130  105  ReferenceProcessor::ReferenceProcessor(MemRegion span,
 131      -                                       bool      atomic_discovery,
 132      -                                       bool      mt_discovery,
 133      -                                       int       mt_degree,
 134  106                                         bool      mt_processing,
      107 +                                       int       mt_processing_degree,
      108 +                                       bool      mt_discovery,
      109 +                                       int       mt_discovery_degree,
      110 +                                       bool      atomic_discovery,
      111 +                                       BoolObjectClosure* is_alive_non_header,
 135  112                                         bool      discovered_list_needs_barrier)  :
 136  113    _discovering_refs(false),
 137  114    _enqueuing_is_done(false),
 138      -  _is_alive_non_header(NULL),
      115 +  _is_alive_non_header(is_alive_non_header),
 139  116    _discovered_list_needs_barrier(discovered_list_needs_barrier),
 140  117    _bs(NULL),
 141  118    _processing_is_mt(mt_processing),
 142  119    _next_id(0)
 143  120  {
 144  121    _span = span;
 145  122    _discovery_is_atomic = atomic_discovery;
 146  123    _discovery_is_mt     = mt_discovery;
 147      -  _num_q               = mt_degree;
 148      -  _max_num_q           = mt_degree;
      124 +  _num_q               = mt_processing_degree;
      125 +  _max_num_q           = MAX2(mt_processing_degree, mt_discovery_degree);
 149  126    _discoveredSoftRefs  = NEW_C_HEAP_ARRAY(DiscoveredList, _max_num_q * subclasses_of_ref);
 150  127    if (_discoveredSoftRefs == NULL) {
 151  128      vm_exit_during_initialization("Could not allocated RefProc Array");
 152  129    }
 153  130    _discoveredWeakRefs    = &_discoveredSoftRefs[_max_num_q];
 154  131    _discoveredFinalRefs   = &_discoveredWeakRefs[_max_num_q];
 155  132    _discoveredPhantomRefs = &_discoveredFinalRefs[_max_num_q];
 156  133    assert(sentinel_ref() != NULL, "_sentinelRef is NULL");
 157  134    // Initialized all entries to _sentinelRef
 158  135    for (int i = 0; i < _max_num_q * subclasses_of_ref; i++) {
 159  136          _discoveredSoftRefs[i].set_head(sentinel_ref());
 160  137      _discoveredSoftRefs[i].set_length(0);
 161  138    }
 162  139    // If we do barreirs, cache a copy of the barrier set.
 163  140    if (discovered_list_needs_barrier) {
 164  141      _bs = Universe::heap()->barrier_set();
 165  142    }
      143 +  setup_policy(false /* default soft ref policy */);
 166  144  }
 167  145  
 168  146  #ifndef PRODUCT
 169  147  void ReferenceProcessor::verify_no_references_recorded() {
 170  148    guarantee(!_discovering_refs, "Discovering refs?");
 171  149    for (int i = 0; i < _max_num_q * subclasses_of_ref; i++) {
 172  150      guarantee(_discoveredSoftRefs[i].empty(),
 173  151                "Found non-empty discovered list");
 174  152    }
 175  153  }
↓ open down ↓ 768 lines elided ↑ open up ↑
 944  922    // for processing so don't depend of _num_q < _max_num_q as part
 945  923    // of the test.
 946  924    bool must_balance = _discovery_is_mt;
 947  925  
 948  926    if ((mt_processing && ParallelRefProcBalancingEnabled) ||
 949  927        must_balance) {
 950  928      balance_queues(refs_lists);
 951  929    }
 952  930    if (PrintReferenceGC && PrintGCDetails) {
 953  931      size_t total = 0;
 954      -    for (int i = 0; i < _num_q; ++i) {
      932 +    for (int i = 0; i < _max_num_q; ++i) {
 955  933        total += refs_lists[i].length();
 956  934      }
 957  935      gclog_or_tty->print(", %u refs", total);
 958  936    }
 959  937  
 960  938    // Phase 1 (soft refs only):
 961  939    // . Traverse the list and remove any SoftReferences whose
 962  940    //   referents are not alive, but that should be kept alive for
 963  941    //   policy reasons. Keep alive the transitive closure of all
 964  942    //   such referents.
 965  943    if (policy != NULL) {
 966  944      if (mt_processing) {
 967  945        RefProcPhase1Task phase1(*this, refs_lists, policy, true /*marks_oops_alive*/);
 968  946        task_executor->execute(phase1);
 969  947      } else {
 970      -      for (int i = 0; i < _num_q; i++) {
      948 +      for (int i = 0; i < _max_num_q; i++) {
 971  949          process_phase1(refs_lists[i], policy,
 972  950                         is_alive, keep_alive, complete_gc);
 973  951        }
 974  952      }
 975  953    } else { // policy == NULL
 976  954      assert(refs_lists != _discoveredSoftRefs,
 977  955             "Policy must be specified for soft references.");
 978  956    }
 979  957  
 980  958    // Phase 2:
 981  959    // . Traverse the list and remove any refs whose referents are alive.
 982  960    if (mt_processing) {
 983  961      RefProcPhase2Task phase2(*this, refs_lists, !discovery_is_atomic() /*marks_oops_alive*/);
 984  962      task_executor->execute(phase2);
 985  963    } else {
 986      -    for (int i = 0; i < _num_q; i++) {
      964 +    for (int i = 0; i < _max_num_q; i++) {
 987  965        process_phase2(refs_lists[i], is_alive, keep_alive, complete_gc);
 988  966      }
 989  967    }
 990  968  
 991  969    // Phase 3:
 992  970    // . Traverse the list and process referents as appropriate.
 993  971    if (mt_processing) {
 994  972      RefProcPhase3Task phase3(*this, refs_lists, clear_referent, true /*marks_oops_alive*/);
 995  973      task_executor->execute(phase3);
 996  974    } else {
 997      -    for (int i = 0; i < _num_q; i++) {
      975 +    for (int i = 0; i < _max_num_q; i++) {
 998  976        process_phase3(refs_lists[i], clear_referent,
 999  977                       is_alive, keep_alive, complete_gc);
1000  978      }
1001  979    }
1002  980  }
1003  981  
1004  982  void ReferenceProcessor::clean_up_discovered_references() {
1005  983    // loop over the lists
1006  984    // Should this instead be
1007  985    // for (int i = 0; i < subclasses_of_ref; i++_ {
↓ open down ↓ 474 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX