Top


定義場所(file name)

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

説明(description)

// The RegisterNatives call being attempted tried to register with a method that
// is not native.  Ask JVM TI what prefixes have been specified.  Then check
// to see if the native method is now wrapped with the prefixes.  See the
// SetNativeMethodPrefix(es) functions in the JVM TI Spec for details.

名前(function name)

static methodOop find_prefixed_native(KlassHandle k,
                                      Symbol* name, Symbol* signature, TRAPS) {

本体部(body)

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

      ResourceMark rm(THREAD);
      methodOop method;
      int name_len = name->utf8_length();
      char* name_str = name->as_utf8();
      int prefix_count;

  {- -------------------------------------------
  (1) 以下の for ループで, JVMTI の SetNativeMethodPrefix(or SetNativeMethodPrefies) で
      指定された全ての prefix に関して iterate する.
      ---------------------------------------- -}

      char** prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count);
      for (int i = 0; i < prefix_count; i++) {

    {- -------------------------------------------
  (1.1) その prefix を付けたメソッド名がシンボルテーブル内に見つからなければ, 次の prefix 候補に移る.
        ---------------------------------------- -}

        char* prefix = prefixes[i];
        int prefix_len = (int)strlen(prefix);

        // try adding this prefix to the method name and see if it matches another method name
        int trial_len = name_len + prefix_len;
        char* trial_name_str = NEW_RESOURCE_ARRAY(char, trial_len + 1);
        strcpy(trial_name_str, prefix);
        strcat(trial_name_str, name_str);
        TempNewSymbol trial_name = SymbolTable::probe(trial_name_str, trial_len);
        if (trial_name == NULL) {
          continue; // no such symbol, so this prefix wasn't used, try the next prefix
        }

    {- -------------------------------------------
  (1.1) シンボルテーブル内に見つかれば, そのメソッド名とシグネチャ部分をもとに methodOop を探す.
        もし methodOop がなければ, 次の prefix 候補に移る.
        ---------------------------------------- -}

        method = Klass::cast(k())->lookup_method(trial_name, signature);
        if (method == NULL) {
          continue; // signature doesn't match, try the next prefix
        }

    {- -------------------------------------------
  (1.1) もし methodOop が見つかりしかも native であれば, 探していたものが見つかったことになる.
        見つかった methodOop をリターン.
        ---------------------------------------- -}

        if (method->is_native()) {
          method->set_is_prefixed_native();
          return method; // wahoo, we found a prefixed version of the method, return it
        }

    {- -------------------------------------------
  (1.1) methodOop は見つかったが native でなければ, まだ prefix が足りない可能性が考えられる.
        今回の prefix はメソッド名に追加し, 次の prefix 候補へと処理を続ける.
        ---------------------------------------- -}

        // found as non-native, so prefix is good, add it, probably just need more prefixes
        name_len = trial_len;
        name_str = trial_name_str;
      }

  {- -------------------------------------------
  (1) 全ての prefix を試して見つからなければ, NULL をリターン.
      ---------------------------------------- -}

      return NULL; // not found
    }

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