{"id":23902910,"url":"https://github.com/mtumilowicz/java-stack","last_synced_at":"2026-02-06T23:33:26.113Z","repository":{"id":110876535,"uuid":"171274478","full_name":"mtumilowicz/java-stack","owner":"mtumilowicz","description":"Projects concerning java stack, frames.","archived":false,"fork":false,"pushed_at":"2020-11-14T17:40:33.000Z","size":382,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-23T04:29:10.217Z","etag":null,"topics":["java-stack","stack"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtumilowicz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-02-18T11:46:59.000Z","updated_at":"2021-04-21T11:20:42.000Z","dependencies_parsed_at":"2023-03-13T13:47:40.809Z","dependency_job_id":null,"html_url":"https://github.com/mtumilowicz/java-stack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mtumilowicz/java-stack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava-stack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava-stack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava-stack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava-stack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtumilowicz","download_url":"https://codeload.github.com/mtumilowicz/java-stack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtumilowicz%2Fjava-stack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29180437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T23:15:33.022Z","status":"ssl_error","status_checked_at":"2026-02-06T23:15:09.128Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java-stack","stack"],"created_at":"2025-01-04T22:51:08.040Z","updated_at":"2026-02-06T23:33:26.107Z","avatar_url":"https://github.com/mtumilowicz.png","language":null,"readme":"# java-stack\n* references\n   * https://www.amazon.com/Java-Language-Features-Modules-Expressions/dp/1484233476  \n   * [How the JVM compiles bytecode into machine code](https://www.youtube.com/watch?v=M8LiOANu3Nk)  \n\n# stack\n* references\n   * https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-2.html#jvms-2.5.2\n   * https://stackoverflow.com/questions/26741925/is-frame-in-jvm-heap-allocated-or-stack-allocated\n\n* each thread in a JVM has its own JVM stack\n* created when thread is created\n* LIFO\n* stores frames\n* holds local variables and partial results\n    * plays a part in method invocation and return\n* is never manipulated directly except to push and pop frames\n* if the computation in a thread requires a larger Java Virtual Machine stack than is permitted, the Java Virtual \nMachine throws a `StackOverflowError`\n* specification permits Java Virtual Machine stacks either to be of a fixed size or to dynamically expand\n* default stack size (HotSpot): 320k in the 32-bit VM, 1024k in the 64-bit VM\n    * https://www.oracle.com/technetwork/java/hotspotfaq-138619.html#threads_oom\n* set stack size: **-Xss**\n\n# frame\n* references\n   * https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-2.html#jvms-2.6  \n   * [2019 - Krzysztof Chruściel - Kilka wskazówek jak projektować użyteczne interfejsy](https://www.youtube.com/watch?v=-_dhEkdlsew)  \n\n* frame size: 4 bytes\n    * as a consequence: operation of adding two `ints` (2 x 4 bytes) pops 2 frames\n    * and operation of adding two `long` (2 x 8 bytes) pops 4 frames\n    * therefore `int sum = 100 + 100L;` will not compile, as `sum` is type of `long`\n    * another consequence: `boolean` (when local variable) takes whole frame - same as `int`\n        * `boolean` as a class fields - optimisation, `boolean` as a local variable - no optimisation\n* is used to store data and partial results, as well as to perform dynamic linking, return values for methods, and \ndispatch exceptions\n* new frame is created each time a method is invoked\n* a frame is destroyed when its method invocation completes, whether that completion is normal or abrupt \n(it throws an uncaught exception)\n* represents method invocation (in a given thread)\n* it is an invocation context of a method\n* for a given thread only one frame is active at any point\n* active frame is called _current frame_ , corresponding method - _current method_, class declaring method - \n_current class_ \n    * frame ceases to be current if its method invokes another method or if its method completes\n* frames are allocated from the Java Virtual Machine stack of the thread creating the frame\n* each frame has its own array of local variables, its own operand stack, and a reference \nto the run-time constant pool of the class of the current method\n\n    ![alt text](img/java-stack-frame.png)\n    ![alt text](img/frame.png)\n    * as arrays in JVM has a fixed size since creation - the sizes of the local variable array and the operand stack \n    are determined at compile-time and are supplied along with the code for the method associated with the frame\n* lifecycle: \n    * when a method is invoked, a new frame is created and becomes current when control transfers to the new method\n    * on method return, the current frame passes back the result of its method invocation, if any, to the previous frame\n    * the current frame is then discarded as the previous frame becomes the current one\n* frame created by a thread is local to that thread and cannot be referenced by any other thread\n* JVM allows to hide some frames for performance reasons\n    \n## local variables\n* references\n   * https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-2.html#jvms-2.6.1\n\n* each frame contains an array of variables known as its local variables\n* length of the local variable array of a frame is determined at compile-time and supplied in the binary \nrepresentation of a class or interface along with the code for the method associated with the frame\n* single local variable can hold a value of type `boolean`, `byte`, `char`, `short`, `int`, `float`, \n`reference`, or `returnAddress`\n* value of type `long` or type `double` occupies two consecutive local variables\n* on class method invocation, any parameters are passed in consecutive local variables starting from local variable `0`\n* on instance method invocation, local variable `0` is always used to pass a reference to the object on which the \ninstance method is being invoked and other parameters are subsequently passed in consecutive local variables \nstarting from local variable `1`\n\n## operand stack\n* references\n   * https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-2.html#jvms-2.6.2\n\n* each frame contains a LIFO stack known as its operand stack\n* example\n    ```\n    iload_0     # Push the value from local variable 0 onto the stack\n    iload_1     # Push the value from local variable 1 onto the stack\n    iadd        # Pops those off the stack, adds them, and pushes the result\n    ```\n    the `iadd` instruction adds two `int` values together - it requires that the `int` values to be \n    added be the top two values of the operand stack, pushed there by previous instructions. \n    1. both of the `int` values are popped from the operand stack. \n    1. they are added\n    1. their sum is pushed back onto the operand stack\n* maximum depth of the operand stack of a frame is determined at compile-time and is supplied along \nwith the code for the method associated with the frame\n* operand stack is empty when the frame that contains it is created\n* JVM instructions\n    * to load constants or values from local variables or fields onto the operand stack\n    * to take operands from the operand stack, operate on them, and push the result back onto the operand stack\n* the operand stack is also used to prepare parameters to be passed to methods and to receive method results\n* an operand stack has an associated depth, where a value of type `long` or `double` contributes two units to the depth \nand a value of any other type contributes one unit\n\n## run-time constant pool\n* references\n   * https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-2.html#jvms-2.5.5\n   * https://stackoverflow.com/questions/10209952/what-is-the-purpose-of-the-java-constant-pool\n\n![alt text](img/frame_construction.png)\n* example\n    ```\n    System.out.println(\"Hello, world!\");\n    ```\n    produces bytecode\n    ```\n    0:   getstatic       #2; //Field java/lang/System.out:Ljava/io/PrintStream;              \n    3:   ldc     #3; //String Hello, world!                                                  \n    5:   invokevirtual   #4; //Method java/io/PrintStream.println:(Ljava/lang/String;)V\n    ```\n    `#2`, `#3`, `#4` - references to the constant pool (reference to field, reference to String, reference to method)\n* contains several kinds of constants: numeric literals known at compile-time to method and field references that \nmust be resolved at run-time\n* each run-time constant pool is allocated from the Java Virtual Machine's method area\n* the run-time constant pool for a class or interface is constructed when the class or interface is created\nby the Java Virtual Machine\n\n# projects\n* https://github.com/mtumilowicz/java8-stack-stackwalking\n* https://github.com/mtumilowicz/java9-stack-stackwalking\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fjava-stack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtumilowicz%2Fjava-stack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtumilowicz%2Fjava-stack/lists"}