JVM изнутри - оптимизация и профилирование

  • Published on
    31-May-2015

  • View
    541

  • Download
    30

Embed Size (px)

DESCRIPTION

How to make a Java Virtual Machine tuning and profile java applications.

Transcript

<ul><li> 1. JVM JazzTeam, Senior Software Engineer </li></ul> <p> 2. ? ?+ 3. ? ?+ ! . 4. JVM JVM memory leaks java- JDK VisualVM 5. JVM: stack (int, float, double, char, ...) -Xss256k Eden Perm gen space Heap space Stack Survivor Old Thread 3 Thread 4 Thread 1 Thread 2 6. JVM: heap space Heap -Xms256m - -Xmx512m - -XX:NewRatio=2 - eden + survivor/survivor Eden , GC ( , survivor space) Eden Perm gen space Heap space Stack Survivor Old Thread 3 Thread 4 Thread 1 Thread 2 7. JVM: heap space Heap Survivor , Tenured generation , : , , JVM, System.gc() Eden Perm gen space Heap space Stack Survivor Old Thread 3 Thread 4 Thread 1 Thread 2 8. JVM: perm gen Permanent generation - -XX:PermSize=32m -XX:MaxPermSize=128m - , Eden Perm gen space Heap space Stack Survivor Old Thread 3 Thread 4 Thread 1 Thread 2 9. Garbage - , - , Copy collection eden survivor, eden Stop the world pauses Mark sweep compact mark - sweep - compact - 10. Memory leaks - , " " // Some image loading functionality Map images = new HashMap(); // We use this method for image caching public Bitmap getBitmap(String name) { if (!images.contains(name)) { // loadBitmap is slow operation, we use caching to speed up this process images.put(name, loadBitmap(name)); } return images.get(name); } ... // Somewhere in the application gallery.onNext(new GalleryListener(Gallery g, String name) { g.setImage(getBitmap(name)); }); , , 11. memory leaks weak soft references WeakReference - GC "" SoftReference - Map&gt; images = new HashMap&gt;(); // We use this method for image caching public Bitmap getBitmap(String name) { if (!images.contains(name) || images.get(name).get() == null) { // loadBitmap is slow operation, we use caching to speed up this process images.put(name, new WeakReference(loadBitmap(name))); } return images.get(name); } 12. memory leaks , , OutputStream out = new FileOutputStream(); try { // Work with stream } finally { out.close(); } PreparedStatement stmt = createStatement(); ResultSet rs = null; try { rs = stmt.executeQuery(); // Work with result set } finally { if (stmt != null) { stmt.close(); } if (rs != null) { rs.close(); } } 13. CPU " ", , 14. java JMX - Java Management Extensions java- , VisualVM JMX 15. JDK jps - JVM jinfo - java- jstack - java- jstat - jmap - jhat - heap 16. VisualVM 17. ? ! kslisenko@gmail.com </p>