简体   繁体   English

Java堆空间和RAM

[英]Java Heap Space and the RAM

I have a question that bothered me after reading an article on analyzing thread dumps. 在阅读有关分析线程转储的文章后,我有一个困扰我的问题。 There was one paragraph which mentioned that the logical maximum heap size in a 32-Bit JVM is 4GB. 有一段提到32位JVM中的逻辑最大堆大小是4GB。

This link states that the maximum heap size on a 32-bit Windows machine will be around 1.4 - 1.6 GB. 链接指出32位Windows计算机上的最大堆大小约为1.4 - 1.6 GB。

My question is, say if you have RAM of say around 8GB, does this mean i can only utilize 1.4-1.6 GB of it if i were to you a 32-bit JVM? 我的问题是,如果你有大约8GB的RAM,这是否意味着我只能使用1.4-1.6 GB,如果我是你的32位JVM? And what will be the maximum size allowed for a 64bit JVM? 那么64位JVM允许的最大大小是多少?

Appreciate your help regarding this as i am confused on the same. 感谢你对此的帮助,因为我对此感到困惑。

specifically on windows, the reason is a combination of the implementation of hotspot (the sun/oracle JVM) and windows dlls. 特别是在Windows上,原因是热点(sun / oracle JVM)和windows dll的实现的组合。

32-bit code has access to a 4GB virtual address space (there are extensions that allow more but i wont be going into those). 32位代码可以访问4GB的虚拟地址空间(有扩展允许更多,但我不会进入那些)。

on 32-bit windows the upper 2GB of this virtual address space are reserved for operating sysem use (some versions of the OS accept the /3GB flag as a boot parameter to allow for 3GB of user-accessible space). 在32位窗口上,此虚拟地址空间的高2GB保留用于操作系统使用(某些版本的OS接受/ 3GB标志作为启动参数以允许3GB的用户可访问空间)。

also, any libraries (*.dlls) you use are mapped into parts of this address space. 此外,您使用的任何库(* .dll)都映射到此地址空间的一部分。 by default the windows base *.dll files are loaded at the ~1.6 GB mark (differs slightly by OS version and patch level) 默认情况下,windows base * .dll文件加载到~1.6 GB标记(OS版本和补丁级别稍有不同)

on top of all this, the hotspot JVM only supports allocating a single, continuous, chunk of memory for use as heap space. 除此之外,热点JVM仅支持分配单个连续的内存块以用作堆空间。

so, if you try and picture this in your head, you'll see that you have a free area of ~2GB with a "wall" of windows *.dlls loaded at ~1.6GB. 所以,如果你试着想象一下这个,你会看到你有一个约2GB的自由区域,有一个“墙”的窗口* .dll加载到~1.6GB。 this is the logic behind that figure. 这是这个数字背后的逻辑。 it also means that even if you provide the /3GB flag the sun/oracle JVM will not be able to make use of it. 它还意味着即使你提供/ 3GB标志,sun / oracle JVM也无法使用它。 some other VMs are better at handling a fragmented heap - like the jrockit VM 其他一些虚拟机更擅长处理碎片堆 - 比如jrockit VM

you could also try rebasing windows dlls so that they load into higher memory addresses and squeeze some more usable heap space, but the process is fragile. 您也可以尝试重新设置Windows dll,以便它们加载到更高的内存地址并挤出更多可用的堆空间,但这个过程很脆弱。

also note that its very possible that drivers/applications loaded on a particular machines (like anti virus software) will inject their own *.dlls into a java process, and those dlls can be loaded at ever lower memory addresses, further shrinking your usable heap space. 另请注意,特定计算机上加载的驱动程序/应用程序(如防病毒软件)很可能会将自己的* .dll注入到java进程中,这些dll可以在更低的内存地址加载,从而进一步缩小可用堆空间。

on 64bit versions of windows the addressable limit is 8-128TB and the physical limit stands at 64TB right now 在64位版本的Windows上,可寻址限制为8-128TB ,物理限制现在为64TB

jvm and also os use paging memory managment system that obtain 4G virtual memory for us in jvm和os也使用分页内存管理系统为我们获取4G虚拟内存

32bit os systems 32位操作系统

but if you have 8G ram you must use 64 bit version of os for maximum performance of os 但是如果你有8G内存,你必须使用64位版本的操作系统来获得最高性能

It depends on your operating system, 32 bit versions of MacOS X and Linux have some ability to access more than 4GB in the kernel but still limit processes to 4GB. 这取决于您的操作系统,32位版本的MacOS X和Linux有一定的能力在内核中访问超过4GB,但仍然将进程限制为4GB。 Other operating systems may restrict process memory further since they need part of the 4GB for themselves. 其他操作系统可能会进一步限制进程内存,因为它们本身需要4GB的一部分。 In general you want to avoid swapping out your JVM to VM so you need to know how much free memory you system has. 通常,您希望避免将JVM交换到VM,因此您需要知道系统有多少可用内存。

2^32 = 4GB is the max total memory you can address with 32 bits. 2 ^ 32 = 4GB是32位可以寻址的最大总内存。

The JVM only gets 1.4-1.6GB on 32 bit machines because you still have to accomodate the operating system. JVM在32位计算机上只能获得1.4-1.6GB,因为您仍然需要适应操作系统。

2^64 = (2^32)^2 is the max total memory you can address with 64 bits. 2 ^ 64 =(2 ^ 32)^ 2是您可以使用64位寻址的最大总内存。 As you can see, it's a much larger number. 正如你所看到的,这是一个更大的数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM