Finding root cause of java.lang.OutOfMemoryError: Java heap space using Eclipse MAT

3.1k views Asked by At

I am trying to find out which method/loop has given java.lang.OutOfMemoryError: Java heap space in my app. I am pretty new to profiling java apps using Eclipse Memory Analyzer.

When Profiling for Memory Leaks is done with Eclipse MAT, using "Path To GC Roots" option displays as in attached Image:

In the Image, it is clear that calling JNI Local has Maximum Retained Heap, But we don't have any JNI calls in our app.

Please review and confirm whether the Memory Leak is caused by calling any Native code (JNI Local) or by using any string iterations or anything else?

for reference here I am attaching total overview and stacktrace of .hprof file:

Accumulated Objects by Class
Label   Number of Objects   Used Heap Size  Retained Heap Size
java.lang.String
First 10 of 15,252,128 objects  15,252,128  488,068,096     2,317,743,632
Thread Details

Thread WorkManager(2)-8

Thread Properties
Object / Stack Frame    java.lang.Thread @ 0x69af09608
Name    WorkManager(2)-8
Shallow Heap    112
Retained Heap   2,384,942,672
Context Class Loader    org.jboss.util.loading.DelegatingClassLoader @ 0x6912bf868
Is Daemon   true

    Total: 6 entries


Thread Stack

