Beispiel #1
0
 private void showStack(ThreadInfo tinfo, int selectFrame) {
   StackTraceListModel model = new StackTraceListModel(tinfo);
   stackModel = model;
   list.setModel(stackModel);
   list.setSelectedIndex(selectFrame);
   list.ensureIndexIsVisible(selectFrame);
 }
Beispiel #2
0
  private void setSelectedIndex(int index) {
    if (index == -1) {
      list.getSelectionModel().clearSelection();
    } else if (list.getModel().getSize() != 0) {
      list.setSelectedIndex(index);

      list.ensureIndexIsVisible(index);
    }
  }
Beispiel #3
0
  private void assembleAction() {
    String line;
    messages = new Vector();

    mainFrame.resetExecWindow();

    save();

    assembleFailed = false;
    haveAssemblyErrors = false;

    if (Assembler.version()) {
      while ((line = Assembler.output()) != null) {
        messages.addElement(line);
      }

      Assembler.setPaths(baseName, sourcePath);

      if (Assembler.assemble()) {
        while ((line = Assembler.output()) != null) {
          System.out.println(line);

          messages.addElement(line);

          if (line.startsWith(" [ERROR:")) {
            haveAssemblyErrors = true;
          }
        }

        messageList.setListData(messages);
        messageList.ensureIndexIsVisible(0);

        mainFrame.showExecWindow(baseName);
      } else {
        assembleFailed = true;
      }
    } else {
      assembleFailed = true;
    }

    if (assembleFailed) {
      String message =
          String.format(
              "Autocoder failed!\nVerify the correctness of autocoder path\n%s",
              AssemblerOptions.assemblerPath);
      System.out.println(message);

      JOptionPane.showMessageDialog(this, message, "ROPE", JOptionPane.ERROR_MESSAGE);
    }
  }
  // FUNCTION TO SIMULATE A STEP IN THE SIMULATION ON THE FRAME
  public void step() {

    /**
     * EACH TIME THE NEXT BUTTON IS PRESSED, ALL THE STATES THAT OCURRED UPTO THE CURRENT STATE ARE
     * EVALUATED. THERE IS A while STATEMENT THAT PERFORMS THIS FUNCTION AND CONTAINS A switch
     * STATEMENT WITHIN IT TO EVALUATE EACH STEP AS IT OCCURS.
     */

    ////////////////////// INITIALIZATION ///////////////////////////////////////

    // UPDATE THE STATE OF THE CACHE AND MEMORY
    for (int i = 0; i < 16; i++) {
      cachePanel.stringBlocks[i] = "";
      cachePanel.boolBlocks[i] = false;
      cachePanel.tag[i] = "";
      cachePanel.boolTags[i] = false;

      statusCacheEmpty[i] = true;
      statusCacheLRU[i] = 0;
    }
    for (int i = 0; i < 8; i++) {
      cachePanel.boolWords[i] = false;
      memoryPanel.boolWords[i] = false;
    }
    for (int i = 0; i < 32; i++) memoryPanel.boolBlocks[i] = false;

    // UPDATE THE BITS IN MAIN MEMORY ADDRESS
    tTag.setText("");
    tWord.setText("");
    tTag.setBackground(new Color(205, 205, 205));
    tWord.setBackground(new Color(205, 205, 205));

    // UPDATE THE CACHE HITS AND MISSES FIELDS
    cacheHits = 0;
    cacheMisses = 0;
    tCacheHits.setText("  0");
    tCacheMisses.setText("  0");

    // UPDATE THE VALUES USED FOR BRINGING MEMORY BLOCKS IN CACHE
    statusLRU = 0;
    memInCache = -1;
    lruCacheBlock = -1;

    // RESET THE VALUE OF addSel
    evaluateIndex = 0;

    // DISABLE ADDRESS GENERATION BUTTONS
    autoGen.setEnabled(false);
    selfGen.setEnabled(false);

    ////////////////////// END INITIALIZATION /////////////////////////////////////

    // IF Next WAS CLICKED, INCREMENT moveStatus
    if (nextClicked) moveStatus++;
    else {
      // DECREMENT moveStatus AND ENABLE NEXT SINCE IT MIGHT BE DISABLED
      moveStatus--;
      next.setEnabled(true);
    }

    // IF NO MORE back MOVES CAN BE MADE, DISABLE back BUTTON
    if (moveStatus == 0) {
      back.setEnabled(false);
      tProgress.setText(
          "You cannot go back any further."
              + "\nPlease click on \"Next\" or \"Restart\" to continue.");
      tProgress.setCaretPosition(0);

      // CLEAR THE SELECTED ADDRESS REFERENCE STRING
      addRefStrList.clearSelection();
    } else
      // ENABLE back BUTTON ONCE THE FIRST MOVE IS MADE
      back.setEnabled(true);

    // INITIALIZE THE VARIABLE THAT KEEPS TRACK OF THE STATE WE ARE CURRENTLY EVALUATING.
    int tempState = 1;

    // CONTINUE TO EVALUATE EACH STATE TILL WE REACH THE CURRENT STATE
    while (tempState <= moveStatus) {

      switch (tempState % 6) {
        case 1: // IF A NEW CYCLE IS BEGINNING, OBTAIN NEXT ADDRESS REFERENCE

          // OBTAIN THE ADDRESS REFERENCE STRING
          addRefStrList.setSelectedIndex(evaluateIndex);

          // ENSURE THAT THE LIST SCROLLS AND SELECTED INDEX IS VISIBLE
          // DUE TO REPAINTING CONSTRAINTS, ONLY DO THIS IN THE CURRENT STATE
          if (tempState == moveStatus) addRefStrList.ensureIndexIsVisible(evaluateIndex);

          // EVALUATE THE TAG, BLOCK AND WORD
          hexAddress = (String) addRefStrList.getSelectedValue();
          int intAddress = Integer.parseInt(hexAddress, 16);
          binAddress = Integer.toBinaryString(intAddress);

          // USING CLASS INTEGER'S parseInt FUNCTION RETURNS A BINARY STRING WITHOUT LEADING 0'S
          // ENSURE THAT binAddress is 8 bits
          if (binAddress.length() < 8) {
            int zeroes = 8 - binAddress.length();
            for (int i = 0; i < zeroes; i++) binAddress = '0' + binAddress;
          }

          tag = binAddress.substring(0, 5);
          word = binAddress.substring(5);

          // CALCULATE THE ACTUAL CACHE AND MEMORY BLOCKS AND WORDS IN QUESTION
          intWordDec = Integer.parseInt(word, 2);
          intBlockDecMem = Integer.parseInt(tag, 2);

          // IF THIS IS THE CURRENT STATE, UPDATE THE PROGRESS FIELD
          if (tempState == moveStatus) {
            tProgress.setText(
                "The memory address we want is obtained from the Address Reference String."
                    + "\nIt is (in hexadecimal): "
                    + hexAddress
                    + ".");
            tProgress.setCaretPosition(0);
          }

          break;

        case 2: // EVALUATE THE BITS IN MAIN MEMORY ADDRESS AND HIGHLIGHT THEM

          // IF THIS IS THE CURRENT STATE, UPDATE THE PROGRESS FIELD
          if (tempState == moveStatus) {
            tProgress.setText(
                "The hexadecimal address "
                    + hexAddress
                    + " evaluates to its binary equivalent "
                    + binAddress
                    + "."
                    + "\nHence the bits in the Main Memory Address are divided into the following fields\n"
                    + tag
                    + " --> Tag,  "
                    + word
                    + " --> Word."
                    + "\nThe tag bits identify the memory block, "
                    + "and the word bits identify the word within the block.");
            tProgress.setCaretPosition(0);

            // HIGHLIGHT THE BITS IN MAIN MEMORY ADDRESS IN GREEN
            tTag.setBackground(Color.green);
            tWord.setBackground(Color.green);
          }

          tTag.setText("      " + tag);
          tWord.setText("  " + word);

          break;

        case 3: // FIND THE CACHE BLOCK IN QUESTION AND HIGHLIGHT IT

          // UNDO HIGHLIGHTS OF PREVIOUS STEP
          tTag.setBackground(new Color(205, 205, 205));
          tWord.setBackground(new Color(205, 205, 205));

          // IF THIS IS THE CURRENT STATE, UPDATE THE PROGRESS FIELD
          if (tempState == moveStatus) {
            tProgress.setText(
                "Every time a memory block is placed in cache, its tag field is stored with it as well."
                    + "\nSo, to find the required memory block in cache, its tag, "
                    + tag
                    + " is compared to all the valid tag fields in cache.");
            tProgress.setCaretPosition(0);
          }

          // GET THE BLOCK IN CACHE WHERE MEMORY BLOCK EXISTS, IF AT ALL
          memInCache = getCacheBlock(tag);

          // IF MEMORY BLOCK IS NOT IN CACHE...
          if (memInCache == -1) {
            if (tempState == moveStatus) {
              tProgress.append(
                  "\n\nSince the memory block is not in cache, there is a cache miss."
                      + "\nSo the block needs to be brought in from memory.");
              tProgress.setCaretPosition(0);
            }

            // GET FIRST EMPTY CACHE BLOCK, IF AVAILABLE
            emptyCacheBlock = getFirstEmptyCacheBlock();

            // IF EMPTY CACHE BLOCK IS AVAILABLE, THIS IS WHERE THE MEMORY WILL BE BROUGHT SO
            // DISPLAY IT
            if (!(emptyCacheBlock == -1)) {

              // IF THIS IS THE CURRENT STATE, UPDATE THE PROGRESS FIELD
              if (tempState == moveStatus) {
                tProgress.append(
                    "\nSince the cache has empty space, the first available block will be filled."
                        + "\nSee the highlighted cache block.");
                tProgress.setCaretPosition(0);
              }

              // HIGHLIGHT THE CACHE BLOCK IN YELLOW
              cachePanel.boolBlocks[emptyCacheBlock] = true;
              cachePanel.boolTags[emptyCacheBlock] = true;

              // STORE THE CHANGED CACHE BLOCK INDEX IN COMMON VARIABLE
              intBlockDec = emptyCacheBlock;
            }

            // ELSE DISPLAY THE LRU CACHE BLOCK WHICH WILL BE REPLACED
            else {

              // IF THIS IS THE CURRENT STATE, UPDATE THE PROGRESS FIELD
              if (tempState == moveStatus) {
                tProgress.append(
                    "\nSince the cache is full, the least recently used cache block will be replaced."
                        + "\nSee the highlighted cache block.");
                tProgress.setCaretPosition(0);
              }

              lruCacheBlock = getLRUCacheBlock();

              // HIGHLIGHT THE CACHE BLOCK IN YELLOW
              cachePanel.boolBlocks[lruCacheBlock] = true;
              cachePanel.boolTags[lruCacheBlock] = true;

              // STORE THE CHANGED CACHE BLOCK INDEX IN COMMON VARIABLE
              intBlockDec = lruCacheBlock;
            }

            // UPDATE COUNT OF CACHE MISSES
            cacheMisses++;
            tCacheMisses.setText("  " + cacheMisses);
          } else {

            if (tempState == moveStatus) {
              tProgress.append(
                  "\n\nSince the required memory block is in cache block "
                      + memInCache
                      + " there is a cache hit.");
              tProgress.setCaretPosition(0);
            }

            // HIGHLIGHT THE CACHE BLOCK IN YELLOW
            // TO CAUSE HIGHLIGHTING ON THE CACHE, WE NEED TO MODIFY IT'S STATE, i.e. IT'S DATA
            // MEMBERS
            cachePanel.boolBlocks[memInCache] = true;
            cachePanel.boolWords[intWordDec] = true;
            cachePanel.boolTags[memInCache] = true;

            // STORE THE CHANGED CACHE BLOCK INDEX IN COMMON VARIABLE
            intBlockDec = memInCache;

            // UPDATE COUNT OF CACHE HITS
            cacheHits++;
            tCacheHits.setText("  " + cacheHits);
          }

          break;

        case 4: // EVALUATE THE MEMORY BLOCK IN QUESTION AND HIGHLIGHT IT

          // UNDO THE HIGHLIGHTS OF THE PREVIOUS STEP
          cachePanel.boolBlocks[intBlockDec] = false;
          cachePanel.boolWords[intWordDec] = false;
          cachePanel.boolTags[intBlockDec] = false;

          // IF THIS IS THE CURRENT STATE, UPDATE THE PROGRESS FIELD
          if (tempState == moveStatus) {
            tProgress.setText(
                "Highlighted is the memory block in question. Since the tag bits are "
                    + tag
                    + ", the memory block, in decimal, is "
                    + intBlockDecMem
                    + ".");
            tProgress.setCaretPosition(0);
          }

          // SET THE MEMORY STATE SO AS TO HIGHLIGHT THE REQUIRED MEMORY BLOCK
          memoryPanel.boolBlocks[intBlockDecMem] = true;

          // SET THE MEMORY STATE SO AS TO HIGHLIGHT THE REQUIRED WORD
          memoryPanel.boolWords[intWordDec] = true;

          break;

        case 5: // HIGHLIGHT THE CACHE BLOCK WITH THE MEMORY BLOCK NOW IN IT

          // UNDO HIGHLIGHTS OF PREVIOUS STEP
          memoryPanel.boolBlocks[intBlockDecMem] = false;
          memoryPanel.boolWords[intWordDec] = false;

          /*
           * NOW, THERE ARE 3 WAYS TO GO FROM HERE
           * 1. IF THERE IS AN EMPTY CACHE BLOCK, SIMPLY BRING THE MEMORY BLOCK INTO CACHE
           * 2. IF THE REQUIRED MEMORY BLOCK IS ALREADY IN CACHE, DO NOTHING
           * 3. IF THE CACHE IS FULL, FIND THE LRU BLOCK AND REPLACE IT WITH THE REQUIRED MEMORY BLOCK
           */

          // IF THE MEMORY BLOCK WAS NOT IN CACHE AND AN EMPTY CACHE BLOCK IS AVAILABLE
          // BRING THE MEMORY BLOCK AND TAG INTO CACHE AND HIGHLIGHT CACHE BLOCK
          if ((memInCache == -1) && !(emptyCacheBlock == -1)) {

            // IF THIS IS THE CURRENT STATE, UPDATE THE PROGRESS FIELD
            if (tempState == moveStatus) {
              tProgress.setText(
                  "As we saw earlier, the required memory block was not in cache."
                      + "\nSince there was empty space in cache, we brought the memory block into it."
                      + "\nWe also stored the tag, "
                      + tag
                      + ", of the memory block with the cache block."
                      + "\n\nRemember that the memory block could be brought into any empty cache block."
                      + "\nIn our example, we are using the first available empty block.");
              tProgress.setCaretPosition(0);
            }

            // UPDATE THE COUNTER FOR THE LRU CACHE BLOCK
            statusLRU++;
            statusCacheLRU[emptyCacheBlock] = statusLRU;
            statusCacheEmpty[emptyCacheBlock] = false;

            // UPDATE THE CACHE ARRAYS KEEPING TRACK OF MEMORY BLOCKS AND TAGS
            cachePanel.stringBlocks[emptyCacheBlock] = "" + intBlockDecMem;
            cachePanel.tag[emptyCacheBlock] = tag;

            // HIGHLIGHT THE CACHE BLOCK IN YELLOW
            cachePanel.boolBlocks[emptyCacheBlock] = true;
            cachePanel.boolWords[intWordDec] = true;
            cachePanel.boolTags[emptyCacheBlock] = true;

            // STORE THE CHANGED CACHE BLOCK INDEX IN COMMON VARIABLE
            intBlockDec = emptyCacheBlock;

          } // END IF

          // IF MEMORY BLOCK IS ALREADY IN CACHE THEN JUST HIGHLIGHT THE CACHE BLOCK
          else if ((memInCache >= 0) && (memInCache < 16)) {

            // IF THIS IS THE CURRENT STATE, UPDATE THE PROGRESS FIELD
            if (tempState == moveStatus) {
              tProgress.setText(
                  "As we saw earlier, the required memory block is already in cache.");
              tProgress.setCaretPosition(0);
            }

            // UPDATE THE COUNTER FOR THE LRU CACHE BLOCK
            statusLRU++;
            statusCacheLRU[memInCache] = statusLRU;

            // HIGHLIGHT THE CACHE BLOCK IN YELLOW
            cachePanel.boolBlocks[memInCache] = true;
            cachePanel.boolWords[intWordDec] = true;
            cachePanel.boolTags[memInCache] = true;

            // STORE THE CHANGED CACHE BLOCK INDEX IN COMMON VARIABLE
            intBlockDec = memInCache;

          } // END ELSE IF

          // IF THE MEMORY BLOCK IS NOT IN CACHE AND THE CACHE IS FULL
          // FIND THE LRU CACHE BLOCK AND REPLACE IT WITH THE MEMORY BLOCK, THEN HIGHLIGHT THE CACHE
          // BLOCK
          else {

            // FIND THE LRU CACHE BLOCK
            lruCacheBlock = getLRUCacheBlock();

            // IF THIS IS THE CURRENT STATE, UPDATE THE PROGRESS FIELD
            if (tempState == moveStatus) {
              tProgress.setText(
                  "As we saw earlier, the cache is full."
                      + "\nSo we picked the least recently used cache block, "
                      + lruCacheBlock
                      + ", and replaced it with the required memory block.");
              tProgress.setCaretPosition(0);
            }

            // UPDATE THE COUNTER FOR THE LRU CACHE BLOCK
            statusLRU++;
            statusCacheLRU[lruCacheBlock] = statusLRU;
            statusCacheEmpty[lruCacheBlock] = false; // redundant stmt

            // UPDATE THE CACHE ARRAYS KEEPING TRACK OF MEMORY BLOCKS AND TAGS
            cachePanel.stringBlocks[lruCacheBlock] = "" + intBlockDecMem;
            cachePanel.tag[lruCacheBlock] = tag;

            // HIGHLIGHT THE CACHE BLOCK IN YELLOW
            cachePanel.boolBlocks[lruCacheBlock] = true;
            cachePanel.boolWords[intWordDec] = true;
            cachePanel.boolTags[lruCacheBlock] = true;

            // STORE THE CHANGED CACHE BLOCK INDEX IN COMMON VARIABLE
            intBlockDec = lruCacheBlock;
          } // END ELSE

          break;

        case 0: // LAST STEP IN CYCLE - CLEANUP STEP!

          // UNDO HIGHLIGHTS OF PREVIOUS STEP
          cachePanel.boolBlocks[intBlockDec] = false;
          cachePanel.boolWords[intWordDec] = false;
          cachePanel.boolTags[intBlockDec] = false;

          tTag.setText("");
          tWord.setText("");

          tTag.setBackground(new Color(205, 205, 205));
          tWord.setBackground(new Color(205, 205, 205));

          // CLEAR THE SELECTED ADDRESS REFERENCE STRING
          addRefStrList.clearSelection();

          // INCREMENT THE INDEX SO AS TO POINT TO THE NEXT ADDRESS REFERENCE STRING
          evaluateIndex++;

          // IF THE LAST ADDRESS REFERENCE STRING HAS BEEN REACHED, DO THE APPROPRIATE
          if (evaluateIndex == listData.size()) {

            if (tempState == moveStatus) {
              tProgress.setText(
                  "This completes the runthrough."
                      + "\nPlease click on \"Restart\", generate the Address Reference String "
                      + "OR click \"Quit\" to finish.");
              tProgress.setCaretPosition(0);
            }
            next.setEnabled(false);

            // ENABLE ADDRESS GENERATION BUTTONS
            autoGen.setEnabled(true);
            selfGen.setEnabled(true);

            reStarted = false;
          }

          // ELSE AN ACCESS CYCLE HAS BEEN COMPLETED SO SHOW THE APPROPRIATE MESSAGE IN THE PROGRESS
          // FIELD
          else {
            if (tempState == moveStatus) {
              tProgress.setText("This completes an access cycle.");
              tProgress.setCaretPosition(0);
            }

            // CLEAR THE SELECTION IN THE ADDRESS REFERENCE STRING
            addRefStrList.clearSelection();
          }

          break;

        default:
          JOptionPane.showMessageDialog(null, "Uh Oh, there's a problem in switch-case!");
      } // END switch

      tempState++;
    } // END while

    // CALL THE REPAINT METHOD
    repaint();
  } // END FUNCTION step