ロード処理は SystemDictionary クラスによって実行される.
SystemDictionary クラスは, クラス名 (及びクラスローダ) からクラス(klassOop)への対応付けを管理している (See: SystemDictionary). まだ SystemDictionary 内に存在しないクラスが要求された場合, SystemDictionary クラスはそのクラスのロード処理を行う.
ロード処理では, 排他のために PlaceholderTable が用いられる (See: PlaceholderTable). また, ロード対象のクラスファイルをパースして klassOop を生成する処理は ClassFileParser::parseClassFile() に実装されている (See: here for details).
SystemDictionary クラスは次のような public メソッドを持つ.
指定されたクラスを返す (必要ならばクラスのロード処理も行う). 見つからなかった場合は NULL を返す.
((cite: hotspot/src/share/vm/classfile/systemDictionary.hpp))
// Returns a class with a given class name and class loader.
// Loads the class if needed. If not found NULL is returned.
指定されたクラスを返す (必要ならばクラスのロード処理も行う). 見つからなかった場合は例外が出る.
((cite: hotspot/src/share/vm/classfile/systemDictionary.hpp))
// Returns a class with a given class name and class loader. Loads the
// class if needed. If not found a NoClassDefFoundError or a
// ClassNotFoundException is thrown, depending on the value on the
// throw_error flag. For most uses the throw_error argument should be set
// to true.
指定されたストリームからクラスファイルを読み取り, クラスのロード処理を行う.
((cite: hotspot/src/share/vm/classfile/systemDictionary.hpp))
// Resolve from stream (called by jni_DefineClass and JVM_DefineClass)
指定されたストリームからクラスファイルを読み取り, クラスのロード処理を行う (SystemDictionary::resolve_from_stream() に類似のメソッドだが, SystemDictionary を更新しない).
((cite: hotspot/src/share/vm/classfile/systemDictionary.hpp))
// Parse new stream. This won't update the system dictionary or
// class hierarchy, simply parse the stream. Used by JVMTI RedefineClasses.
なお, InitOption の種別で Pre, Pre_JSR292 のものは SystemDictionary::resolve_or_fail(), それ以降のものは SystemDictionary::resolve_or_null() を使用するらしい.
((cite: hotspot/src/share/vm/classfile/systemDictionary.hpp))
enum InitOption {
Pre, // preloaded; error if not present
Pre_JSR292, // preloaded if EnableInvokeDynamic
// Order is significant. Options before this point require resolve_or_fail.
// Options after this point will use resolve_or_null instead.
Opt, // preload tried; NULL if not present
Opt_Only_JDK14NewRef, // preload tried; use only with NewReflection
Opt_Only_JDK15, // preload tried; use only with JDK1.5+
Opt_Kernel, // preload tried only #ifdef KERNEL
OPTION_LIMIT,
CEIL_LG_OPTION_LIMIT = 4 // OPTION_LIMIT <= (1<<CEIL_LG_OPTION_LIMIT)
};
SystemDictionary::resolve_or_null(Symbol *class_name, Handle class_loader, Handle protection_domain, TRAPS)
-> * 配列クラスの場合:
-> SystemDictionary::resolve_array_class_or_null()
-> * オブジェクト型の配列クラスの場合: (一次元配列のクラスだけでなく, 多次元配列のクラスも含む)
-> SystemDictionary::resolve_instance_class_or_null()
-> (後述)
-> Klass::array_klass()
* プリミティブ型の配列クラスの場合: (一次元配列のクラスだけでなく, 多次元配列のクラスも含む)
-> Universe::typeArrayKlassObj()
-> Klass::array_klass()
* 配列クラスではない場合:
-> SystemDictionary::resolve_instance_class_or_null()
-> (1) ロード対象のクラスに対応する PlaceholderEntry を PlaceholderTable 内に登録する.
-> PlaceholderTable::find_and_add()
(1) 実際のロード処理を行う.
-> SystemDictionary::load_instance_class()
-> 使用する ClassLoader が指定されているかどうかで 2通りに分岐.
* 使用する ClassLoader が指定されていない場合
(1) まずは, shared archive (Class Data Sharing の領域) から探す.
-> SystemDictionary::load_shared_class()
(2) 見つからなければ, HotSpot 内蔵のクラスローダ(ブートストラップ・クラスローダ)でロードを試みる.
-> ClassLoader::load_classfile()
-> ClassFileParser::parseClassFile()
-> (See: here for details)
-> ClassLoader::add_package()
(3) (#ifdef KERNEL の場合) #TODO
-> SystemDictionary::download_and_retry_class_load()
(4) 以上の処理でクラスで見つかった場合は, SystemDictionary に登録する.
-> SystemDictionary::find_or_define_instance_class()
-> SystemDictionary::define_instance_class()
-> (1) クラスローダーにクラスを登録する
-> JavaCalls::call()
-> (See: here for details)
-> java.lang.ClassLoader.addClass()
(2) クラスを SystemDictionary に追加する
-> SystemDictionary::add_to_hierarchy()
-> Universe::flush_dependents_on()
-> SystemDictionary::update_dictionary()
-> Dictionary::add_klass()
-> instanceKlass::eager_initialize()
* 使用する ClassLoader が指定されている場合
(1) 指定された ClassLoader の loadClassInternal() もしくは loadClass() でロードを行う.
-> JavaCalls::call_special() or JavaCalls::call_virtual()
SystemDictionary::resolve_or_null(Symbol *class_name, TRAPS) -> SystemDictionary::resolve_or_null(Symbol *class_name, Handle class_loader, Handle protection_domain, TRAPS) -> (上述)
SystemDictionary::resolve_or_fail(Symbol *class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) -> SystemDictionary::resolve_or_null(Symbol *class_name, Handle class_loader, Handle protection_domain, TRAPS) -> (上記参照) -> SystemDictionary::handle_resolution_exception()
SystemDictionary::resolve_or_fail(Symbol *class_name, bool throw_error, TRAPS) -> SystemDictionary::resolve_or_fail(Symbol *class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) -> (上述)
#TODO
SystemDictionary::parse_stream(Symbol *class_name, Handle class_loader, Handle protection_domain, ClassFileStream *st, TRAPS) -> SystemDictionary::parse_stream(Symbol *class_name, Handle class_loader, Handle protection_domain, ClassFileStream *st, KlassHandle host_klass, GrowableArray< Handle > *cp_patches, TRAPS) -> (下記参照)
SystemDictionary::parse_stream(Symbol *class_name, Handle class_loader, Handle protection_domain, ClassFileStream *st, KlassHandle host_klass, GrowableArray< Handle > *cp_patches, TRAPS) -> ClassFileParser::parseClassFile() -> (See: here for details) -> SystemDictionary::add_to_hierarchy()
SystemDictionary::resolve_from_stream()
-> (1) クラスファイルのパース処理を行う
-> ClassFileParser::parseClassFile()
-> (See: here for details)
(1) SystemDictionary に登録する.
* 並行に処理できる場合:
-> SystemDictionary::find_or_define_instance_class()
-> SystemDictionary::define_instance_class()
-> (下記参照)
* 〃できない場合:
-> SystemDictionary::define_instance_class()
-> (1) クラスローダーにクラスを登録する
-> JavaCalls::call()
-> (See: here for details)
-> java.lang.ClassLoader.addClass()
(2) クラスを SystemDictionary に追加する
-> SystemDictionary::add_to_hierarchy()
-> Universe::flush_dependents_on()
-> SystemDictionary::update_dictionary()
-> Dictionary::add_klass()
(#Under Construction) See: here for details
See: here for details
See: here for details
See: here for details
(#Under Construction)
See: here for details
See: here for details
See: here for details
See: here for details
(#Under Construction) See: here for details
See: here for details
See: here for details
See: here for details
See: here for details
(#Under Construction) See: here for details
See: here for details
(#Under Construction) See: here for details
(#Under Construction)
See: here for details
See: here for details
(#Under Construction) See: here for details
(#Under Construction)
This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.