MemoryLint. Petr Nejedlý, Radim Kubacki SUN Microsystems, BOF-9066

Similar documents
Test Patterns in Java

From Java Code to Java Heap Understanding the Memory Usage of Your Application

NetBeans Rich Client Platform Simpletests. Anton Epple Eppleton IT Consulting

Bugs in software. Using Static Analysis to Find Bugs. David Hovemeyer

Effective Java Heap Memory Analysis on Enterprise-Scale SAP Memory Analyzer. Vedran Lerenc, SAP NetWeaver Java Server Technology October 11th 2007

Building a Java ME Test Suite in 15 Minutes

Managed runtimes & garbage collection. CSE 6341 Some slides by Kathryn McKinley

Efficient Java (with Stratosphere) Arvid Heise, Large Scale Duplicate Detection

Managed runtimes & garbage collection

Java Garbage Collection. Carol McDonald Java Architect Sun Microsystems, Inc.

LAB-6340: Advanced Java ME Programming - Streaming Video From Server to Your Device

NASA World Wind Java SDK

Eclipse Memory Analyzer Graduation, Move and 1.0 Release Review

Bytecode Manipulation Techniques for Dynamic Applications for the Java Virtual Machine

Product Updates TPFUG 2019, Denver

Java Language Modularity With Superpackages

Programming Web Apps for Tiny Devices with Java Card 3.0 Connected Edition

Practical Lessons in Memory Analysis

AUTOMATED HEAPDUMP ANALYSIS FOR DEVELOPERS, TESTERS, AND SUPPORT EMPLOYEES

Swinging from the Outside

Enough java.lang.string to Hang Ourselves...

Bill Bridge. Oracle Software Architect NVM support for C Applications

Building Memory-efficient Java Applications: Practices and Challenges

Principles of Software Construction: Objects, Design, and Concurrency

Writing a Sony PlayStation Emulator Using Java Technology

Basic Steps and Features Walk-through

(f) Given what we know about linked lists and arrays, when would we choose to use one data structure over the other?

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

JavaServer Faces Technology, AJAX, and Portlets: It s Easy if You Know How!

Real Time: Understanding the Trade-offs Between Determinism and Throughput

Eclipse Memory Analyzer Release Review 0.8

Emulating the Java ME Platform on Java SE

Bringing Life to Swing Desktop Applications

Static Code Analysis to Find Bugs. Wright.edu CS7140 Spring 2013 (Slides collected from many sources)

ANALYZING THE MOST COMMON PERFORMANCE AND MEMORY PROBLEMS IN JAVA. 18 October 2017

Chair of Software Engineering. Languages in Depth Series: Java Programming. Prof. Dr. Bertrand Meyer. Exercise Session 10

ABL source code analysis with SonarQube. Gilles QUERRET Riverside Software

Defective Java Code: Turning WTF code into a learning experience

Using Aspect-Oriented Programming to Streamline Mobile Application Development

Defective Java Code: Turning WTF code into a learning experience

JCudaMP: OpenMP/Java on CUDA

Singleton. Computer Science and Engineering College of Engineering The Ohio State University. Lecture 29

Java performance - not so scary after all

Sun Java Studio Creator. Ken Paulsen Staff Engineer Sun Microsystems, Incorporated (Slides by: Craig R. McClanahan)

Fall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up

JRuby: Bringing Ruby to the JVM

CS 11 java track: lecture 1

IBD Intergiciels et Bases de Données

Testing Concurrent Software

Atomicity CS 2110 Fall 2017

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

CQ Beacon Android SDK V2.0.1

High Performance Clients 1

Introduction To NetBeans 5.5

New Compiler Optimizations in the Java HotSpot Virtual Machine

Effec%ve So*ware. Lecture 9: JVM - Memory Analysis, Data Structures, Object Alloca=on. David Šišlák

Lecture 18. Collision Resolution

