- 浏览: 102678 次
- 性别:
- 来自: 武汉
最新评论
-
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 926在java里面使用动态 ... -
小议偏向锁
2009-02-02 22:18 2023java SE6采用偏向锁以提高性能。 个人理解,偏向 ... -
java中调用接口及调用继承类效率区别
2009-01-19 22:34 5178都说调用接口要比调 ... -
hotsphot中的ResourceArea
2008-11-09 21:38 1338在ClassLoader::load_cla ... -
athrow程序执行代码
2008-10-10 14:38 1033看看openjdk中的athrow处理流程 { ... -
Object中notify方法
2008-10-08 10:48 2274Object.java类中notify调用的是shar ... -
Object中wait方法
2008-09-18 10:59 3653Object.wait调用 ... -
自定义类加载器loadClass
2008-09-17 15:43 1448自定义类加载器继承ClassLoader类,使用自定义类加载器 ... -
openjdk中的同步代码
2008-09-16 15:24 1802在java虚拟机中的方法同步synchroni ... -
java栈帧中的对象引用
2008-09-12 11:14 3941openjdk中的java栈帧是如何布置的呢, ... -
System.gc初步分析
2008-09-11 09:48 4289openjdk中的垃圾回收是一个庞大的课题,如何标记 ... -
openjdk的周期线程
2008-09-10 10:04 1320openjdk中周期 ... -
java线程启动代码
2008-09-09 11:24 1995上次写了个《Th ... -
InterpreterRuntime::_new阅读
2008-09-05 14:52 1364InterpreterRuntime::_new为解释 ... -
java解释器的阅读
2008-09-05 10:09 1624前面已经提到了j ... -
JavaCalls::call代码阅读
2008-09-04 10:34 2841JavaCalls::call为hotspot调用j ... -
hotspot中的OO对象分析
2008-08-30 23:03 2189hotspot中的OO对象,涉 ... -
类的加载
2008-08-20 16:00 1285类通过(*env)->FindClass,也就是 ... -
Thread的调用
2008-08-19 11:03 2141在java里面创建线程new Thread().sta ... -
openJdk学习
2008-07-15 11:05 3578学习openJdk,主要 ...
相关推荐
《深入解析ClassFileParser:库廷大学软件工程实践之精华》 在软件工程的学习与实践中,理解并解析Java字节码是至关重要的技能之一。库廷大学为了培养学生的这一能力,特别开发了一款名为ClassFileParser的工具。...
jvm 类文件解析器 这是一个(部分实现的)Rust 库和用于解析 JVM 类文件的程序。 $ cargo +nightly run classes/Dummy.class Classfile /home/chris/Code/jvm-class-file-parser/classes/Dummy.class ...
基于springboot大学生就业信息管理系统源码数据库文档.zip
基于java的驾校收支管理可视化平台的开题报告
时间序列 原木 间隔5秒钟 20241120
毕业设计&课设_基于 Vue 的电影在线预订与管理系统:后台 Java(SSM)代码,为毕业设计项目.zip
基于springboot课件通中小学教学课件共享平台源码数据库文档.zip
基于java的网上购物商城的开题报告
Delphi人脸检测与识别Demo1fdef-main.zip
基于java的咖啡在线销售系统的开题报告
基于java的自助医疗服务系统的开题报告.docx
内容概要:本文档全面介绍了Visual Basic(VB)编程语言的基础知识和高级应用。首先概述了VB的基本特性和开发环境,随后详细讲述了VB的数据类型、变量、运算符、控制结构、数组、过程与函数、变量作用域等内容。接着介绍了窗体设计、控件使用、菜单与工具栏的设计,文件操作、数据库访问等关键知识点。最后讨论了VB的学习方法、发展历史及其在桌面应用、Web应用、数据库应用、游戏开发和自动化脚本编写等领域的广泛应用前景。 适合人群:初学者和中级程序员,尤其是希望快速掌握Windows桌面应用开发的人群。 使用场景及目标:①掌握VB的基础语法和开发环境;②学会使用VB创建复杂的用户界面和功能完整的应用程序;③理解数据库操作、文件管理和网络编程等高级主题。 其他说明:Visual Basic是一种简单易学且功能强大的编程语言,尤其适合用于开发Windows桌面应用。文中不仅覆盖了基础知识,还包括了大量的实用案例和技术细节,帮助读者快速提升编程技能。
基于java的疫情期间高校防控系统开题报告.docx
基于springboot+vue社区老年人帮扶系统源码数据库文档.zip
基于java的超市商品管理系统的开题报告.docx
基于SpringBoot房屋买卖平台源码数据库文档.zip
xdu限通院23微处理器系统与应用大作业(两只老虎),适应于汇编语言keil软件,
<项目介绍> - 新闻类网站系统,基于SSM(Spring、Spring MVC、MyBatis)+MySQL开发,高分成品毕业设计,附带往届论文 - 不懂运行,下载完可以私聊问,可远程教学 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 --------
基于java的学生网上请假系统的开题报告.docx
社会经济繁荣发展的今天,电子商务得到了飞速发展,网上交易越来越彰显出其独特的优越性,在人们的日常生活中,出现了各种类型的交易网站。其中一个就是车辆易主交易网站,它是一个服务于用户买卖二手车辆的交易网站,为用户提供了平等互利、方便快捷的网上交易平台,通过这一类型的网站,用户可自由出售和购买车辆。 本课题主要根据车辆本身的特性,充分发挥互联网的特点与优势,构建一个以二手车辆为商品、基于互联网平台的车辆易主业务交易管理系统,并根据车辆易主业务交易管理系统的应用需求,进行需求分析,进而对网站系统作规划设计。采用IDEA为运行平台,以SSH为框架,运用HTML语言、JSP技术、MySql数据库、JSP与后台数据库链接等关键技术建设二手车网上交易系统,构建车辆易主交易系统的会员注册与登录,网站首页展示、用户发布商品车辆,用户求购商品车辆,分页浏览、购物系统、用户后台管理、管理员用户后台管理等功能,并使这些功能得以实现并更好为用户服务。网站整体构建完成且测试成功后,用户可以进入网站进行注册、登录,登录后,用户可以在网站上发布自己的闲置车辆或者寻找想要购买的车辆,还可以收藏车辆,管理发布和收藏的车辆,