• Nashorn引擎导致metaspace oom


    () {","marks":[]}]}]},{"type":"block","id":"Y0MX-1687172537783","name":"code-line","data":{},"nodes":[{"type":"text","id":"YBXq-1687172537782","leaves":[{"text":"        @Throws(Exception::class)","marks":[]}]}]},{"type":"block","id":"RxjE-1687172537785","name":"code-line","data":{},"nodes":[{"type":"text","id":"B7Wl-1687172537784","leaves":[{"text":"        override fun create(): Invocable {","marks":[]}]}]},{"type":"block","id":"PwG1-1687172537787","name":"code-line","data":{},"nodes":[{"type":"text","id":"0HMi-1687172537786","leaves":[{"text":"            val factory = NashornScriptEngineFactory()","marks":[]}]}]},{"type":"block","id":"OW8L-1687172537789","name":"code-line","data":{},"nodes":[{"type":"text","id":"dHCu-1687172537788","leaves":[{"text":"            val params = arrayOf(\"--loader-per-compile=false\")","marks":[]}]}]},{"type":"block","id":"HHJL-1687172537791","name":"code-line","data":{},"nodes":[{"type":"text","id":"8470-1687172537790","leaves":[{"text":"            val engine = factory.getScriptEngine(*params)","marks":[]}]}]},{"type":"block","id":"ma34-1687172537793","name":"code-line","data":{},"nodes":[{"type":"text","id":"vwK1-1687172537792","leaves":[{"text":"            engine.eval(acornCode)","marks":[]}]}]},{"type":"block","id":"Vh29-1687172537795","name":"code-line","data":{},"nodes":[{"type":"text","id":"oBUq-1687172537794","leaves":[{"text":"            return engine as Invocable","marks":[]}]}]},{"type":"block","id":"56R3-1687172537797","name":"code-line","data":{},"nodes":[{"type":"text","id":"CGb1-1687172537796","leaves":[{"text":"        }","marks":[]}]}]},{"type":"block","id":"ulDw-1687172537799","name":"code-line","data":{},"nodes":[{"type":"text","id":"dHsn-1687172537798","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"v1Rp-1687172537802","name":"code-line","data":{},"nodes":[{"type":"text","id":"lJqW-1687172537801","leaves":[{"text":"        override fun wrap(obj: Invocable): PooledObject {","marks":[]}]}]},{"type":"block","id":"AtZJ-1687172537804","name":"code-line","data":{},"nodes":[{"type":"text","id":"6r7U-1687172537803","leaves":[{"text":"            return DefaultPooledObject(obj)","marks":[]}]}]},{"type":"block","id":"uEar-1687172537806","name":"code-line","data":{},"nodes":[{"type":"text","id":"ZDSz-1687172537805","leaves":[{"text":"        }","marks":[]}]}]},{"type":"block","id":"lH0x-1687172537808","name":"code-line","data":{},"nodes":[{"type":"text","id":"dbsQ-1687172537807","leaves":[{"text":"    }","marks":[]}]}]}],"state":{}},{"type":"block","id":"i8Tg-1687172504167","name":"paragraph","data":{"style":{}},"nodes":[{"type":"text","id":"lbtY-1687172504166","leaves":[{"text":"改造前测试200次 发现创建了200个ScripLoader ","marks":[]}]}],"state":{}},{"type":"block","id":"hDmQ-1687172635848","name":"paragraph","data":{"style":{}},"nodes":[{"type":"text","id":"mFxL-1687172635847","leaves":[{"text":"改造后发现ScriptLoader数量不再变化了","marks":[]}]}],"state":{}},{"type":"block","id":"0hoL-1687172601753","name":"paragraph","data":{"style":{}},"nodes":[{"type":"text","id":"ckzL-1687172601752","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"HJGI-1687172602313","name":"image","data":{"version":1,"url":"https://note.youdao.com/yws/res/7/WEBRESOURCEbc9b0e8f133aeb21c66857f4bcb2a337","width":994,"height":349},"nodes":[],"state":{"loading":false,"renderSource":"https://note.youdao.com/yws/res/7/WEBRESOURCEbc9b0e8f133aeb21c66857f4bcb2a337","initialSize":{"width":994,"height":349}}},{"type":"block","id":"E5iE-1687172602316","name":"paragraph","data":{"style":{}},"nodes":[{"type":"text","id":"4orF-1687172602315","leaves":[{"text":"","marks":[]}]}],"state":{}}]">
     
    0
     
    0
     
    从报错内容很清楚是Metaspace区域oom了
    大部分情况下,程序运行中不会出现过多的类加载数量的变动,先导入dump文件检查是否有异常的classLoader或者有异常动态生成的class
    发现了下面这个classLoader数量异常,项目中用到nashorn这块js引擎来做动态js脚本执行
    0
    通过查阅nashorn源码发现
     
     
     
    0
    默认为true代表每次compile js脚本都会新创建一个classLoader,用下面的方式改造一下js引擎的创建方式
     
    改造前测试200次 发现创建了200个ScripLoader
    改造后测试发现ScriptLoader数量不再变化了
     
    0
     
  • 相关阅读:
    计算机毕业设计Java陕菜食谱网站(源码+系统+mysql数据库+lw文档)
    HTTP 之 options预请求 nginx 解决跨域 postman调试跨域问题
    雷达编程实战之提高探测速度
    【Vue2.x源码系列02】模版编译(AST、Optimize 、Render)
    成像雷达量产突破:木牛携手全球合作伙伴突破智驾瓶颈
    绿色低碳,数字为先:万应低代码推动能源资产管理优化
    信号线上串接电阻的作用
    JAVA 短剧系统小程序的开发流程
    Windows10安装麒麟桌面V10双系统
    AJAX
  • 原文地址:https://www.cnblogs.com/yudongdong/p/17491975.html