tomcat启动的时候,报这个错,在bin目录下的hs_err_pid7752.log

#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 1048576 bytes for AllocateHeap
# Possible reasons:
#   The system is out of physical RAM or swap space
#   In 32 bit mode, the process size limit was hit
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Use 64 bit Java on a 64 bit OS
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
#  Out of Memory Error (memory/allocation.inline.hpp:61), pid=7752, tid=4676
#
# JRE version:  (7.0_79-b15) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Call to MiniDumpWriteDump() failed
#

---------------  T H R E A D  ---------------

Current thread (0x0000000002501000):  JavaThread "Unknown thread" [_thread_in_vm, id=4676, stack(0x0000000002920000,0x0000000002a20000)]

Stack: [0x0000000002920000,0x0000000002a20000]
[error occurred during error reporting (printing stack bounds), id 0xc0000005]

阅读 8.8k
3 个回答

看提示是说分配 1048576 字节的 Native 内存 时失败了. native 内存不足, 不代表 JVM 的堆内存不足, 因为 native 内存是由 C 语言中的 malloc 所分配的, 它不包含在堆内存中. 出现 native 分配失败的情况, 一般就是因为整个操作系统的物理内存不足了, 导致没有多余的内存空间分配给 native 内存.

而上面的错误提示也给出了解决方法:

Possible solutions:
  Reduce memory load on the system
  Increase physical memory or swap space
  Check if swap backing store is full
  Use 64 bit Java on a 64 bit OS
  Decrease Java heap size (-Xmx/-Xms)
  Decrease number of Java threads
  Decrease Java thread stack sizes (-Xss)

其中提到了三点关键的:

  1. 减少堆内存(-Xmx/-Xms);

  2. 减少 Java 线程数.

  3. 减少 Java 的线程堆栈大小(-Xss).

为什么这样做呢? 因为 native 内存不在 Heap 中, 因此 JVM 所占用的实际内存由: native 内存 + Heap 内存 + 栈内存 + 其他, 因此减少 Heap 内存, 那么可用的 native 内存就提高了.

1048576 bytes 这是 1Mb 吧。只给堆分配这么点内存吗?

看样子是内存不足导致的

推荐问题
宣传栏