Esempio n. 1
0
  public void modifyBlock(Address address, int setNumber, boolean isWrite) {

    Block[] block = setAssociativeArray.get(setNumber);

    if (isWrite) block[address.getIndex()].setDirtyBit(1);

    block[address.getIndex()].setValidBit(1);
    block[address.getIndex()].incrementCounter();

    try {
      if (isWrite) cacheLogger.writeHit(setNumber, address);
      else cacheLogger.readHit(setNumber, address);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 2
0
  private Block getBlockWithMinimumCounter(Address address) {

    ArrayList<Block> tempBlockArray = new ArrayList<Block>();

    for (int n = 0; n < associativity; n++) {
      Block[] blocks = setAssociativeArray.get(n);
      if (blocks[address.getIndex()].getHitCounter() == 0)
        tempBlockArray.add(blocks[address.getIndex()]);
    }

    if (tempBlockArray.isEmpty()) {
      for (int n = 0; n < associativity; n++) {
        Block[] blocks = setAssociativeArray.get(n);
        if (blocks[address.getIndex()].getHitCounter() == 1)
          tempBlockArray.add(blocks[address.getIndex()]);
      }
    }

    if (tempBlockArray.isEmpty()) {
      for (int n = 0; n < associativity; n++) {
        Block[] blocks = setAssociativeArray.get(n);
        if (blocks[address.getIndex()].getHitCounter() == 2)
          tempBlockArray.add(blocks[address.getIndex()]);
      }
    }

    return tempBlockArray.get((new Random()).nextInt(tempBlockArray.size()));
  }
Esempio n. 3
0
  public void addAddress(Address address, boolean isWrite) {

    int setNumber = searchEmptyBlock(address.getIndex());
    Block block = null;

    if (runningMode == 0) {
      // For Part I
      if (setNumber == -1) setNumber = (new Random()).nextInt(associativity);

      Block[] blocks = setAssociativeArray.get(setNumber);
      block = blocks[address.getIndex()];
    } else {
      // For Part II

      if (setNumber == -1) block = getBlockWithMinimumCounter(address);
      else {
        Block[] blocks = setAssociativeArray.get(setNumber);
        block = blocks[address.getIndex()];
      }
    }

    int tempOldDirtyBit = block.getDirtyBit();

    if (isWrite) block.setDirtyBit(1);
    else block.setDirtyBit(0);

    block.setTag(address.getTag());
    block.setValidBit(1);
    block.setHitCounter(0);

    try {
      if (isWrite) cacheLogger.writeMiss(setNumber, address, tempOldDirtyBit);
      else cacheLogger.readMiss(setNumber, address, tempOldDirtyBit);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 4
0
 /**
  * @param newAddress new Address
  * @return new Customer with replaced or added Address
  */
 public static Customer addOrReplaceAddress(Customer customer, Address newAddress) {
   List<Address> newAddresses =
       customer
           .getAddresses()
           .stream()
           .map(
               address ->
                   Objects.equals(newAddress.getIndex(), address.getIndex())
                       ? newAddress
                       : address)
           .collect(Collectors.toList());
   if (!newAddresses.contains(newAddress)) {
     newAddresses.add(newAddress);
   }
   return new Customer(
       customer.id,
       customer.firstname,
       customer.lastname,
       newAddresses,
       customer.contacts,
       customer.taxNumber,
       customer.taxCountry);
 }