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

android如何实现OOM治理

一,原理

static void VMDebug_attachAgent(JNIEnv* env, jclass, jstring agent) {
  if (agent == nullptr) {
    ScopedObjectAccess soa(env);
    ThrowNullPointerException("agent is null");
    return;
  }

  if (!Dbg::IsJdwpAllowed()) {
    ScopedObjectAccess soa(env);
    ThrowSecurityException("Can't attach agent, process is not debuggable.");
    return;
  }

  std::string filename;
  {
    ScopedUtfChars chars(env, agent);
    if (env->ExceptionCheck()) {
      return;
    }
    filename = chars.c_str();
  }

  Runtime::Current()->AttachAgent(filename);
}

二,开启JVMTI监控呢能力

 SetEventNotification(jvmti_env, JVMTI_ENABLE,JVMTI_EVENT_GARBAGE_COLLECTION_START);//监听GC 开始
    SetEventNotification(jvmti_env, JVMTI_ENABLE,JVMTI_EVENT_GARBAGE_COLLECTION_FINISH);//监听GC 结束
    SetEventNotification(jvmti_env, JVMTI_ENABLE,JVMTI_EVENT_NATIVE_METHOD_BIND);//监听native method bind
    SetEventNotification(jvmti_env, JVMTI_ENABLE,JVMTI_EVENT_VM_OBJECT_ALLOC);//监听对象分配
    SetEventNotification(jvmti_env, JVMTI_ENABLE,JVMTI_EVENT_OBJECT_FREE);//监听对象释放
    SetEventNotification(jvmti_env, JVMTI_ENABLE,JVMTI_EVENT_CLASS_FILE_LOAD_HOOK);//监听类文件加载
    SetEventNotification(jvmti_env,JVMTI_ENABLE, JVMTI_EVENT_METHOD_ENTRY);//方法进入
    SetEventNotification(jvmti_env,JVMTI_ENABLE, JVMTI_EVENT_METHOD_EXIT);//方法退出

    SetEventNotification(jvmti_env,JVMTI_ENABLE, JVMTI_EVENT_THREAD_START);//线程开始
    SetEventNotification(jvmti_env,JVMTI_ENABLE, JVMTI_EVENT_THREAD_END);//线程结束

模拟oom

 val bytes = ByteArray(1024 * 1024 * 1024)

2025-02-05 12:04:05.902: methodEntry {Ljava/lang/OutOfMemoryError; <init>} 
2025-02-05 12:04:05.917: methodEntry {Ljava/lang/OutOfMemoryError; <init>} 

 可以看到通过JVMTI技术可以快速的定位到OOM位置


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

相关文章:

  • MAC电脑配置VSCode写JAVA
  • 系统架构设计师—系统架构设计篇—软件可靠性
  • Docker 配置镜像源
  • 【JavaScript】09-构造函数+数据常用函数
  • matlab慕课学习3.1
  • 大模型工具Ollama存在安全风险
  • 【无脑 海螺AI api 合成音频 实例 】
  • HTML星球大冒险之路线图
  • 图形编辑器基于Paper.js教程24:图像转gcode的重构,元素翻转,旋转
  • AI革命编程学习:Python语法速通与高阶突破全实战(第二部分:AI辅助调试与高阶编程)
  • PaddleDetection目标检测自定义训练
  • 主流大语言模型中Token的生成过程本质是串行的
  • sparkTTS window 安装
  • 什么是Flask
  • 论文阅读笔记——π0: A Vision-Language-Action Flow Model for General Robot Control
  • 【华三】STP端口角色与状态深度解析
  • 游戏引擎学习第149天
  • [数据结构]堆详解
  • TDengine 接入帆软 BI 工具
  • 深度学习算法实战——语音识别(主页有源码)