欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > openjdk17 jvm byte数组 内存溢出 在C++源码体现

openjdk17 jvm byte数组 内存溢出 在C++源码体现

2024/12/27 8:33:38 来源:https://blog.csdn.net/u014200244/article/details/144117769  浏览:    关键词:openjdk17 jvm byte数组 内存溢出 在C++源码体现

##内存泄露java代码,实验对象 byte数组

import java.util.ArrayList;
import java.util.List;public class OutOfMemoryTest {public static void main(String[] args) {List<byte[]> bytes = new ArrayList<>();while(true) {byte[] b = new byte[1024 * 1024 * 10];bytes.add(b);}}}

##gdb掉用栈

Thread 2 "java" hit Breakpoint 1, MemAllocator::Allocation::check_out_of_memory (this=0x7ffff7bfe5a0) at /home/yym/openjdk17/jdk17-master/src/hotspot/share/gc/shared/memAllocator.cpp:126
126       if (!_thread->in_retryable_allocation()) {
(gdb) bt
#0  MemAllocator::Allocation::check_out_of_memory (this=0x7ffff7bfe5a0) at /home/yym/openjdk17/jdk17-master/src/hotspot/share/gc/shared/memAllocator.cpp:126
#1  0x00007ffff677afee in MemAllocator::Allocation::~Allocation (this=0x7ffff7bfe5a0, __in_chrg=<optimized out>)at /home/yym/openjdk17/jdk17-master/src/hotspot/share/gc/shared/memAllocator.cpp:84
#2  0x00007ffff677a0ab in MemAllocator::allocate (this=0x7ffff7bfe620) at /home/yym/openjdk17/jdk17-master/src/hotspot/share/gc/shared/memAllocator.cpp:373
#3  0x00007ffff6019669 in CollectedHeap::array_allocate (this=0x7ffff00453d0, klass=0x100040820, size=1310722, length=10485760, do_zero=true, __the_thread__=0x7ffff0028920)at /home/yym/openjdk17/jdk17-master/src/hotspot/share/gc/shared/collectedHeap.inline.hpp:41
#4  0x00007ffff6b8bcae in TypeArrayKlass::allocate_common (this=0x100040820, length=10485760, do_zero=true, __the_thread__=0x7ffff0028920)at /home/yym/openjdk17/jdk17-master/src/hotspot/share/oops/typeArrayKlass.cpp:93
#5  0x00007ffff60b06c8 in TypeArrayKlass::allocate (this=0x100040820, length=10485760, __the_thread__=0x7ffff0028920)at /home/yym/openjdk17/jdk17-master/src/hotspot/share/oops/typeArrayKlass.hpp:68
#6  0x00007ffff685bfc1 in oopFactory::new_typeArray (type=T_BYTE, length=10485760, __the_thread__=0x7ffff0028920)at /home/yym/openjdk17/jdk17-master/src/hotspot/share/memory/oopFactory.cpp:93
#7  0x00007ffff63685ea in InterpreterRuntime::newarray (current=0x7ffff0028920, type=T_BYTE, size=10485760)at /home/yym/openjdk17/jdk17-master/src/hotspot/share/interpreter/interpreterRuntime.cpp:259
#8  0x00007fffe1023c72 in ?? ()
#9  0x00007ffff7ab2c00 in TemplateInterpreter::_active_table () from /home/yym/openjdk17/jdk17-master/build/linux-x86_64-server-slowdebug/jdk/lib/server/libjvm.so
#10 0x00007fffe1023bf1 in ?? ()
#11 0x00007ffff7bfe7a0 in ?? ()
#12 0x00007fffd9c0f272 in ?? ()
#13 0x00007ffff7bfe808 in ?? ()
#14 0x00007fffd9c0f300 in ?? ()
#15 0x0000000000000000 in ?? ()

##InterpreterRuntime::newarray JVM字节码指令new数组,CollectedHeap::array_allocate分配数组空间。MemAllocator::allocate内存分配

##~Allocation()析构函数,调用check_out_of_memory()   查看*_obj_ptr是否为空,为空抛出内存溢出

oop obj() const { return *_obj_ptr; }

~Allocation() {if (!check_out_of_memory()) {verify_after();notify_allocation();}}bool MemAllocator::Allocation::check_out_of_memory() {JavaThread* THREAD = _thread; // For exception macros.assert(!HAS_PENDING_EXCEPTION, "Unexpected exception, will result in uninitialized storage");if (obj() != NULL) {return false;}const char* message = _overhead_limit_exceeded ? "GC overhead limit exceeded" : "Java heap space";std::cout << "@@@@yym%%%%" << message << std::endl;if (!_thread->in_retryable_allocation()) {// -XX:+HeapDumpOnOutOfMemoryError and -XX:OnOutOfMemoryError supportreport_java_out_of_memory(message);if (JvmtiExport::should_post_resource_exhausted()) {JvmtiExport::post_resource_exhausted(JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_JAVA_HEAP,message);}oop exception = _overhead_limit_exceeded ?Universe::out_of_memory_error_gc_overhead_limit() :Universe::out_of_memory_error_java_heap();THROW_OOP_(exception, true);} else {THROW_OOP_(Universe::out_of_memory_error_retry(), true);}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com