博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jvm Classload method介绍
阅读量:6985 次
发布时间:2019-06-27

本文共 2424 字,大约阅读时间需要 8 分钟。

1,jvm Classload默认几个重要方法介绍
findClass:Finds and loads the class with the specified name from the URL search path.找到class文件并把字节码载入到内存中,假设自己定义的载入器仅覆盖了findClass,而未覆盖loadClass(即载入规则一样,但载入路径不同);则调用getClass().getClassLoader()返回的仍然是AppClassLoader!由于真正load类的,还是AppClassLoader
defineClass:Converts an array of bytes into an instance of class. 创建类对象,将字节流解析成JVM可以识别的Class对象
loadClass:Loads the class with the specified binary name.自己定义的载入器能够覆盖该方法loadClass(),以便定义不同的载入机制.比如Servlet中的WebappClassLoader覆盖了该方法,在WEB-INFO/classes文件夹下查找类文件;在载入时,假设成功,则缓存到ResourceEntry对象。——不同的载入机制。
2,其他一些方法
resolveClass:载入完字节码后,会依据须要进行验证、解析
defineClass:字节流解析成JVM可以识别的Class对象。不可覆盖
findLoadedClass:假设类已经载入过,则直接返回 Returns the class with the given name binary name if this loader has been recorded by the Java virtual machine as an initiating
3,调用规则:loadClass-->findClass-->defineClass--->resolveClass(可选)
4,JVM默认不能热部署类,由于载入类时会去调用findLoadedClass(),假设类已被载入,就不会再次载入。JVM推断类是否被载入有两个条件:完整类名是否一样、ClassLoader是否是同一个。
loadClass方法代码:
   
protected Class
loadClass(String name, boolean resolve) throws ClassNotFoundException { synchronized (getClassLoadingLock(name)) { // First, check if the class has already been loaded Class c = findLoadedClass(name); if (c == null) { long t0 = System.nanoTime(); try { if (parent != null) { c = parent.loadClass(name, false); } else { c = findBootstrapClassOrNull(name); } } catch (ClassNotFoundException e) { // ClassNotFoundException thrown if class not found // from the non-null parent class loader } if (c == null) { // If still not found, then invoke findClass in order // to find the class. long t1 = System.nanoTime(); c = findClass(name); // this is the defining class loader; record the stats sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0); sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1); sun.misc.PerfCounter.getFindClasses().increment(); } } if (resolve) { resolveClass(c); } return c; } }

转载地址:http://opmpl.baihongyu.com/

你可能感兴趣的文章
面试总结,坚定自己的想法
查看>>
数据库隐式类型转换
查看>>
解决WCF调用多次之后没有响应的问题 转
查看>>
【BZOJ2318】【spoj4060】game with probability Problem 概率DP
查看>>
空格&nbsp在不同浏览器中显示距离不一致问题解决方法
查看>>
Nancy 学习-身份认证(Basic Authentication) 继续跨平台
查看>>
分享5个主流的HTML5开发工具
查看>>
基于Ionic2的开源项目
查看>>
QEMU-KVM中的多线程压缩迁移技术
查看>>
Android下创建一个SQLite数据库
查看>>
软件产品与代码版本管理指南
查看>>
分析Linux内核创建一个新进程的过程【转】
查看>>
sql如何分组选择显示最新的一条数据
查看>>
周锦民:腾讯在线教育视频互动直播间技术实践
查看>>
.NET HttpPost 上传文件图片到服务器
查看>>
[perl] 正则表达式实现多模式匹配
查看>>
RCP之病人信息系统开发总结(1):数据库设计
查看>>
js数组操作,拼写好像,没看清楚就容易出错的。
查看>>
C# winform搜索提示的一些想法
查看>>
table的thead/tbody/tfoot/tr/th/td
查看>>