From 19cf2fba3c4cac70a2bfad8c7702c57d6cad1e8f Mon Sep 17 00:00:00 2001 From: emteere <47253321+emteere@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:20:10 -0400 Subject: [PATCH] GP-4712 refactoring, adding back in cache with no locking --- .../processors/sleigh/ContextCache.java | 19 ++++++++++++++++--- .../processors/sleigh/SleighLanguage.java | 9 ++++----- .../program/model/pcode/HighFunction.java | 4 +--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/ContextCache.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/ContextCache.java index 5b1e562b72..639898eccb 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/ContextCache.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/ContextCache.java @@ -15,16 +15,19 @@ */ package ghidra.app.plugin.processors.sleigh; -import ghidra.program.model.address.Address; -import ghidra.program.model.lang.*; - import java.math.BigInteger; import java.util.Arrays; +import generic.stl.Pair; +import ghidra.program.model.address.Address; +import ghidra.program.model.lang.*; + public class ContextCache { private int context_size = 0; private Register contextBaseRegister = null; + Pair lastValue = null; + public ContextCache() { } @@ -55,7 +58,13 @@ public class ContextCache { private int[] getWords(BigInteger value) { + Pair lastValueTmp = lastValue; + if (lastValueTmp != null && value.equals(lastValueTmp.first)) { + return lastValueTmp.second; + } + int[] words = new int[context_size]; + byte[] bytes = value.toByteArray(); int byteIndexDiff = context_size * 4 - bytes.length; for (int i = 0; i < context_size; i++) { @@ -66,6 +75,10 @@ public class ContextCache { } words[i] = word; } + + lastValueTmp = new Pair(value, words); + lastValue = lastValueTmp; + return words; } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java index 0e810c2b1f..1688ba427b 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java @@ -378,13 +378,12 @@ public class SleighLanguage implements Language { if (!instructProtoMap.containsKey(hashcode)) { newProto.cacheInfo(buf, context, true); } - - res = instructProtoMap.get(hashcode); - if (res == null) { // We have a prototype we have never seen - // before, build it fully - instructProtoMap.put(hashcode, newProto); + res = instructProtoMap.putIfAbsent(hashcode, newProto); + // if there was no previous value, assume newProto inserted + if (res == null) { res = newProto; } + if (inDelaySlot && res.hasDelaySlots()) { throw new NestedDelaySlotException(); } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java index 1f0068159d..ce492b49ad 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunction.java @@ -51,7 +51,6 @@ public class HighFunction extends PcodeSyntaxTree { private List jumpTables; private List protoOverrides; private Address entryPoint; - private AddressSpace entryAddrSpace; /** * @param function function associated with the higher level function abstraction. @@ -67,7 +66,6 @@ public class HighFunction extends PcodeSyntaxTree { this.compilerSpec = compilerSpec; AddressSpace stackSpace = function.getProgram().getAddressFactory().getStackSpace(); entryPoint = function.getEntryPoint(); - entryAddrSpace = entryPoint.getAddressSpace(); localSymbols = new LocalSymbolMap(this, stackSpace); globalSymbols = new GlobalSymbolMap(this); proto = new FunctionPrototype(localSymbols, function); @@ -304,7 +302,7 @@ public class HighFunction extends PcodeSyntaxTree { private void decodeJumpTableList(Decoder decoder) throws DecoderException { int el = decoder.openElement(ELEM_JUMPTABLELIST); while (decoder.peekElement() != 0) { - JumpTable table = new JumpTable(entryAddrSpace); + JumpTable table = new JumpTable(entryPoint.getAddressSpace()); table.decode(decoder); if (!table.isEmpty()) { if (jumpTables == null) {