【问题标题】:Java Runtime.getRuntime().freeMemory() issuesJava Runtime.getRuntime().freeMemory() 问题
【发布时间】:2014-05-29 21:14:33
【问题描述】:

我搜索并看到了一些线程,但没有一个能解决我遇到的具体问题。

我正在尝试使用Runtime.getRuntime().freeMemory()Runtime.getRuntime().maxMemory()Runtime.getRuntime().totalMemory() 监控我的内存使用情况。

在一次运行中,它说在声明数组之前有 2245273792 个空闲字节,但程序在尝试声明一个 1104674816 字节的数组时内存不足并崩溃:

    Free memory (bytes): 2245273792 
    Maximum memory (bytes): 6710886400
    Total memory available to JVM (bytes): 5606211584
    OpenJDK 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000728280000, 1104674816, 0) failed; error='Cannot allocate memory' (errno=12)

     There is insufficient memory for the Java Runtime Environment to continue.
     Native memory allocation (malloc) failed to allocate 1104674816 bytes for committing reserved memory.
     An error report file with more information is saved as:

编辑:当它分配的内存少于可用量的一半时,它怎么可能耗尽内存?内存不足对这个程序来说是非常糟糕的;有没有办法可以保证我分配的资源不会超过可用资源?首先调用 System.gc() 会使空闲/可用内存的数量更可靠吗?如果程序即将耗尽内存,我可以抛出某种异常,而不是让它崩溃吗?

它崩溃的命令是:float[][] A = new float[NUM_SEQ_TOTAL_P1][NUM_SEQ_TOTAL_P2]; with NUM_SEQ_TOTAL_P1 = 16009, NUM_SEQ_TOTAL_P2 = 16937。

编辑:根据评论者的要求,将错误日志的一部分粘贴在下面。

 There is insufficient memory for the Java Runtime Environment to continue.
 Native memory allocation (malloc) failed to allocate 1104674816 bytes for committing reserved memory.
 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 (os_linux.cpp:2769), pid=14802, tid=140058464728832

 JRE version: OpenJDK Runtime Environment (7.0_55-b14) (build 1.7.0_55-b14)
 Java VM: OpenJDK 64-Bit Server VM (24.51-b03 mixed mode linux-amd64 compressed oops)
 Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again


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

Current thread (0x00007f61f0071000):  VMThread [stack: 0x00007f61e6f9b000,0x00007f61e709c000] [id=14806]

Stack: [0x00007f61e6f9b000,0x00007f61e709c000],  sp=0x00007f61e709a470,  free space=1021k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x917b35]  VMError::report_and_die()+0x175
V  [libjvm.so+0x468144]  report_vm_out_of_memory(char const*, int, unsigned long, char const*)+0x74
V  [libjvm.so+0x79a81b]  os::pd_commit_memory(char*, unsigned long, unsigned long, bool)+0x20b
V  [libjvm.so+0x7950df]  os::commit_memory(char*, unsigned long, unsigned long, bool)+0x1f
V  [libjvm.so+0x8053cb]  PSVirtualSpace::expand_by(unsigned long)+0x5b
V  [libjvm.so+0x7f519b]  PSOldGen::expand_by(unsigned long) [clone .part.80]+0x1b
V  [libjvm.so+0x7f535b]  PSOldGen::expand(unsigned long) [clone .part.81]+0xdb
V  [libjvm.so+0x7f6288]  PSOldGen::resize(unsigned long)+0x188
V  [libjvm.so+0x7fd2e3]  PSParallelCompact::invoke_no_policy(bool)+0x9c3
V  [libjvm.so+0x80350d]  PSScavenge::invoke()+0x17d
V  [libjvm.so+0x7b9b33]  ParallelScavengeHeap::failed_mem_allocate(unsigned long)+0x63
V  [libjvm.so+0x919544]  VM_ParallelGCFailedAllocation::doit()+0x84
V  [libjvm.so+0x91d9e7]  VM_Operation::evaluate()+0x47
V  [libjvm.so+0x91c3b8]  VMThread::evaluate_operation(VM_Operation*)+0x318
V  [libjvm.so+0x91c85a]  VMThread::loop()+0x25a
V  [libjvm.so+0x91cc62]  VMThread::run()+0x72
V  [libjvm.so+0x7974e2]  java_start(Thread*)+0xf2

