Search code examples
mavenearjboss-eap-6dcevmhotswapagent

Hotswap-agent on JBoss EAP 6.1 - java.lang.OutOfMemoryError: PermGen space


I have an EAR project I'm deploying to Jboss EAP 6.1. The product of my maven build looks like this:

myapp-ear
├── myapp-ejb.jar
├── myapp-web.war
├── lib
│   ├── activation.jar
│   ├── activiti-bpmn-converter.jar
│   ├── activiti-bpmn-model.jar
.....
│   ├── xml-apis.jar
│   └── xmlbeans.jar
└── META-INF
    ├── application.xml
    ├── hotswap-agent.properties
    ├── myapp-ds.xml
    ├── jboss-deployment-structure.xml
    └── MANIFEST.MF

Here's what I get in the jboss log when when I deploy my app:

21:34:55,570 INFO  [stdout] (MSC service thread 1-5) HOTSWAP AGENT: 21:34:55.569 INFO (org.hotswap.agent.config.PluginRegistry) - Plugin 'org.hotswap.agent.plugin.jbossmodules.JBossModulesPlugin' initialized in ClassLoader 'ModuleClassLoader for Module "deployment.myapp-ds.xml:main" from Service Module Loader'.
21:35:04,357 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015876: Starting deployment of "null" (runtime-name: "myapp-web.war")
21:35:04,357 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "null" (runtime-name: "myapp-ejb.jar")
21:35:04,781 INFO  [org.jboss.as.jpa] (MSC service thread 1-3) JBAS011401: Read persistence.xml for myproject
21:35:05,306 INFO  [stdout] (MSC service thread 1-7) HOTSWAP AGENT: 21:35:05.306 INFO (org.hotswap.agent.config.PluginRegistry) - Plugin 'org.hotswap.agent.plugin.jbossmodules.JBossModulesPlugin' initialized in ClassLoader 'ModuleClassLoader for Module "deployment.myapp-ear.ear:main" from Service Module Loader'.

and

21:35:05,488 INFO  [stdout] (MSC service thread 1-6) HOTSWAP AGENT: 21:35:05.487 INFO (org.hotswap.agent.config.PluginRegistry) - Plugin 'org.hotswap.agent.plugin.hotswapper.HotswapperPlugin' initialized in ClassLoader 'ModuleClassLoader for Module "deployment.myapp-ear.ear.myapp-web.war:main" from Service Module Loader'.
21:35:05,520 INFO  [stdout] (MSC service thread 1-4) HOTSWAP AGENT: 21:35:05.517 INFO (org.hotswap.agent.config.PluginRegistry) - Plugin 'org.hotswap.agent.plugin.jbossmodules.JBossModulesPlugin' initialized in ClassLoader 'ModuleClassLoader for Module "deployment.myapp-ear.ear.myapp-ejb.jar:main" from Service Module Loader'.

The problem is that when I deploy my ear into jboss it takes about 10 times it's normal time and when I try to access the application from a browser it throws a "PermGen space: java.lang.OutOfMemoryError: PermGen space". I tired increasing my PermGen memory to 700MB but no luck. So I suspected that hotswap-agent is watching all the classes in my EAR including the ones in the lib directory which's causing it to consume too much memory.

The next place I looked into is disabling hotswap by default, by placing autoHotswap=false in hotswap-agent.properties. I tried placing this file in the EAR as shown above and the EJB and WAR classpaths but it didn't make any difference. I also tried, to no avail, adding to the JVM_OPTS like so:

-javaagent:/workspace/tools/hotswap-agent-1.0.jar=disablePlugin=Deltaspike,disablePlugin=JavaBeans,autoHotswap=false"

So my question is, how does one control the hotswap-agent in my environment? Also is there a way to only watch classes in a specified package, say "com.foobar"? Finally, what's the right way to configure hotswap-agent for an ear deployment on jboss.


Solution

  • Finally got hotswap-agent working in my project with the help of Vladimir in the hotswap-agent forum. This what he said that helped solve the runaway PermGen memory:

    JBossAS has single classLoader for each module like jar, war etc. On that account there can be a lot of module classloaders in the running JbossAS. Alongside HotswapAgent copies it's classes to each of that module classloaders (it is necessary otherwise HotswapAgent doesn't work inside module classloader). Hence the same HotswapAgent's class can be loaded by JVM multiple times ! As far as the copying of globaly disabled plugin, it is bug, we should fix it. You can just remove unused plugins directly from hotswap-agent.jar as a workaround, it should help with performance.

    Once I removed the unneeded plugins from the jar I could start jboss within reasonable time and PermGen memory.