@Override
  public void setupProcedureResume(boolean isFinal, int[] dependencies) {
    assert (dependencies != null);
    assert (dependencies.length > 0);

    WorkUnit w =
        new WorkUnit(
            m_site.getSiteTracker(),
            null,
            dependencies,
            m_hsId,
            m_nonCoordinatingSites,
            true,
            m_allowMismatchedResults);
    if (isFinal) w.nonTransactional = true;
    for (int depId : dependencies) {
      if (m_missingDependencies == null) {
        m_missingDependencies = new HashMap<Integer, WorkUnit>();
      }
      // We are missing the dependency: record this fact
      assert (!m_missingDependencies.containsKey(depId));
      m_missingDependencies.put(depId, w);
    }
    if (m_stackFrameDropWUs == null) m_stackFrameDropWUs = new ArrayList<WorkUnit>();
    for (WorkUnit sfd : m_stackFrameDropWUs) sfd.m_stackCount++;
    m_stackFrameDropWUs.add(w);

    // Find any stack frame drop work marked ready in the ready set,
    // and if it's not really ready, take it out.
    for (WorkUnit wu : m_readyWorkUnits) {
      if (wu.shouldResumeProcedure()) {
        if (wu.m_stackCount > 0) m_readyWorkUnits.remove(wu);
      }
    }
  }
Exemplo n.º 2
0
  @Test
  public void test7() throws Exception {
    HotSpotInstalledCode installedBenchmarkCode =
        getInstalledCode("queueTest", Object.class, Object.class);
    ArrayDeque<Object> q = new ArrayDeque<>();
    Object[] objects = new Object[512];
    for (int i = 0; i < objects.length; i++) {
      objects[i] = new Object();
    }
    int j = 0;
    while (j < objects.length) {
      if (!installedBenchmarkCode.isValid()) {
        // This can get invalidated due to lack of MDO update
        installedBenchmarkCode = getInstalledCode("queueTest", Object.class, Object.class);
      }
      installedBenchmarkCode.executeVarargs(q, objects[j]);
      j++;
    }

    System.gc();
    Assert.assertTrue(q.size() == objects.length);
    Assert.assertTrue(!q.isEmpty());
    j = 0;
    while (j < objects.length) {
      Assert.assertTrue(objects[j] == q.remove());
      j++;
    }

    Assert.assertTrue(q.size() == 0);
    Assert.assertTrue(q.isEmpty());
  }
Exemplo n.º 3
0
 synchronized void add(Chunk c) throws InterruptedException {
   int len = c.getData().length;
   if (BLOCK_WHEN_FULL) while (len + dataSizeBytes > maxDataSize) wait();
   else chunks.remove();
   dataSizeBytes += len;
   chunks.add(c);
 }
Exemplo n.º 4
0
  private void provaCoaArrayDeque() {
    ArrayDeque<String> array = new ArrayDeque<>();
    System.out.println("EMPTY? " + array.isEmpty());
    for (int comptador = 0; comptador < 10; comptador++) {
      array.add(comptador + "");
    }

    System.out.println("EMPTY? " + array.isEmpty());
    System.out.println("Total? " + array.size());
    System.out.println(array.remove());
    System.out.println("Total? " + array.size());
    System.out.println(array.element());
    array.clear();
    System.out.println("Total? " + array.size());
  }
 protected void processNextWord() throws InterruptedException {
   if (!mWordQueue.isEmpty()) {
     String word = mWordQueue.remove();
     mSpritzHandler.sendMessage(mSpritzHandler.obtainMessage(MSG_PRINT_WORD, word));
     Thread.sleep(getInterWordDelay() * delayMultiplierForWord(word));
     // If word is end of a sentence, add three blanks
     if (word.contains(".") || word.contains("?") || word.contains("!")) {
       for (int x = 0; x < 3; x++) {
         mSpritzHandler.sendMessage(mSpritzHandler.obtainMessage(MSG_PRINT_WORD, "  "));
         Thread.sleep(getInterWordDelay());
       }
     }
   } else {
     if (mBus != null) {
       mBus.post(new SpritzFinishedEvent());
     }
   }
 }
Exemplo n.º 6
0
 /** 广度优先遍历 采用非递归实现 需要辅助数据结构:队列 */
 public void levelOrderTraversal() {
   if (root == null) {
     System.out.println("empty tree");
     return;
   }
   ArrayDeque<TreeNode> queue = new ArrayDeque<TreeNode>();
   queue.add(root);
   while (queue.isEmpty() == false) {
     TreeNode node = queue.remove();
     System.out.print(node.value + "    ");
     if (node.left != null) {
       queue.add(node.left);
     }
     if (node.right != null) {
       queue.add(node.right);
     }
   }
   System.out.print("\n");
 }