VM_Operation (0x00007f61f8b6b2e0): ParallelGCFailedAllocation, mode: safepoint, requested by thread 0x00007f61f000a000


---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x00007f61f00a1800 JavaThread "Service Thread" daemon [_thread_blocked, id=14812, stack(0x00007f61e680c000,0x00007f61e690d000)]
  0x00007f61f009f000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=14811, stack(0x00007f61e690d000,0x00007f61e6a0e000)]
  0x00007f61f009c000 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=14810, stack(0x00007f61e6a0e000,0x00007f61e6b0f000)]
  0x00007f61f009a000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=14809, stack(0x00007f61e6b0f000,0x00007f61e6c10000)]
  0x00007f61f0077800 JavaThread "Finalizer" daemon [_thread_blocked, id=14808, stack(0x00007f61e6d99000,0x00007f61e6e9a000)]
  0x00007f61f0075800 JavaThread "Reference Handler" daemon [_thread_blocked, id=14807, stack(0x00007f61e6e9a000,0x00007f61e6f9b000)]
  0x00007f61f000a000 JavaThread "main" [_thread_blocked, id=14803, stack(0x00007f61f8a6c000,0x00007f61f8b6d000)]

Other Threads:
=>0x00007f61f0071000 VMThread [stack: 0x00007f61e6f9b000,0x00007f61e709c000] [id=14806]
  0x00007f61f00ac000 WatcherThread [stack: 0x00007f61e670b000,0x00007f61e680c000] [id=14813]

VM state:at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread:  ([mutex/lock_event])
[0x00007f61f0005ea0] ExpandHeap_lock - owner thread: 0x00007f61f0071000
[0x00007f61f0006520] Threads_lock - owner thread: 0x00007f61f0071000
[0x00007f61f0006a20] Heap_lock - owner thread: 0x00007f61f000a000

Heap
 PSYoungGen      total 1638400K, used 205885K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 0% used [0x000000076a000000,0x000000076a000000,0x000000079c000000)
  from space 819200K, 25% used [0x00000007ce000000,0x00000007da90f408,0x0000000800000000)
  to   space 819200K, 0% used [0x000000079c000000,0x000000079c000000,0x00000007ce000000)
 ParOldGen       total 3836416K, used 3836085K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 99% used [0x000000063e000000,0x000000072822d6b8,0x0000000728280000)
 PSPermGen       total 21504K, used 5549K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b518,0x0000000634f00000)

Card table byte_map: [0x00007f61f487d000,0x00007f61f56e1000] byte_map_base: 0x00007f61f16e0000

Polling page: 0x00007f61f8b7d000

Code Cache  [0x00007f61ed000000, 0x00007f61ed270000, 0x00007f61f0000000)
 total_blobs=653 nmethods=373 adapters=234 free_code_cache=46884Kb largest_free_block=47925312

Compilation events (10 events):
Event: 697.652 Thread 0x00007f61f009c000  394             playingAgent.tartanian7.PlayerAction::access$0 (5 bytes)
Event: 697.652 Thread 0x00007f61f009c000 nmethod 394 0x00007f61ed1f0150 code [0x00007f61ed1f0280, 0x00007f61ed1f02d8]
Event: 729.745 Thread 0x00007f61f009f000  395             java.nio.Buffer::remaining (10 bytes)
Event: 729.745 Thread 0x00007f61f009f000 nmethod 395 0x00007f61ed1eff50 code [0x00007f61ed1f0080, 0x00007f61ed1f00d8]
Event: 921.702 Thread 0x00007f61f009c000  396             playingAgent.riverSolver.DoylesGameRiver2::getRiverStrategy (451 bytes)
Event: 921.710 Thread 0x00007f61f009f000  397             playingAgent.tartanian7.PokerUtils::countRoundDelimiters (42 bytes)
Event: 921.714 Thread 0x00007f61f009f000 nmethod 397 0x00007f61ed1f8350 code [0x00007f61ed1f84a0, 0x00007f61ed1f86b8]
Event: 921.720 Thread 0x00007f61f009f000  398             java.lang.String::startsWith (7 bytes)
Event: 921.724 Thread 0x00007f61f009f000 nmethod 398 0x00007f61ed108010 code [0x00007f61ed108160, 0x00007f61ed108338]
Event: 922.063 Thread 0x00007f61f009c000 nmethod 396 0x00007f61ed23db90 code [0x00007f61ed23e6e0, 0x00007f61ed244d78]

GC Heap History (10 events):
Event: 922.966 GC heap after
Heap after GC invocations=137 (full 23):
 PSYoungGen      total 1638400K, used 280234K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 0% used [0x000000076a000000,0x000000076a000000,0x000000079c000000)
  from space 819200K, 34% used [0x00000007ce000000,0x00000007df1aa930,0x0000000800000000)
  to   space 819200K, 0% used [0x000000079c000000,0x000000079c000000,0x00000007ce000000)
 ParOldGen       total 3836416K, used 2558981K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 66% used [0x000000063e000000,0x00000006da301608,0x0000000728280000)
 PSPermGen       total 21504K, used 5548K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b068,0x0000000634f00000)
}
Event: 941.023 GC heap before
{Heap before GC invocations=138 (full 23):
 PSYoungGen      total 1638400K, used 1099434K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 100% used [0x000000076a000000,0x000000079c000000,0x000000079c000000)
  from space 819200K, 34% used [0x00000007ce000000,0x00000007df1aa930,0x0000000800000000)
  to   space 819200K, 0% used [0x000000079c000000,0x000000079c000000,0x00000007ce000000)
 ParOldGen       total 3836416K, used 2558981K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 66% used [0x000000063e000000,0x00000006da301608,0x0000000728280000)
 PSPermGen       total 21504K, used 5548K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b258,0x0000000634f00000)
Event: 941.125 GC heap after
Heap after GC invocations=138 (full 23):
 PSYoungGen      total 1638400K, used 463312K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 0% used [0x000000076a000000,0x000000076a000000,0x000000079c000000)
  from space 819200K, 56% used [0x000000079c000000,0x00000007b8474158,0x00000007ce000000)
  to   space 819200K, 0% used [0x00000007ce000000,0x00000007ce000000,0x0000000800000000)
 ParOldGen       total 3836416K, used 2559185K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 66% used [0x000000063e000000,0x00000006da334680,0x0000000728280000)
 PSPermGen       total 21504K, used 5548K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b258,0x0000000634f00000)
}
Event: 971.960 GC heap before
{Heap before GC invocations=139 (full 23):
 PSYoungGen      total 1638400K, used 1282512K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 100% used [0x000000076a000000,0x000000079c000000,0x000000079c000000)
  from space 819200K, 56% used [0x000000079c000000,0x00000007b8474158,0x00000007ce000000)
  to   space 819200K, 0% used [0x00000007ce000000,0x00000007ce000000,0x0000000800000000)
 ParOldGen       total 3836416K, used 2559185K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 66% used [0x000000063e000000,0x00000006da334680,0x0000000728280000)
 PSPermGen       total 21504K, used 5549K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b518,0x0000000634f00000)
Event: 971.996 GC heap after
Heap after GC invocations=139 (full 23):
 PSYoungGen      total 1638400K, used 130974K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 0% used [0x000000076a000000,0x000000076a000000,0x000000079c000000)
  from space 819200K, 15% used [0x00000007ce000000,0x00000007d5fe7b78,0x0000000800000000)
  to   space 819200K, 0% used [0x000000079c000000,0x000000079c000000,0x00000007ce000000)
 ParOldGen       total 3836416K, used 2559301K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 66% used [0x000000063e000000,0x00000006da351710,0x0000000728280000)
 PSPermGen       total 21504K, used 5549K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b518,0x0000000634f00000)
}
Event: 972.098 GC heap before
{Heap before GC invocations=140 (full 23):
 PSYoungGen      total 1638400K, used 950174K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 100% used [0x000000076a000000,0x000000079c000000,0x000000079c000000)
  from space 819200K, 15% used [0x00000007ce000000,0x00000007d5fe7b78,0x0000000800000000)
  to   space 819200K, 0% used [0x000000079c000000,0x000000079c000000,0x00000007ce000000)
 ParOldGen       total 3836416K, used 2559301K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 66% used [0x000000063e000000,0x00000006da351710,0x0000000728280000)
 PSPermGen       total 21504K, used 5549K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b518,0x0000000634f00000)
