java 我应该使用 32 位还是 64 位 JDK?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16369044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:46:37  来源:igfitidea点击:

Should I use 32-bit or 64-bit JDK?

java

提问by user2348638

Years ago, I tried 64-bit JDK but it was really buggy.

多年前,我尝试过 64 位 JDK,但它确实有问题。

How stable would you say it is now? Would you recommend it? Should I install 64-bit JDK + eclipse or stick to 32-bit? Also, are there any advantages of 64-bit over 32-bit other than bypassing the 4 GB memory limit?

你说它现在有多稳定?你会推荐它吗?我应该安装 64 位 JDK + eclipse 还是坚持使用 32 位?另外,除了绕过 4 GB 内存限制之外,64 位比 32 位还有什么优势吗?

采纳答案by acdcjunior

Only begin to bother with that if you want to build an application that will use a lot of memory (namely, a heap larger than 2GB).

如果您想构建一个将使用大量内存(即大于 2GB 的堆)的应用程序,则只需要开始考虑这一点。

Allow me to quote Red Hat:

请允许我引用 Red Hat:

The real advantage of the 64-bit JVM is that heap sizes much larger than 2GB can be used. Large page memory with the 64-bit JVM give further optimizations. The following graph shows the results running from 4GB heap sizes, in two gigabyte increments, up to 20GB heap.

64 位 JVM 的真正优势在于可以使用远大于 2GB 的堆大小。带有 64 位 JVM 的大页面内存提供了进一步的优化。下图显示了从 4GB 堆大小(以 2 GB 为增量)到 20GB 堆的运行结果。

That, in a pretty graph:

那,在一个漂亮的图表中:

32 bit vs 64 bit JVMs in performance

32 位与 64 位 JVM 的性能对比

See, no big difference.

看,没多大区别。

See more (more graphs, yay!) in: Java Virtual Machine Tuning

查看更多(更多图表,是的!):Java 虚拟机调优

回答by Christian Kuetbach

I think the answer can be found pretty simple.

我认为答案很简单。

Answer the question: "Do I need more than 4GB of RAM?".

回答问题:“我需要超过 4GB 的内存吗?”。

A 64 bit JVM is as stable as a 32 bit JVM. There are no differences. In fact a Java Application running in a 64 bit JVM will consume more RAM compared to a 32 bit JVM. All internal datastructures will need more RAM.

64 位 JVM 与 32 位 JVM 一样稳定。没有区别。实际上,与 32 位 JVM 相比,在 64 位 JVM 中运行的 Java 应用程序将消耗更多 RAM。所有内部数据结构都需要更多 RAM。

My eclipse is running in a 64bit JVM.

我的日食在 64 位 JVM 中运行。

回答by Chris M.

Are you going to deploy to a 32 or a 64 bit environment? If you're affinitized to an environment in production then your development environment should use the same environment type.

您打算部署到 32 位还是 64 位环境?如果您与生产环境相关联,那么您的开发环境应该使用相同的环境类型。

If you're platform agnostic, go with x64 and don't even think about it. The platform is mature and stable. It gives you tremendous room to scale up as you can just add memory and make your heaps bigger.

如果您与平台无关,请使用 x64,甚至不要考虑它。平台成熟稳定。它为您提供了巨大的扩展空间,因为您只需添加内存并使堆更大。

Nobody wants to tell a CEO, "Sorry, we chose x86 and can't scale up like we hoped. It's a month long project project to retest and replatform everything for x64."

没有人愿意告诉 CEO,“抱歉,我们选择了 x86,但无法像我们希望的那样扩展。这是一个为期一个月的项目,旨在为 x64 重新测试和重新构建所有平台。”

回答by Juned Ahsan

The only differences between 32-bit and 64-bit builds of any program are the sizes of machine words, the amount of addressable memory, and the Operating System ABI in use. With Java, the language specification means that the differences in machine word size and OS ABI should not matter at all unless you're using native code as well. (Native code must be built to be the same as the word-size of the JVM that will load it; you can't mix 32-bit and 64-bit builds in the same process without very exotic coding indeed, and you shouldn't be doing that with Java about.)

任何程序的 32 位和 64 位版本之间的唯一区别是机器字的大小、可寻址内存的数量和使用的操作系统 ABI。对于 Java,语言规范意味着机器字大小和操作系统 ABI 的差异根本无关紧要,除非您也使用本机代码。(本机代码必须构建为与加载它的 JVM 的字大小相同;如果没有非常奇特的编码,您不能在同一进程中混合 32 位和 64 位构建,并且您不应该不要用 Java 来做这件事。)

The 64-bitter uses 64-bit pointers. If you have 4GB+ RAM, and are running Java programs that keep 4GB+ of data structures in memory, the 64-bitter will accommodate that. The big fat pointers can point to any byte in a 4GB+ memory space.

64 位使用 64 位指针。如果您有 4GB+ 的 RAM,并且正在运行在内存中保留 4GB+ 数据结构的 Java 程序,那么 64 位将容纳它。大胖指针可以指向 4GB+ 内存空间中的任何字节。

But if your programs use less memory, and you run the 64-bit JVM, pointers in will still occupy 64 bits (8 bytes) each. This will cause data structures to be bigger, which will eat up memory unnecessarily.

但是,如果您的程序使用较少的内存,并且您运行 64 位 JVM,则每个指针仍将占用 64 位(8 字节)。这将导致数据结构更大,这将不必要地消耗内存。