Ghidra is a software reverse engineering (SRE) framework
GP-1411: keying space cache by identity
Dan9d12f6c57ac4
diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LogicalBreakpointInternal.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LogicalBreakpointInternal.javaindex 6a2219d44a..9d17df1b79 100644--- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LogicalBreakpointInternal.java+++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/service/breakpoint/LogicalBreakpointInternal.java@@ -35,6 +35,7 @@ import ghidra.util.Msg;import ghidra.util.database.UndoableTransaction;import ghidra.util.exception.CancelledException;import ghidra.util.task.TaskMonitor;+import utilities.util.IDHashed;interface LogicalBreakpointInternal extends LogicalBreakpoint {public static class ProgramBreakpoint {@@ -248,33 +249,6 @@ interface LogicalBreakpointInternal extends LogicalBreakpoint {}static class TraceBreakpointSet {- private static class IDHashed<T> {- final T obj;-- public IDHashed(T obj) {- this.obj = obj;- }-- @Override- public String toString() {- return obj.toString();- }-- @Override- public int hashCode() {- return System.identityHashCode(obj);- }-- @Override- public boolean equals(Object o) {- if (!(o instanceof IDHashed<?>)) {- return false;- }- IDHashed<?> that = (IDHashed<?>) o;- return this.obj.equals(that.obj);- }- }-private final TraceRecorder recorder;private final Trace trace;private final Address address;diff --git a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/TraceAddressSnapSpace.java b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/TraceAddressSnapSpace.javaindex 36e1e474ea..8f4f3da38e 100644--- a/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/TraceAddressSnapSpace.java+++ b/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/model/TraceAddressSnapSpace.java@@ -22,9 +22,11 @@ import ghidra.program.model.address.Address;import ghidra.program.model.address.AddressSpace;import ghidra.trace.model.map.UnsignedUtils;import ghidra.util.database.spatial.rect.EuclideanSpace2D;+import utilities.util.IDHashed;public class TraceAddressSnapSpace implements EuclideanSpace2D<Address, Long> {- private static final Map<AddressSpace, TraceAddressSnapSpace> SPACES = new HashMap<>();+ private static final Map<IDHashed<AddressSpace>, TraceAddressSnapSpace> SPACES =+ new HashMap<>();/*** Get the trace-address-snap space for a given address space@@ -38,7 +40,8 @@ public class TraceAddressSnapSpace implements EuclideanSpace2D<Address, Long> {*/public static TraceAddressSnapSpace forAddressSpace(AddressSpace space) {synchronized (SPACES) {- return SPACES.computeIfAbsent(space, TraceAddressSnapSpace::new);+ return SPACES.computeIfAbsent(new IDHashed<>(space),+ s -> new TraceAddressSnapSpace(space));}}diff --git a/Ghidra/Debug/ProposedUtils/src/main/java/utilities/util/IDHashed.java b/Ghidra/Debug/ProposedUtils/src/main/java/utilities/util/IDHashed.javanew file mode 100644index 0000000000..3b500d98ba--- /dev/null+++ b/Ghidra/Debug/ProposedUtils/src/main/java/utilities/util/IDHashed.java@@ -0,0 +1,43 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package utilities.util;++public class IDHashed<T> {+ public final T obj;++ public IDHashed(T obj) {+ this.obj = obj;+ }++ @Override+ public String toString() {+ return obj.toString();+ }++ @Override+ public int hashCode() {+ return System.identityHashCode(obj);+ }++ @Override+ public boolean equals(Object o) {+ if (!(o instanceof IDHashed<?>)) {+ return false;+ }+ IDHashed<?> that = (IDHashed<?>) o;+ return this.obj.equals(that.obj);+ }+}