Top


定義場所(file name)

hotspot/src/share/vm/services/management.cpp

説明(description)

// Gets an array containing the amount of memory allocated on the Java
// heap for a set of threads (in bytes).  Each element of the array is
// the amount of memory allocated for the thread ID specified in the
// corresponding entry in the given array of thread IDs; or -1 if the
// thread does not exist or has terminated.

名前(function name)

JVM_ENTRY(void, jmm_GetThreadAllocatedMemory(JNIEnv *env, jlongArray ids,
                                             jlongArray sizeArray))

本体部(body)

  {- -------------------------------------------
  (1) もし, 配列であるべき引数が NULL だった場合は, NullPointerException.
      ---------------------------------------- -}

      // Check if threads is null
      if (ids == NULL || sizeArray == NULL) {
        THROW(vmSymbols::java_lang_NullPointerException());
      }

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

      ResourceMark rm(THREAD);
      typeArrayOop ta = typeArrayOop(JNIHandles::resolve_non_null(ids));
      typeArrayHandle ids_ah(THREAD, ta);

      typeArrayOop sa = typeArrayOop(JNIHandles::resolve_non_null(sizeArray));
      typeArrayHandle sizeArray_h(THREAD, sa);

  {- -------------------------------------------
  (1) 引数の配列(ids_ah)をチェックしておく.
      (もし不正な値であれば IllegalArgumentException)
      ---------------------------------------- -}

      // validate the thread id array
      validate_thread_id_array(ids_ah, CHECK);

  {- -------------------------------------------
  (1) もし, 引数で渡された配列(= 返値を入れるべき配列)の長さが
      スレッド数と異なっていれば, IllegalArgumentException.
      ---------------------------------------- -}

      // sizeArray must be of the same length as the given array of thread IDs
      int num_threads = ids_ah->length();
      if (num_threads != sizeArray_h->length()) {
        THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
                  "The length of the given long array does not match the length of "
                  "the given array of thread IDs");
      }

  {- -------------------------------------------
  (1) 引数で渡された配列(ids)中の各スレッドIDについて, 
      Thread::cooked_allocated_bytes() でメモリ確保量を取得し, 
      結果を格納する配列(sizeArray_h)内に値を入れていく.
      ---------------------------------------- -}

      MutexLockerEx ml(Threads_lock);
      for (int i = 0; i < num_threads; i++) {
        JavaThread* java_thread = find_java_thread_from_id(ids_ah->long_at(i));
        if (java_thread != NULL) {
          sizeArray_h->long_at_put(i, java_thread->cooked_allocated_bytes());
        }
      }
    JVM_END

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