2017-10-03 5 views
3

Je n'arrive pas à comprendre le prologue de la fonction que génère le poteau Java. Considérez cet exemple fictif:Présentation de la fonction Java Hotspot Prologue

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

Le code généré pour getLen, par C2, est la suivante:

[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::[email protected] (line 6) 

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

Question:

  1. Quel est le but de mov %eax,-0x14000(%rsp)?
  2. L'exemple de code n'a pas de synchronisation; Alors, quelle est l'entrée sub $0x10,%rsp ;*synchronization?

Répondre

1

Le 14000 est un nombre magique, la recherche de ce révèle question connexe: Why do hotspot generated compiled methods stash eax high up the stack before execution? - a aussi une réponse avec un lien non-travail, que vous pouvez tenter de trouver sur archive.org (je ne l'ai pas essayé). La chose push bp + decrement sp ressemble à une partie d'une configuration de cadre de pile standard pour moi (https://en.m.wikibooks.org/wiki/X86_Disassembly/Functions_and_Stack_Frames), bien que la partie store-sp-into-bp soit manquante.