mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
Replace uses of LongObjectHashTable with Java's HashMap
This commit is contained in:
parent
7af55169c0
commit
e3aebe3adb
22 changed files with 407 additions and 767 deletions
|
@ -21,7 +21,6 @@ package ghidra.program.database;
|
|||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import db.Record;
|
||||
import ghidra.program.model.address.KeyRange;
|
||||
|
@ -199,18 +198,21 @@ public class DBObjectCache<T extends DatabaseObject> {
|
|||
* @param keyRanges key ranges to delete
|
||||
*/
|
||||
private void deleteLargeKeyRanges(List<KeyRange> keyRanges) {
|
||||
map.keySet()
|
||||
.stream()
|
||||
.filter(key -> keyRangesContain(keyRanges, key))
|
||||
.collect(Collectors.toList())
|
||||
.forEach(key -> {
|
||||
KeyedSoftReference ref = map.remove(key);
|
||||
DatabaseObject obj = ref.get();
|
||||
if (obj != null) {
|
||||
obj.setDeleted();
|
||||
ref.clear();
|
||||
}
|
||||
});
|
||||
map.values().removeIf(ref -> checkRef(ref, keyRanges));
|
||||
}
|
||||
|
||||
private boolean checkRef(KeyedSoftReference ref, List<KeyRange> keyRanges) {
|
||||
long key = ref.getKey();
|
||||
if (keyRangesContain(keyRanges, key)) {
|
||||
DatabaseObject obj = ref.get();
|
||||
if (obj != null) {
|
||||
obj.setDeleted();
|
||||
ref.clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -267,27 +269,6 @@ public class DBObjectCache<T extends DatabaseObject> {
|
|||
return invalidateCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates a range of objects in the cache.
|
||||
* @param startKey the first key in the range to invalidate.
|
||||
* @param endKey the last key in the range to invalidate.
|
||||
*/
|
||||
public synchronized void invalidate(long startKey, long endKey) {
|
||||
processQueue();
|
||||
if (endKey - startKey < map.size()) {
|
||||
for (long i = startKey; i <= endKey; i++) {
|
||||
doInvalidate(i);
|
||||
}
|
||||
}
|
||||
else {
|
||||
map.keySet()
|
||||
.stream()
|
||||
.filter(key -> (key >= startKey && key <= endKey))
|
||||
.collect(Collectors.toList())
|
||||
.forEach(key -> doInvalidate(key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the object with the given key from the cache.
|
||||
* @param key the key of the object to remove.
|
||||
|
@ -305,25 +286,6 @@ public class DBObjectCache<T extends DatabaseObject> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates the object with given key.
|
||||
* @param key the key of the object to invalidate.
|
||||
*/
|
||||
public synchronized void invalidate(long key) {
|
||||
processQueue();
|
||||
doInvalidate(key);
|
||||
}
|
||||
|
||||
private void doInvalidate(long key) {
|
||||
KeyedSoftReference ref = map.get(key);
|
||||
if (ref != null) {
|
||||
T obj = ref.get();
|
||||
if (obj != null) {
|
||||
obj.setInvalid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addToHardCache(T obj) {
|
||||
hardCache.addLast(obj);
|
||||
if (hardCache.size() > hardCacheSize) {
|
||||
|
|
|
@ -16,13 +16,14 @@
|
|||
package ghidra.program.database;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import db.*;
|
||||
import ghidra.program.model.address.AddressSpace;
|
||||
import ghidra.program.model.address.OverlayAddressSpace;
|
||||
import ghidra.program.model.lang.Language;
|
||||
import ghidra.program.util.LanguageTranslator;
|
||||
import ghidra.util.datastruct.LongObjectHashtable;
|
||||
import ghidra.util.exception.AssertException;
|
||||
import ghidra.util.exception.DuplicateNameException;
|
||||
|
||||
|
@ -115,7 +116,7 @@ class OverlaySpaceAdapterDB {
|
|||
}
|
||||
|
||||
void updateOverlaySpaces(ProgramAddressFactory factory) throws IOException {
|
||||
LongObjectHashtable<OverlayAddressSpace> map = new LongObjectHashtable<>();
|
||||
Map<Long, OverlayAddressSpace> map = new HashMap<>();
|
||||
for (AddressSpace space : factory.getAllAddressSpaces()) {
|
||||
if (space instanceof OverlayAddressSpace) {
|
||||
OverlayAddressSpace os = (OverlayAddressSpace) space;
|
||||
|
@ -162,11 +163,10 @@ class OverlaySpaceAdapterDB {
|
|||
}
|
||||
}
|
||||
if (map.size() != 0) {
|
||||
long[] keys = map.getKeys();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
OverlayAddressSpace space = map.remove(keys[i]);
|
||||
for (OverlayAddressSpace space : map.values()) {
|
||||
factory.removeOverlaySpace(space.getName());
|
||||
}
|
||||
map.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ import ghidra.program.model.lang.CompilerSpec;
|
|||
import ghidra.util.*;
|
||||
import ghidra.util.classfinder.ClassTranslator;
|
||||
import ghidra.util.datastruct.FixedSizeHashMap;
|
||||
import ghidra.util.datastruct.LongObjectHashtable;
|
||||
import ghidra.util.exception.*;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
|
@ -3490,15 +3489,15 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
|
|||
}
|
||||
|
||||
class IdsToDataTypeMap {
|
||||
private Map<UniversalID, LongObjectHashtable<DataType>> map = new HashMap<>();
|
||||
private Map<UniversalID, Map<Long, DataType>> map = new HashMap<>();
|
||||
|
||||
DataType getDataType(UniversalID sourceID, UniversalID dataTypeID) {
|
||||
if (sourceID == null || sourceID.equals(universalID)) {
|
||||
sourceID = LOCAL_ARCHIVE_UNIVERSAL_ID;
|
||||
}
|
||||
LongObjectHashtable<DataType> idMap = map.get(sourceID);
|
||||
Map<Long, DataType> idMap = map.get(sourceID);
|
||||
if (idMap == null) {
|
||||
idMap = new LongObjectHashtable<>();
|
||||
idMap = new HashMap<>();
|
||||
map.put(sourceID, idMap);
|
||||
}
|
||||
DataType dt = idMap.get(dataTypeID.getValue());
|
||||
|
@ -3527,7 +3526,7 @@ abstract public class DataTypeManagerDB implements DataTypeManager {
|
|||
else {
|
||||
sourceID = sourceArchive.getSourceArchiveID();
|
||||
}
|
||||
LongObjectHashtable<DataType> idMap = map.get(sourceID);
|
||||
Map<Long, DataType> idMap = map.get(sourceID);
|
||||
if (idMap != null) {
|
||||
idMap.remove(dataTypeID.getValue());
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import ghidra.program.model.symbol.*;
|
|||
import ghidra.program.util.LanguageTranslator;
|
||||
import ghidra.util.Lock;
|
||||
import ghidra.util.Msg;
|
||||
import ghidra.util.datastruct.LongObjectHashtable;
|
||||
import ghidra.util.exception.*;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
|
@ -122,7 +121,7 @@ public class ExternalManagerDB implements ManagerDB, ExternalManager {
|
|||
monitor.initialize(oldNameAdapter.getRecordCount());
|
||||
int cnt = 0;
|
||||
|
||||
LongObjectHashtable<String> nameMap = new LongObjectHashtable<>();
|
||||
Map<Long, String> nameMap = new HashMap<>();
|
||||
|
||||
RecordIterator iter = oldNameAdapter.getRecords();
|
||||
while (iter.hasNext()) {
|
||||
|
|
|
@ -18,7 +18,8 @@ package ghidra.program.database.map;
|
|||
import java.util.*;
|
||||
|
||||
import ghidra.program.model.address.*;
|
||||
import ghidra.util.datastruct.*;
|
||||
import ghidra.util.datastruct.Range;
|
||||
import ghidra.util.datastruct.SortedRangeList;
|
||||
|
||||
/**
|
||||
* AddressSetView implementation that handles image base changes. NOTE: THIS IMPLEMENTATION
|
||||
|
@ -33,8 +34,7 @@ public class NormalizedAddressSet implements AddressSetView {
|
|||
|
||||
private AddressMap addrMap;
|
||||
|
||||
private LongObjectHashtable<SortedRangeList> baseLists =
|
||||
new LongObjectHashtable<SortedRangeList>();
|
||||
private Map<Long, SortedRangeList> baseLists = new HashMap<>();
|
||||
private ArrayList<Long> bases = new ArrayList<Long>();
|
||||
|
||||
private Comparator<Long> baseComparator = new Comparator<Long>() {
|
||||
|
@ -108,7 +108,7 @@ public class NormalizedAddressSet implements AddressSetView {
|
|||
* Removes all addresses from this set.
|
||||
*/
|
||||
public void clear() {
|
||||
baseLists = new LongObjectHashtable<SortedRangeList>();
|
||||
baseLists = new HashMap<>();
|
||||
bases = new ArrayList<Long>();
|
||||
}
|
||||
|
||||
|
@ -251,9 +251,9 @@ public class NormalizedAddressSet implements AddressSetView {
|
|||
@Override
|
||||
public int getNumAddressRanges() {
|
||||
int n = 0;
|
||||
long[] keys = baseLists.getKeys();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
SortedRangeList list = baseLists.get(keys[i]);
|
||||
|
||||
for (long key : baseLists.keySet()) {
|
||||
SortedRangeList list = baseLists.get(key);
|
||||
n += list.getNumRanges();
|
||||
}
|
||||
return n;
|
||||
|
@ -286,9 +286,8 @@ public class NormalizedAddressSet implements AddressSetView {
|
|||
@Override
|
||||
public long getNumAddresses() {
|
||||
long n = 0;
|
||||
long[] keys = baseLists.getKeys();
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
SortedRangeList list = baseLists.get(keys[i]);
|
||||
for (long key : baseLists.keySet()) {
|
||||
SortedRangeList list = baseLists.get(key);
|
||||
n += list.getNumValues();
|
||||
}
|
||||
return n;
|
||||
|
|
|
@ -32,9 +32,7 @@ import ghidra.program.model.listing.ProgramContext;
|
|||
import ghidra.program.util.RangeMapAdapter;
|
||||
import ghidra.program.util.RegisterValueStore;
|
||||
import ghidra.util.Lock;
|
||||
import ghidra.util.datastruct.LongObjectHashtable;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.exception.VersionException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
/**
|
||||
|
@ -61,7 +59,7 @@ public class OldProgramContextDB implements ProgramContext, DefaultProgramContex
|
|||
* address ranges using the PropertyMap utilities.
|
||||
*/
|
||||
private HashMap<String, Register> registersMap;
|
||||
private LongObjectHashtable<AddressRangeMapDB> valueMaps;
|
||||
private Map<Integer, AddressRangeMapDB> valueMaps;
|
||||
private Register baseContextRegister;
|
||||
protected Map<Register, RegisterValueStore> defaultRegisterValueMap;
|
||||
|
||||
|
@ -88,7 +86,7 @@ public class OldProgramContextDB implements ProgramContext, DefaultProgramContex
|
|||
defaultRegisterValueMap = new HashMap<Register, RegisterValueStore>();
|
||||
|
||||
registersMap = new HashMap<String, Register>();
|
||||
valueMaps = new LongObjectHashtable<AddressRangeMapDB>();
|
||||
valueMaps = new HashMap<>();
|
||||
registerSpaceSize = 0;
|
||||
|
||||
for (Register register : registers) {
|
||||
|
@ -350,7 +348,7 @@ public class OldProgramContextDB implements ProgramContext, DefaultProgramContex
|
|||
public void invalidateCache(boolean all) throws IOException {
|
||||
lock.acquire();
|
||||
try {
|
||||
valueMaps.removeAll();
|
||||
valueMaps.clear();
|
||||
}
|
||||
finally {
|
||||
lock.release();
|
||||
|
|
|
@ -306,29 +306,11 @@ public abstract class DefaultPropertyMap implements PropertyMap {
|
|||
* @throws ClassNotFoundException if the class for the object being
|
||||
* read is not in the class path
|
||||
*/
|
||||
public void restoreProperties(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
public void restoreProperties(ObjectInputStream ois)
|
||||
throws IOException, ClassNotFoundException {
|
||||
propertyMgr.restoreProperties(ois);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write all properties in the map to the given output stream.
|
||||
* @throws IOException if there is a problem writing to the stream
|
||||
*/
|
||||
public void saveAll(ObjectOutputStream out) throws IOException {
|
||||
propertyMgr.saveAll(out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore properties read from the given input stream.
|
||||
* @param in input stream
|
||||
* @throws IOException if there is a problem reading from the stream
|
||||
* @throws ClassNotFoundException if the class for the object being
|
||||
* read is not in the class path
|
||||
*/
|
||||
public void restoreAll(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
propertyMgr.restoreAll(in);
|
||||
}
|
||||
|
||||
private class AddressPropertyIterator implements AddressIterator {
|
||||
|
||||
private LongIterator iter;
|
||||
|
@ -350,7 +332,8 @@ public abstract class DefaultPropertyMap implements PropertyMap {
|
|||
|
||||
AddressPropertyIterator(Address start, Address end, boolean forward) {
|
||||
iter =
|
||||
propertyMgr.getPropertyIterator(addrMap.getKey(start), addrMap.getKey(end), forward);
|
||||
propertyMgr.getPropertyIterator(addrMap.getKey(start), addrMap.getKey(end),
|
||||
forward);
|
||||
this.forward = forward;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue