Recently I started getting PermGen space issue in my new jasper report application when tested under heavy load. I'm using groovy as expression evaluator for reports, by specifying language="groovy in my jrxml file. As groovy expressions, create classes at runtime, I'm suspecting this to be the root cause for permgen filling up. I tried up setting up jvm options like -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled , but it did not help in solving the problem. Even in excpetion stacktrace (given below) also, classloader is trying to load the newly built class into permgen at the time of failure. Has anyone experienced this problem using groovy with jasper reports? My reports get filled asynchronously in a separate thread using capabalities provided by AsynchronousFillHandle class provided by jasper. Does this have any connection towards the classloader not releasing the loaded runtime classes? Any suggestions would be greatly appreciated.
Exception in thread "Thread-563" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-565" at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.define(ClassLoaderForClassArtifacts.java:42)
at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:86)
at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:84)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.defineClassAndGetConstructor(ClassLoaderForClassArtifacts.java:84)
at org.codehaus.groovy.runtime.callsite.CallSiteGenerator.compilePogoMethod(CallSiteGenerator.java:215)
at org.codehaus.groovy.reflection.CachedMethod.createPogoMetaMethodSite(CachedMethod.java:220)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.createCachedMethodSite(PogoMetaMethodSite.java:206)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.createPogoMetaMethodSite(PogoMetaMethodSite.java:182)
at groovy.lang.MetaClassImpl.createPogoCallCurrentSite(MetaClassImpl.java:3034)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallCurrentSite(CallSiteArray.java:93)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
at Section_1_1348126593121_343308.evaluate(calculator_Section_1_1348126593121_343308:253)
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:190)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)
at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:884)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:421)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:406)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:257)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:457)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2037)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:771)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportContent(JRVerticalFiller.java:301)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:148)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
As a first bet...
Try to increase the perm gen size, like this:
-XX:MaxPermSize=128m
By default its 64m.
Hope this helps
Related
on ubuntu 14.04, using openJDK8, When i start jprofiler, it has some error like below.
I struggle one day, at last still failed to start it.
java.lang.ExceptionInInitializerError
at java.awt.Component.<clinit>(Component.java:593)
at javax.swing.ImageIcon$2.run(ImageIcon.java:130)
at javax.swing.ImageIcon.<clinit>(ImageIcon.java:100)
at com.jprofiler.frontend.ab.a(ejt:315)
at com.jprofiler.frontend.ab.<clinit>(ejt:47)
at com.jprofiler.frontend.FrontendApplication.E(ejt:1038)
at com.jprofiler.frontend.IntegrationApplication.main(ejt:8)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.exe4j.runtime.LauncherEngine.launch(LauncherEngine.java:85)
at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:62)
Caused by: java.lang.NullPointerException
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1847)
at java.awt.Toolkit.loadLibraries(Toolkit.java:1633)
at java.awt.Toolkit.<clinit>(Toolkit.java:1670)
... 20 more
java.lang.NoClassDefFoundError: Could not initialize class java.awt.Toolkit
at javax.swing.ImageIcon.<init>(ImageIcon.java:198)
at javax.swing.ImageIcon.<init>(ImageIcon.java:217)
at com.ejt.framework.gui.eo.<init>(ejt:37)
at com.ejt.framework.gui.eo.a(ejt:17)
at com.jprofiler.frontend.ab.a(ejt:315)
at com.jprofiler.frontend.ab.<clinit>(ejt:47)
at com.jprofiler.frontend.FrontendApplication.E(ejt:1038)
at com.jprofiler.frontend.IntegrationApplication.main(ejt:8)
at com.install4j.runtime.launcher.UnixLauncher.main(UnixLauncher.java:62)
This a new problem with Java 8u242. It will be fixed shortly in JProfiler 11.1.1. The temporary workaround is to run JProfiler with a different JRE.
Since there is some interest, I will explain what the bug was:
The reason for this bug is that JProfiler set the private field ClassLoader.sys_paths to null to force a reevaluation of the java.library.path system property. This was a common hack to add directories to the library pack so that dependent native libraries could be loaded. Since a commit that was released as part of 8u242, the new private method ClassLoader.initLibraryPaths()has to be called after setting that field to null, otherwise no native libraries can be loaded.
Suddenly my project gets an error when deploying. The error I get is Caused by: java.lang.OutOfMemoryError: Metaspace and I've read one possibility is to change the metaspace max size with this line of code:
-XX:MaxMetaspaceSize=3200m
In which file I need to put this option? Also there is a better way whithout modifying default settings?
-XX:MaxMetaspaceSize=3200m is java argument. You have to add it to all other arguments like -cp.
Which file is depends on how you start your application.
In my application I'm creating lots of java classes at runtime with javassist library. At some point a java.lang.OutOfMemoryError: Metaspace is thrown but java process monitoring (based on java.lang.management.MemoryPoolMXBean) reports that there is plenty of free metaspace. Why is that? And how to use 100% of metaspace memory pool?
I've created a minimal application that reproduces the problem https://github.com/vlkv/java_metaspace_oom
Donwload it, cd to the project dir and then execute 'ant run'. In this app, I've set -XX:MaxMetaspaceSize=100m, but OOM is thrown at some point around 23564Kb of metaspace used.
Call stack of the error is:
javassist.CannotCompileException: by java.lang.OutOfMemoryError: Metaspace
at javassist.ClassPool.toClass(ClassPool.java:1170)
at javassist.CtClass.toClass(CtClass.java:1316)
at com.tradingview.Main.generateRandomClass(Main.java:53)
at com.tradingview.Main.main(Main.java:24)
Caused by: java.lang.OutOfMemoryError: Metaspace
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at javassist.ClassPool.toClass2(ClassPool.java:1183)
at javassist.ClassPool.toClass(ClassPool.java:1164)
... 3 more
Wow, I've just found an answer.
The problem is that in my application I create a separate new ClassLoader for every generated Class. I've done a modification in my sample app that puts all the generated classes to one ClassLoader and after that, OOM is thrown at the point when free metaspace is almost zero. The fix is here https://github.com/vlkv/java_metaspace_oom/commit/d6bcade51f79758e2413d1852c771f163392c294 branch fix_of_the_problem
Does somebody knows about what are the limits for class loaders in java process? And how to increase them?
Also found this Why MetaSpace Size is twice as big as Used MetaSpace?
I am getting this java.lang.OutOfMemoryError: PermGen space Exception. I am using Eclipse Juno and Tomcat 7.0. This Exception occurs at least once in every 10-15 Minutes in a console. How to resolve it?
Feb 25, 2016 10:23:23 AM org.springframework.beans.factory.support.DefaultListableBeanFactory destroyBean
SEVERE: Destroy method on bean with name 'mvcUrlPathHelper' threw an exception
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2895)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2895)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:375)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:242)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:925)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:932)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:997)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:547)
Feb 25, 2016 10:23:24 AM org.springframework.beans.factory.support.DefaultListableBeanFactory destroyBean
SEVERE: Destroy method on bean with name 'mvcPathMatcher' threw an exception
java.lang.OutOfMemoryError: PermGen space
Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space
What is java.lang.OutOfMemoryError: PermGen space?
Ans:
The java.lang.OutOfMemoryError: PermGen space message indicates that the Permanent Generation’s area in memory is exhausted.
Any Java applications is allowed to use a limited amount of memory. The exact amount of memory your particular application can use is specified during application startup.
Java memory is separated into different regions which can be seen in the following image:
What will be the solution for this error PermGen space?
Ans:
For Heap,
export JVM_ARGS="-Xms1024m -Xmx1024m"
For Permgen,
JVM_ARGS="-XX:PermSize=512M -XX:MaxPermSize=512m"
You can give also additional section
-XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC XX:+CMSClassUnloadingEnabled
You can also give more additional section :)
-XX:PermSize=512m -XX:MaxPermSize=512m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -XX:SurvivorRatio=2 -XX:MaxTenuringThreshold=128 -XX:TargetSurvivorRatio=90 -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:+CMSIncrementalPacing -XX:CMSIncrementalDutyCycleMin=0 -XX:CMSIncrementalDutyCycle=10 -XX:+UseTLAB -XX:+CMSParallelRemarkEnabled -XX:+CMSClassUnloadingEnabled
Metaspace: A new memory space is born
The JDK 8 HotSpot JVM is now using native memory for the representation of class metadata and is called Metaspace; similar to the Oracle JRockit and IBM JVM's.
The good news is that it means no more java.lang.OutOfMemoryError: PermGen space problems and no need for you to tune and monitor this memory space anymore.
Related Link:
https://plumbr.eu/outofmemoryerror/java-heap-space
https://plumbr.eu/outofmemoryerror/permgen-space
http://stas-blogspot.blogspot.in/2011/07/most-complete-list-of-xx-options-for.html#UseConcMarkSweepGC
https://www.javacodegeeks.com/2013/12/decoding-java-lang-outofmemoryerror-permgen-space.html
http://www.javavillage.in/reasons-outofmemory-permespace.php
Dealing with "java.lang.OutOfMemoryError: PermGen space" error
Java 8 Links
What is the use of MetaSpace in Java 8?
https://blogs.oracle.com/poonam/entry/about_g1_garbage_collector_permanent
https://plumbr.eu/outofmemoryerror/metaspace
https://dzone.com/articles/java-8-permgen-metaspace
It is easy to configure Java for more PermGenSpace but I would recommend to migrate to Java 1.8 runtime instead. Install Java 8 SDK and add two lines like
-vm
D:/jdk8/jre/bin/javaw.exe
to eclipse.ini. This problem is fixed starting from Java 1.8 and does not longer require any hacks.
Instead making changes in eclipse.ini, its better to install Java 8.
I Installed Java 8 and now I am not getting java.lang.OutOfMemoryError: PermGen space Exception.
Here is the below Errors occurred while running java webapplication:-
INFO: Initializing Spring root WebApplicationContext
2014-11-02 23:26:35,690 ERROR org.springframework.web.context.ContextLoader - Context initialization failed
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1850)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1850)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:211)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:385)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1138)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1177)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:222)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:505)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:362)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3934)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4429)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
Will anyone help me to solve this error? Is there any possibility to solve this problem?
Tomcat has limited JVM PermGen space to manage all the applications running on it, thus when you say redeploy a application without managing the permgen properly it will consume more and more of it until it crashes, requiring full server restart.
T
his article has explanations on how to manage this problem.
http://www.mkyong.com/tomcat/tomcat-javalangoutofmemoryerror-permgen-space/
Naturally more powerful servers/workstations will not see this error as quickly and have more room to move with (regarding configuration).
e.g. my weakling laptop gets the permgen error after 10 redployments, where as my main server can do unlimited due to proper management and resource availability.
If it's running within Eclipse perhaps you need to set the Eclipse permgen:
Increasing heap space in Eclipse: (java.lang.OutOfMemoryError)