jvm interpreter

jvm interpreter

解释器的初始化
JNI_CreateJavaVM
|
|--> Threads::create_vm
|
|--> init_globals
|
|-->interpreter_init
|
|-->AbstractInterpreter::initialize
|
|-->TemplateTable::initialize
一个解释器就是不断地读取当前的指令,然后是一个大的switch语句。
传统解释器技术,是指对于java的bytecode,仍是其处理的基本单位。但是对于每个bytecode
的实现,则是采用的汇编技术。
void TemplateTable::iconst(int value) {
transition(vtos, itos);
if (value == 0) {
__ xorl(eax, eax);
} else {
__ movl(eax, value);
}
}

TemplateTable是解释器对这种技术的一个称呼。每一个java bytecode对应一个Template,
所有的Template构成TemplateTable。
上面的代码就是iconst_<i>的实现。

有几点要注意
一、方法TemplateTable::iconst的实现和CPU相关。上面的代码实际上是intel CPU下的代码,
其位于:\hotspot\src\cpu\i486\vm\templateTable_i486.cpp

二、__ xorl(eax, eax); 中的 __ 是什么?
#define __ _masm->
所以 __ xorl(eax, eax); <==> _masm->xorl(eax, eax);
而_masm的定义是 static InterpreterMacroAssembler* _masm; (templateTable.hpp line92)

三、InterpreterMacroAssembler的实现又是和CPU相关的。
InterpreterMacroAssembler的父类是:Assembler,它的实现也是和CPU相关的。
下面是xorl的一个实现
void Assembler::xorl(Register dst, Register src) {
emit_arith(0x33, 0xC0, dst, src);
}
emit_arith的调用了emit_byte方法,而emit_byte的核心代码是:
inline void AbstractAssembler::emit_byte(int x) {
// ...
*(unsigned char*)_code_pos = (unsigned char)x;
_code_pos += sizeof(unsigned char);
// ...
}
其中的_code_pos是一个内存缓冲区。
0x33 0xC0对应的Intel汇编语言正是:xor eax, eax
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值