From daafa516bb91b111b5e878a23ffd7ea8d25120b1 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Sun, 9 Oct 2022 14:55:46 -0400 Subject: [PATCH] Don't synchronize on Boolean/Integer object This fixes numerous warnings like this: Boolean is a value-based type which is a discouraged argument for the synchronized statement and: Integer is a value-based type which is a discouraged argument for the synchronized statement --- .../dsf/gdb/tests/GDBRemoteTracepointsTest.java | 2 +- .../tests/dsf/gdb/tests/MIBreakpointsTest.java | 2 +- .../tests/dsf/gdb/tests/MICatchpointsTest.java | 2 +- .../cdt/tests/dsf/gdb/tests/MIMemoryTest.java | 17 +++++------------ 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/GDBRemoteTracepointsTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/GDBRemoteTracepointsTest.java index 2e94151b37d..cb31fe695f1 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/GDBRemoteTracepointsTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/GDBRemoteTracepointsTest.java @@ -217,7 +217,7 @@ public void doAfterTest() throws Exception { // ********************************************************************* // Below are utility methods. // ********************************************************************* - private static Boolean lock = true; + private static Object lock = new Object(); enum Events { BP_ADDED, BP_UPDATED, BP_REMOVED, BP_HIT diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java index 972529a6947..a1bfabf7236 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIBreakpointsTest.java @@ -109,7 +109,7 @@ public class MIBreakpointsTest extends BaseParametrizedTestCase { protected IExpressions fExpressionService; protected IGDBControl fCommandControl; // Event Management - protected static Boolean lock = true; + protected static Object lock = new Object(); protected enum Events { BP_ADDED, BP_UPDATED, BP_REMOVED, BP_HIT, WP_HIT, WP_OOS diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MICatchpointsTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MICatchpointsTest.java index 2a7e3801c81..e2cb46745b8 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MICatchpointsTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MICatchpointsTest.java @@ -104,7 +104,7 @@ public class MICatchpointsTest extends BaseParametrizedTestCase { private IExpressions fExpressionService; // Event Management - private static Boolean fEventHandlerLock = true; + private static Object fEventHandlerLock = new Object(); private enum Events { BP_ADDED, BP_UPDATED, BP_REMOVED, BP_HIT diff --git a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIMemoryTest.java b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIMemoryTest.java index 0ba82236d66..95cd82d191e 100644 --- a/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIMemoryTest.java +++ b/dsf-gdb/org.eclipse.cdt.tests.dsf.gdb/src/org/eclipse/cdt/tests/dsf/gdb/tests/MIMemoryTest.java @@ -25,6 +25,7 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.concurrent.ExecutionException; +import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.cdt.core.IAddress; import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants; @@ -86,7 +87,7 @@ public class MIMemoryTest extends BaseParametrizedTestCase { // Keeps track of the MemoryChangedEvents private final int BLOCK_SIZE = 256; private IAddress fBaseAddress; - private Integer fMemoryChangedEventCount = 0; + private AtomicInteger fMemoryChangedEventCount = new AtomicInteger(0); private boolean[] fMemoryAddressesChanged = new boolean[BLOCK_SIZE]; @Rule @@ -168,9 +169,7 @@ public void doAfterTest() throws Exception { */ @DsfServiceEventHandler public void eventDispatched(IMemoryChangedEvent e) { - synchronized (fMemoryChangedEventCount) { - fMemoryChangedEventCount++; - } + fMemoryChangedEventCount.incrementAndGet(); IAddress[] addresses = e.getAddresses(); for (int i = 0; i < addresses.length; i++) { int offset = Math.abs(addresses[i].distanceTo(fBaseAddress).intValue()); @@ -183,9 +182,7 @@ public void eventDispatched(IMemoryChangedEvent e) { // Clears the counters private void clearEventCounters() { - synchronized (fMemoryChangedEventCount) { - fMemoryChangedEventCount = 0; - } + fMemoryChangedEventCount.set(0); synchronized (fMemoryAddressesChanged) { for (int i = 0; i < BLOCK_SIZE; i++) fMemoryAddressesChanged[i] = false; @@ -194,11 +191,7 @@ private void clearEventCounters() { // Returns the total number of events received private int getEventCount() { - int count; - synchronized (fMemoryChangedEventCount) { - count = fMemoryChangedEventCount; - } - return count; + return fMemoryChangedEventCount.get(); } // Returns the number of distinct addresses reported