当前位置: 首页 > article >正文

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 support
    report_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);
  }
}


http://www.kler.cn/a/414019.html

相关文章:

  • 【CSS in Depth 2 精译_062】第 10 章 CSS 中的容器查询(@container)概述 + 10.1 容器查询的一个简单示例
  • 【uniapp】轮播图
  • ESP32 wifi smartConfig 配网时密码错误导致一直死循环问题解决
  • 【61-70期】Java面试题深度解析:从集合框架到线程安全的最佳实践
  • spring boot 观察者设计模式代码实现教程
  • android 11添加切换分屏功能
  • 使用TensorRT LLM的量化实践
  • BASLER工业相机维修不能触发拍照如何处理解决这个问题
  • Qt-系统相关(2)多线程网络
  • React 第九节 组件之间通讯之props 和回调函数
  • 数字IC后端实现之PR工具中如何避免出现一倍filler的缝隙?
  • Binder架构
  • 常见的Web安全漏洞——XSS
  • MySQL中group by实战详细案例笔记
  • 利用dockerCompose一键部署前后端分离项目
  • 大模型时代的具身智能系列专题(十八)
  • [BUUCTF]ciscn_2019_n_8
  • 【YOLO系列复现】二、基于YOLOv6的目标检测:YOLOv6训练自己的数据集(史诗级详细教程)
  • FBX福币交易所固态电池板块逆市掀涨停潮
  • [代码随想录算法01] 704. 二分查找、27. 移除元素、977有序数组的平方
  • mfc110u.dll是什么意思,mfc110u.dll丢失解决方法大全详解
  • 【论文复现】YOLOv5复现
  • [极客大挑战 2019]HardSQL--详细解析
  • matlab显示sin二维图
  • JavaScript对象笔记
  • 跟李笑来学美式俚语(Most Common American Idioms): Part 36