前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JVM2调用函数续

JVM2调用函数续

作者头像
江湖评谈
发布2023-02-12 15:20:25
1230
发布2023-02-12 15:20:25
举报
文章被收录于专栏:天下风云天下风云

前言 再来理解下JVM调用java函数

概括

代码语言:javascript
复制
generate_all函数里面调用了method_entry宏,这个宏的定义如下:

#define method_entry(kind)
{ 
   CodeletMark cm(_masm, "method entry point (kind = " #kind ")");
   Interpreter::_entry_table[Interpreter::kind] = generate_method_entry(Interpreter::kind);
}

宏定义里面调用了generate_method_entry函数。
后者对函数进行编译,如果有,则直接从talbe表里取出来。如果没有则调用generate_normal_entry编译函数,返回函数头的地址entry_point

entry_point = Interpreter::entry_for_kind(synchronized ? Interpreter::zerolocals_synchronized : Interpreter::zerolocals);
if (entry_point == NULL) {
entry_point = generate_normal_entry(synchronized);
}

entry_for_kind原型如下://直接从 _entry_table里面取函数头
static address entry_for_kind(MethodKind k) 
{ assert(0 <= k && k < number_of_method_entries, "illegal kind");
return _entry_table[k]; }

generate_normal_entry和generate_call_entry一样都是编译函数。不同的是generate_normal_entry返回的是一个桩(stub),这个桩是个帧栈布局好的函数头地址,里面包含了entry_point的调用。参照上面的宏定义会存储到_entry_table这个表里面。后面按照kind去取函数的sub桩地址
代码语言:javascript
复制
_call_stub_entry

StubRoutines::_call_stub_entry = generate_call_stub(StubRoutines::_call_stub_return_address)

当call_stub调用的时候,会被替换成_call_stub_entry函数。后者排列好了寄存器和栈的执行顺序,在它里面调用了entry_point。

结尾:

作者:江湖评谈

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2023-01-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 江湖评谈 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档