- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这SO answer澄清了一些关于 -Xmx
JVM 标志的事情。为了进行实验,我做了以下事情:
import java.util.List;
import java.util.ArrayList;
public class FooMain {
private static String memoryMsg() {
return String.format("%s. %s. %s"
, String.format("total memory is: [%d]",Runtime.getRuntime().totalMemory())
, String.format("free memory is: [%d]",Runtime.getRuntime().freeMemory())
, String.format("max memory is: [%d]",Runtime.getRuntime().maxMemory()));
}
public static void main(String args[]) {
String msg = null;
try {
System.out.println(memoryMsg());
List<Object> xs = new ArrayList<>();
int i = 0 ;
while (true) {
xs.add(new byte[1000]);
msg = String.format("%d 1k arrays added.\n%s.\n"
, ++i
, memoryMsg());
}
} finally {
System.out.printf(msg);
}
}
}
用javac FooMain.java
编译它。当我以 500 万字节的最大堆大小运行它时,我得到:
java -Xmx5000000 FooMain
total memory is: [5242880]. free memory is: [4901096]. max memory is: [5767168]
4878 1k arrays added.
total memory is: [5767168]. free memory is: [543288]. max memory is: [5767168].
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.lang.String.toCharArray(String.java:2748)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:3048)
at java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2744)
at java.util.Formatter$FormatSpecifier.print(Formatter.java:2702)
at java.util.Formatter.format(Formatter.java:2488)
at java.util.Formatter.format(Formatter.java:2423)
at java.lang.String.format(String.java:2792)
at FooMain.memoryMsg(FooMain.java:7)
at FooMain.main(FooMain.java:21)
虽然数字足够接近,但它们似乎不是很准确(除了最后的total memory
exactly max memory
)。特别是 5368 个 1000 字节的数组,每个数组应该占用超过 5000000 甚至 5242880 字节。这些数字应该如何理解?
这是我正在使用的 java:
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) Server VM (build 24.80-b11, mixed mode)
最佳答案
查看 OpenJDK 源代码,确定最大堆大小的逻辑非常复杂,并且由很多变量决定。实际堆大小在 hotspot/src/share/vm/memory/collectorPolicy.cpp
中设置,它使用提供的 -Xmx 值作为输入,并使用以下代码将其对齐:
align_size_up(MaxHeapSize, max_alignment());
align_size_up 定义为:
#define align_size_up_(size, alignment) (((size) + ((alignment) - 1)) & ~((alignment) - 1))
而max_alignment是虚拟内存页面大小和JVM垃圾收集卡大小的乘积。 VM 页面大小为 4096 字节,卡大小为 512 字节。代入这些值会得到 6324224 字节的实际 MaxHeapSize,这与您看到的数字非常吻合。
注意:我只是简单地查看了 JVM 代码,所以我可能错过了一些东西,但答案似乎与您所看到的相加。
关于java - -Xmx 是硬性限制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33164666/
我真的很困惑。 Xmx 根据 java 文档,是允许的最大堆大小。 Xms 是所需的最小 Java 堆大小,在 JVM 启动时分配。 在 32 位 JVM(4GB 内存)上,java -Xmx1536
我有一个疑问。让我们假设我有两个参数传递给 JVM: -Xms256mb -Xmx1024mb 在程序开始时分配了 256MB。接下来,创建一些对象,JVM 进程尝试分配更多内存。假设 JVM 需要分
我试图在Windows机器上运行Elasticsearch,但是出现错误“无法创建Java虚拟机”。 Windows 10、32GB RAM,64位 JVM 1.8.0_201 Elasticsear
我正在使用一个名为 Talend 的 BI 数据集成工具,该工具使用 Java 在 Eclipse 上构建。 在启 Action 业时,它说 Could not create the Java vir
我使用 -Xms256m and -Xmx256m JVM options 将初始和最大 Java 堆大小设置为 256MB . GC 日志(使用 -XX:+PrintHeapAtGC)表明堆大小为
我正在使用 java -Xmx60g 命令运行以下代码。 每个阵列应该在 8.5GB 左右,总共 17GB。该机器总共有 64GB,其中有 63GB“免费”。它打印 DONE DECLARING RI
这SO answer澄清了一些关于 -Xmx JVM 标志的事情。为了进行实验,我做了以下事情: import java.util.List; import java.util.ArrayList;
我有很多 JVM 在 Linux Redhat 上运行,具有 32GB 的物理内存和 32GB 的虚拟内存。这些 JVM 配置为具有超过 32GB 的 Xmx 总值,并且可能让 Linux 使用了它的
我们知道我们可以在 window->preferences->java->installed jres->edit->default vm arguments 中设置 -Xmx1024M 在 ecli
我的 Java 应用程序通过运行“java -jar j.jar”进程来运行另一个 Java 应用程序。众所周知,J.jar 会根据给定的数据集使用大量内存,并且经常会获得 OutOfMemoryEr
有没有办法限制javac的最大虚拟内存使用量?运行 java 时,我可以使用“-XmxAm”(其中 A 是可用兆字节数)运行它来限制它。 javac 有这样的东西吗?谢谢。 最佳答案 您可以使用 -J
问题 我有一个包含大量公式的 .xlsx 文件。我想将此文件转换为新的 .xlsx 文件,其中所有公式都替换为其绝对值。为什么? 可能与这个问题无关。 我做了什么? 我的目标是在尽可能少的堆内存中执行
我正在 Fedora 上运行 jre 6u24 (Linux xxx 2.6.33.7.2-rt30 #1 SMP PREEMPT RT Mon Mar 21 00:50:23 UTC 2011 i6
在阅读了诸如this和JEP-346之类的答案之后,我意识到G1确实将内存释放回了操作系统。 但是,它是否将内存释放回操作系统,甚至导致当前的内存使用量可能降至初始堆内存以下(即,在此JEP之前,对于
我有两台运行 Mac OS X El Capitan 和 Ubuntu 16.04 LTS 的计算机。两者都安装了 Java SDK 1.8.0_101。 当我尝试在 Ubuntu 上启动游戏服务器时
当我尝试使用 -Xms32m -Xmx128m 加载列表中的 39MB 文本时出现内存不足错误。所以我开始一点一点地增加Xmx,直到加载成功,发现我至少需要Xmx170m才能加载内存中的39MB文件
JacORB 通知服务的 JVM (java 1.6) 消耗内存超过 -Xmx 值,设置为 240MB。 Windows 任务管理器中的 java exe 超过 900MB Privatebytes,
在 JDK 8 ,默认最大堆大小为 1/4th of the physical memory or 1GB 并且可以使用 -Xmx 开关覆盖它: You can override this defau
我在我的应用程序中遇到了臭名昭著的 OutOfMemoryException,我没有简单地增加可用的堆空间量,而是试图查看问题所在,以防万一,出现某种泄漏从我的应用程序。 我添加了 JVM 参数 -X
在 java 中,我们可以使用 xmx 参数定义进程可以占用的最大内存。对于 perm gen,我们可以定义 MaxPermSize。 perm gen 空间也是使用分配的内存的一部分xmx参数。 那
我是一名优秀的程序员,十分优秀!