JVM标志CMSClassUnloadingEnabled实际上做了什么? [英] What does JVM flag CMSClassUnloadingEnabled actually do?

查看:250
本文介绍了JVM标志CMSClassUnloadingEnabled实际上做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能为我的生活找到Java VM标志 CMSClassUnloadingEnabled 实际上做的定义,除了一些非常模糊的高级定义,如摆脱您的PermGen问题(它没有,顺便说一句。

I cannot for the life of me find a definition of what the Java VM flag CMSClassUnloadingEnabled actually does, other than some very fuzzy high-level definitions such as "gets rid of your PermGen problems" (which it doesn't, btw).

我查看了Sun的/ Oracle网站,甚至选项列表实际上并没有说出它的作用。

I have looked on Sun's/Oracle's site, and even the options list doesn't actually say what it does.

基于名称标志,我猜测CMS垃圾收集器默认情况下没有卸载类,这个标志打开它 - 但我不能确定。

Based upon the name of the flag, I'm guessing that the CMS Garbage Collector doesn't by default unload classes, and this flag turns it on - but I can't be sure.

推荐答案

更新这个答案与Java 5-7相关,Java 8修复了这个问题: https://blogs.oracle.com/poonam/about-g1-garbage-collector,-permanent-generation-and-metaspace 荣誉转到 mt.uulu

Update This answer is relevant for Java 5-7, Java 8 has this fixed: https://blogs.oracle.com/poonam/about-g1-garbage-collector,-permanent-generation-and-metaspace Kudos go to mt.uulu

对于Java 5-7:

For Java 5-7:

世界上标准的Oracle / Sun VM外观是:类是永远的。因此,一旦加载,即使没有人关心,它们也会留在记忆中。这通常没有问题,因为你没有那么多纯粹的设置类(=一次用于安装,然后再没有用过)。因此,即使他们占用1MB,谁也在乎。

The standard Oracle/Sun VM look on the world is: Classes are forever. So once loaded, they stay in memory even if no one cares anymore. This usually is no problem since you don't have that many purely "setup" classes (= used once for setup and then never again). So even if they take up 1MB, who cares.

但是最近,我们有像Groovy这样的语言,它们在运行时定义了类。每次运行脚本时,都会创建一个(或多个)新类,它们永远保留在PermGen中。如果您正在运行服务器,则意味着您有内存泄漏。

But lately, we have languages like Groovy, that define classes at runtime. Every time you run a script, one (or more) new classes are created and they stay in PermGen forever. If you're running a server, that means you have a memory leak.

如果启用 CMSClassUnloadingEnabled GC也将扫除PermGen,并删除不再使用的类。

If you enable CMSClassUnloadingEnabled the GC will sweep PermGen, too, and remove classes which are no longer used.

您还必须启用 UseConcMarkSweepGC (感谢 Sam Hasler )。请参阅此答案: https://stackoverflow.com/a/372​​0052/2541

You will also have to enable UseConcMarkSweepGC (thanks to Sam Hasler). See this answer: https://stackoverflow.com/a/3720052/2541

这篇关于JVM标志CMSClassUnloadingEnabled实际上做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