Setting JVM maxperm size outside of Eclipse.ini - linux

I'm using eclipse64 3.7.1 with Linux RHEL5 64 I have 8gigs of ram.
No matter how large I set the
-Dosgi.requiredJavaVersion=1.5
-XX:MaxPermSize=1024M
-Xms1024m
-Xmx1024m
I continue to get errors like:
Error while logging event loop exception:
java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.
Is there anywhere else I can configure memory options that relate to eclipse and the JVM? Please help.

If you're getting that exception even after setting the max PermGen size to 1024M, it is likely that you have classloader leaks in your application. Increasing the PermGen size will mitigate these exceptions for a while but might not be very helpful for a long-running application.
You might find this article useful: http://blogs.oracle.com/fkieviet/entry/classloader_leaks_the_dreaded_java

Related

Running Jmeter script through jenkins Out of Memory error while generating report

I am facing an Out of Memory issue while running Jmeter script through Jenkins.The process is there is code written in framework that will convert the generated XML file result to CSV then HTML to Publish the report in dashboard.
I have already tried Increasing Heap space pf Jenkins server to 25 GB out of 32 GB.It seems Initially it takes 1 Gb then after some times it throws the error even though it still have 24 GB pf memory available in heap ,I ran free -h for this.
Also tried increasing Jmeter memory by
set HEAP=-Xms1g -Xmx8g -XX:MaxMetaspaceSize=512m
The script executed fine in Jnekins server which is on Windows.But it throsw error when the jenkin server is on Linux mode.
Hear is my error log.
/var/lib/jenkins/workspace/ITT2_Execution/Resources/csvReportPath/ITT2_Unicast_Broker_Download_count.xml/var/lib/jenkins/workspace/ITT2_Execution/Resources//Configuration/transformGaurav.xsl/var/lib/jenkins/workspace/ITT2_Execution/jmeter_reports/ITT2_Unicast_Broker_Download_2_Oct_2019_19_3_52_Count.html{titleReport=ITT2_Unicast_Broker_DownloadCountReport, dateReport=2-Oct-2019 22:02:38}
Finished Parsing
/var/lib/jenkins/workspace/ITT2_Execution/Resources/csvReportPath/AutomationReport_5.2.4.2018.20_2_Oct_2019_19_3_52_count.xml/var/lib/jenkins/workspace/ITT2_Execution/Resources//Configuration/transformGaurav.xsl/var/lib/jenkins/workspace/ITT2_Execution/jmeter_reports/AutomationReport_5.2.4.2018.20_2_Oct_2019_19_3_52.html{titleReport=nullCountReport, dateReport=2-Oct-2019 22:02:39}
JVMDUMP039I Processing dump event "systhrow", detail "java/lang/OutOfMemoryError" at 2019/10/02 18:33:10 - please wait.
JVMDUMP039I Processing dump event "systhrow", detail "java/lang/OutOfMemoryError" at 2019/10/02 18:33:10 - please wait.
JVMDUMP032I JVM requested Heap dump using '/var/lib/jenkins/workspace/ITT2_Execution/heapdump.20191002.183310.40181.0001.phd' in response to an event
JVMDUMP010I Heap dump written to /var/lib/jenkins/workspace/ITT2_Execution/heapdump.20191002.183310.40181.0001.phd
JVMDUMP032I JVM requested System dump using '/var/lib/jenkins/workspace/ITT2_Execution/core.20191002.183310.40181.0002.dmp' in response to an event
JVMDUMP010I System dump written to /var/lib/jenkins/workspace/ITT2_Execution/core.20191002.183310.40181.0002.dmp
JVMDUMP032I JVM requested Java dump using '/var/lib/jenkins/workspace/ITT2_Execution/javacore.20191002.183310.40181.0003.txt' in response to an event
JVMDUMP010I Java dump written to /var/lib/jenkins/workspace/ITT2_Execution/javacore.20191002.183310.40181.0003.txt
JVMDUMP032I JVM requested Snap dump using '/var/lib/jenkins/workspace/ITT2_Execution/Snap.20191002.183310.40181.0005.trc' in response to an event
JVMDUMP010I Snap dump written to /var/lib/jenkins/workspace/ITT2_Execution/Snap.20191002.183310.40181.0005.trc
JVMDUMP013I Processed dump event "systhrow", detail "java/lang/OutOfMemoryError".
JVMDUMP032I JVM requested Heap dump using '/var/lib/jenkins/workspace/ITT2_Execution/heapdump.20191002.183310.40181.0004.phd' in response to an event
JVMDUMP010I Heap dump written to /var/lib/jenkins/workspace/ITT2_Execution/heapdump.20191002.183310.40181.0004.phd
JVMDUMP032I JVM requested Java dump using '/var/lib/jenkins/workspace/ITT2_Execution/javacore.20191002.183310.40181.0006.txt' in response to an event
JVMDUMP010I Java dump written to /var/lib/jenkins/workspace/ITT2_Execution/javacore.20191002.183310.40181.0006.txt
JVMDUMP032I JVM requested Snap dump using '/var/lib/jenkins/workspace/ITT2_Execution/Snap.20191002.183310.40181.0007.trc' in response to an event
JVMDUMP010I Snap dump written to /var/lib/jenkins/workspace/ITT2_Execution/Snap.20191002.183310.40181.0007.trc
JVMDUMP013I Processed dump event "systhrow", detail "java/lang/OutOfMemoryError".
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:90)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:508)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:811)
Caused by: java.lang.OutOfMemoryError: Java heap space
at org.apache.xerces.xni.XMLString.toString(Unknown Source)
at org.apache.xerces.parsers.AbstractDOMParser.characters(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanCharReference(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at utils.APIReportProcessing.fetchAPIReportDetailModuleWise(APIReportProcessing.java:110)
at jmeterRun.RunProcess.prepareFinalResultsMerged(RunProcess.java:228)
at jmeterRun.ControllerJMeter.main(ControllerJMeter.java:139)
... 6 more
[WARNING] Attempt to (de-)serialize anonymous class hudson.maven.reporters.MavenArtifactArchiver$2; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
[WARNING] Attempt to (de-)serialize anonymous class hudson.maven.reporters.MavenFingerprinter$1; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/
Thanks
Bibek
The JMeter process runs in the Java Virtual Machine (JVM) under various settings and arguments. The Java Heap Space (as referred to in the error message) is the memory the JVM takes from the underlying operating system to allocate space for the creation of necessary objects.
JMeter’s default configuration (see jmeter.bat for Windows or jmeter for non-Windows systems scripts) assumes a heap space of 512 megabytes only. This is actually pretty low considering many modern smartphones have up to four times more! If your test is running massive objects which go over 512Mb, you’ll get an OOM error and your test will fail.
Fortunately, there’s a simple solution. Just increase the maximum heap size to ~80% of your total available physical RAM. To do this, find the following line in your JMeter startup script:
HEAP="-Xms1g -Xmx25g"
Now change the -Xmx value accordingly. For example: if you want to set the maximum heap size to 25 gigabytes, you’ll need to change the line to:
HEAP="-Xms1g -Xmx25g"
To apply the change, you’ll need to restart JMeter.
As per Understand the OutOfMemoryError Exception article:
Exception in thread thread_name: java.lang.OutOfMemoryError: Java heap space
Cause: The detail message Java heap space indicates object could not be allocated in the Java heap. This error does not necessarily imply a memory leak. The problem can be as simple as a configuration issue, where the specified heap size (or the default size, if it is not specified) is insufficient for the application.
In other cases, and in particular for a long-lived application, the message might be an indication that the application is unintentionally holding references to objects, and this prevents the objects from being garbage collected. This is the Java language equivalent of a memory leak. Note: The APIs that are called by an application could also be unintentionally holding object references.
One other potential source of this error arises with applications that make excessive use of finalizers. If a class has a finalize method, then objects of that type do not have their space reclaimed at garbage collection time. Instead, after garbage collection, the objects are queued for finalization, which occurs at a later time. In the Oracle Sun implementation, finalizers are executed by a daemon thread that services the finalization queue. If the finalizer thread cannot keep up, with the finalization queue, then the Java heap could fill up and this type of OutOfMemoryError exception would be thrown. One scenario that can cause this situation is when an application creates high-priority threads that cause the finalization queue to increase at a rate that is faster than the rate at which the finalizer thread is servicing that queue.
Action: You can find more information about how to monitor objects for which finalization is pending in Monitor the Objects Pending Finalization.
So use Java Memory Map tool to investigate the largest objects and what process do they belong to.
Also it appears you're running Jenkins on Linux or other Unix-like os while SET command is Windows-specific. In addition Jenkins doesn't respect HEAP environment variable, it uses JAVA_ARGS and/or JENKINS_JAVA_OPTIONS instead.
For JMeter:
HEAP="-Xms1g -Xmx8g" && export HEAP
For Jenkins:
JENKINS_JAVA_OPTIONS="-Xms1g -Xmx8g" && export JENKINS_JAVA_OPTIONS
More information:
How to add Java arguments to Jenkins?
9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure

GC graph shows there is a memory leak but unable to track in the dump

We have a Java Micorservice in our application which is connected to Postgres as well as Phoenix. We are using Spring Boot 2.x.
The problem is we are executing endurance testing for our application for about 8 hours and we could observe that the used heap is keep on increasing though we used the recommended suggestions for VM arguments, looks like a memory leak. we analysed the heap dump however the root cause is not exactly clear for us, can some experts help based on the results?
The VM arguments that we are actually using are:
-XX:ConcGCThreads=8 -XX:+DisableExplicitGC -XX:InitialHeapSize=536870912 -XX:InitiatingHeapOccupancyPercent=45 -XX:MaxGCPauseMillis=1000 -XX:MaxHeapFreeRatio=70 -XX:MaxHeapSize=536870912 -XX:MinHeapFreeRatio=40 -XX:ParallelGCThreads=16 -XX:+PrintAdaptiveSizePolicy -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:StringDeduplicationAgeThreshold=1 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC -XX:+UseStringDeduplication
We are expecting the used heap should be flat in the GC log, however memory consumption is not released and it keeps on increasing.
Heap Dump:
GC graph:
I'm not sure which tool you are using above, but I would be looking for the dominator hierarchy in the heap. Eclipse MAT is a good tool to analyse heap dumps and it can point you in the direction of what's actually holding the memory and you can decide if you want to categorise it as a leak or not. Regardless of the label you attach, if the application is going to crash after a while because it runs out of memory, then it is a problem.
This blog also discusses diagnosing this type of problems.

Expiring Daemon because JVM heap space is exhausted

I just updated the Android Studio to 3.5 Beta 1 and I'm getting
Expiring Daemon because JVM heap space is exhausted
message while the build is running. Also, the build is taking more time to complete. Does anyone have any idea regarding this?
This can be fixed by increasing the configured max heap size for the project.
Through IDE:
Add the below lines into the gradle.properties file. Below memory size (1) can be configured based on the RAM availability
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2560m
Through GUI:
In the Settings, search for 'Memory Settings' and increase the IDE max heap size and Daemon max heap size as per the system RAM availability.
(1)
$ man java
...
-Xmxsize
Specifies the maximum size (in bytes) of the memory allocation pool in bytes. This value
must be a multiple of 1024 and greater than 2 MB. Append the letter k or K to indicate
kilobytes, m or M to indicate megabytes, g or G to indicate gigabytes. The default value
is chosen at runtime based on system configuration. For server deployments, -Xms and
-Xmx are often set to the same value. See the section "Ergonomics" in Java SE HotSpot
Virtual Machine Garbage Collection Tuning Guide at
http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html.
The following examples show how to set the maximum allowed size of allocated memory to
80 MB using various units:
-Xmx83886080
-Xmx81920k
-Xmx80m
The -Xmx option is equivalent to -XX:MaxHeapSize.
...
I was able to solve this for my React Native project by configuring the following:
1. gradle.properties
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
2. app/build.gradle
android {
dexOptions {
javaMaxHeapSize "3g"
}
}
The solution is to increase Android build memory.
As you add more modules to your app, there is an incredible demand placed on the Android build system, and the default memory settings will not work. To avoid OutOfMemoryErrors during Android builds, you should uncomment the alternate gradle memory setting present in /android/gradle.properties:
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
You can find gradle.properties inside android folder.
P.S.
What we are doing this and why it helps?
Let me clear some basic terminology for understanding the whole thing.
Daemon : - A daemon is a computer program that runs as a background process, rather than being under the direct control of an interactive user.
Android Studio 2.1 enables a new feature: Dex In Process, that can dramatically increase the speed of full clean builds as well as improving Instant Run performance.
To take advantage of Dex In Process, you’ll need to modify your gradle.properties file and increase the amount of memory allocated to the Gradle Daemon VM by 1 Gb, to a minimum of 2 Gb, using the org.gradle.jvmargs property:
Specifies the JVM arguments used for the daemon process.
The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m
Default value:
-Xmx10248m -XX:MaxPermSize=256m
The default Gradle Daemon VM memory allocation is 1 gigabyte — which is insufficient to support dexInProcess, so to take advantage you’ll need to set it to at least 2 gigabytes.
Dex in process works by allowing multiple DEX processes to run within a single VM that’s also shared with Gradle, which is why you need to allocate the extra memory before it can be enabled — that memory will be shared between Gradle and multiple DEX processes.
If you’ve increased the javaMaxHeapSize in your module-level build.gradle file beyond the default of 1 gigabyte, you’ll need increase the memory assigned to the Gradle Daemon correspondingly.
When there’s enough memory assigned Dex in Process is enabled by default, improving overall build performance and removing the overhead of starting multiple parallel VM instances. The result is a significant improvement in all build times, including Instant Run, incremental, and full builds.
Source :
https://medium.com/google-developers/faster-android-studio-builds-with-dex-in-process-5988ed8aa37e
https://rnfirebase.io/#increasing-android-build-memory
Balance memory consumption and build speed using gradle options. For sample
Android Studio 2022.1.1 (PC RAM 16GB)
Gradle v7.3.3 (./gradle/wrapper/gradle-wrapper.properties)
AGP v7.2.0 (./build.gradle)
com.android.tools.build:gradle:7.2.0
Cache Fix Gradle Plugin
org.gradle.android.cache-fix:org.gradle.android.cache-fix.gradle.plugin:2.5.3
This Google Services dependency version supports Gradle Configuration Cache
com.google.gms:google-services:4.3.5
./gradle.properties
android.enableJetifier=true
android.jetifier.ignorelist=bcprov-jdk15on
android.useAndroidX=true
kapt.incremental.apt=true
kapt.use.worker.api=true
kotlin.daemon.jvm.options=-Xms1g -Xmx4g
manifestmerger.enabled=true
org.gradle.caching=true
org.gradle.configureondemand=true
org.gradle.daemon=true
org.gradle.jvmargs=-XX:InitialHeapSize=1g -XX:MaxHeapSize=6g -XX:MaxPermSize=2g -XX:MaxMetaspaceSize=2g -XX:NewSize=1g -XX:MaxNewSize=2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.unsafe.configuration-cache=true
org.gradle.unsafe.configuration-cache-problems=warn
Useful links:
https://proandroiddev.com/how-we-reduced-our-gradle-build-times-by-over-80-51f2b6d6b05b
https://developer.android.com/studio/build/profile-your-build#using-the-gradle---profile-option
In my case it was some kind of gradle bug probably. We had actually no memory problems, but the message kept on appearing. My solution was:
gradlew --no-daemon

How to analyze memory leaks in Java 8 compressed class space?

Some Context: We have upgraded the environment of a web application from running on Java 7 to running on Java 8 and Tomcat 8 (64-bit arch, Heap size about 2 GB, PermGen size=256 MB, no constraints on metaspace size). After a while, we started getting the following error:
java.lang.OutOfMemoryError: Compressed class space
which means that the space needed for UseCompressedClassPointers exceeded CompressedClassSpaceSize. At that moment VisualVM showed a 2 GB metaspace size.
Now with the VisualVM tool, we can see the Metaspace size is constatnly increasing with every request about 3 MB, however the heap does not seem to do so. The heap usage has a saw zigzag shape going back to the same low point after every GC.
I can tell that the application is leaking Metadata only when using a Java JAXB operation, but I couldn't prove it with VisualVM.
The application depends on webservices-rt-1.4 as a JAXB implementation provider. The application uses marshalling, unmarshalling. The class generation from XSD is done with maven-jaxb2-plugin-0.13.1.
Update:
After tracing class loading and unloading, I found out that the same JAXB classes is loaded into memory by WebAppClassLoader multiple times but never cleaned up. Moreover, there are no instances to them in the heap. I debugged and I saw that JDK is calls the method
javax.xml.bind.JAXBContext com.sun.xml.bind.v2.ContextFactory.createContext by reflection and that's when the class are created.
I though the classes are cleaned up by GC. Is it the responsibility of the classLoader to clean up?
Questions: Is there a way to analyze the metaspace objects? Why do I have a leak in metaspace but not in heap? aren't they related? Is that even possible?
Why would the app work fine with PermGen but not Metaspace?
I am facing similar issue.
In my case, memory leak was caused by JAXBContext.newInstance(...) invoke.
Solutions:
wrap this new instance as singleton (https://github.com/javaee/jaxb-v2/issues/581) or
use -Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true VM parameter, like in answer Old JaxB and JDK8 Metaspace OutOfMemory Issue
I had similar issue and adding -Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true in setenv.sh as JVM OPT arguments it resolve OOM metaspace issue.

how to check heap size allocated for jvm by linux

I have apache-tomcat as my web server.
I want to check what heap size is allocated for jvm by linux.
Also from where, I can modify it.
A simple way on Linux is to run the following:
ps -ef |grep tomcat
Look for the starting and maximum JVM memory:
-Xms1024m -Xmx4096m
In this case it is allocating 1G on startup and the Maximum is 4G.
You can easily check the heap size memory allocation using JConsole, if you have a path to your jre/jdk set up correctly on the system you should be able to start it with command jconsole from anywhere.
For managing your heap memory allocation you can have a look here: http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html
The heap size used by Tomcat is defined in its configuration.
This is the place where you can both check and change it.
If you're unsure about where this configuration is saved, I'd suggest looking at the Tomcat documentation where this is explained together with all configuration values.
If you need more information from the server but cannot log into it interactively (or don't have a GUI or JMX set up etc) you can include javamelody in your POM file/libs and it will create a page at host:8080//monitoring with all kinds of good information, including heap size, GC statistics and permgen size.
This is NOT a safe thing to leave running in a production environment - if you need it all the time at least lock it down!

Resources