<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Aptos;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Aptos",sans-serif;
mso-ligatures:standardcontextual;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#467886;
text-decoration:underline;}
span.EmailStyle22
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif">Hi, Kenneth,
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif">> From my C/C++ days I learned that the actual amount of RAM used was related to the word size of a CPU
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif">> so that when a byte is read you are really reading a word. This meant to me that if I had 10 variables of
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif">> type byte, not in an array, it would consume 80 bytes of RAM.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif">I’m afraid you are confused about that, too. There have been computers that would do that, but they have been obsolete for decades. I’m pretty sure Java has never run on a
“word addressed” machine. <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif">On any remotely modern processor architecture, ten byte-sized variables will only occupy ten bytes of space. The way they get fetched into the processor is somewhat complicated
but ensures that several of them will normally be fetched in one read. <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Calibri",sans-serif;color:black;mso-fareast-language:EN-GB">With best regards,<br>
<br>
-- <br>
John Dallman (he/him) <br>
<br>
Siemens Industry Software Limited<br>
DI SW PLM PE OT PC PDE<br>
Kett House, Station Road, <br>
Cambridge CB1 2JH, United Kingdom<br>
<a href="mailto:john.dallman@siemens.com"><span style="color:blue">mailto:john.dallman@siemens.com</span></a><br>
<a href="http://www.sw.siemens.com/" target="_blank"><span style="color:blue">www.sw.siemens.com</span></a></span><span style="font-size:10.0pt;font-family:"Calibri",sans-serif;color:black;mso-ligatures:none;mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:10.0pt;font-family:"Calibri",sans-serif;color:black;mso-ligatures:none;mso-fareast-language:EN-GB"><img border="0" width="202" height="80" style="width:2.1041in;height:.8333in" id="Picture_x0020_1" src="cid:image001.gif@01DC088C.AD1DFEA0" alt="Logo"></span><span style="font-size:10.0pt;font-family:"Calibri",sans-serif;color:black;mso-fareast-language:EN-GB"><br>
</span><span style="font-size:8.0pt;font-family:"Calibri",sans-serif;color:black;mso-fareast-language:EN-GB">Siemens Industry Software Limited registered office: Pinehurst 2, Pinehurst Road, Farnborough, Hampshire, GU14 7BF, United Kingdom. Registered in England
and Wales No. 03476850.<br>
<br>
This communication contains information which is confidential and may also be privileged. It is for the exclusive use of the addressee. If you are not the addressee please note that any distribution, reproduction, copying, publication or use of this communication
or the information is prohibited. If you have received this communication in error, please contact us immediately and also delete the communication from your computer.</span><span style="font-size:10.0pt;font-family:"Calibri",sans-serif;color:black;mso-fareast-language:EN-GB">
<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-family:"Calibri",sans-serif;mso-ligatures:none;mso-fareast-language:EN-GB">From:</span></b><span lang="EN-US" style="font-family:"Calibri",sans-serif;mso-ligatures:none;mso-fareast-language:EN-GB"> discuss
<discuss-retn@openjdk.org> <b>On Behalf Of </b>Shipilev, Aleksey<br>
<b>Sent:</b> 08 August 2025 17:35<br>
<b>To:</b> Kenneth Fogel <kfogel@dawsoncollege.qc.ca>; discuss@openjdk.org<br>
<b>Subject:</b> Re: Memory Usage in Java<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">Hi Kenneth,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The answers to most of these questions are, “No, this is not how it works in any modern JVM”.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I would really recommend playing with JOL, especially look through its Samples:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="https://github.com/openjdk/jol">https://github.com/openjdk/jol</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="https://github.com/openjdk/jol/tree/master/jol-samples/src/main/java/org/openjdk/jol/samples">https://github.com/openjdk/jol/tree/master/jol-samples/src/main/java/org/openjdk/jol/samples</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">And maybe read this for even more discussion:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><a href="https://shipilev.net/jvm/objects-inside-out/">https://shipilev.net/jvm/objects-inside-out/</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">-Aleksey<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-CA" style="font-size:12.0pt;font-family:"Calibri",sans-serif;color:black;mso-ligatures:none;mso-fareast-language:EN-GB">From:
</span></b><span lang="EN-CA" style="font-size:12.0pt;font-family:"Calibri",sans-serif;color:black;mso-ligatures:none;mso-fareast-language:EN-GB">discuss <<a href="mailto:discuss-retn@openjdk.org">discuss-retn@openjdk.org</a>> on behalf of Kenneth Fogel <<a href="mailto:kfogel@dawsoncollege.qc.ca">kfogel@dawsoncollege.qc.ca</a>><br>
<b>Date: </b>Friday, 8. August 2025 at 18:11<br>
<b>To: </b>"<a href="mailto:discuss@openjdk.org">discuss@openjdk.org</a>" <<a href="mailto:discuss@openjdk.org">discuss@openjdk.org</a>><br>
<b>Subject: </b>[EXTERNAL] Memory Usage in Java<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span lang="EN-CA" style="font-size:12.0pt;mso-ligatures:none;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
</div>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" style="border-collapse:collapse">
<tbody>
<tr style="height:15.25pt">
<td width="1123" valign="top" style="width:842.35pt;border:solid #ED7D31 1.5pt;padding:0cm 5.4pt 0cm 5.4pt;height:15.25pt">
<p><strong><span style="font-family:"Aptos",sans-serif;color:black;background:#FFFF99">CAUTION</span></strong><span style="color:black;background:#FFFF99">: This email originated from outside of the organization. Do not click links or open attachments unless
you can confirm the sender and know the content is safe.</span><o:p></o:p></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span lang="EN-CA" style="font-size:12.0pt;mso-ligatures:none;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span lang="EN-US">Please let me know where I might ask this question or find the answer if this is not the right place.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">In a book I am working on I am writing about how Java deals with memory allocation for the primitive types on a 64 bit CPU. I know the size of primitive variable types such as byte is 1, int is 4, etc. and that the size
is related to the range of allowable values. From my C/C++ days I learned that the actual amount of RAM used was related to the word size of a CPU so that when a byte is read you are really reading a word. This meant to me that if I had 10 variables of type
byte, not in an array, it would consume 80 bytes of RAM. From my reading it appears to be the same in Java except for arrays. Is this accurate? For example, an int is 4 bytes but when Java runs on a 64 bit CPU is it really reading and writing 8 bytes? If it
is, can we say that the 4 bytes of padding is RAM dead space that cannot be used for anything else?
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thank you for your time,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Ken Fogel<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
<p class="MsoNormal"><span style="font-size:12.0pt;mso-ligatures:none;mso-fareast-language:EN-GB"><br>
<br>
<br>
Amazon Web Services Development Center Germany GmbH<br>
Tamara-Danz-Str. 13<br>
10243 Berlin<br>
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss<br>
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B<br>
Sitz: Berlin<br>
Ust-ID: DE 365 538 597<o:p></o:p></span></p>
</div>
</body>
</html>