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.
Related
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?
For 3 days now, I have been trying to install glassfish 4.1 on eclipse Luna version 4.4.1. I first installed the plugin from eclipse marketplace then added it in my runtime using jdk 8. I also made jdk my default since eclipse default uses jre. I have to point out that I have been been using glassfish on netbeans and tomcat on eclipse but I decided to play around with glassfish on eclipse. Every information I got on the internet didn't fix my issue.
Below is the error I got in the console. Right now, this is driving me nuts so I have decided to come to you for direction.
Thanks
Launching GlassFish on Felix platform
ERROR: Unable to create cache directory: C:\Program Files\glassfish-4.1\glassfish\domains\domain1\osgi-cache\felix
ERROR: Error creating bundle cache. (java.lang.RuntimeException: Unable to create cache directory.)
java.lang.RuntimeException: Unable to create cache directory.
at org.apache.felix.framework.cache.BundleCache.<init>(BundleCache.java:131)
at org.apache.felix.framework.Felix.init(Felix.java:640)
at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiFrameworkLauncher$1.run(OSGiFrameworkLauncher.java:88)
Exception in thread "Thread-1" java.lang.RuntimeException: org.osgi.framework.BundleException: Error creating bundle cache.
at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiFrameworkLauncher$1.run(OSGiFrameworkLauncher.java:90)
Caused by: org.osgi.framework.BundleException: Error creating bundle cache.
at org.apache.felix.framework.Felix.init(Felix.java:645)
at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiFrameworkLauncher$1.run(OSGiFrameworkLauncher.java:88)
Caused by: java.lang.RuntimeException: Unable to create cache directory.
at org.apache.felix.framework.cache.BundleCache.<init>(BundleCache.java:131)
at org.apache.felix.framework.Felix.init(Felix.java:640)
... 1 more
Exception in thread "main" java.lang.reflect.InvocationTargetException
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:483)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain.main(GlassFishMain.java:97)
at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:54)
Caused by: org.glassfish.embeddable.GlassFishException: java.lang.NullPointerException
at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishRuntimeBuilder.build(OSGiGlassFishRuntimeBuilder.java:170)
at org.glassfish.embeddable.GlassFishRuntime._bootstrap(GlassFishRuntime.java:157)
at org.glassfish.embeddable.GlassFishRuntime.bootstrap(GlassFishRuntime.java:110)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain$Launcher.launch(GlassFishMain.java:112)
... 6 more
Caused by: java.lang.NullPointerException
at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishRuntimeBuilder.newFramework(OSGiGlassFishRuntimeBuilder.java:241)
at com.sun.enterprise.glassfish.bootstrap.osgi.OSGiGlassFishRuntimeBuilder.build(OSGiGlassFishRuntimeBuilder.java:135)
... 9 more
Error stopping framework: java.lang.NullPointerException
java.lang.NullPointerException
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain$Launcher$1.run(GlassFishMain.java:203)
Java HotSpot(TM) Client VM warning: ignoring option MaxPermSize=192m; support was removed in 8.0
Run Eclipse or any other IDE you use in Administrator mode.
Works for me.
I think your comment deserves to be posted as the main answer but I have been trying to mark your comment as answer but I wash't able to. So I decided to post post your comment here and then back it up with my own experience.
Answer by unwichtich:
I guess this is a similar problem. The cause may be that you have installed Glassfish in c:\Program Files. You can try to move your Glassfish installation to a directory where your normal user account has full access rights but you then have to change the path to the Glassfish installation in Eclipse.
My own experience:
Turns out that all the problems I had with the glassfish server (including exit code 1 error) was because glassfish could not handle folder names with spaces in it. So I moved the glassfish-4.1 folder from C:\Program File\glassfish-4.1.. path to C:\ glassfish-4.1.. It wiped all my tears away. This is really important in eclipse and netbeans IDEs (if you are installing the netbeans that does not come with a glassfish bundled zip).
I had the same problem and fixed it by installing Glassfish under C:\ instead of C:\Program Files. Try that.
use JDk 7 instead of JDK 8 am also faced the same issue i just changed to jdk7 its working now.
I try to run nvvp for profiling cuda code in command line
nvvp ./my_app
But ,I get following error
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
I understand problem is with java not able to allocate sufficient heap to run the app. Based on what I read about this issue in SO (and else where in internet) I try following
java -Xmx128m nvvp ./myapp
It doesn't solve my problem and I get following message
Exception in thread "main" java.lang.NoClassDefFoundError: nvvp
Caused by: java.lang.ClassNotFoundException: nvvp
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:264)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332)
Could not find the main class: nvvp. Program will exit.
This is following that worked in my case
setenv _JAVA_OPTIONS "-Xms512m -Xmx1024m"
However, _JAVA_OPTIONS seemingly can have multiple names across the different systems, hence find the right one before using it. It shows following while it has picked up correct variable
nvvp ./cb_dgemm_prof
Picked up _JAVA_OPTIONS: -Xms512m -Xmx1024m
If variable is not set up properly, you might not see the line above.
This message says that JVM was not able to allocate enough memory for the heap from OS, -Xmx/-Xms will not help in this case.
Please answer the questions I posted in a comment so we could find what is causing this problem...
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
I am having intermittent issues saving the response HTML in HtmlUnit.
Caused by: java.io.IOException: Unable to save file:C:\ccview\PP50773_4.0_walter\TSC_hca\Applications\HCA_J2EE\HCA\target\HtmlUnitTests\single\1\com\pnc\tsc\hca\ui\test\SiteCrawler\crawlSiteAsProvider\10.SiteCrawler.crawl.html
at com.pnc.tsc.hca.ui.util.GetUtil.save(GetUtil.java:128)
at com.pnc.tsc.hca.ui.util.GetUtil.add(GetUtil.java:75)
at com.pnc.tsc.hca.ui.util.GetUtil.click(GetUtil.java:49)
at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:87)
at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:61)
at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:63)
at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:63)
at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:63)
at com.pnc.tsc.hca.ui.test.SiteCrawler.crawl(SiteCrawler.java:54)
at com.pnc.tsc.hca.ui.test.SiteCrawler.crawlSiteAsProvider(SiteCrawler.java:50)
... 15 more
Caused by: java.lang.RuntimeException: java.io.IOException: The system cannot find the path specified
at com.gargoylesoftware.htmlunit.html.XmlSerializer.getAttributesFor(XmlSerializer.java:165)
at com.gargoylesoftware.htmlunit.html.XmlSerializer.printOpeningTag(XmlSerializer.java:126)
at com.gargoylesoftware.htmlunit.html.XmlSerializer.printXml(XmlSerializer.java:83)
at com.gargoylesoftware.htmlunit.html.XmlSerializer.printXml(XmlSerializer.java:93)
at com.gargoylesoftware.htmlunit.html.XmlSerializer.printXml(XmlSerializer.java:93)
at com.gargoylesoftware.htmlunit.html.XmlSerializer.asXml(XmlSerializer.java:73)
at com.gargoylesoftware.htmlunit.html.XmlSerializer.save(XmlSerializer.java:55)
at com.gargoylesoftware.htmlunit.html.HtmlPage.save(HtmlPage.java:2259)
at com.pnc.tsc.hca.ui.util.GetUtil.save(GetUtil.java:126)
... 24 more
Caused by: java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)
at com.gargoylesoftware.htmlunit.html.XmlSerializer.createFile(XmlSerializer.java:216)
at com.gargoylesoftware.htmlunit.html.XmlSerializer.getAttributesFor(XmlSerializer.java:160)
... 32 more
Now, the parent directory exists and some other files have already been written to the directory. Looking at the filename, I don't see anything that would stand out as a red flag indicating the filename is bad.
What can I do to correct this error?
Thanks,
Walter
Well, you are well within the maximum path length. The exception trace clearly believes it is a path problem.
I would try some additional tests to help isolate the problem. Check the directory before writing with: File.exists(), File.isDirectory(), File.isWritable(). Similar checks on the file itself. May want to see if the disk is full too.
If you can get a little more information on the source of the problem, we can get it resolved.