Beispiel #1
0
 /**
  * @param usedRate must be power of 2 minus 1, and it determines the likelihood that calling the
  *     used method actually moves the node in the usage list. The higher the used rate value, the
  *     less likely that calling the used method does anything. The used rate value should be
  *     proportional to the total cache size. For larger caches, exact MRU ordering is less
  *     critical, and the cost of updating the ordering is also higher. Hence, a larger used rate
  *     value is recommended.
  */
 NodeUsageList(LocalDatabase db, long usedRate, int maxSize) {
   if (maxSize <= 0) {
     throw new IllegalArgumentException();
   }
   mDatabase = db;
   mPageSize = db.pageSize();
   mUsedRate = usedRate;
   acquireExclusive();
   mMaxSize = maxSize;
   releaseExclusive();
 }
Beispiel #2
0
  /**
   * Caller must acquire latch, which is released by this method.
   *
   * @param arena optional
   * @param mode MODE_UNEVICTABLE
   */
  private Node doAllocLatchedNode(Object arena, int mode) throws DatabaseException {
    try {
      mDatabase.checkClosed();

      /*P*/ byte[] page;
      /*P*/
      // [
      page = p_calloc(arena, mPageSize);
      /*P*/
      // |
      /*P*/
      // page = mDatabase.mFullyMapped ? p_nonTreePage() : p_calloc(arena, mPageSize);
      /*P*/
      // ]

      Node node = new Node(this, page);
      node.acquireExclusive();
      mSize++;

      if ((mode & MODE_UNEVICTABLE) == 0) {
        Node most = mMostRecentlyUsed;
        node.mLessUsed = most;
        if (most == null) {
          mLeastRecentlyUsed = node;
        } else {
          most.mMoreUsed = node;
        }
        mMostRecentlyUsed = node;
      }

      // Return with node latch still held.
      return node;
    } finally {
      releaseExclusive();
    }
  }