Top


定義場所(file name)

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

説明(description)

// Threads_lock NOT held, java_thread not protected by lock
// java_thread - pre-checked
// owned_monitor_count_ptr - pre-checked for NULL
// owned_monitors_ptr - pre-checked for NULL

名前(function name)

jvmtiError
JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {

本体部(body)

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

      jvmtiError err = JVMTI_ERROR_NONE;
      JavaThread* calling_thread = JavaThread::current();

  {- -------------------------------------------
  (1) 作業中に使用する配列を確保しておく.
      ---------------------------------------- -}

      // growable array of jvmti monitors info on the C-heap
      GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
          new (ResourceObj::C_HEAP) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true);

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

      uint32_t debug_bits = 0;

  {- -------------------------------------------
  (1) java_thread 引数で指定されたスレッドが所有するモニター情報(およびそれらのモニターをロックしているスタックフレームの深さ)を取得する.
      取得方法は以下の2通り.

      * 対象のスレッドがサスペンドしている場合: 
        JvmtiEnvBase::get_owned_monitors() で取得.

      * 対象のスレッドがサスペンドしていない場合: 
        VM_GetOwnedMonitorInfo で取得.
      ---------------------------------------- -}

      if (is_thread_fully_suspended(java_thread, true, &debug_bits)) {
        err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
      } else {
        // JVMTI get monitors info at safepoint. Do not require target thread to
        // be suspended.
        VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list);
        VMThread::execute(&op);
        err = op.result();
      }

  {- -------------------------------------------
  (1) 取得処理が成功していたら, 取得した情報を
      owned_monitors_ptr 引数および owned_monitor_count_ptr 引数で指定された場所にコピーする.
      ---------------------------------------- -}

      jint owned_monitor_count = owned_monitors_list->length();
      if (err == JVMTI_ERROR_NONE) {
        if ((err = allocate(owned_monitor_count * sizeof(jobject *),
                          (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) {
          // copy into the returned array
          for (int i = 0; i < owned_monitor_count; i++) {
            (*owned_monitors_ptr)[i] =
              ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
          }
          *owned_monitor_count_ptr = owned_monitor_count;
        }
      }

  {- -------------------------------------------
  (1) 作業用の配列(及びその中身)を開放する.
      ---------------------------------------- -}

      // clean up.
      for (int i = 0; i < owned_monitor_count; i++) {
        deallocate((unsigned char*)owned_monitors_list->at(i));
      }
      delete owned_monitors_list;

  {- -------------------------------------------
  (1) リターン
      ---------------------------------------- -}

      return err;
    } /* end GetOwnedMonitorInfo */

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