Translation and execution are different stages
A compiler transforms a program from one representation into another. Its output may be machine code, bytecode or another intermediate form. An interpreter executes a representation by processing its operations. These are not mutually exclusive product categories: one runtime can combine both techniques. Java source is commonly translated into class files, while a JVM implementation may interpret bytecode and compile frequently executed portions into native code. Distinguish the language’s required behavior from the execution strategy selected by a particular implementation. The presence of an interpreter does not imply that no compilation ever occurs.
What the runtime takes responsibility for
A runtime provides services needed while a program executes, including calls, exceptions, checks and memory management. In the JVM model, per-thread frames contain local variables and operand stacks, while objects belong to a logical heap. Specification-level regions do not require one fixed physical layout. Optimizations may even eliminate an allocation when its observable behavior can be preserved. Reason about lifetimes and reachability using the runtime model, not only a source-code line. Native resources and references held by libraries can remain relevant even after an application variable seems to have gone out of scope.
Examine optimization assumptions through JIT
A frequently called method may receive the same type repeatedly, allowing an implementation to optimize around that observation. If a different type appears later, guards or deoptimization may be needed to preserve the specified behavior. This helps explain why a first invocation can differ from a warmed-up run. Benchmarks must account for warm-up, whether the intended work survives optimization and how its result is consumed. Not every JVM uses the same compiler or thresholds, however. Report the implementation, version and configuration when making a concrete performance claim rather than treating one observed strategy as a universal language rule.
Garbage collection is not every kind of cleanup
Garbage collection reclaims memory the system can establish is no longer usable by the program. A large reachable cache can remain retained even if it is no longer useful, so automatic collection does not eliminate memory-retention bugs. Files and sockets may require an explicit lifecycle separate from heap reclamation. Relying on an unspecified collection time can exhaust an external resource limit before cleanup occurs. Collectors trade among pause time, throughput and additional memory, among other constraints. Automatic reclamation simplifies ownership responsibilities but neither supplies deterministic cleanup of every resource nor makes memory management cost-free.
Follow representation changes for one expression
Trace 2+x*3 through tokens, a syntax tree, and executable work. Even without written parentheses, the multiplication is a subtree on the right of addition. A tree interpreter follows that structure and reads x from an environment. Another implementation might translate the same tree into stack-machine instructions. Identify the input representation, output representation, and component executing each stage.
The companion tiny language covers integers, names, arithmetic, and parentheses, not a complete class or function system. It defines evaluation order and division failure, and its constant-folding checks preserve those behaviors. Compilation does not authorize changing meaning, and interpretation does not forbid optimization. State each transformation as a contract about representation and preserved behavior.
| Stage | Representation | What to check |
|---|---|---|
| Lexing/parsing | Text → tokens → tree | Grammar and complete consumption |
| Evaluation/code generation | Tree → behavior or another instruction form | Results, failures, effects |
| Allocation | Runtime storage | Allocated bytes in the stated interval |
| GC | Roots and reference graph | Reachable live set |
| FFI | Foreign types and storage | Widths, lengths, borrows, release |
Put construction, allocation, and retention on separate timelines
A source loop may construct Pair five hundred thousand times, but source construction count, actual allocated bytes, and retained live bytes are not interchangeable. The allocation experiment compares a local calculation with a method publishing references outside itself. It measures a current-thread allocation-counter difference, consumes the result, and states warmup and measurement boundaries.
Zero bytes in the local case do not mean that every object was moved onto a stack. Separate object storage may have been eliminated. Meanwhile, the GC model computes a set reachable from roots; it is not an allocation measurement. Distinguish heavy short-lived allocation from gradual cache retention. Start a memory explanation by naming the question and metric rather than treating every increasing number as the same phenomenon.
Ownership and collection answer different questions
The ownership guide follows Rust String moves, borrows, and final use through successful and rejected programs. The GC guide follows roots, cycles, and cache retention. Both concern memory responsibility, but they are not simply an identical check performed at different times. Keep the language and rule set visible when comparing them.
Both also require attention to external resources. Show the interval between acquiring and returning a file on normal and exceptional paths. The time a value becomes unreachable need not be the time its descriptor closes. Express a required release boundary through scoped mechanisms or an explicit completion protocol. A comparison of memory-management strategies cannot justify omitting resource lifecycle design. The companion file-descriptor experiment makes that distinction observable without claiming a full process sandbox.
Continue into native boundaries and runtime evidence
At an FFI, verify matching types and lengths, storage ownership, and the valid borrowing interval. The Python/C example specifies fixed-width elements, a size_t count, and a 64-bit output. C borrows only during the call. A collector does not automatically define an external borrowing contract, and errors need their own transfer rule too.
The JIT guide follows feedback, assumptions, guards, and reconstructed continuation state. It also explains why a slowdown alone does not prove deoptimization. Record version, flags, inputs, raw diagnostics, and counter meanings when investigating a runtime. Keep explanatory diagrams separate from measurements. Choose the next lesson by the question: representation transformation, lifetime, reachability, runtime optimization, or a foreign-language boundary.