What does the machine memory look like when you see a picture like this:
To fully answer this question, you need to take the systems
classes.
But it is useful to have an idea of the memory, even if the details
are not exactly correct.
Method calls (Stack) |
Objects (Heap) |
Address |
Value |
Description |
0xbeef0098 | ?? | @1.overhead |
0xbeef0090 | 0xface0000 | @1.args |
0xbeef0088 | 0xface0010 | @1.list |
0xbeef0080 | ?? | @2.overhead |
0xbeef0078 | 0xface0010 | @2.a |
0xbeef0070 | 3 | @2.i |
0xbeef0068 | 2 | @2.result |
|
Address |
Value |
Description |
0xface0038 | 5.0 | Array.data[3] |
0xface0030 | 5.0 | Array.data[2] |
0xface0028 | 11.0 | Array.data[1] |
0xface0020 | 5.0 | Array.data[0] |
0xface0018 | 4 | Array.length |
0xface0010 | ?? | Array.overhead |
0xface0008 | 0 | Array.length |
0xface0000 | ?? | Array.overhead |
|
Above, I show two parts of memory. On the left is storage for
method calls (commonly called the stack), on the right is
storage for objects (commonly called the heap). Arrays are
objects in java. Machine addresses are shown as hexadecimal numbers
beginning with the prefix 0x
.
Each entry includes some overhead.
-
For methods, the overhead includes the return address.
This tells the machine what code should be executed when the
method returns. If you are interested, you can read
more.
-
For objects, the overhead indicates the runtime type of the
object. This is used to implement runtime type queries, such as
the
getClass()
method. If you are interested, you can
read
more.