Top


定義場所(file name)

hotspot/src/share/vm/prims/jni.cpp

名前(function name)

static jmethodID get_method_id(JNIEnv *env, jclass clazz, const char *name_str,
                               const char *sig, bool is_static, TRAPS) {

本体部(body)

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

      // %%%% This code should probably just call into a method in the LinkResolver
      //
      // The class should have been loaded (we have an instance of the class
      // passed in) so the method and signature should already be in the symbol
      // table.  If they're not there, the method doesn't exist.
      const char *name_to_probe = (name_str == NULL)
                            ? vmSymbols::object_initializer_name()->as_C_string()
                            : name_str;
      TempNewSymbol name = SymbolTable::probe(name_to_probe, (int)strlen(name_to_probe));
      TempNewSymbol signature = SymbolTable::probe(sig, (int)strlen(sig));

  {- -------------------------------------------
  (1) もし指定されたメソッド名やシグネチャが SynbolTable 内に見つからなければ, NoSuchMethodError.
      ---------------------------------------- -}

      if (name == NULL || signature == NULL) {
        THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
      }

  {- -------------------------------------------
  (1) もし指定されたクラスがプリミティブ型用のクラスだった場合は, NoSuchMethodError.
      ---------------------------------------- -}

      // Throw a NoSuchMethodError exception if we have an instance of a
      // primitive java.lang.Class
      if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(clazz))) {
        THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
      }

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

      KlassHandle klass(THREAD,
                   java_lang_Class::as_klassOop(JNIHandles::resolve_non_null(clazz)));

  {- -------------------------------------------
  (1) 対象のクラスオブジェクトに対して Klass::initialize() を呼び, 
      リンクや初期化が終わっていなければ終わらせておく.
      ---------------------------------------- -}

      // Make sure class is linked and initialized before handing id's out to
      // methodOops.
      Klass::cast(klass())->initialize(CHECK_NULL);

  {- -------------------------------------------
  (1) 以下の if ブロックの中で dynamic dispatch 処理を行い, 
      指定内容に合う methodOop を探し出す.
      ---------------------------------------- -}

      methodOop m;
      if (name == vmSymbols::object_initializer_name() ||
          name == vmSymbols::class_initializer_name()) {
        // Never search superclasses for constructors
        if (klass->oop_is_instance()) {
          m = instanceKlass::cast(klass())->find_method(name, signature);
        } else {
          m = NULL;
        }
      } else {
        m = klass->lookup_method(name, signature);
        // Look up interfaces
        if (m == NULL && klass->oop_is_instance()) {
          m = instanceKlass::cast(klass())->lookup_method_in_all_interfaces(name,
                                                                       signature);
        }
      }

  {- -------------------------------------------
  (1) もし methodOop が見つからなかったり, static 指定されているのに 
      static ではないメソッドが見つかってしまったら (あるいはその逆だったら), NoSuchMethodError.
      ---------------------------------------- -}

      if (m == NULL || (m->is_static() != is_static)) {
        THROW_MSG_0(vmSymbols::java_lang_NoSuchMethodError(), name_str);
      }

  {- -------------------------------------------
  (1) instanceKlass::get_jmethod_id() で見つけた methodOop の jmethod_id を取得し, それをリターンする.
      ---------------------------------------- -}

      return m->jmethod_id();
    }

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