[JLS,12,Chapter2] Java Run-Time Data Areas-Java Virtual Machine Stacks

2258 ワード

Java、Rust技術交流グループ: 783303214   
           記事について:Thread stack sizeの誤り
           本文の中で:スタックの大きさは固定的で、1つの文は妥当でない言い方で、JLSのスタックのデータの構造の定義によって :JVM仮想マシンスタックは自動的に拡張され、拡張を試みるために必要なメモリが拡張操作をサポートできないか、拡張後のスタックサイズが新しいスレッドをサポートするのに十分ではなく、OOM異常を放出する
原文:
2.5.2. Java Virtual Machine Stacks
         Each Java Virtual Machine thread has a private Java Virtual Machine stack, created at the same time as the thread. A Java Virtual Machine stack stores frames (§2.6). A Java Virtual Machine stack is analogous to the stack of a conventional language such as C: it holds local variables and partial results, and plays a part in method invocation and return. Because the Java Virtual Machine stack is never manipulated directly except to push and pop frames, frames may be heap allocated. The memory for a Java Virtual Machine stack does not need to be contiguous.
          In the First Edition of The Java® Virtual Machine Specification, the Java Virtual Machine stack was known as the Java stack.
          This specification permits Java Virtual Machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation. If the Java Virtual Machine stacks are of a fixed size, the size of each Java Virtual Machine stack may be chosen independently when that stack is created.
          A Java Virtual Machine implementation may provide the programmer or the user control over the initial size of Java Virtual Machine stacks, as well as, in the case of dynamically expanding or contracting Java Virtual Machine stacks, control over the maximum and minimum sizes.
         The following exceptional conditions are associated with Java Virtual Machine stacks:
  • If the computation in a thread requires a larger Java Virtual Machine stack than is permitted, the Java Virtual Machine throws a  StackOverflowError .
  • If Java Virtual Machine stacks can be dynamically expanded, and expansion is attempted but insufficient memory can be made available to effect the expansion, or if insufficient memory can be made available to create the initial Java Virtual Machine stack for a new thread, the Java Virtual Machine throws an  OutOfMemoryError .