WorkManager(2)-8
  at java.lang.StringCoding.decode(Ljava/lang/String;[BII)[C (StringCoding.java:185)
  at java.lang.String.<init>([BIILjava/lang/String;)V (String.java:451)
  at java.lang.String.<init>([BLjava/lang/String;)V (String.java:523)
  at java.io.UnixFileSystem.list(Ljava/io/File;)[Ljava/lang/String; (Native Method)
  at java.io.File.list()[Ljava/lang/String; (File.java:990)
  at java.io.File.listFiles(Ljava/io/FilenameFilter;)[Ljava/io/File; (File.java:1107)
  at com.adobe.idp.dsc.service.file.impl.WatchedFolderUtils.resolveDuplicateFile(Ljava/lang/String;Z)Ljava/io/File; (WatchedFolderUtils.java:515)
  at com.adobe.idp.dsc.provider.service.file.write.impl.FileResultHandlerImpl.resolveDestination(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Ljava/io/File; (FileResultHandlerImpl.java:308)
  at com.adobe.idp.dsc.provider.service.file.write.impl.FileResultHandlerImpl.preserveFiles(Lcom/adobe/idp/dsc/registry/infomodel/Endpoint;Ljava/lang/String;Ljava/lang/String;)V (FileResultHandlerImpl.java:817)
  at com.adobe.idp.dsc.provider.service.file.write.impl.FileResultHandlerImpl.saveResults(Lcom/adobe/idp/dsc/InvocationResponse;Lcom/adobe/idp/dsc/registry/infomodel/Endpoint;Ljava/lang/String;Ljava/lang/String;)V (FileResultHandlerImpl.java:493)
  at com.adobe.idp.dsc.provider.service.file.write.impl.FileResultHandlerImpl.handleSuccess(Ljava/lang/Object;Ljava/util/Map;)V (FileResultHandlerImpl.java:104)
  at com.adobe.idp.dsc.provider.service.file.write.impl.FileResultHandlerImpl.handleSuccess(Lcom/adobe/idp/dsc/InvocationResponse;)V (FileResultHandlerImpl.java:73)
  at sun.reflect.GeneratedMethodAccessor2229.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (Method.java:616)
  at com.adobe.idp.dsc.component.impl.DefaultPOJOInvokerImpl.invoke(Lcom/adobe/idp/dsc/InvocationRequest;)Lcom/adobe/idp/dsc/InvocationResponse; (DefaultPOJOInvokerImpl.java:118)
  at com.adobe.idp.dsc.interceptor.impl.InvocationInterceptor.intercept(Lcom/adobe/idp/dsc/component/ComponentContext;Lcom/adobe/idp/dsc/InvocationRequest;Lcom/adobe/idp/dsc/interceptor/RequestInterceptorChain;)Lcom/adobe/idp/dsc/InvocationResponse; (InvocationInterceptor.java:140)
  at com.adobe.idp.dsc.interceptor.impl.RequestInterceptorChainImpl.proceed(Lcom/adobe/idp/dsc/component/ComponentContext;Lcom/adobe/idp/dsc/InvocationRequest;)Lcom/adobe/idp/dsc/InvocationResponse; (RequestInterceptorChainImpl.java:60)
  at com.adobe.idp.dsc.interceptor.impl.DocumentPassivationInterceptor.intercept(Lcom/adobe/idp/dsc/component/ComponentContext;Lcom/adobe/idp/dsc/InvocationRequest;Lcom/adobe/idp/dsc/interceptor/RequestInterceptorChain;)Lcom/adobe/idp/dsc/InvocationResponse; (DocumentPassivationInterceptor.java:53)
  at com.adobe.idp.dsc.interceptor.impl.RequestInterceptorChainImpl.proceed(Lcom/adobe/idp/dsc/component/ComponentContext;Lcom/adobe/idp/dsc/InvocationRequest;)Lcom/adobe/idp/dsc/InvocationResponse; (RequestInterceptorChainImpl.java:60)
  at com.adobe.idp.dsc.transaction.interceptor.TransactionInterceptor$1.doInTransaction(Lcom/adobe/idp/dsc/transaction/TransactionContext;)Ljava/lang/Object; (TransactionInterceptor.java:74)
  at com.adobe.idp.dsc.transaction.impl.ejb.adapter.EjbTransactionCMTAdapterBean.execute(Lcom/adobe/idp/dsc/transaction/TransactionContext;Lcom/adobe/idp/dsc/transaction/TransactionCallback;)Ljava/lang/Object; (EjbTransactionCMTAdapterBean.java:357)
  at com.adobe.idp.dsc.transaction.impl.ejb.adapter.EjbTransactionCMTAdapterBean.doSupports(Lcom/adobe/idp/dsc/transaction/TransactionDefinition;Lcom/adobe/idp/dsc/transaction/TransactionCallback;)Ljava/lang/Object; (EjbTransactionCMTAdapterBean.java:227)
  at sun.reflect.GeneratedMethodAccessor698.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (Method.java:616)
  at org.jboss.invocation.Invocation.performCall(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object; (Invocation.java:386)
  at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (StatelessSessionContainer.java:233)
  at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (CachedConnectionInterceptor.java:156)
  at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (StatelessSessionInstanceInterceptor.java:173)
  at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (CallValidationInterceptor.java:63)
  at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(Lorg/jboss/invocation/Invocation;Z)Ljava/lang/Object; (AbstractTxInterceptor.java:121)
  at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (TxInterceptorCMT.java:378)
  at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (TxInterceptorCMT.java:181)
  at org.jboss.ejb.plugins.SecurityInterceptor.process(Lorg/jboss/invocation/Invocation;Z)Ljava/lang/Object; (SecurityInterceptor.java:228)
  at org.jboss.ejb.plugins.SecurityInterceptor.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (SecurityInterceptor.java:211)
  at org.jboss.ejb.plugins.security.PreSecurityInterceptor.process(Lorg/jboss/invocation/Invocation;Z)Ljava/lang/Object; (PreSecurityInterceptor.java:97)
  at org.jboss.ejb.plugins.security.PreSecurityInterceptor.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (PreSecurityInterceptor.java:81)
  at org.jboss.ejb.plugins.LogInterceptor.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (LogInterceptor.java:205)
  at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (ProxyFactoryFinderInterceptor.java:138)
  at org.jboss.ejb.SessionContainer.internalInvoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (SessionContainer.java:650)
  at org.jboss.ejb.Container.invoke(Lorg/jboss/invocation/Invocation;)Ljava/lang/Object; (Container.java:1092)
  at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object; (BaseLocalProxyFactory.java:436)
  at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object; (StatelessSessionProxy.java:103)
  at $Proxy289.doSupports(Lcom/adobe/idp/dsc/transaction/TransactionDefinition;Lcom/adobe/idp/dsc/transaction/TransactionCallback;)Ljava/lang/Object; (Unknown Source)
  at com.adobe.idp.dsc.transaction.impl.ejb.EjbTransactionProvider.execute(Lcom/adobe/idp/dsc/transaction/TransactionDefinition;Lcom/adobe/idp/dsc/transaction/TransactionCallback;)Ljava/lang/Object; (EjbTransactionProvider.java:104)
1

There are 1 answers

0
Holger On

Your stacktrace shows the method UnixFileSystem.list(File) which is a native method and it’s creating a string array for storing the file names. The remaining question is why it is creating an array of size 16 million. The method starts with an array of size 16 and will double it once the directory scan has more iterations than the array size. So the number of iterations now are between 8 million and 16 million. You either have that unbelievable number of files in that directory or there is a problem in the loop termination condition in that native code.