mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 19:44:41 +02:00
8042474: Clean up duplicated code in RSHashTable
Removed duplicate code in RSHashTable to fetch SparsePRTEntries Reviewed-by: tschatzl, brutisso
This commit is contained in:
parent
395c71590f
commit
09c2deeb5a
2 changed files with 10 additions and 42 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* 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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -194,23 +194,16 @@ bool RSHashTable::add_card(RegionIdx_t region_ind, CardIdx_t card_index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RSHashTable::get_cards(RegionIdx_t region_ind, CardIdx_t* cards) {
|
bool RSHashTable::get_cards(RegionIdx_t region_ind, CardIdx_t* cards) {
|
||||||
int ind = (int) (region_ind & capacity_mask());
|
SparsePRTEntry* entry = get_entry(region_ind);
|
||||||
int cur_ind = _buckets[ind];
|
if (entry == NULL) {
|
||||||
SparsePRTEntry* cur;
|
return false;
|
||||||
while (cur_ind != NullEntry &&
|
|
||||||
(cur = entry(cur_ind))->r_ind() != region_ind) {
|
|
||||||
cur_ind = cur->next_index();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur_ind == NullEntry) return false;
|
|
||||||
// Otherwise...
|
// Otherwise...
|
||||||
assert(cur->r_ind() == region_ind, "Postcondition of loop + test above.");
|
entry->copy_cards(cards);
|
||||||
assert(cur->num_valid_cards() > 0, "Inv");
|
|
||||||
cur->copy_cards(cards);
|
|
||||||
return true;
|
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 ind = (int) (region_ind & capacity_mask());
|
||||||
int cur_ind = _buckets[ind];
|
int cur_ind = _buckets[ind];
|
||||||
SparsePRTEntry* cur;
|
SparsePRTEntry* cur;
|
||||||
|
@ -246,28 +239,9 @@ bool RSHashTable::delete_entry(RegionIdx_t region_ind) {
|
||||||
return true;
|
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*
|
SparsePRTEntry*
|
||||||
RSHashTable::entry_for_region_ind_create(RegionIdx_t region_ind) {
|
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) {
|
if (res == NULL) {
|
||||||
int new_ind = alloc_entry();
|
int new_ind = alloc_entry();
|
||||||
assert(0 <= new_ind && (size_t)new_ind < capacity(), "There should be room.");
|
assert(0 <= new_ind && (size_t)new_ind < capacity(), "There should be room.");
|
||||||
|
@ -365,7 +339,7 @@ bool RSHashTableIter::has_next(size_t& card_index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RSHashTable::contains_card(RegionIdx_t region_index, CardIdx_t card_index) const {
|
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));
|
return (e != NULL && e->contains_card(card_index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* 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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -119,12 +119,6 @@ class RSHashTable : public CHeapObj<mtGC> {
|
||||||
int _free_region;
|
int _free_region;
|
||||||
int _free_list;
|
int _free_list;
|
||||||
|
|
||||||
// Requires that the caller hold a lock preventing parallel modifying
|
|
||||||
// operations, and that the the table be less than completely full. If
|
|
||||||
// an entry for "region_ind" is already in the table, finds it and
|
|
||||||
// returns its address; otherwise returns "NULL."
|
|
||||||
SparsePRTEntry* entry_for_region_ind(RegionIdx_t region_ind) const;
|
|
||||||
|
|
||||||
// Requires that the caller hold a lock preventing parallel modifying
|
// Requires that the caller hold a lock preventing parallel modifying
|
||||||
// operations, and that the the table be less than completely full. If
|
// operations, and that the the table be less than completely full. If
|
||||||
// an entry for "region_ind" is already in the table, finds it and
|
// an entry for "region_ind" is already in the table, finds it and
|
||||||
|
@ -158,7 +152,7 @@ public:
|
||||||
|
|
||||||
void add_entry(SparsePRTEntry* e);
|
void add_entry(SparsePRTEntry* e);
|
||||||
|
|
||||||
SparsePRTEntry* get_entry(RegionIdx_t region_id);
|
SparsePRTEntry* get_entry(RegionIdx_t region_id) const;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue