Sunday, May 31, 2020

How to Setup a Standalone Memory Analyzer for Windows 10

The Eclipse Memory Analyzer is a fast and feature-rich Java heap analyzer that helps you find memory leaks and analyze high memory consumption issues.

Standalone vs Plug-ins


You can install the Memory Analyzer into an Eclipse IDE (see [1]).  However, a standalone Memory Analyzer is useful if you do not want to install a full-fledged IDE on the system you are running the heap analysis.  To download a standalone Memory Analyzer, click here.

Prerequisite


For this illustration, we have downloaded
Eclipse Memory Analyzer Version 1.10.0 ―Windows (x86_64)
which requires a minimum Java version of 1.8.0.

Setups


After unzipping the file, a new folder named mat was created:
C:\Users\<username>\Downloads\mat

You can create a Windows Command Script (.cmd) with the same name in the same folder using the following content:

set PATH=C:\Program Files\Java\jdk-10\bin;
start MemoryAnalyzer.exe

To avoid running MAT with the wrong JRE, we have set its PATH environment variable pointing to a JDK installation with Java version of 18.3.0:

$ cd "/cygdrive/c/Program Files/Java/jdk-10/bin"
$ ./java.exe --version
java 10 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)

To enable MAT handling large heap dumps (i.e., .hprof), you may increase the heap size of MAT runtime by changing its MemoryAnalyzer.ini in the same folder:[7]

-startup
plugins/org.eclipse.equinox.launcher_1.5.0.v20180512-1130.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.700.v20180518-1200
-vmargs
-Xmx10g

For example, we have set its max heap size to be 10 GB.

Getting a Heap Dump


The Memory Analyzer can work with HPROF binary formatted heap dumps. Those heap dumps are written by HotSpot and any VM derived from HotSpot. Depending on your scenario, your OS platform and your JDK version, you may have different options to acquire a heap dump.[2]

As a developer, you want to trigger a heap dump on demand. On Windows, use JDK and JConsole. On Linux and Mac OS X, you can also use jmap or jcmd that comes with JDK.


Via MAT:

Via Java VM parameters:
  • -XX:+HeapDumpOnOutOfMemoryError  –XX:HeapDumpPath=[file path]
    • writes heap dump on the first Out Of Memory Error (recommended)
  • -XX:+HeapDumpOnCtrlBreak 
    • writes heap dump together with thread dump on CTRL+BREAK
    • -XX:+HeapDumpOnCtrlBreak in HotSpot JVM (by Sun/Oracle) is present in 1.4.2_12 or higher and 1.5.0_14 or higher. For JVMs 1.6, 1.7, 1.8 this option is no more present, but you can use the "jmap" or "jcmd" tools.

Via Tools:
  • jmap
    • jmap -dump:format=b,file=snapshot.jmap <process id>
    • It is recommended to use the latest utility jcmd instead of jmap utility for enhanced diagnostics and reduced performance overhead. 
  • jcmd
    • jcmd <process id/main class> GC.heap_dump Myheapdump
  • JConsole
    • Launch jconsole.exe and invoke operation dumpHeap() on HotSpotDiagnostic MBean
  • SAP JVMMon
    • Launch jvmmon.exe and call menu for dumping the heap
Example 1 Create a Heap Dump using jmap

bash-4.2$ ${JAVA_HOME}/bin/jmap -dump:format=b,file=MyJmapHeapdump.hprof 82734
Dumping heap to /tmp/NM_OOM/MyJmapHeapdump.hprof ...
Heap dump file created

Example 2 Create a Heap Dump using jcmd

$ /bi/app/jdk/bin/jcmd 82734 GC.heap_dump MyJcmdHeapdump.hprof
82734:
Heap dump file created

Notes

  • By default, the heap dump will be generated in the "current directory" of the Java application.[6] 
    • jmap generates heap dump in the directory where you run jmap, which is different from jcmd's behavior.
  • The dump file can be huge, up to Gigabytes, so ensure that the target file system has enough space.
  • Need to login as the same user as your process' to attach to it

References

