gpt4 book ai didi

java - 理解Java热点函数序言

转载 作者:搜寻专家 更新时间:2023-11-01 03:32:23 25 4
gpt4 key购买 nike

我无法理解 Java hotpot 生成的函数序言。考虑这个虚拟示例:

public static int getLen(String s) {
return s.length();
}

public static void main(String[] args) {
for(int i = 0; i < 1_000_000; i++) {
getLen("abcd");
}
}

C2 为 getLen 生成的代码是:

[Entry Point]
[Verified Entry Point]
[Constants]
# {method} {0x00007fbed3fc2318} 'getLen' '(Ljava/lang/String;)I' in 'examples/Main'
# parm0: rsi:rsi = 'java/lang/String'
# [sp+0x20] (sp of caller)
0x00007fbefd11a960: mov %eax,-0x14000(%rsp)
0x00007fbefd11a967: push %rbp
0x00007fbefd11a968: sub $0x10,%rsp ;*synchronization entry
; - examples.Main::getLen@-1 (line 6)

0x00007fbefd11a96c: mov 0xc(%rsi),%r11d ;*getfield value
; - java.lang.String::length@1 (line 623)
; - examples.Main::getLen@1 (line 6)
; implicit exception: dispatches to 0x00007fbefd11a981
0x00007fbefd11a970: mov 0xc(%r12,%r11,8),%eax ;*arraylength
; - java.lang.String::length@4 (line 623)
; - examples.Main::getLen@1 (line 6)
; implicit exception: dispatches to 0x00007fbefd11a991

问题:

  1. mov %eax,-0x14000(%rsp) 的目的是什么?
  2. 示例代码没有同步;那么什么是 sub $0x10,%rsp ;*synchronization 条目?

最佳答案

14000 是一个神奇的数字,搜索它会发现相关问题:Why do hotspot generated compiled methods stash eax high up the stack before execution? - 也有一些带有无效链接的答案,您可以尝试在 archive.org 上找到它(我没有尝试过)。 push bp+decrement sp 对我来说看起来像是一些标准堆栈框架设置的一部分(https://en.m.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Frames),尽管缺少 store-sp-into-bp 部分。

关于java - 理解Java热点函数序言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46554028/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com