Understanding Java Hotspot Function Prologue

Viewed 79

I'm having trouble understanding the function prologue that Java hotpot generates. Consider this dummy example:

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");
    }
}

The generated code for getLen, by C2, is:

[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

Question:

  1. What is the purpose of mov %eax,-0x14000(%rsp)?
  2. The sample code has no synchronization; so what is sub $0x10,%rsp ;*synchronization entry?
1 Answers
Related