Nashorn引擎导致metaspace oom|全球快播报
发布时间:2023-06-19 19:23:22 文章来源:博客园


(资料图片仅供参考)

(){","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":"overridefuncreate():Invocable{","marks":[]}]}]},{"type":"block","id":"PwG1-1687172537787","name":"code-line","data":{},"nodes":[{"type":"text","id":"0HMi-1687172537786","leaves":[{"text":"valfactory=NashornScriptEngineFactory()","marks":[]}]}]},{"type":"block","id":"OW8L-1687172537789","name":"code-line","data":{},"nodes":[{"type":"text","id":"dHCu-1687172537788","leaves":[{"text":"valparams=arrayOf(\"--loader-per-compile=false\")","marks":[]}]}]},{"type":"block","id":"HHJL-1687172537791","name":"code-line","data":{},"nodes":[{"type":"text","id":"8470-1687172537790","leaves":[{"text":"valengine=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":"returnengineasInvocable","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":"overridefunwrap(obj:Invocable):PooledObject{","marks":[]}]}]},{"type":"block","id":"AtZJ-1687172537804","name":"code-line","data":{},"nodes":[{"type":"text","id":"6r7U-1687172537803","leaves":[{"text":"returnDefaultPooledObject(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":{}}]">从报错内容很清楚是Metaspace区域oom了大部分情况下,程序运行中不会出现过多的类加载数量的变动,先导入dump文件检查是否有异常的classLoader或者有异常动态生成的class发现了下面这个classLoader数量异常,项目中用到nashorn这块js引擎来做动态js脚本执行通过查阅nashorn源码发现https://github.com/JetBrains/jdk8u_nashorn/blob/master/src/jdk/nashorn/internal/runtime/Context.java#L1304有_loader_per_compile参数可以控制ClassLoader的创建是否复用https://github.com/JetBrains/jdk8u_nashorn/blob/master/src/jdk/nashorn/internal/runtime/resources/Options.properties#L211-L216默认为true代表每次compile js脚本都会新创建一个classLoader,用下面的方式改造一下js引擎的创建方式改造前测试200次 发现创建了200个ScripLoader改造后测试发现ScriptLoader数量不再变化了
关键词:

热门推荐HOT

最近更新

猜你喜欢LOVE

Copyright @ 2001-2023 www.u74.cn All Rights Reserved 商业时报网 版权所有 关于我们

网站信息内容, 均为相关单位具有著作权,未经书面授权,转载注明出处
未经商业时报网书面授权,请勿建立镜像,转载请注明来源,违者依法必究

皖ICP备2022009963号-4
联系邮箱:39 60 29 14 2@qq.com

关于我们 | 联系方式 | 供稿服务 | 版权声明 | 友情链接 | 合作伙伴 |