SleighLanguage: Use more performant ConcurrentHashMap

This commit is contained in:
sad-dev 2024-06-18 16:31:08 +08:00 committed by GitHub
parent 03cc1b8468
commit 789cbd9241
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,6 +20,7 @@ import static ghidra.pcode.utils.SlaFormat.*;
import java.io.*; import java.io.*;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -88,7 +89,7 @@ public class SleighLanguage implements Language {
/** /**
* Cached instruction prototypes * Cached instruction prototypes
*/ */
private LinkedHashMap<Integer, SleighInstructionPrototype> instructProtoMap; private ConcurrentHashMap<Integer, SleighInstructionPrototype> instructProtoMap;
private DecisionNode root = null; private DecisionNode root = null;
/** /**
* table of AddressSpaces * table of AddressSpaces
@ -148,7 +149,7 @@ public class SleighLanguage implements Language {
buildVolatileSymbolAddresses(); buildVolatileSymbolAddresses();
xrefRegisters(); xrefRegisters();
instructProtoMap = new LinkedHashMap<>(); instructProtoMap = new ConcurrentHashMap<>();
initParallelHelper(); initParallelHelper();
} }
@ -378,16 +379,14 @@ public class SleighLanguage implements Language {
newProto.cacheInfo(buf, context, true); newProto.cacheInfo(buf, context, true);
} }
synchronized (instructProtoMap) { res = instructProtoMap.get(hashcode);
res = instructProtoMap.get(hashcode); if (res == null) { // We have a prototype we have never seen
if (res == null) { // We have a prototype we have never seen // before, build it fully
// before, build it fully instructProtoMap.put(hashcode, newProto);
instructProtoMap.put(hashcode, newProto); res = newProto;
res = newProto; }
} if (inDelaySlot && res.hasDelaySlots()) {
if (inDelaySlot && res.hasDelaySlots()) { throw new NestedDelaySlotException();
throw new NestedDelaySlotException();
}
} }
} }
catch (MemoryAccessException e) { catch (MemoryAccessException e) {