Domain-Driven Design Activity

JSR 311: JAX-RS: The Java API for RESTful Web Services

Interview Questions I received in 2017 and 2018

Java One 2007 Conference Notes Juixe

Java Roads Less Traveled

Bug Hunting and Static Analysis

Sicherheit beim Build

Testing Concurrent Software

JSR 292 Cookbook: Fresh Recipes with New Ingredients

Concepts of Object-Oriented Programming Peter Müller

Petr Suchomel Architect, NetBeans Mobility

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008

Introduction to Java

ENTERPRISE JAVABEANS TM (EJB TM ) 3.1 TECHNOLOGY

Certified Core Java Developer VS-1036

IBM Tivoli Composite Application Manager for Microsoft Applications: Microsoft.NET Framework Agent Fix Pack 13.

Incremental Evaluation of OCL invariants in the Essential MOF object model

Day 6. COMP1006/1406 Summer M. Jason Hinek Carleton University

Concepts of Object-Oriented Programming Peter Müller

Twelve Reasons To Use NetBeans Software Episode 2

CS61BL Summer 2013 Midterm 2

Whiz-Bang Graphics and Media Performance for Java Platform, Micro Edition (JavaME)

Creating Manageable Systems With JMX, Spring, AOP, and Groovy

Who is our rival? Upcoming. Testing. Ariane 5 rocket (1996) Ariane 5 rocket 3/8/18. Real programmers need no testing!

Borland Optimizeit Enterprise Suite 6

Advanced programming for Java platform. Introduction

Improve and Expand JavaServer Faces Technology with JBoss Seam

The Proxy Pattern. Design Patterns In Java Bob Tarr

COMP90015: Distributed Systems Assignment 1 Multi-threaded Dictionary Server (15 marks)

1 Shyam sir JAVA Notes

IWOMP Dresden, Germany

Selected Java Topics

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Class, Variable, Constructor, Object, Method Questions

Adding Telephony to Java Technology-Based Enterprise Applications

Eclipse Memory Analyzer Release Review

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

Workaround Swing Bugs

Linked Lists: Locking, Lock-Free, and Beyond. Companion slides for The Art of Multiprocessor Programming by Maurice Herlihy & Nir Shavit

Topic 6: Inner Classes

Servlet Performance and Apache JServ

Software Engineering Large Practical: Preferences, storage, and testing

When the Servlet Model Doesn't Serve. Gary Murphy Hilbert Computing, Inc.

Transcription:

MemoryLint Petr Nejedlý, Radim Kubacki SUN Microsystems, http://www.sun.com/, http://www.netbeans.org BOF-9066 2007 JavaOne SM Conference Session BOF-9066

Goal Get ideas how to analyze content of Java heap Find how to analyze data structures of your application. Check for the patterns that reveals memory leaks, inefficient use of memory or other mistakes 2007 JavaOne SM Conference Session BOF-9066 2

Agenda Motivation Existing tools Next step MemoryLint Q&A 2007 JavaOne SM Conference Session BOF-9066 3

Agenda Motivation Existing tools Next step MemoryLint Q&A 2007 JavaOne SM Conference Session BOF-9066 4

Motivation Why to use tools? Same errors are repeated They have to be checked and fixed again and again Patterns are often similar Evaluate larger data structures to get better picture of application behavior Memory consumption of module system, project infrastructure, editor's data 2007 JavaOne SM Conference Session BOF-9066 5

Motivation Why to use tools? What can we automate? Pattern detection in... sources: PMD, Checkstyle bytecode: FindBugs data:??? Find problems as soon as possible during development Make it easy for everyone to run the scan 2007 JavaOne SM Conference Session BOF-9066 6

Agenda Motivation Existing tools Next step MemoryLint Q&A 2007 JavaOne SM Conference Session BOF-9066 7