Event: 972.296 GC heap after
Heap after GC invocations=140 (full 23):
 PSYoungGen      total 1638400K, used 817538K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 0% used [0x000000076a000000,0x000000076a000000,0x000000079c000000)
  from space 819200K, 99% used [0x000000079c000000,0x00000007cde60b18,0x00000007ce000000)
  to   space 819200K, 0% used [0x00000007ce000000,0x00000007ce000000,0x0000000800000000)
 ParOldGen       total 3836416K, used 2689286K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 70% used [0x000000063e000000,0x00000006e2241b50,0x0000000728280000)
 PSPermGen       total 21504K, used 5549K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b518,0x0000000634f00000)
}
Event: 972.397 GC heap before
{Heap before GC invocations=141 (full 23):
 PSYoungGen      total 1638400K, used 1636738K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 100% used [0x000000076a000000,0x000000079c000000,0x000000079c000000)
  from space 819200K, 99% used [0x000000079c000000,0x00000007cde60b18,0x00000007ce000000)
  to   space 819200K, 0% used [0x00000007ce000000,0x00000007ce000000,0x0000000800000000)
 ParOldGen       total 3836416K, used 2689286K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 70% used [0x000000063e000000,0x00000006e2241b50,0x0000000728280000)
 PSPermGen       total 21504K, used 5549K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b518,0x0000000634f00000)
