Top


定義場所(file name)

hotspot/src/share/vm/gc_implementation/shared/concurrentGCThread.cpp

名前(function name)

SurrogateLockerThread* SurrogateLockerThread::make(TRAPS) {

本体部(body)

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

      klassOop k =
        SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(),
                                          true, CHECK_NULL);
      instanceKlassHandle klass (THREAD, k);

  {- -------------------------------------------
  (1) 新しい java.lang.Thread オブジェクト(以下の thread_oop)を確保する.
      ---------------------------------------- -}

      instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL);

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

      const char thread_name[] = "Surrogate Locker Thread (Concurrent GC)";
      Handle string = java_lang_String::create_from_str(thread_name, CHECK_NULL);

  {- -------------------------------------------
  (1) JavaCalls::call_special() 経由で java.lang.Thread() のコンストラクタを呼び出し, 
      thread_oop オブジェクトを初期化しておく.
      ---------------------------------------- -}

      // Initialize thread_oop to put it into the system threadGroup
      Handle thread_group (THREAD, Universe::system_thread_group());
      JavaValue result(T_VOID);
      JavaCalls::call_special(&result, thread_oop,
                              klass,
                              vmSymbols::object_initializer_name(),
                              vmSymbols::threadgroup_string_void_signature(),
                              thread_group,
                              string,
                              CHECK_NULL);

  {- -------------------------------------------
  (1) 新しい SurrogateLockerThread オブジェクトを確保する (この際に対応する新しいスレッドが生成される).

      生成されたスレッドについては, java_lang_Thread::set_thread() を呼んで
      thread_oop オブジェクトの eetop フィールドにセットしておく. (See: [here](no30595cP.html) for details)
      (あわせて, java_lang_Thread::set_priority() 等を呼んで thread_oop オブジェクトの優先度等も設定しておく)

      最後に Thread::start() を呼んで, 生成した SurrogateLockerThread スレッドの実行を開始させる.

      (なお, これらの処理は Threads_lock で排他した状態で行う)
      (また, SurrogateLockerThread オブジェクトの確保に失敗した場合は vm_exit_during_initialization() で異常終了)
      ---------------------------------------- -}

      SurrogateLockerThread* res;
      {
        MutexLocker mu(Threads_lock);
        res = new SurrogateLockerThread();

        // At this point it may be possible that no osthread was created for the
        // JavaThread due to lack of memory. We would have to throw an exception
        // in that case. However, since this must work and we do not allow
        // exceptions anyway, check and abort if this fails.
        if (res == NULL || res->osthread() == NULL) {
          vm_exit_during_initialization("java.lang.OutOfMemoryError",
                                        "unable to create new native thread");
        }
        java_lang_Thread::set_thread(thread_oop(), res);
        java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
        java_lang_Thread::set_daemon(thread_oop());

        res->set_threadObj(thread_oop());
        Threads::add(res);
        Thread::start(res);
      }

  {- -------------------------------------------
  (1) 
      ---------------------------------------- -}

      os::yield(); // This seems to help with initial start-up of SLT

  {- -------------------------------------------
  (1) 結果をリターン.
      ---------------------------------------- -}

      return res;
    }

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