专栏名称: ImportNew
伯乐在线旗下账号,专注Java技术分享,包括Java基础技术、进阶技能、架构设计和Java技术领域动态等。
目录
相关文章推荐
ImportNew  ·  GitHub 第 10 ... ·  10 小时前  
ImportNew  ·  1 个空指针,捅破谷歌云的天…… ·  昨天  
Java编程精选  ·  SpringBoot 内置的 10 ... ·  昨天  
ImportNew  ·  苹果抛弃 Java!转用 Swift ... ·  2 天前  
程序员晓梦  ·  卧槽!又是一个Java神器! ·  2 天前  
程序员晓梦  ·  卧槽!又是一个Java神器! ·  2 天前  
51好读  ›  专栏  ›  ImportNew

JVM 模板解释器 – 字节码的 resolve 过程(下)

ImportNew  · 公众号  · Java  · 2017-02-05 21:59

正文

请到「今天看啥」查看全文


bool is_static = (byte == Bytecodes::_getstatic || byte == Bytecodes::_putstatic);

bool is_put    = (byte == Bytecodes::_putfield  || byte == Bytecodes::_putstatic);

// Check if there's a resolved klass containing the field

if (resolved_klass.is_null()) {

ResourceMark rm(THREAD);

THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());

}

/************************

* 关键点1

*************************/

// Resolve instance field

KlassHandle sel_klass(THREAD, resolved_klass->find_field(field, sig, &fd));

// check if field exists; i.e., if a klass containing the field def has been selected

if (sel_klass.is_null()) {

ResourceMark rm(THREAD);

THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());

}

if (!check_access)

// Access checking may be turned off when calling from within the VM.

return;

/************************

* 关键点2

*************************/

// check access

check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK);

// check for errors

if (is_static != fd.is_static()) {

// ...

THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg);

}

// Final fields can only be accessed from its own class.

if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) {

THROW(vmSymbols::java_lang_IllegalAccessError());

}

// initialize resolved_klass if necessary

// note 1: the klass which declared the field must be initialized (i.e, sel_klass)

//         according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99)

//

// note 2: we don't want to force initialization if we are just checking

//         if the field access is legal; e.g., during compilation

if (is_static && initialize_class) {

sel_klass->initialize(CHECK);

}

if (sel_klass() != current_klass()) {

HandleMark hm(THREAD);

Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader());

Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader());

{

ResourceMark rm(THREAD);

/************************

* 关键点3

*************************/

Symbol* failed_type_symbol =







请到「今天看啥」查看全文