src/share/vm/gc_implementation/g1/sparsePRT.cpp

Print this page
rev 6361 : 8042474: Clean up duplicated code in RSHashTable
Summary: Removed duplicate code in RSHashTable to fetch SparsePRTEntries
Reviewed-by:
Contributed-by: Andreas Sjoberg <andreas.sjoberg@oracle.com>

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -192,27 +192,21 @@
   assert(e->num_valid_cards() > 0, "Postcondition");
   return res != SparsePRTEntry::overflow;
 }
 
 bool RSHashTable::get_cards(RegionIdx_t region_ind, CardIdx_t* cards) {
-  int ind = (int) (region_ind & capacity_mask());
-  int cur_ind = _buckets[ind];
-  SparsePRTEntry* cur;
-  while (cur_ind != NullEntry &&
-         (cur = entry(cur_ind))->r_ind() != region_ind) {
-    cur_ind = cur->next_index();
-  }
 
-  if (cur_ind == NullEntry) return false;
+  SparsePRTEntry* entry = get_entry(region_ind);
+  if (entry == NULL) {
+    return false;
+  }
   // Otherwise...
-  assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
-  assert(cur->num_valid_cards() > 0, "Inv");
-  cur->copy_cards(cards);
+  entry->copy_cards(cards);
   return true;
 }
 
-SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) {
+SparsePRTEntry* RSHashTable::get_entry(RegionIdx_t region_ind) const {
   int ind = (int) (region_ind & capacity_mask());
   int cur_ind = _buckets[ind];
   SparsePRTEntry* cur;
   while (cur_ind != NullEntry &&
          (cur = entry(cur_ind))->r_ind() != region_ind) {

@@ -245,31 +239,12 @@
   _occupied_entries--;
   return true;
 }
 
 SparsePRTEntry*
-RSHashTable::entry_for_region_ind(RegionIdx_t region_ind) const {
-  assert(occupied_entries() < capacity(), "Precondition");
-  int ind = (int) (region_ind & capacity_mask());
-  int cur_ind = _buckets[ind];
-  SparsePRTEntry* cur;
-  while (cur_ind != NullEntry &&
-         (cur = entry(cur_ind))->r_ind() != region_ind) {
-    cur_ind = cur->next_index();
-  }
-
-  if (cur_ind != NullEntry) {
-    assert(cur->r_ind() == region_ind, "Loop postcondition + test");
-    return cur;
-  } else {
-    return NULL;
-  }
-}
-
-SparsePRTEntry*
 RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) {
-  SparsePRTEntry* res = entry_for_region_ind(region_ind);
+  SparsePRTEntry* res = get_entry(region_ind);
   if (res == NULL) {
     int new_ind = alloc_entry();
     assert(0 <= new_ind && (size_t)new_ind < capacity(), "There should be room.");
     res = entry(new_ind);
     res->init(region_ind);

@@ -363,11 +338,11 @@
   // Otherwise, there were no entry.
   return false;
 }
 
 bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
-  SparsePRTEntry* e = entry_for_region_ind(region_index);
+  SparsePRTEntry* e = get_entry(region_index);
   return (e != NULL && e->contains_card(card_index));
 }
 
 size_t RSHashTable::mem_size() const {
   return sizeof(RSHashTable) +