Top


定義場所(file name)

hotspot/src/share/vm/oops/instanceKlass.cpp

名前(function name)

methodOop instanceKlass::find_method(objArrayOop methods, Symbol* name, Symbol* signature) {

本体部(body)

  {- -------------------------------------------
  (1) methods() の中をバイナリサーチで探索するだけ.
      (正確には, まず name でバイナリサーチし, 
       一致するものがあれば
       その時点での探索範囲の下限から上限までの間で name と sig の両方が一致するものを探す.
       一致するものがあれば結果をリターン.
       一致するものがなければ NULL をリターン)
      ---------------------------------------- -}

      int len = methods->length();
      // methods are sorted, so do binary search
      int l = 0;
      int h = len - 1;
      while (l <= h) {
        int mid = (l + h) >> 1;
        methodOop m = (methodOop)methods->obj_at(mid);
        assert(m->is_method(), "must be method");
        int res = m->name()->fast_compare(name);
        if (res == 0) {
          // found matching name; do linear search to find matching signature
          // first, quick check for common case
          if (m->signature() == signature) return m;
          // search downwards through overloaded methods
          int i;
          for (i = mid - 1; i >= l; i--) {
            methodOop m = (methodOop)methods->obj_at(i);
            assert(m->is_method(), "must be method");
            if (m->name() != name) break;
            if (m->signature() == signature) return m;
          }
          // search upwards
          for (i = mid + 1; i <= h; i++) {
            methodOop m = (methodOop)methods->obj_at(i);
            assert(m->is_method(), "must be method");
            if (m->name() != name) break;
            if (m->signature() == signature) return m;
          }
          // not found
    #ifdef ASSERT
          int index = linear_search(methods, name, signature);
          assert(index == -1, err_msg("binary search should have found entry %d", index));
    #endif
          return NULL;
        } else if (res < 0) {
          l = mid + 1;
        } else {
          h = mid - 1;
        }
      }

  {- -------------------------------------------
  (1) (デバッグ用の処理) (#ifdef ASSERT 時にのみ実行)
      ---------------------------------------- -}

    #ifdef ASSERT
      int index = linear_search(methods, name, signature);
      assert(index == -1, err_msg("binary search should have found entry %d", index));
    #endif

  {- -------------------------------------------
  (1) (ここに来るのは name が一致するものが見つからなかったケース)
      NULL をリターン
      ---------------------------------------- -}

      return NULL;
    }

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