24 comments:

  1. Nice blog on the web. Today, Emblix solutions as one of the best and top most service-oriented Digital Marketing Agency in Hyderabad and India, Which provides high-quality result-oriented Digital Services ranging from SEO to Web Design, Social Media Marketing and more,

    ReplyDelete
  2. Putlocker may be a seamless portal for television, series, movies, songs, etc. for free. it's not mainly for any film or language, from Hollywood to Bollywood, one can have access to each possible movie. In fact, unlike other portals who operate completely illegally, Putlocker has an official site named Putlocker.com that a broad base of individuals is mad.

    For the official content recorded, over 1.6 million people worldwide made access to it portal on a per-day basis. because of the piracy issues, it faced a report by motion picture Association of America, which led to its pack up by the united kingdom court Order. it had been considered together of the highest 250 sites visited by the people worldwide. Although, thanks to its massive fan base, Putlockers remains operated under different proxy websites.

    ReplyDelete
  3. Nice post thankx for sharing the information about "How to Setup a Standalone Memory Analyzer for Windows 10" if you want to know about Download Alexa app for windows 10pc just visit here.

    ReplyDelete
  4. If you would like to manage your Alexa device then you’ll Download Alexa app from the App store, and it’s a web site, etc. Alexa could be a voice assistant who takes your voice commands to perform several tasks like play music, set alarms, notifications, weather updates, and far a lot of. If you’ve got any queries in the Download Alexa app or any programming error can return whereas mistreatment, you’ll decide the Download Alexa app for iPhone . after you Download Alexa app on your phone. you’ll get to sign on into it by coming into your Alexa accounts username and countersign. you’ll additionally optimize it’s functioning in line with your wants by creating changes in its settings.

    ReplyDelete
  5. Excellent Blog, it has been interesting. Visit Ogen Infosystem for the best Website Designing services in Delhi, India.
    Web Design Company

    ReplyDelete
  6. Nice post thankx for sharing the information if you want to know about Roku account setup

    ReplyDelete
  7. Download Ring app on your iPhone or Android device. The app will be your main point of access for your Doorbell 2. It's where you'll receive alerts and be able to talk with visitors via the live video screen.

    ReplyDelete
  8. very helpful post thanks for sharing the information to
    install Alexa app on windows 7 just visit this link.

    ReplyDelete
  9. Clik here to Download Alexa app for windos 10 pc from this link to get your Alexa app download for windows

    ReplyDelete
  10. Very helpfull blog..click here that How Do I Reset Wifi on Alexa from this link

    ReplyDelete
  11. Nice blog thanks for sharing!!!!
    How To Setup a Roku Account on Roku com link?
    To create a Roku account is very simple, to make it, it will take only 2 mint time to follow the step and create an account.

    ReplyDelete
  12. Nice post thanks for sharing the information. Kindle is an outstanding device launched by Amazon as it takes book admirers to a whole new world of imagination just contact
    Phone number for kindle customer

    ReplyDelete
  13. Nice post thanks for sharing the information if you are having problems with Kobo Black Screen issue then click here

    ReplyDelete
  14. Very interesting blog. A lot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definitely interested in this one.
    More about nice blogs:
    bitdefender.com/activate

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. This comment has been removed by the author.

    ReplyDelete
  17. Do you want to know how to solve canon printer is offline mac issue? Don’t know how to deal with this error? Not to worry, our experts will guide you and tell you in detail about the reason behind this error. To know more visit the website Printer Offline Error.

    ReplyDelete
  18. If you are looking for affordable and high quality hydrogen water bottle? Then you can contact us at h2lifech.com and get the best hydrogen water bottle at reasonable prices.

    ReplyDelete
  19. It is so great to get information about this loop, very helpful and informative.

    Visit us:- alexa.amazon.com
    Espn.com/activate
    Hulu.com/activate

    ReplyDelete
  20. Healthy Life Human is a fitness and nutrition blog, where we share healthy recipes, workouts for weight loss, and tips for living a healthier life
    Healthy Life Human

    ReplyDelete
  21. Navigate the intricate world of business through the lens of The Global Hues. Our articles dissect market dynamics, emerging trends, and strategies, offering readers a comprehensive understanding of today's business landscape.

    theglobalhues

    ReplyDelete