[讨论] 有关 generate_call_stub stack 布局问题
huangriyan
2014-09-09
在 call_helper 中, call_stub 调用如下
StubRoutines::call_stub()( (address)&link, // (intptr_t*)&(result->_value), // see NOTE above (compiler problem) result_val_address, // see NOTE above (compiler problem) result_type, method(), entry_point, args->parameters(), args->size_of_parameters(), CHECK ); 但跳转到 generate_call_stub(X86-32为例) 后,其栈帧布局改为如下: [ return_from_Java ] <--- rsp // [ argument word n ] // ... // -N [ argument word 1 ] // -7 [ Possible padding for stack alignment ] // -6 [ Possible padding for stack alignment ] // -5 [ Possible padding for stack alignment ] // -4 [ mxcsr save ] <--- rsp_after_call // -3 [ saved rbx, ] // -2 [ saved rsi ] // -1 [ saved rdi ] // 0 [ saved rbp, ] <--- rbp, // 1 [ return address ] // 2 [ ptr. to call wrapper ] // 3 [ result ] // 4 [ result_type ] // 5 [ method ] // 6 [ entry_point ] // 7 [ parameters ] // 8 [ parameter_size ] // 9 [ thread ] address generate_call_stub 现请教一下:其栈中多出的部分: [ return_from_Java ] <--- rsp // [ argument word n ] // ... // -N [ argument word 1 ] // -7 [ Possible padding for stack alignment ] // -6 [ Possible padding for stack alignment ] // -5 [ Possible padding for stack alignment ] // -4 [ mxcsr save ] <--- rsp_after_call // -3 [ saved rbx, ] // -2 [ saved rsi ] // -1 [ saved rdi ] // 0 [ saved rbp, ] <--- rbp, 是什么时候、在什么地方压栈的? |
|
rink1969
2014-09-10
StubRoutines::call_stub()调用的不是generate_call_stub,而是generate_call_stub 生成的一段汇编
参见 http://hllvm.group.iteye.com/group/topic/41107 里面R大的回答 你说的多出的这部分内容就是在这段汇编里面压的 |
|
huangriyan
2014-09-10
我也知道是这段代码是生成汇编的(我之前的表述有误),其函数入口为
address start = __ pc(); 但就是无法找到其那段汇编压入栈的,因为按代码 address start = __ pc(); // stub code parameters / addresses assert(frame::entry_frame_call_wrapper_offset == 2, "adjust this code"); bool sse_save = false; const Address rsp_after_call(rbp, -4 * wordSize); // same as in generate_catch_exception()! const int locals_count_in_bytes (4*wordSize); const Address mxcsr_save (rbp, -4 * wordSize); const Address saved_rbx (rbp, -3 * wordSize); const Address saved_rsi (rbp, -2 * wordSize); const Address saved_rdi (rbp, -1 * wordSize); const Address result (rbp, 3 * wordSize); const Address result_type (rbp, 4 * wordSize); const Address method (rbp, 5 * wordSize); const Address entry_point (rbp, 6 * wordSize); const Address parameters (rbp, 7 * wordSize); const Address parameter_size(rbp, 8 * wordSize); const Address thread (rbp, 9 * wordSize); 入口程序 address start = __ pc(); 到 const Address mxcsr_save (rbp, -4 * wordSize); 并没有压栈操作,所以不知是在哪里压栈的 |
|
ZHH2009
2014-09-10
|
|
rink1969
2014-09-10
huangriyan 写道 我也知道是这段代码是生成汇编的(我之前的表述有误),其函数入口为
address start = __ pc(); 但就是无法找到其那段汇编压入栈的,因为按代码 address start = __ pc(); // stub code parameters / addresses assert(frame::entry_frame_call_wrapper_offset == 2, "adjust this code"); bool sse_save = false; const Address rsp_after_call(rbp, -4 * wordSize); // same as in generate_catch_exception()! const int locals_count_in_bytes (4*wordSize); const Address mxcsr_save (rbp, -4 * wordSize); const Address saved_rbx (rbp, -3 * wordSize); const Address saved_rsi (rbp, -2 * wordSize); const Address saved_rdi (rbp, -1 * wordSize); const Address result (rbp, 3 * wordSize); const Address result_type (rbp, 4 * wordSize); const Address method (rbp, 5 * wordSize); const Address entry_point (rbp, 6 * wordSize); const Address parameters (rbp, 7 * wordSize); const Address parameter_size(rbp, 8 * wordSize); const Address thread (rbp, 9 * wordSize); 入口程序 address start = __ pc(); 到 const Address mxcsr_save (rbp, -4 * wordSize); 并没有压栈操作,所以不知是在哪里压栈的 你贴的这段只是在定义变量 下面才是真正的代码 // stub code __ enter(); __ movptr(rcx, parameter_size); // parameter counter __ shlptr(rcx, Interpreter::logStackElementSize); // convert parameter count to bytes __ addptr(rcx, locals_count_in_bytes); // reserve space for register saves __ subptr(rsp, rcx); __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack // save rdi, rsi, & rbx, according to C calling conventions __ movptr(saved_rdi, rdi); __ movptr(saved_rsi, rsi); __ movptr(saved_rbx, rbx); |
|
huangriyan
2014-09-10
谢谢大神们,小弟明白了
现有的汇编勉勉强强应付得过来, |