1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Simple changes for Sonar warnings

Change-Id: Ic47b9cef191d1f59514327cdb2f612869da12b16
This commit is contained in:
Marc Khouzam 2015-08-14 11:15:20 -04:00
parent f8292e1bc4
commit 22fb739c9b

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2014 Wind River Systems and others. * Copyright (c) 2007, 2015 Wind River Systems and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Map; import java.util.Map;
@ -76,8 +77,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
public class MemoryChangedEvent extends AbstractDMEvent<IMemoryDMContext> public class MemoryChangedEvent extends AbstractDMEvent<IMemoryDMContext>
implements IMemoryChangedEvent implements IMemoryChangedEvent
{ {
IAddress[] fAddresses; private IAddress[] fAddresses;
IDMContext fContext;
public MemoryChangedEvent(IMemoryDMContext context, IAddress[] addresses) { public MemoryChangedEvent(IMemoryDMContext context, IAddress[] addresses) {
super(context); super(context);
@ -193,7 +193,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
*/ */
@Override @Override
public void getMemory(IMemoryDMContext memoryDMC, IAddress address, long offset, public void getMemory(IMemoryDMContext memoryDMC, IAddress address, long offset,
int word_size, int word_count, DataRequestMonitor<MemoryByte[]> drm) int wordSize, int wordCount, DataRequestMonitor<MemoryByte[]> drm)
{ {
if (memoryDMC == null) { if (memoryDMC == null) {
drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Unknown context type", null)); //$NON-NLS-1$); drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Unknown context type", null)); //$NON-NLS-1$);
@ -201,19 +201,19 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
return; return;
} }
if (word_size < 1) { if (wordSize < 1) {
drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Word size not supported (< 1)", null)); //$NON-NLS-1$ drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Word size not supported (< 1)", null)); //$NON-NLS-1$
drm.done(); drm.done();
return; return;
} }
if (word_count < 0) { if (wordCount < 0) {
drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Invalid word count (< 0)", null)); //$NON-NLS-1$ drm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Invalid word count (< 0)", null)); //$NON-NLS-1$
drm.done(); drm.done();
return; return;
} }
getMemoryCache(memoryDMC).getMemory(memoryDMC, address.add(offset), word_size, word_count, drm); getMemoryCache(memoryDMC).getMemory(memoryDMC, address.add(offset), wordSize, wordCount, drm);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -221,7 +221,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
*/ */
@Override @Override
public void setMemory(IMemoryDMContext memoryDMC, IAddress address, long offset, public void setMemory(IMemoryDMContext memoryDMC, IAddress address, long offset,
int word_size, int word_count, byte[] buffer, RequestMonitor rm) int wordSize, int wordCount, byte[] buffer, RequestMonitor rm)
{ {
if (memoryDMC == null) { if (memoryDMC == null) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Unknown context type", null)); //$NON-NLS-1$); rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Unknown context type", null)); //$NON-NLS-1$);
@ -229,25 +229,25 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
return; return;
} }
if (word_size < 1) { if (wordSize < 1) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Word size not supported (< 1)", null)); //$NON-NLS-1$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Word size not supported (< 1)", null)); //$NON-NLS-1$
rm.done(); rm.done();
return; return;
} }
if (word_count < 0) { if (wordCount < 0) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Invalid word count (< 0)", null)); //$NON-NLS-1$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Invalid word count (< 0)", null)); //$NON-NLS-1$
rm.done(); rm.done();
return; return;
} }
if (buffer.length < word_count * word_size) { if (buffer.length < wordCount * wordSize) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Buffer too short", null)); //$NON-NLS-1$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, IDsfStatusConstants.INTERNAL_ERROR, "Buffer too short", null)); //$NON-NLS-1$
rm.done(); rm.done();
return; return;
} }
getMemoryCache(memoryDMC).setMemory(memoryDMC, address, offset, word_size, word_count, buffer, rm); getMemoryCache(memoryDMC).setMemory(memoryDMC, address, offset, wordSize, wordCount, buffer, rm);
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -255,7 +255,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
*/ */
@Override @Override
public void fillMemory(IMemoryDMContext memoryDMC, IAddress address, long offset, public void fillMemory(IMemoryDMContext memoryDMC, IAddress address, long offset,
int word_size, int count, byte[] pattern, RequestMonitor rm) int wordSize, int count, byte[] pattern, RequestMonitor rm)
{ {
if (memoryDMC == null) { if (memoryDMC == null) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Unknown context type", null)); //$NON-NLS-1$); rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, INTERNAL_ERROR, "Unknown context type", null)); //$NON-NLS-1$);
@ -263,7 +263,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
return; return;
} }
if (word_size < 1) { if (wordSize < 1) {
rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Word size not supported (< 1)", null)); //$NON-NLS-1$ rm.setStatus(new Status(IStatus.ERROR, GdbPlugin.PLUGIN_ID, NOT_SUPPORTED, "Word size not supported (< 1)", null)); //$NON-NLS-1$
rm.done(); rm.done();
return; return;
@ -288,13 +288,13 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
System.arraycopy(pattern, 0, buffer, i * length, length); System.arraycopy(pattern, 0, buffer, i * length, length);
} }
int word_count = buffer.length / word_size; int word_count = buffer.length / wordSize;
if (buffer.length % word_size != 0) { if (buffer.length % wordSize != 0) {
word_count ++; word_count ++;
} }
// All is clear: go for it // All is clear: go for it
getMemoryCache(memoryDMC).setMemory(memoryDMC, address, offset, word_size, word_count, buffer, rm); getMemoryCache(memoryDMC).setMemory(memoryDMC, address, offset, wordSize, word_count, buffer, rm);
} }
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
@ -305,18 +305,18 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
* @param memoryDMC * @param memoryDMC
* @param address * @param address
* @param offset * @param offset
* @param word_size * @param wordSize
* @param word_count in addressable units * @param wordCount in addressable units
* @param drm * @param drm
* *
* @since 1.1 * @since 1.1
*/ */
protected void readMemoryBlock(IDMContext dmc, IAddress address, final long offset, protected void readMemoryBlock(IDMContext dmc, IAddress address, final long offset,
final int word_size, final int word_count, final DataRequestMonitor<MemoryByte[]> drm) final int wordSize, final int wordCount, final DataRequestMonitor<MemoryByte[]> drm)
{ {
if (fDataReadMemoryBytes) { if (fDataReadMemoryBytes) {
fCommandCache.execute( fCommandCache.execute(
fCommandFactory.createMIDataReadMemoryBytes(dmc, address.toString(), offset, word_count, word_size), fCommandFactory.createMIDataReadMemoryBytes(dmc, address.toString(), offset, wordCount, wordSize),
new DataRequestMonitor<MIDataReadMemoryBytesInfo>(getExecutor(), drm) { new DataRequestMonitor<MIDataReadMemoryBytesInfo>(getExecutor(), drm) {
@Override @Override
protected void handleSuccess() { protected void handleSuccess() {
@ -326,12 +326,12 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
} }
@Override @Override
protected void handleFailure() { protected void handleFailure() {
drm.setData(createInvalidBlock(word_size * word_count)); drm.setData(createInvalidBlock(wordSize * wordCount));
drm.done(); drm.done();
} }
}); });
} else { } else {
if (word_size != 1) { if (wordSize != 1) {
//The word-size is specified within the resulting command data-read-memory //The word-size is specified within the resulting command data-read-memory
//The word-size is defined in bytes although in the MI interface it's not clear if the meaning is //The word-size is defined in bytes although in the MI interface it's not clear if the meaning is
//octets or system dependent bytes (minimum addressable memory). //octets or system dependent bytes (minimum addressable memory).
@ -345,12 +345,12 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
* be on 1 row of [count] columns, no char interpretation. * be on 1 row of [count] columns, no char interpretation.
*/ */
int mode = MIFormat.HEXADECIMAL; int mode = MIFormat.HEXADECIMAL;
int nb_rows = 1; int nbRows = 1;
int nb_cols = word_count; int nbCols = wordCount;
Character asChar = null; Character asChar = null;
fCommandCache.execute( fCommandCache.execute(
fCommandFactory.createMIDataReadMemory(dmc, offset, address.toString(), mode, word_size, nb_rows, nb_cols, asChar), fCommandFactory.createMIDataReadMemory(dmc, offset, address.toString(), mode, wordSize, nbRows, nbCols, asChar),
new DataRequestMonitor<MIDataReadMemoryInfo>(getExecutor(), drm) { new DataRequestMonitor<MIDataReadMemoryInfo>(getExecutor(), drm) {
@Override @Override
protected void handleSuccess() { protected void handleSuccess() {
@ -360,7 +360,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
} }
@Override @Override
protected void handleFailure() { protected void handleFailure() {
drm.setData(createInvalidBlock(word_size * word_count)); drm.setData(createInvalidBlock(wordSize * wordCount));
drm.done(); drm.done();
} }
} }
@ -371,8 +371,9 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
private MemoryByte[] createInvalidBlock(int size) { private MemoryByte[] createInvalidBlock(int size) {
// Bug234289: If memory read fails, return a block marked as invalid // Bug234289: If memory read fails, return a block marked as invalid
MemoryByte[] block = new MemoryByte[size]; MemoryByte[] block = new MemoryByte[size];
for (int i = 0; i < block.length; i++) for (int i = 0; i < block.length; i++) {
block[i] = new MemoryByte((byte) 0, (byte) 0); block[i] = new MemoryByte((byte) 0, (byte) 0);
}
return block; return block;
} }
@ -380,25 +381,25 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
* @param memoryDMC * @param memoryDMC
* @param address * @param address
* @param offset * @param offset
* @param word_size * @param wordSize
* @param word_count in addressable units * @param wordCount in addressable units
* @param buffer * @param buffer
* @param rm * @param rm
* *
* @since 1.1 * @since 1.1
*/ */
protected void writeMemoryBlock(final IDMContext dmc, final IAddress address, final long offset, protected void writeMemoryBlock(final IDMContext dmc, final IAddress address, final long offset,
final int word_size, final int word_count, final byte[] buffer, final RequestMonitor rm) final int wordSize, final int wordCount, final byte[] buffer, final RequestMonitor rm)
{ {
if (fDataReadMemoryBytes) { if (fDataReadMemoryBytes) {
// Use -data-write-memory-bytes for performance, // Use -data-write-memory-bytes for performance,
fCommandCache.execute( fCommandCache.execute(
fCommandFactory.createMIDataWriteMemoryBytes(dmc, address.add(offset).toString(), fCommandFactory.createMIDataWriteMemoryBytes(dmc, address.add(offset).toString(),
(buffer.length == word_count*word_size) ? buffer : Arrays.copyOf(buffer, word_count*word_size)), (buffer.length == wordCount*wordSize) ? buffer : Arrays.copyOf(buffer, wordCount*wordSize)),
new DataRequestMonitor<MIInfo>(getExecutor(), rm) new DataRequestMonitor<MIInfo>(getExecutor(), rm)
); );
} else { } else {
if (word_size != 1) { if (wordSize != 1) {
//The word-size is specified within the resulting command data-write-memory //The word-size is specified within the resulting command data-write-memory
//The word-size is defined in bytes although in the MI interface it's not clear if the meaning is //The word-size is defined in bytes although in the MI interface it's not clear if the meaning is
//octets or system dependent bytes (minimum addressable memory). //octets or system dependent bytes (minimum addressable memory).
@ -411,17 +412,17 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
// Each byte is written individually (GDB power...) // Each byte is written individually (GDB power...)
// so we need to keep track of the count // so we need to keep track of the count
final CountingRequestMonitor countingRM = new CountingRequestMonitor(getExecutor(), rm); final CountingRequestMonitor countingRM = new CountingRequestMonitor(getExecutor(), rm);
countingRM.setDoneCount(word_count); countingRM.setDoneCount(wordCount);
// We will format the individual bytes in decimal // We will format the individual bytes in decimal
int format = MIFormat.DECIMAL; int format = MIFormat.DECIMAL;
String baseAddress = address.toString(); String baseAddress = address.toString();
// Issue an MI request for each byte to write // Issue an MI request for each byte to write
for (int i = 0; i < word_count; i++) { for (int i = 0; i < wordCount; i++) {
String value = new Byte(buffer[i]).toString(); String value = Byte.toString(buffer[i]);
fCommandCache.execute( fCommandCache.execute(
fCommandFactory.createMIDataWriteMemory(dmc, offset + i, baseAddress, format, word_size, value), fCommandFactory.createMIDataWriteMemory(dmc, offset + i, baseAddress, format, wordSize, value),
new DataRequestMonitor<MIDataWriteMemoryInfo>(getExecutor(), countingRM) new DataRequestMonitor<MIDataWriteMemoryInfo>(getExecutor(), countingRM)
); );
} }
@ -497,10 +498,11 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
if (expAddress != IExpressions.IExpressionDMLocation.INVALID_ADDRESS) { if (expAddress != IExpressions.IExpressionDMLocation.INVALID_ADDRESS) {
final int count = expression.getSize(); final int count = expression.getSize();
final Addr64 address; final Addr64 address;
if (expAddress instanceof Addr64) if (expAddress instanceof Addr64) {
address = (Addr64) expAddress; address = (Addr64) expAddress;
else } else {
address = new Addr64(expAddress.getValue()); address = new Addr64(expAddress.getValue());
}
final IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(context, IMemoryDMContext.class); final IMemoryDMContext memoryDMC = DMContexts.getAncestorOfType(context, IMemoryDMContext.class);
getMemoryCache(memoryDMC).refreshMemory(memoryDMC, address, 0, getAddressableSize(memoryDMC), count, true, getMemoryCache(memoryDMC).refreshMemory(memoryDMC, address, 0, getAddressableSize(memoryDMC), count, true,
@ -525,7 +527,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
// This class is really the equivalent of a C struct (old habits die hard...) // This class is really the equivalent of a C struct (old habits die hard...)
// For simplicity, everything is public. // For simplicity, everything is public.
private class MemoryBlock { private static class MemoryBlock {
public IAddress fAddress; public IAddress fAddress;
public long fLengthInAddressableUnits; public long fLengthInAddressableUnits;
public long fLengthInOctets; public long fLengthInOctets;
@ -544,7 +546,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
// Address-ordered data structure to cache the memory blocks. // Address-ordered data structure to cache the memory blocks.
// Contiguous blocks are merged if possible. // Contiguous blocks are merged if possible.
@SuppressWarnings("serial") @SuppressWarnings("serial")
private class SortedMemoryBlockList extends LinkedList<MemoryBlock> { private static class SortedMemoryBlockList extends LinkedList<MemoryBlock> {
public SortedMemoryBlockList() { public SortedMemoryBlockList() {
super(); super();
@ -702,8 +704,8 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
* @return A list of the sub-blocks to fetch in order to fill enough gaps in the memory cache * @return A list of the sub-blocks to fetch in order to fill enough gaps in the memory cache
* to service the request * to service the request
*/ */
private LinkedList<MemoryBlock> getListOfMissingBlocks(IAddress reqBlockStart, int word_count, int word_size) { private List<MemoryBlock> getListOfMissingBlocks(IAddress reqBlockStart, int wordCount, int wordSize) {
int octetCount = word_count * word_size; int octetCount = wordCount * wordSize;
LinkedList<MemoryBlock> list = new LinkedList<MemoryBlock>(); LinkedList<MemoryBlock> list = new LinkedList<MemoryBlock>();
ListIterator<MemoryBlock> it = fMemoryBlockList.listIterator(); ListIterator<MemoryBlock> it = fMemoryBlockList.listIterator();
@ -716,10 +718,10 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
// Case where we miss a block before the cached block // Case where we miss a block before the cached block
if (reqBlockStart.distanceTo(cachedBlockStart).longValue() >= 0) { if (reqBlockStart.distanceTo(cachedBlockStart).longValue() >= 0) {
int lengthInOctets = (int) Math.min(reqBlockStart.distanceTo(cachedBlockStart).longValue()*word_size, octetCount); int lengthInOctets = (int) Math.min(reqBlockStart.distanceTo(cachedBlockStart).longValue()*wordSize, octetCount);
// If both blocks start at the same location, no need to create a new cached block // If both blocks start at the same location, no need to create a new cached block
if (lengthInOctets > 0) { if (lengthInOctets > 0) {
int lengthInAddressableUnits = lengthInOctets / word_size; int lengthInAddressableUnits = lengthInOctets / wordSize;
MemoryBlock newBlock = new MemoryBlock(reqBlockStart, lengthInOctets, lengthInAddressableUnits, new MemoryByte[0]); MemoryBlock newBlock = new MemoryBlock(reqBlockStart, lengthInOctets, lengthInAddressableUnits, new MemoryByte[0]);
list.add(newBlock); list.add(newBlock);
} }
@ -734,14 +736,14 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
{ {
// Start of the requested block already in cache // Start of the requested block already in cache
// Adjust request block start and length for the next iteration // Adjust request block start and length for the next iteration
octetCount -= reqBlockStart.distanceTo(cachedBlockEnd).longValue()*word_size; octetCount -= reqBlockStart.distanceTo(cachedBlockEnd).longValue()*wordSize;
reqBlockStart = cachedBlockEnd; reqBlockStart = cachedBlockEnd;
} }
} }
// Case where we miss a block at the end of the cache // Case where we miss a block at the end of the cache
if (octetCount > 0) { if (octetCount > 0) {
int addressesLength = octetCount / word_size; int addressesLength = octetCount / wordSize;
MemoryBlock newBlock = new MemoryBlock(reqBlockStart, octetCount, addressesLength, new MemoryByte[0]); MemoryBlock newBlock = new MemoryBlock(reqBlockStart, octetCount, addressesLength, new MemoryByte[0]);
list.add(newBlock); list.add(newBlock);
} }
@ -775,10 +777,10 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
* @param count Its length * @param count Its length
* @return The cached memory content * @return The cached memory content
*/ */
private MemoryByte[] getMemoryBlockFromCache(IAddress reqBlockStart, int word_count, int word_size) { private MemoryByte[] getMemoryBlockFromCache(IAddress reqBlockStart, int wordCount, int wordSize) {
int count = word_count * word_size; int count = wordCount * wordSize;
IAddress reqBlockEnd = reqBlockStart.add(word_count); IAddress reqBlockEnd = reqBlockStart.add(wordCount);
MemoryByte[] resultBlock = new MemoryByte[count]; MemoryByte[] resultBlock = new MemoryByte[count];
ListIterator<MemoryBlock> iter = fMemoryBlockList.listIterator(); ListIterator<MemoryBlock> iter = fMemoryBlockList.listIterator();
@ -791,7 +793,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
if (cachedBlockStart.distanceTo(reqBlockStart).longValue() >= 0 if (cachedBlockStart.distanceTo(reqBlockStart).longValue() >= 0
&& reqBlockEnd.distanceTo(cachedBlockEnd).longValue() >= 0) && reqBlockEnd.distanceTo(cachedBlockEnd).longValue() >= 0)
{ {
int pos = (int) cachedBlockStart.distanceTo(reqBlockStart).longValue() * word_size; int pos = (int) cachedBlockStart.distanceTo(reqBlockStart).longValue() * wordSize;
System.arraycopy(cachedBlock.fBlock, pos, resultBlock, 0, count); System.arraycopy(cachedBlock.fBlock, pos, resultBlock, 0, count);
} }
@ -799,7 +801,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
else if (reqBlockStart.distanceTo(cachedBlockStart).longValue() >= 0 else if (reqBlockStart.distanceTo(cachedBlockStart).longValue() >= 0
&& cachedBlockStart.distanceTo(reqBlockEnd).longValue() > 0) && cachedBlockStart.distanceTo(reqBlockEnd).longValue() > 0)
{ {
int pos = (int) reqBlockStart.distanceTo(cachedBlockStart).longValue() * word_size; int pos = (int) reqBlockStart.distanceTo(cachedBlockStart).longValue() * wordSize;
int length = (int) Math.min(cachedBlock.fLengthInOctets, count - pos); int length = (int) Math.min(cachedBlock.fLengthInOctets, count - pos);
System.arraycopy(cachedBlock.fBlock, 0, resultBlock, pos, length); System.arraycopy(cachedBlock.fBlock, 0, resultBlock, pos, length);
} }
@ -808,7 +810,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
else if (cachedBlockStart.distanceTo(reqBlockStart).longValue() >= 0 else if (cachedBlockStart.distanceTo(reqBlockStart).longValue() >= 0
&& reqBlockStart.distanceTo(cachedBlockEnd).longValue() > 0) && reqBlockStart.distanceTo(cachedBlockEnd).longValue() > 0)
{ {
int pos = (int) cachedBlockStart.distanceTo(reqBlockStart).longValue() * word_size; int pos = (int) cachedBlockStart.distanceTo(reqBlockStart).longValue() * wordSize;
int length = (int) Math.min(cachedBlock.fLengthInOctets - pos, count); int length = (int) Math.min(cachedBlock.fLengthInOctets - pos, count);
System.arraycopy(cachedBlock.fBlock, pos, resultBlock, 0, length); System.arraycopy(cachedBlock.fBlock, pos, resultBlock, 0, length);
} }
@ -821,14 +823,14 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
* the content with the actual memory just read from the target. * the content with the actual memory just read from the target.
* *
* @param modBlockStart * @param modBlockStart
* @param word_count - Number of addressable units * @param wordCount - Number of addressable units
* @param modBlock * @param modBlock
* @param word_size - Number of octets per addressable unit * @param wordSize - Number of octets per addressable unit
*/ */
private void updateMemoryCache(IAddress modBlockStart, int word_count, MemoryByte[] modBlock, int word_size) { private void updateMemoryCache(IAddress modBlockStart, int wordCount, MemoryByte[] modBlock, int wordSize) {
IAddress modBlockEnd = modBlockStart.add(word_count); IAddress modBlockEnd = modBlockStart.add(wordCount);
ListIterator<MemoryBlock> iter = fMemoryBlockList.listIterator(); ListIterator<MemoryBlock> iter = fMemoryBlockList.listIterator();
int count = word_count * word_size; int count = wordCount * wordSize;
while (iter.hasNext()) { while (iter.hasNext()) {
MemoryBlock cachedBlock = iter.next(); MemoryBlock cachedBlock = iter.next();
@ -845,7 +847,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
if (cachedBlockStart.distanceTo(modBlockStart).longValue() >= 0 if (cachedBlockStart.distanceTo(modBlockStart).longValue() >= 0
&& modBlockEnd.distanceTo(cachedBlockEnd).longValue() >= 0) && modBlockEnd.distanceTo(cachedBlockEnd).longValue() >= 0)
{ {
int pos = (int) cachedBlockStart.distanceTo(modBlockStart).longValue() * word_size; int pos = (int) cachedBlockStart.distanceTo(modBlockStart).longValue() * wordSize;
System.arraycopy(modBlock, 0, cachedBlock.fBlock, pos, count); System.arraycopy(modBlock, 0, cachedBlock.fBlock, pos, count);
} }
@ -853,7 +855,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
else if (modBlockStart.distanceTo(cachedBlockStart).longValue() >= 0 else if (modBlockStart.distanceTo(cachedBlockStart).longValue() >= 0
&& cachedBlockEnd.distanceTo(modBlockEnd).longValue() >= 0) && cachedBlockEnd.distanceTo(modBlockEnd).longValue() >= 0)
{ {
int pos = (int) modBlockStart.distanceTo(cachedBlockStart).longValue() * word_size; int pos = (int) modBlockStart.distanceTo(cachedBlockStart).longValue() * wordSize;
System.arraycopy(modBlock, pos, cachedBlock.fBlock, 0, (int) cachedBlock.fLengthInOctets); System.arraycopy(modBlock, pos, cachedBlock.fBlock, 0, (int) cachedBlock.fLengthInOctets);
} }
@ -861,8 +863,8 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
else if (cachedBlockStart.distanceTo(modBlockStart).longValue() >= 0 else if (cachedBlockStart.distanceTo(modBlockStart).longValue() >= 0
&& modBlockStart.distanceTo(cachedBlockEnd).longValue() > 0) && modBlockStart.distanceTo(cachedBlockEnd).longValue() > 0)
{ {
int pos = (int) cachedBlockStart.distanceTo(modBlockStart).longValue() * word_size; int pos = (int) cachedBlockStart.distanceTo(modBlockStart).longValue() * wordSize;
int length = (int) modBlockStart.distanceTo(cachedBlockEnd).longValue() * word_size; int length = (int) modBlockStart.distanceTo(cachedBlockEnd).longValue() * wordSize;
System.arraycopy(modBlock, 0, cachedBlock.fBlock, pos, length); System.arraycopy(modBlock, 0, cachedBlock.fBlock, pos, length);
} }
@ -870,8 +872,8 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
else if (cachedBlockStart.distanceTo(modBlockEnd).longValue() > 0 else if (cachedBlockStart.distanceTo(modBlockEnd).longValue() > 0
&& modBlockEnd.distanceTo(cachedBlockEnd).longValue() >= 0) && modBlockEnd.distanceTo(cachedBlockEnd).longValue() >= 0)
{ {
int pos = (int) modBlockStart.distanceTo(cachedBlockStart).longValue() * word_size; int pos = (int) modBlockStart.distanceTo(cachedBlockStart).longValue() * wordSize;
int length = (int) cachedBlockStart.distanceTo(modBlockEnd).longValue() * word_size; int length = (int) cachedBlockStart.distanceTo(modBlockEnd).longValue() * wordSize;
System.arraycopy(modBlock, pos, cachedBlock.fBlock, 0, length); System.arraycopy(modBlock, pos, cachedBlock.fBlock, 0, length);
} }
} }
@ -881,15 +883,15 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
/** /**
* @param memoryDMC * @param memoryDMC
* @param address the memory block address (on the target) * @param address the memory block address (on the target)
* @param word_size the size, in bytes, of an addressable item * @param wordSize the size, in bytes, of an addressable item
* @param word_count the number of addressable units to read * @param wordCount the number of addressable units to read
* @param drm the asynchronous data request monitor * @param drm the asynchronous data request monitor
*/ */
public void getMemory(IMemoryDMContext memoryDMC, final IAddress address, final int word_size, public void getMemory(IMemoryDMContext memoryDMC, final IAddress address, final int wordSize,
final int word_count, final DataRequestMonitor<MemoryByte[]> drm) final int wordCount, final DataRequestMonitor<MemoryByte[]> drm)
{ {
// Determine the number of read requests to issue // Determine the number of read requests to issue
LinkedList<MemoryBlock> missingBlocks = getListOfMissingBlocks(address, word_count, word_size); List<MemoryBlock> missingBlocks = getListOfMissingBlocks(address, wordCount, wordSize);
int numberOfRequests = missingBlocks.size(); int numberOfRequests = missingBlocks.size();
// A read request will be issued for each block needed // A read request will be issued for each block needed
@ -899,7 +901,7 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
@Override @Override
protected void handleSuccess() { protected void handleSuccess() {
// We received everything so read the result from the memory cache // We received everything so read the result from the memory cache
drm.setData(getMemoryBlockFromCache(address, word_count, word_size)); drm.setData(getMemoryBlockFromCache(address, wordCount, wordSize));
drm.done(); drm.done();
} }
}; };
@ -910,12 +912,12 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
MemoryBlock block = missingBlocks.get(i); MemoryBlock block = missingBlocks.get(i);
final IAddress startAddress = block.fAddress; final IAddress startAddress = block.fAddress;
final int length = (int) block.fLengthInAddressableUnits; final int length = (int) block.fLengthInAddressableUnits;
readMemoryBlock(memoryDMC, startAddress, 0, word_size, length, readMemoryBlock(memoryDMC, startAddress, 0, wordSize, length,
new DataRequestMonitor<MemoryByte[]>(getSession().getExecutor(), drm) { new DataRequestMonitor<MemoryByte[]>(getSession().getExecutor(), drm) {
@Override @Override
protected void handleSuccess() { protected void handleSuccess() {
MemoryByte[] block = getData(); MemoryByte[] block = getData();
int lenghtInaddressableUnits = block.length / word_size; int lenghtInaddressableUnits = block.length / wordSize;
MemoryBlock memoryBlock = new MemoryBlock(startAddress, block.length, lenghtInaddressableUnits, block); MemoryBlock memoryBlock = new MemoryBlock(startAddress, block.length, lenghtInaddressableUnits, block);
fMemoryBlockList.add(memoryBlock); fMemoryBlockList.add(memoryBlock);
countingRM.done(); countingRM.done();
@ -928,17 +930,17 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
* @param memoryDMC * @param memoryDMC
* @param address the memory block address (on the target) * @param address the memory block address (on the target)
* @param offset the offset from the start address * @param offset the offset from the start address
* @param word_size the size, in bytes, of an addressable item * @param wordSize the size, in bytes, of an addressable item
* @param word_count the number of addressable units to write * @param wordCount the number of addressable units to write
* @param buffer the source buffer * @param buffer the source buffer
* @param rm the asynchronous request monitor * @param rm the asynchronous request monitor
*/ */
public void setMemory(final IMemoryDMContext memoryDMC, final IAddress address, public void setMemory(final IMemoryDMContext memoryDMC, final IAddress address,
final long offset, final int word_size, final int word_count, final byte[] buffer, final long offset, final int wordSize, final int wordCount, final byte[] buffer,
final RequestMonitor rm) final RequestMonitor rm)
{ {
writeMemoryBlock( writeMemoryBlock(
memoryDMC, address, offset, word_size, word_count, buffer, memoryDMC, address, offset, wordSize, wordCount, buffer,
new RequestMonitor(getSession().getExecutor(), rm) { new RequestMonitor(getSession().getExecutor(), rm) {
@Override @Override
protected void handleSuccess() { protected void handleSuccess() {
@ -947,14 +949,14 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
fCommandCache.reset(); fCommandCache.reset();
// Re-read the modified memory block to asynchronously update of the memory cache // Re-read the modified memory block to asynchronously update of the memory cache
readMemoryBlock(memoryDMC, address, offset, word_size, word_count, readMemoryBlock(memoryDMC, address, offset, wordSize, wordCount,
new DataRequestMonitor<MemoryByte[]>(getExecutor(), rm) { new DataRequestMonitor<MemoryByte[]>(getExecutor(), rm) {
@Override @Override
protected void handleSuccess() { protected void handleSuccess() {
updateMemoryCache(address.add(offset), word_count, getData(), word_size); updateMemoryCache(address.add(offset), wordCount, getData(), wordSize);
// Send the MemoryChangedEvent // Send the MemoryChangedEvent
IAddress[] addresses = new IAddress[word_count]; IAddress[] addresses = new IAddress[wordCount];
for (int i = 0; i < word_count; i++) { for (int i = 0; i < wordCount; i++) {
addresses[i] = address.add(offset + i); addresses[i] = address.add(offset + i);
} }
getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties()); getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties());
@ -969,36 +971,36 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
* @param memoryDMC * @param memoryDMC
* @param address * @param address
* @param offset * @param offset
* @param word_size * @param wordSize
* @param word_count * @param wordCount
* @param sendMemoryEvent Indicates if a IMemoryChangedEvent should be sent if the memory cache has changed. * @param sendMemoryEvent Indicates if a IMemoryChangedEvent should be sent if the memory cache has changed.
* @param rm * @param rm
*/ */
public void refreshMemory(final IMemoryDMContext memoryDMC, final IAddress address, public void refreshMemory(final IMemoryDMContext memoryDMC, final IAddress address,
final long offset, final int word_size, final int word_count, final boolean sendMemoryEvent, final long offset, final int wordSize, final int wordCount, final boolean sendMemoryEvent,
final RequestMonitor rm) final RequestMonitor rm)
{ {
// Check if we already cache part of this memory area (which means it // Check if we already cache part of this memory area (which means it
// is used by a memory service client that will have to be updated) // is used by a memory service client that will have to be updated)
LinkedList<MemoryBlock> list = getListOfMissingBlocks(address, word_count, word_size); List<MemoryBlock> list = getListOfMissingBlocks(address, wordCount, wordSize);
int sizeToRead = 0; int sizeToRead = 0;
for (MemoryBlock block : list) { for (MemoryBlock block : list) {
sizeToRead += block.fLengthInAddressableUnits; sizeToRead += block.fLengthInAddressableUnits;
} }
// If none of the requested memory is in cache, just get out // If none of the requested memory is in cache, just get out
if (sizeToRead == word_count) { if (sizeToRead == wordCount) {
rm.done(); rm.done();
return; return;
} }
// Read the corresponding memory block // Read the corresponding memory block
fCommandCache.reset(); fCommandCache.reset();
readMemoryBlock(memoryDMC, address, offset, word_size, word_count, readMemoryBlock(memoryDMC, address, offset, wordSize, wordCount,
new DataRequestMonitor<MemoryByte[]>(getExecutor(), rm) { new DataRequestMonitor<MemoryByte[]>(getExecutor(), rm) {
@Override @Override
protected void handleSuccess() { protected void handleSuccess() {
MemoryByte[] oldBlock = getMemoryBlockFromCache(address, word_count, word_size); MemoryByte[] oldBlock = getMemoryBlockFromCache(address, wordCount, wordSize);
MemoryByte[] newBlock = getData(); MemoryByte[] newBlock = getData();
boolean blocksDiffer = false; boolean blocksDiffer = false;
for (int i = 0; i < oldBlock.length; i++) { for (int i = 0; i < oldBlock.length; i++) {
@ -1008,11 +1010,11 @@ public class MIMemory extends AbstractDsfService implements IMemory, ICachingSer
} }
} }
if (blocksDiffer) { if (blocksDiffer) {
updateMemoryCache(address.add(offset), word_count, newBlock, word_size); updateMemoryCache(address.add(offset), wordCount, newBlock, wordSize);
if (sendMemoryEvent) { if (sendMemoryEvent) {
// Send the MemoryChangedEvent // Send the MemoryChangedEvent
final IAddress[] addresses = new IAddress[word_count]; final IAddress[] addresses = new IAddress[wordCount];
for (int i = 0; i < word_count; i++) { for (int i = 0; i < wordCount; i++) {
addresses[i] = address.add(offset + i); addresses[i] = address.add(offset + i);
} }
getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties()); getSession().dispatchEvent(new MemoryChangedEvent(memoryDMC, addresses), getProperties());