- 浏览: 103592 次
- 性别:
- 来自: 武汉
最新评论
-
hatedance:
这个bytecodeInterpreter应该已经被遗弃了,现 ...
openjdk中的同步代码 -
Mr_lee_2012:
是啊,好文章,谢过。
java栈帧中的对象引用 -
ZangXT:
有些性能要求比较高的系统会考虑这一点的,典型的如JPC,尽量避 ...
java中调用接口及调用继承类效率区别 -
tinywind:
你有没有注意到load_classfile开始定义了个Reso ...
hotsphot中的ResourceArea -
qianli-2010:
java中调用接口及调用继承类效率区别
instanceKlassHandle ClassFileParser::parseClassFile(symbolHandle name,
Handle class_loader,
Handle protection_domain,
symbolHandle& parsed_name,
TRAPS)
是一个非常复杂的方法。
unsigned char *cached_class_file_bytes = NULL;
jint cached_class_file_length;
//加载的类文件流
ClassFileStream* cfs = stream();
// Timing
PerfTraceTime vmtimer(ClassLoader::perf_accumulated_time());
_has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
if (JvmtiExport::should_post_class_file_load_hook()) {
unsigned char* ptr = cfs->buffer();
unsigned char* end_ptr = cfs->buffer() + cfs->length();
JvmtiExport::post_class_file_load_hook(name, class_loader, protection_domain,
&ptr, &end_ptr,
&cached_class_file_bytes,
&cached_class_file_length);
if (ptr != cfs->buffer()) {
cfs = new ClassFileStream(ptr, end_ptr - ptr, cfs->source());
set_stream(cfs);
}
}
instanceKlassHandle nullHandle;
// Figure out whether we can skip format checking (matching classic VM behavior)
_need_verify = Verifier::should_verify_for(class_loader());
// Set the verify flag in stream
cfs->set_verify(_need_verify);
// 类名不能为空
_class_name = name.not_null()? name : vmSymbolHandles::unknown_class_name();
cfs->guarantee_more(8, CHECK_(nullHandle)); // magic, major, minor
// 文件模数,看是否java文件格式
u4 magic = cfs->get_u4_fast();
guarantee_property(magic == JAVA_CLASSFILE_MAGIC,
"Incompatible magic value %u in class file %s",
magic, CHECK_(nullHandle));
// jdk的版本号
u2 minor_version = cfs->get_u2_fast();
u2 major_version = cfs->get_u2_fast();
// Check version numbers - we check this even with verifier off
if (!is_supported_version(major_version, minor_version)) {
if (name.is_null()) {
Exceptions::fthrow(
THREAD_AND_LOCATION,
vmSymbolHandles::java_lang_UnsupportedClassVersionError(),
"Unsupported major.minor version %u.%u",
major_version,
minor_version);
} else {
ResourceMark rm(THREAD);
Exceptions::fthrow(
THREAD_AND_LOCATION,
vmSymbolHandles::java_lang_UnsupportedClassVersionError(),
"%s : Unsupported major.minor version %u.%u",
name->as_C_string(),
major_version,
minor_version);
}
return nullHandle;
}
_major_version = major_version;
_minor_version = minor_version;
// Check if verification needs to be relaxed for this class file
// Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376)
_relax_verify = Verifier::relax_verify_for(class_loader());
// 对常量池进行解析,常量池存放文件字符串、final变量值、类名、方法名等常量。
constantPoolHandle cp = parse_constant_pool(CHECK_(nullHandle));
int cp_size = cp->length();
cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len
// Access flags
AccessFlags access_flags;
...
u2 super_class_index = cfs->get_u2_fast();
//只有java.lang.Object没有超类
if (super_class_index == 0) {
check_property(class_name() == vmSymbols::java_lang_Object(),
"Invalid superclass index %u in class file %s",
super_class_index,
CHECK_(nullHandle));
} else {
check_property(valid_cp_range(super_class_index, cp_size) &&
cp->tag_at(super_class_index).is_unresolved_klass(),
"Invalid superclass index %u in class file %s",
super_class_index,
CHECK_(nullHandle));
// The class name should be legal because it is checked when parsing constant pool.
// However, make sure it is not an array type.
if (_need_verify) {
guarantee_property(cp->unresolved_klass_at(super_class_index)->byte_at(0) != JVM_SIGNATURE_ARRAY,
"Bad superclass name in class file %s", CHECK_(nullHandle));
}
}
//先解析类的接口
u2 itfs_len = cfs->get_u2_fast();
objArrayHandle local_interfaces;
if (itfs_len == 0) {
local_interfaces = objArrayHandle(THREAD, Universe::the_empty_system_obj_array());
} else {
local_interfaces = parse_interfaces(cp, itfs_len, class_loader, protection_domain, &vmtimer, _class_name, CHECK_(nullHandle));
}
// Fields (offsets are filled in later)
struct FieldAllocationCount fac = {0,0,0,0,0,0,0,0,0,0};
objArrayHandle fields_annotations;
typeArrayHandle fields = parse_fields(cp, access_flags.is_interface(), &fac, &fields_annotations, CHECK_(nullHandle));
// Methods
bool has_final_method = false;
AccessFlags promoted_flags;
promoted_flags.set_flags(0);
// These need to be oop pointers because they are allocated lazily
// inside parse_methods inside a nested HandleMark
objArrayOop methods_annotations_oop = NULL;
objArrayOop methods_parameter_annotations_oop = NULL;
objArrayOop methods_default_annotations_oop = NULL;
objArrayHandle methods = parse_methods(cp, access_flags.is_interface(),
&promoted_flags,
&has_final_method,
&methods_annotations_oop,
&methods_parameter_annotations_oop,
&methods_default_annotations_oop,
CHECK_(nullHandle));
objArrayHandle methods_annotations(THREAD, methods_annotations_oop);
objArrayHandle methods_parameter_annotations(THREAD, methods_parameter_annotations_oop);
objArrayHandle methods_default_annotations(THREAD, methods_default_annotations_oop);
// We check super class after class file is parsed and format is checked
if (super_class_index > 0) {
symbolHandle sk (THREAD, cp->klass_name_at(super_class_index));
if (access_flags.is_interface()) {
// Before attempting to resolve the superclass, check for class format
// errors not checked yet.
guarantee_property(sk() == vmSymbols::java_lang_Object(),
"Interfaces must have java.lang.Object as superclass in class file %s",
CHECK_(nullHandle));
}
//解析超类
klassOop k = SystemDictionary::resolve_super_or_fail(class_name,
sk,
class_loader,
protection_domain,
true,
CHECK_(nullHandle));
KlassHandle kh (THREAD, k);
super_klass = instanceKlassHandle(THREAD, kh());
if (super_klass->is_interface()) {
ResourceMark rm(THREAD);
Exceptions::fthrow(
THREAD_AND_LOCATION,
vmSymbolHandles::java_lang_IncompatibleClassChangeError(),
"class %s has interface %s as super class",
class_name->as_klass_external_name(),
super_klass->external_name()
);
return nullHandle;
}
// Make sure super class is not final
if (super_klass->is_final()) {
THROW_MSG_(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class", nullHandle);
}
}
// Compute the transitive list of all unique interfaces implemented by this class
objArrayHandle transitive_interfaces = compute_transitive_interfaces(super_klass, local_interfaces, CHECK_(nullHandle));
// sort methods,这里主要是用于vtable的构造和快速查找吧
typeArrayHandle method_ordering = sort_methods(methods,
methods_annotations,
methods_parameter_annotations,
methods_default_annotations,
CHECK_(nullHandle));
// promote flags from parse_methods() to the klass' flags
access_flags.add_promoted_flags(promoted_flags.as_int());
// Size of Java vtable (in words)
int vtable_size = 0;
int itable_size = 0;
int num_miranda_methods = 0;
klassVtable::compute_vtable_size_and_num_mirandas(vtable_size,
num_miranda_methods,
super_klass(),
methods(),
access_flags,
class_loader(),
class_name(),
local_interfaces());
// Size of Java itable (in words)
itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(transitive_interfaces);
// Field size and offset computation
int nonstatic_field_size = super_klass() == NULL ? 0 : super_klass->nonstatic_field_size();
....
next_static_oop_offset = (instanceKlass::header_size() +
align_object_offset(vtable_size) +
align_object_offset(itable_size)) * wordSize;
next_static_double_offset = next_static_oop_offset +
(fac.static_oop_count * heapOopSize);
...
//在上面进行实例大小的计算
int instance_size;
instance_size = align_object_size(next_nonstatic_type_offset / wordSize);
assert(instance_size == align_object_size(instanceOopDesc::header_size() + nonstatic_field_size), "consistent layout helper value");
// Size of non-static oop map blocks (in words) allocated at end of klass
//oop map block主要用于gc操作
int nonstatic_oop_map_size = compute_oop_map_size(super_klass, nonstatic_oop_map_count, first_nonstatic_oop_offset);
// Compute reference type
ReferenceType rt;
if (super_klass() == NULL) {
rt = REF_NONE;
} else {
rt = super_klass->reference_type();
}
// We can now create the basic klassOop for this klass,在这里面就有Object header
//垃圾回收会用到的标志,都在里面,粗略来看,一个java对象在jvm里面还涉及Oject header、oop map 大小
//vtable\itable、静态域等
klassOop ik = oopFactory::new_instanceKlass(
vtable_size, itable_size,
static_field_size, nonstatic_oop_map_size,
rt, CHECK_(nullHandle));
instanceKlassHandle this_klass (THREAD, ik);
assert(this_klass->static_field_size() == static_field_size &&
this_klass->nonstatic_oop_map_size() == nonstatic_oop_map_size, "sanity check");
// 填充解析好的各项值
this_klass->set_access_flags(access_flags);
jint lh = Klass::instance_layout_helper(instance_size, false);
this_klass->set_layout_helper(lh);
...
// 解析类的属性
parse_classfile_attributes(cp, this_klass, CHECK_(nullHandle));
// Make sure this is the end of class file stream
guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle));
// Initialize static fields
this_klass->do_local_static_fields(&initialize_static_field, CHECK_(nullHandle));
// VerifyOops believes that once this has been set, the object is completely loaded.
// Compute transitive closure of interfaces this class implements
this_klass->set_transitive_interfaces(transitive_interfaces());
// Fill in information needed to compute superclasses.
this_klass->initialize_supers(super_klass(), CHECK_(nullHandle));
// Initialize itable offset tables
klassItable::setup_itable_offset_table(this_klass);
// Do final class setup
fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_length);
set_precomputed_flags(this_klass);
// reinitialize modifiers, using the InnerClasses attribute
int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle));
this_klass->set_modifier_flags(computed_modifiers);
// check if this class can access its super class
check_super_class_access(this_klass, CHECK_(nullHandle));
// check if this class can access its superinterfaces
check_super_interface_access(this_klass, CHECK_(nullHandle));
// check if this class overrides any final method
check_final_method_override(this_klass, CHECK_(nullHandle));
// check that if this class is an interface then it doesn't have static methods
if (this_klass->is_interface()) {
check_illegal_static_method(this_klass, CHECK_(nullHandle));
}
...
instanceKlassHandle this_klass (THREAD, preserve_this_klass);
return this_klass;
}
发表评论
-
java动态代理
2009-11-19 16:21 940在java里面使用动态 ... -
小议偏向锁
2009-02-02 22:18 2047java SE6采用偏向锁以提高性能。 个人理解,偏向 ... -
java中调用接口及调用继承类效率区别
2009-01-19 22:34 5200都说调用接口要比调 ... -
hotsphot中的ResourceArea
2008-11-09 21:38 1354在ClassLoader::load_cla ... -
athrow程序执行代码
2008-10-10 14:38 1053看看openjdk中的athrow处理流程 { ... -
Object中notify方法
2008-10-08 10:48 2290Object.java类中notify调用的是shar ... -
Object中wait方法
2008-09-18 10:59 3685Object.wait调用 ... -
自定义类加载器loadClass
2008-09-17 15:43 1465自定义类加载器继承ClassLoader类,使用自定义类加载器 ... -
openjdk中的同步代码
2008-09-16 15:24 1848在java虚拟机中的方法同步synchroni ... -
java栈帧中的对象引用
2008-09-12 11:14 3958openjdk中的java栈帧是如何布置的呢, ... -
System.gc初步分析
2008-09-11 09:48 4342openjdk中的垃圾回收是一个庞大的课题,如何标记 ... -
openjdk的周期线程
2008-09-10 10:04 1342openjdk中周期 ... -
java线程启动代码
2008-09-09 11:24 2009上次写了个《Th ... -
InterpreterRuntime::_new阅读
2008-09-05 14:52 1396InterpreterRuntime::_new为解释 ... -
java解释器的阅读
2008-09-05 10:09 1634前面已经提到了j ... -
JavaCalls::call代码阅读
2008-09-04 10:34 2864JavaCalls::call为hotspot调用j ... -
hotspot中的OO对象分析
2008-08-30 23:03 2201hotspot中的OO对象,涉 ... -
类的加载
2008-08-20 16:00 1297类通过(*env)->FindClass,也就是 ... -
Thread的调用
2008-08-19 11:03 2157在java里面创建线程new Thread().sta ... -
openJdk学习
2008-07-15 11:05 3595学习openJdk,主要 ...
相关推荐
《深入解析ClassFileParser:库廷大学软件工程实践之精华》 在软件工程的学习与实践中,理解并解析Java字节码是至关重要的技能之一。库廷大学为了培养学生的这一能力,特别开发了一款名为ClassFileParser的工具。...
jvm 类文件解析器 这是一个(部分实现的)Rust 库和用于解析 JVM 类文件的程序。 $ cargo +nightly run classes/Dummy.class Classfile /home/chris/Code/jvm-class-file-parser/classes/Dummy.class ...
1.程序功能说明: MATLAB实现多种群遗传算法(完整代码) 逼近C=[9,8,7,6,5,4,3,2,1]的9维向量. 2.代码说明:注释清晰,参数和变量说明清晰,方便更改、方便初学者使用,模块化编程,方便替换目标函数。运行环境Windows7及以上操作系统,MATLAB2014a及以上版本。 3.适用专业:计算机、电子信息工程、数学、物理、机械工程、土木工程等专业的大学生、研究生毕业设计,各类专业的课程设计、海外留学生作业等。 4作者介绍:资深算法工程师, 从事Matlab、Python算法仿真工作15年,专业研究遗传算法、粒子群算法、蚁群算法、鲸鱼算法、狼群算法等. 有问题联系QQ: 1579325979
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
免费JAVA毕业设计 2024成品源码+论文+录屏+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
小学元旦晚会PPT 模版
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
MATLAB中的语义分割技术探究与应用实践,matlab,语义分割 ,matlab; 语义分割,Matlab语义分割技术解析
免费JAVA毕业设计 2024成品源码+论文+数据库+启动教程 启动教程:https://www.bilibili.com/video/BV1SzbFe7EGZ 项目讲解视频:https://www.bilibili.com/video/BV1Tb421n72S 二次开发教程:https://www.bilibili.com/video/BV18i421i7Dx
1、文件内容:pulseaudio-10.0-6.el7_9.rpm以及相关依赖 2、文件形式:tar.gz压缩包 3、安装指令: #Step1、解压 tar -zxvf /mnt/data/output/pulseaudio-10.0-6.el7_9.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm 4、安装指导:私信博主,全程指导安装
"基于OpenCV与深度学习的人脸表情识别系统:利用Python与PyQt构建的可视化实时检测工具",基于OpenCV的人脸表情识别系统 相关技术:python,opencv,pyqt,深度学习 (请自行安装向日葵远程软件,以便提供远程帮助) 可编译为.exe文件。 软件说明:摄像头实时检测,加载照片,视频均可。 有基础的同学,可自行修改完善。 第一张和第二张为运行截图。 ,基于OpenCV的人脸表情识别系统; Python; OpenCV; PyQt; 深度学习; 实时检测; 照片和视频支持; 可编译为.exe文件; 运行截图。,"基于OpenCV与深度学习的人脸表情识别系统"
,步进方案,步进源码,两相步进矢量控制,超前角控制两种模式,成熟产品方案 支持特殊功能定制
三相储能PCS双向能量流动与Matlab仿真控制研究——基于SVPWM调制技术的建模与应用,三相储能PCS(Matlab仿真) 1.可实现Grid to Battery,Battery to Grid的能量双向流动。 2.本仿真基于Matlab仿真建立的模型, 3.采用SVPWM进行控制 ,三相储能PCS; 双向能量流动; Matlab仿真; SVPWM控制,三相储能PCS:能量双向流Matlab仿真模型(SVPWM控制)
deepseek部署教程.md
nodejs010-nodejs-ansicolors-0.3.2-1.el6.centos.alt.noarch.rpm
基于三菱PLC的四路抢答器控制系统原理及实践:含带解释的梯形图与IO分配图解,三菱 MCGS 基于PLC的四路抢答器控制系统 带解释的梯形图接线图原理图图纸,io分配,组态画面 ,三菱MCGS; PLC四路抢答器; 控制系统; 梯形图接线图; 原理图图纸; IO分配; 组态画面。,三菱PLC四路抢答器控制系统原理图及组态画面解析
基于运动数据时空特征提取的人类运动片段.pdf
基于机器学习的选股模型及投资组合研究.pdf
ollama安装包。。。。。。。。。。。。。。。。。
nodejs010-nodejs-ansistyles-0.1.3-1.el6.centos.alt.x86_64.rpm