Event: 972.791 GC heap after
Heap after GC invocations=141 (full 23):
 PSYoungGen      total 1638400K, used 817782K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 0% used [0x000000076a000000,0x000000076a000000,0x000000079c000000)
  from space 819200K, 99% used [0x00000007ce000000,0x00000007ffe9d998,0x0000000800000000)
  to   space 819200K, 0% used [0x000000079c000000,0x000000079c000000,0x00000007ce000000)
 ParOldGen       total 3836416K, used 3506825K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 91% used [0x000000063e000000,0x00000007140a2668,0x0000000728280000)
 PSPermGen       total 21504K, used 5549K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b518,0x0000000634f00000)
}
Event: 972.791 GC heap before
{Heap before GC invocations=142 (full 24):
 PSYoungGen      total 1638400K, used 817782K [0x000000076a000000, 0x0000000800000000, 0x0000000800000000)
  eden space 819200K, 0% used [0x000000076a000000,0x000000076a000000,0x000000079c000000)
  from space 819200K, 99% used [0x00000007ce000000,0x00000007ffe9d998,0x0000000800000000)
  to   space 819200K, 0% used [0x000000079c000000,0x000000079c000000,0x00000007ce000000)
 ParOldGen       total 3836416K, used 3506825K [0x000000063e000000, 0x0000000728280000, 0x000000076a000000)
  object space 3836416K, 91% used [0x000000063e000000,0x00000007140a2668,0x0000000728280000)
 PSPermGen       total 21504K, used 5549K [0x0000000633a00000, 0x0000000634f00000, 0x000000063e000000)
  object space 21504K, 25% used [0x0000000633a00000,0x0000000633f6b518,0x0000000634f00000)

Deoptimization events (10 events):
Event: 388.757 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed200cd4 method=java.util.ComparableTimSort.mergeHi(IIII)V @ 234
Event: 425.767 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed226240 method=java.util.ComparableTimSort.mergeHi(IIII)V @ 642
Event: 425.768 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed226240 method=java.util.ComparableTimSort.mergeHi(IIII)V @ 642
Event: 451.013 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed229d20 method=java.util.ComparableTimSort.mergeHi(IIII)V @ 404
Event: 451.013 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed229d20 method=java.util.ComparableTimSort.mergeHi(IIII)V @ 404
Event: 518.661 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed22c5c8 method=java.util.ComparableTimSort.mergeHi(IIII)V @ 509
Event: 518.661 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed22c5c8 method=java.util.ComparableTimSort.mergeHi(IIII)V @ 509
Event: 576.223 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed22399c method=java.util.ComparableTimSort.mergeLo(IIII)V @ 129
Event: 626.762 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed22399c method=java.util.ComparableTimSort.mergeLo(IIII)V @ 129
Event: 805.388 Thread 0x00007f61f000a000 Uncommon trap: reason=array_check action=maybe_recompile pc=0x00007f61ed232884 method=java.util.ComparableTimSort.mergeHi(IIII)V @ 160

Internal exceptions (10 events):
Event: 95.779 Thread 0x00007f61f000a000 Threw 0x000000076e72f270 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244
Event: 95.780 Thread 0x00007f61f000a000 Threw 0x000000076e732680 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244
Event: 95.866 Thread 0x00007f61f000a000 Threw 0x000000076ea384b0 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244
Event: 118.330 Thread 0x00007f61f000a000 Threw 0x0000000770f9b6f0 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244
Event: 118.332 Thread 0x00007f61f000a000 Threw 0x0000000770fba0d8 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244
Event: 118.528 Thread 0x00007f61f000a000 Threw 0x00000007713a1fc0 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244
Event: 118.529 Thread 0x00007f61f000a000 Threw 0x00000007713a9628 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244
Event: 118.533 Thread 0x00007f61f000a000 Threw 0x00000007713bea90 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244
Event: 118.545 Thread 0x00007f61f000a000 Threw 0x00000007713e8238 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244
Event: 118.546 Thread 0x00007f61f000a000 Threw 0x00000007713eb0f8 at /build/buildd/openjdk-7-7u55-2.4.7/build/openjdk/hotspot/src/share/vm/prims/jvm.cpp:1244

Events (10 events):
Event: 972.069 Executing VM operation: RevokeBias done
Event: 972.069 Executing VM operation: RevokeBias
Event: 972.069 Executing VM operation: RevokeBias done
Event: 972.069 Executing VM operation: RevokeBias
Event: 972.069 Executing VM operation: RevokeBias done
Event: 972.069 Executing VM operation: RevokeBias
Event: 972.069 Executing VM operation: RevokeBias done
Event: 972.069 Executing VM operation: RevokeBias
Event: 972.296 Executing VM operation: RevokeBias done
Event: 972.296 Executing VM operation: RevokeBias

Dynamic libraries:[omitted]


VM Arguments:
jvm_args: -Xmx7200m 
java_command: [omitted]
Launcher Type: SUN_STANDARD

Environment Variables: [omitted]

Signal Handlers:
SIGSEGV: [libjvm.so+0x918620], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGBUS: [libjvm.so+0x918620], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGFPE: [libjvm.so+0x795e30], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGPIPE: [libjvm.so+0x795e30], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGXFSZ: [libjvm.so+0x795e30], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGILL: [libjvm.so+0x795e30], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGUSR1: SIG_DFL, sa_mask[0]=0x00000000, sa_flags=0x00000000
SIGUSR2: [libjvm.so+0x795cd0], sa_mask[0]=0x00000000, sa_flags=0x10000004
SIGHUP: [libjvm.so+0x795eb0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGINT: [libjvm.so+0x795eb0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGTERM: [libjvm.so+0x795eb0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004
SIGQUIT: [libjvm.so+0x795eb0], sa_mask[0]=0x7ffbfeff, sa_flags=0x10000004


---------------  S Y S T E M  ---------------

OS:Ubuntu 14.04 (trusty)
uname:Linux 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64
libc:glibc 2.19 NPTL 2.19 
rlimit: STACK 8192k, CORE 0k, NPROC 59937, NOFILE 4096, AS infinity
load average:1.80 1.67 1.50

/proc/meminfo:
MemTotal:        7693824 kB
MemFree:          634168 kB
Buffers:           12600 kB
Cached:           290332 kB
SwapCached:            0 kB
Active:          6799656 kB
Inactive:         151160 kB
Active(anon):    6647936 kB
Inactive(anon):      200 kB
Active(file):     151720 kB
Inactive(file):   150960 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                36 kB
Writeback:             0 kB
AnonPages:       6647924 kB
Mapped:            18848 kB
Shmem:               236 kB
Slab:              41348 kB
SReclaimable:      32536 kB
SUnreclaim:         8812 kB
KernelStack:         848 kB
PageTables:        17104 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     3846912 kB
Committed_AS:    6744548 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       14888 kB
VmallocChunk:   34359719127 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:     7872512 kB
DirectMap2M:           0 kB


CPU:total 2 (16 cores per cpu, 2 threads per core) family 6 model 62 stepping 4, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, aes, erms, ht, tsc

/proc/cpuinfo:
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 62
model name  : Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
stepping    : 4
microcode   : 0x415
cpu MHz     : 2500.058
cache size  : 25600 KB
physical id : 1
siblings    : 2
core id     : 0
cpu cores   : 1
apicid      : 32
initial apicid  : 32
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu de tsc msr pae cx8 apic sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt tsc_deadline_timer aes rdrand hypervisor lahf_lm ida arat epb pln pts dtherm fsgsbase erms
bogomips    : 5000.11
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 62
model name  : Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz
stepping    : 4
microcode   : 0x415
cpu MHz     : 2500.058
cache size  : 25600 KB
physical id : 1
siblings    : 2
core id     : 0
cpu cores   : 1
apicid      : 32
initial apicid  : 32
fpu     : yes
fpu_exception   : yes
cpuid level : 13
wp      : yes
flags       : fpu de tsc msr pae cx8 apic sep cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt tsc_deadline_timer aes rdrand hypervisor lahf_lm ida arat epb pln pts dtherm fsgsbase erms
bogomips    : 5000.11
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:



Memory: 4k page, physical 7693824k(634168k free), swap 0k(0k free)

vm_info: OpenJDK 64-Bit Server VM (24.51-b03) for linux-amd64 JRE (1.7.0_55-b14), built on Apr 17 2014 20:08:07 by "buildd" with gcc 4.8.2

time: Thu May 29 20:30:58 2014
elapsed time: 979 seconds

【问题讨论】:

  • 请澄清您所说的“声明一个数组”是什么意思。导致崩溃的实际代码是什么?
  • 浮点数[][] A = 新浮点数[NUM_SEQ_TOTAL_P1][NUM_SEQ_TOTAL_P2];
  • 崩溃时的值为 NUM_SEQ_TOTAL_P1 = 16009,NUM_SEQ_TOTAL_P2 = 16937。
  • 好的,很公平。我还是不知道怎么回事,抱歉。但它是创建导致问题的数组,而不是声明它。那么你能告诉我 - 它在哪里说“包含更多信息的错误报告文件另存为:” - 错误报告文件为您提供了哪些额外信息?
  • 错误报告文件很长,我不知道如何理解它。有没有办法可以将它附加到我的帖子中?

标签: java memory memory-management


【解决方案1】:

由于运行时报告 2.245gig 免费,并在需要 1.104gig 时报告失败,因此请求应该成功似乎是合乎逻辑的。但是当您需要 1.104gig 时,您确实需要一个 连续 内存块。当连续块不可用时,JVM 会报告 OutOfMemory 异常。

对堆碎片进行一些搜索。堆碎片是您的根本问题。

一种可能的解决方案是使用 nio 字节缓冲区和 allocateDirect。
内存分配在 JVM 堆空间之外。

来自 JavaDoc:

可以通过调用 allocateDirect 工厂来创建直接字节缓冲区 这个类的方法。此方法返回的缓冲区通常具有 比非直接缓冲区更高的分配和释放成本。 直接缓冲区的内容可能位于正常之外 垃圾收集堆,因此它们对内存占用的影响 应用可能不明显。因此建议直接 缓冲区主要分配给大的、长寿命的缓冲区,这些缓冲区是 受制于底层系统的本机 I/O 操作。一般来说它 最好仅在产生可测量增益时才分配直接缓冲区 在节目表现上。

【讨论】:

  • 非常感谢 - 我会调查堆碎片。不幸的是,这里需要大型数组。但是,我可以控制数组的大小——我希望它们尽可能大,同时不超过可用内存量。但是,如果无法提前知道可用的连续空闲内存量,这似乎非常困难。
  • @beserious 不幸的是,这里需要大数组我不这么认为。尝试使用内存数据库来存储大量数据并毫无问题地查询它们。
【解决方案2】:

正如其他人所提到的,您不应该创建一个 1 GB 的大型二维数组,因为需要分配一块连续的内存来容纳它。但是,您可以创建一个 数组数组,其尺寸正好符合您的要求。这是因为每个子数组都会在堆上独立初始化。

而不是这个:

float[][] A = new float[NUM_SEQ_TOTAL_P1][NUM_SEQ_TOTAL_P2];

这样做:

float[][] A = new float[NUM_SEQ_TOTAL_P1][];
for (int i = 0; i < NUM_SEQ_TOTAL_P1; i++) {
  A[i] = new float[NUM_SEQ_TOTAL_P2];
}

【讨论】:

  • 哇,非常感谢,这可能会解决我的问题!乍一看,这似乎会稍微增加数组声明的运行时间,但我不确定。但无论如何,我的首要任务是避免内存崩溃,所以这是值得的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
  • 2012-06-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多