Existing tools What do we have now? Profilers Usually good for memory leak hunting Object count/sizes, retained size, reference path Requires skillset to find problems Hard to automate Generally can't do custom/advanced analysis 2007 JavaOne SM Conference Session BOF-9066 8

Existing tools What do we have now? JHat/OQL Good concept Get a heap dump and analyze it in many ways Difficult to use Slow on larger heaps 2007 JavaOne SM Conference Session BOF-9066 9

Agenda Motivation Existing tools Next step MemoryLint Q&A 2007 JavaOne SM Conference Session BOF-9066 10

MemoryLint What is it? Automatic analysis tool Processes rules, provides report Extensible framework Has API for writing custom rules Builds on top of NetBeans Profiler's heap model Experimental platform... What kind of problematic patterns do you encounter?... but usable out of the box Few precooked rules, will demo them 2007 JavaOne SM Conference Session BOF-9066 11

MemoryLint Overview JVM Memory Lint Results Heap dump Heap model Rules Profiler integration 2007 JavaOne SM Conference Session BOF-9066 12

MemoryLint What do we look for? Known problems Memory leaks Memory waste CPU optimizations Correctness problems Interresting statistics Who uses all that HashMaps? Your ideas 2007 JavaOne SM Conference Session BOF-9066 13

MemoryLint Rule examples Memory leaks UI widgets, documents, classloaders Improperly used WeakHashMap Memory waste String class: too many identical strings, oversized Retained memory Patterns HashMap with bad distribution of entries Cache statistics 2007 JavaOne SM Conference Session BOF-9066 14

MemoryLint More ideas Duplicate listener registrations Sparsely populated arrays or duplicated entries Duplicated fields Unused/should-be-static fields Instances of Boolean IdentityHashMap with equal but not identical key (catch String only for example) Listener strongly reachable from singleton only WeakHashMap with most keys gone 2007 JavaOne SM Conference Session BOF-9066 15

Rule Examples: String public final class String implements Serializable, Comparable<String>, CharSequence { /** The value is used for character storage. */ private final char value[]; /** The offset is the first index of the storage that is used private final int offset; /** The count is the number of characters in the String. */ private final int count; /** Cache the hash code for the string */ private int hash; // Default to 0... 2007 JavaOne SM Conference Session BOF-9066 16

Rule Examples: String // curroff is 5631, len is 3 String s = doccontent.substring (curroff, len); 2007 JavaOne SM Conference Session BOF-9066 17

Rule Examples: HashMap Chaining of entries with bad hash function HashMap table Entry[] Entry next Entry next Entry next 2007 JavaOne SM Conference Session BOF-9066 18

Rule Examples: LeakHashMap Weak key strongly reachable from value WeakHashMap table Entry[] Entry referent value value key heap 2007 JavaOne SM Conference Session BOF-9066 19

DEMO Samples 2007 JavaOne SM Conference Session BOF-9066 20

Rule's Anatomy public class MyRule extends IteratingRule { public MyRule() { super( name, desc, classnamepattern ); } /** Called once for each rule to prepare helpers. */ protected void preparerule(memorylint context) {...} /** Called once for each heap instance matching the * classnamepattern. Can be called paralelly from * several worker threads. */ protected void perform(instance in) {...} /** Called once all matching instances processed. Allows * to compute and push the results lately */ protected void summary() {...}... } 2007 JavaOne SM Conference Session BOF-9066 21

Summary Memory problems are common Memory problems repeat Solving memory problems needs to be simplified (automated) You may be surprised how much low hanging fruit can be hidden in your application... we were ourselves... 2007 JavaOne SM Conference Session BOF-9066 22

For More Information List http://performance.netbeans.org/memorylint/ http://profiler.netbeans.org/ 2007 JavaOne SM Conference Session BOF-9066 23

Q&A Petr Nejedlý petr.nejedly@sun.com Radim Kubacki radim.kubacki@sun.com 2007 JavaOne SM Conference Session BOF-9066 24