Top


定義場所(file name)

hotspot/src/share/vm/runtime/biasedLocking.cpp

名前(function name)

static HeuristicsResult update_heuristics(oop o, bool allow_rebias) {

本体部(body)

  {- -------------------------------------------
  (1) (変数宣言など)
      ---------------------------------------- -}

      markOop mark = o->mark();

  {- -------------------------------------------
  (1) もし mark フィールが非 biased locking pattern であれば, ここで終了 (HR_NOT_BIASED をリターン).
      (biased されていないオブジェクトについては, この関数でやることは何もない)
      ---------------------------------------- -}

      if (!mark->has_bias_pattern()) {
        return HR_NOT_BIASED;
      }

  {- -------------------------------------------
  (1) (変数宣言など)
      ---------------------------------------- -}

      // Heuristics to attempt to throttle the number of revocations.
      // Stages:
      // 1. Revoke the biases of all objects in the heap of this type,
      //    but allow rebiasing of those objects if unlocked.
      // 2. Revoke the biases of all objects in the heap of this type
      //    and don't allow rebiasing of these objects. Disable
      //    allocation of objects of that type with the bias bit set.
      Klass* k = o->blueprint();
      jlong cur_time = os::javaTimeMillis();
      jlong last_bulk_revocation_time = k->last_biased_lock_bulk_revocation_time();
      int revocation_count = k->biased_lock_revocation_count();

  {- -------------------------------------------
  (1) もし, 以前 bulk rebias が起こしたことがあるが, 直近の bulk rebias からは充分時間が経過していた場合には
      (そしてまだ revoke 数も bulk revoke の基準には達していなければ), 
      revoke 数を 0 にリセットする.
      ---------------------------------------- -}

      if ((revocation_count >= BiasedLockingBulkRebiasThreshold) &&
          (revocation_count <  BiasedLockingBulkRevokeThreshold) &&
          (last_bulk_revocation_time != 0) &&
          (cur_time - last_bulk_revocation_time >= BiasedLockingDecayTime)) {
        // This is the first revocation we've seen in a while of an
        // object of this type since the last time we performed a bulk
        // rebiasing operation. The application is allocating objects in
        // bulk which are biased toward a thread and then handing them
        // off to another thread. We can cope with this allocation
        // pattern via the bulk rebiasing mechanism so we reset the
        // klass's revocation count rather than allow it to increase
        // monotonically. If we see the need to perform another bulk
        // rebias operation later, we will, and if subsequently we see
        // many more revocation operations in a short period of time we
        // will completely disable biasing for this type.
        k->set_biased_lock_revocation_count(0);
        revocation_count = 0;
      }

  {- -------------------------------------------
  (1) revocation_count の値をアトミックに 1 増加させた後, 増加後の値に応じて以下の値をリターンする.
      * BiasedLockingBulkRevokeThreshold に等しければ, HR_BULK_REVOKE
      * BiasedLockingBulkRebiasThreshold に等しければ, HR_BULK_REBIAS
      * それ以外であれば, HR_SINGLE_REVOKE

      (ここの条件に, "<= BiasedLockingBulkRevokeThreshold" と = が含まれているのは, 
       複数きたときに最初の一人以外は HR_BULK_REVOKE にさせないようにするため?? #TODO)
      ---------------------------------------- -}

      // Make revocation count saturate just beyond BiasedLockingBulkRevokeThreshold
      if (revocation_count <= BiasedLockingBulkRevokeThreshold) {
        revocation_count = k->atomic_incr_biased_lock_revocation_count();
      }

      if (revocation_count == BiasedLockingBulkRevokeThreshold) {
        return HR_BULK_REVOKE;
      }

      if (revocation_count == BiasedLockingBulkRebiasThreshold) {
        return HR_BULK_REBIAS;
      }

      return HR_SINGLE_REVOKE;
    }

This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.