クラスの初期化処理は以下の契機で開始される.
HotSpot の起動時 (See: here for details)
HotSpot の起動時に, 幾つかの標準ライブラリのクラスが初期化される
実行時コンスタントプールのシンボルの解決(resolution)時 (See: here for details)
(static フィールドへのアクセス, static メソッドへのアクセス, インスタンスの生成, 等により) 実行時コンスタントプール中のクラス名/インターフェース名の解決が行われた際, 対象がまだ初期化されていなければ初期化処理が実行される
上記以外のフィールド/メソッドへのアクセス時やインスタンス生成時 (JNI 関数, Reflection APIs, etc)
対象のクラスがまだ初期化されていなければ, 初期化処理が実行される
クラスの初期化を伴う API が明示的に呼ばれたとき (java.lang.Class.forName(), JNI の FindClass(), etc)
対象のクラスがまだ初期化されていなければ, 初期化処理が実行される
その他 (HotSpot の内部処理で初期化が必要になった際, etc)
(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
(See: here for details) -> LinkResolver::resolve_field() -> Klass::initialize() -> (See: here for details)
(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)
(#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_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)
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_java_lang_Class_forName0() (= java.lang.Class.forName0()) -> (同上) (※) なお, この関数はクラスローダーとして「loader 引数で指定されたクラスローダ」を使用.
jni_FindClass() -> find_class_from_class_loader() -> Klass::initialize() -> (See: here for details)
(#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)
MethodHandles::encode_target
MethodHandles::init_DirectMethodHandle
MethodHandles::raise_exception
See: here for details
See: here for details
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.