Exemplo n.º 7
0
  /** Performs heuristic header substitution. */
  public IPath getPreferredRepresentativeHeaderByHeuristic(InclusionRequest request) {
    Set<IIndexFile> indexFiles = request.getDeclaringFiles().keySet();
    String symbolName = request.getBinding().getName();
    ArrayDeque<IIndexFile> front = new ArrayDeque<IIndexFile>();
    HashSet<IIndexFile> processed = new HashSet<IIndexFile>();

    try {
      // Look for headers without an extension and a matching name.
      if (fContext.isCXXLanguage()) {
        front.addAll(indexFiles);
        processed.addAll(indexFiles);

        while (!front.isEmpty()) {
          IIndexFile file = front.remove();

          String path = IncludeUtil.getPath(file);

          if (!hasExtension(path) && getFilename(path).equalsIgnoreCase(symbolName)) {
            // A C++ header without an extension and with a name which matches the name
            // of the symbol which should be declared is a perfect candidate for inclusion.
            return IndexLocationFactory.getAbsolutePath(file.getLocation());
          }

          // Process the next level of the include hierarchy.
          IIndexInclude[] includes = fContext.getIndex().findIncludedBy(file, 0);
          for (IIndexInclude include : includes) {
            IIndexFile includer = include.getIncludedBy();
            if (!processed.contains(includer)) {
              front.add(includer);
              processed.add(includer);
            }
          }
        }
      }

      // Repeat the process, this time only looking for headers without an extension.
      front.clear();
      front.addAll(indexFiles);
      processed.clear();
      processed.addAll(indexFiles);

      while (!front.isEmpty()) {
        IIndexFile file = front.remove();

        String path = IncludeUtil.getPath(file);

        if (fContext.isCXXLanguage() && !hasExtension(path)) {
          // A C++ header without an extension is still a very good candidate for inclusion.
          return IndexLocationFactory.getAbsolutePath(file.getLocation());
        }

        // Process the next level of the include hierarchy.
        IIndexInclude[] includes = fContext.getIndex().findIncludedBy(file, 0);
        for (IIndexInclude include : includes) {
          IIndexFile includer = include.getIncludedBy();
          if (!processed.contains(includer)) {
            URI uri = includer.getLocation().getURI();
            if (IncludeUtil.isSource(includer, fContext.getProject()) || isWorkspaceFile(uri)) {
              return IndexLocationFactory.getAbsolutePath(file.getLocation());
            }
            front.add(includer);
            processed.add(includer);
          }
        }
      }
    } catch (CoreException e) {
      CUIPlugin.log(e);
    }

    return request.getCandidatePaths().iterator().next();
  }
Exemplo n.º 8
0
  public static void recur(int[][] board, int z) {
    int[][] tempBoard = new int[4][4];
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        tempBoard[i][j] = board[i][j];
      }
    }
    Moves.storeNext();
    // GUI.ThreesGUI gui = new GUI.ThreesGUI();
    ArrayDeque<String> finalmoves = new ArrayDeque<String>();
    ArrayDeque<String> temp = new ArrayDeque<String>();
    LinkedList<Object> temp2 = new LinkedList<Object>();
    LinkedList<Object> temp3 = new LinkedList<Object>();

    String nextMove = "";
    for (int i = 0; i < z; i++) {

      temp = new ArrayDeque<String>(AStar(tempBoard, 50));

      temp.poll();
      temp.poll();
      tempBoard = GUI.Threes.board.clone();

      temp3 = Moves.doMove(tempBoard, temp, false);
      temp3.poll();
      temp3.poll();
      int k = 0;
      boolean gameon = true;
      while (!temp.isEmpty() && k < 5 && gameon) {
        nextMove = temp.pollLast();

        if (nextMove.equals("L")) {
          gameon = GUI.Threes.Left();
        } else if (nextMove.equals("R")) {
          gameon = GUI.Threes.Right();
        } else if (nextMove.equals("U")) {
          gameon = GUI.Threes.Up();
        } else if (nextMove.equals("D")) {
          gameon = GUI.Threes.Down();
        } else nextMove = "X";
        k++;
        if (!nextMove.equals("X") && gameon) {
          finalmoves.addFirst(nextMove);
          Moves.popNext();
        }
      }
      // tempBoard = GUI.Threes.board.clone();

      // if(!nextMove.equals("X"))
      // finalmoves.addFirst(nextMove);
      // Moves.popNext();
      if (!gameon) {
        i = z;
      }
    }
    System.out.println("contents of finalmoves");
    int movesize = finalmoves.size();
    ArrayDeque<String> printemp = new ArrayDeque<String>(finalmoves);
    for (int i = 0; i < movesize; i++) {
      System.out.print(printemp.remove());
    }
    System.out.println();
    temp2 = Moves.doMove(board, finalmoves, true);
    System.out.println("heuristic score was: " + temp2.remove(0));

    System.out.println("Final score was: " + temp2.remove(0));
    GUI.Threes.finalBoard();

    System.out.println("Move string was");
    while (!temp2.isEmpty()) {
      System.out.print(temp2.remove());
    }
    System.out.println();
  }