Up Top

Class のロード/リンク/初期化 : 初期化処理 (1) : 初期化処理の開始点


概要(Summary)

クラスの初期化処理は以下の契機で開始される.

処理の流れ (概要)(Execution Flows : Summary)

起動中の標準ライブラリクラスの初期化処理

(HotSpot の起動時処理) (See: here for details)
-> Threads::create_vm()
   -> Klass::initialize() (※)
      -> (See: here for details)
   -> initialize_class()
      -> Klass::initialize()
         -> (See: here for details)

(※) 初期化されているのは java.util.HashMap 及び java.lang.StringValue

実行時コンスタントプールのシンボルの解決(resolution)時

static フィールドへのアクセス時

(See: here for details)
-> LinkResolver::resolve_field()
   -> Klass::initialize()
      -> (See: here for details)

static メソッドへのアクセス時

(See: here for details)
-> LinkResolver::resolve_static_call()
   -> Klass::initialize()
      -> (See: here for details)

インスタンスの生成時

(See: )
-> InterpreterRuntime::_new()
   -> Klass::initialize()
      -> (See: here for details)

(See: ) 
-> Runtime1::new_instance()
   -> Klass::initialize()
      -> (See: here for details)
  
(See: ) 
-> OptoRuntime::new_instance_C()
   -> Klass::initialize()
      -> (See: here for details)

上記以外のフィールド/メソッドへのアクセスやインスタンス生成を行う処理

Reflection API による処理時

(#Under Construction)

(#TODO)
-> Reflection::invoke()
   -> Klass::initialize()
      -> (See: here for details)
  
(#TODO)
-> Reflection::invoke_constructor()
   -> Klass::initialize()
      -> (See: here for details)
  
(#TODO)
-> Reflection::resolve_field()
   -> Klass::initialize()
      -> (See: here for details)

JNI 関数による処理時

jni_GetFieldID()
-> Klass::initialize()
   -> (See: here for details)

jni_GetStaticFieldID()
-> Klass::initialize()
   -> (See: here for details)
jni_GetMethodID()
-> get_method_id()
   -> Klass::initialize()
      -> (See: here for details)

jni_GetStaticMethodID()
-> get_method_id()
   -> (同上)
jni_AllocObject()
-> alloc_object()
   -> Klass::initialize()
      -> (See: here for details)

jni_NewObject()
-> alloc_object()
   -> (同上)

jni_NewObjectV()
-> alloc_object()
   -> (同上)

jni_NewObjectA()
-> alloc_object()
   -> (同上)
jni_NewObjectArray()
-> Klass::initialize()
   -> (See: here for details)
jni_FromReflectedMethod()
-> Klass::initialize()
   -> (See: here for details)

jni_FromReflectedField()
-> Klass::initialize()
   -> (See: here for details)
jni_NewDirectByteBuffer()
-> initializeDirectBufferSupport()
   -> lookupDirectBufferClasses()
      -> lookupOne()
         -> find_class_from_class_loader()
            -> Klass::initialize()
               -> (See: here for details)

jni_GetDirectBufferAddress()
-> initializeDirectBufferSupport()
   -> (同上)

jni_GetDirectBufferCapacity()
-> initializeDirectBufferSupport()
   -> (同上)

上記以外のインスタンス生成時

(See: here for details)
-> Exceptions::new_exception()
   -> Klass::initialize()
      -> (See: here for details)
(#TODO)
-> Management::load_and_initialize_klass()
   -> Klass::initialize()
      -> (See: here for details)
java.lang.ClassLoader.setDefaultAssertionStatus()
-> java.lang.ClassLoader.initializeJavaAssertionMaps()
   -> JVM_AssertionStatusDirectives() (= java.lang.ClassLoader.retrieveDirectives())
      -> JavaAssertions::createAssertionStatusDirectives()
         -> Klass::initialize()
            -> (See: here for details)

java.lang.ClassLoader.setPackageAssertionStatus()
-> java.lang.ClassLoader.initializeJavaAssertionMaps()
   -> (同上)

java.lang.ClassLoader.setClassAssertionStatus()
-> java.lang.ClassLoader.initializeJavaAssertionMaps()
   -> (同上)
(See: here for details)
-> get_system_properties()
   -> get_properties()
      -> load_and_initialize_klass()
         -> Klass::initialize()
            -> (See: here for details)
  
(See: here for details)
-> get_agent_properties()
   -> get_properties()
      -> (同上)
  java_lang_StackTraceElement::create()
  -> Klass::initialize()
     -> (See: here for details)

  java_lang_reflect_Constructor::create()
  -> Klass::initialize()
     -> (See: here for details)

  java_lang_reflect_Field::create()
  -> Klass::initialize()
     -> (See: here for details)

  sun_reflect_ConstantPool::create()
  -> Klass::initialize()
     -> (See: here for details)

  java_lang_boxing_object::initialize_and_allocate()
  -> Klass::initialize()
     -> (See: here for details)

  java_security_AccessControlContext::create()
  -> Klass::initialize()
     -> (See: here for details)

クラスの初期化を伴う API が明示的に呼ばれたとき

java.lang.Class.forName(String className)

java.lang.Class.forName(String className) (※)
-> Java_java_lang_Class_forName0()  (= java.lang.Class.forName0())
   -> JVM_FindClassFromClassLoader()
      -> find_class_from_class_loader()
         -> Klass::initialize()
            -> (See: here for details)

(※) なお, この関数はクラスローダーとして「現在のクラスを定義するクラスローダ」を使用.

java.lang.Class.forName(String name, boolean initialize, ClassLoader loader)

java.lang.Class.forName(String name, boolean initialize, ClassLoader loader) (※)
-> Java_java_lang_Class_forName0()  (= java.lang.Class.forName0())
   -> (同上)

(※) なお, この関数はクラスローダーとして「loader 引数で指定されたクラスローダ」を使用.

JNI の FindClass() (See: here for details)

jni_FindClass()
-> find_class_from_class_loader()
   -> Klass::initialize()
      -> (See: here for details)

その他

HotSpot の内部処理で初期化が必要になった際

(#TODO)
-> Unsafe_EnsureClassInitialized() (= sun.misc.Unsafe.ensureClassInitialized())
   -> Klass::initialize()
      -> (See: here for details)

不明

(使われていない?)
JVM_AllocateNewObject
-> Klass::initialize()
   -> (See: here for details)

(使われていない?)
JVM_AllocateNewArray
-> Klass::initialize()
   -> (See: here for details)

(使われていない?)
JVM_NewInstance
-> Klass::initialize()
   -> (See: here for details)

(使われていない?)
 JVM_FindClassFromClass()
 -> find_class_from_class_loader()
    -> Klass::initialize()
       -> (See: here for details)

(使われていない?)
JVM_LoadClass0()
-> find_class_from_class_loader()
    -> Klass::initialize()
       -> (See: here for details)

未整理(#TODO)

MethodHandles::encode_target

MethodHandles::init_DirectMethodHandle

MethodHandles::raise_exception

処理の流れ (詳細)(Execution Flows : Details)

Threads::create_vm()

See: here for details

initialize_class()

See: here for details


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