Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction Into Java Profiling

Introduction Into Java Profiling

Conference Talk for Coding Serbia conference.
Introduction into purpose of profiling and what mechanics are used to do it.
The second half of the talk were live demos of the referenced code examples and how to work with a profiler.

Fabian Lange

October 17, 2013
Tweet

More Decks by Fabian Lange

Other Decks in Technology

Transcript

  1. Quiz /** * Appends the specified element to the end

    of this list. * * @param e element to be appended to this list * @return <tt>true</tt> (as specified by {@link Collection#add}) */ public boolean add(E e) { ensureCapacityInternal(size + 1); // Increments modCount!! elementData[size++] = e; return true; }
  2. Becoming a Cheeta O Execute less code O Waste less

    memory O Spend less time waiting
  3. Code O Code execution consumes CPU cycles O Common issues

    O Frequent invocation O Long algorithm O Unnecessary code
  4. javac private static final boolean PRINT = false; public static

    void main(String[] args) { if (PRINT) { System.out.println("Hello Serbia"); } }
  5. HotSpot boolean print = false; public void doStuff() { for

    (int i = 0; i < 10_000_000; i++) { if (print) { System.out.println("Hello Serbia"); } } }
  6. Memory O Java has automatic memory management O Common issues

    are O Garbage Collection O Memory Leaks
  7. Garbage Collection O Limit Waste Long count = 0L; for

    (int i = 0; i < 10_000_000; i++) { count += i; }
  8. Garbage Collection O Limit Waste Long count = 0L; for

    (int i = 0; i < 10_000_000; i++) { count = new Long(count.longValue()+ i); }
  9. Memory Leaks O Forgotten reference keeps objects alive Map<Double, String>

    cache = new HashMap<>(); Double key = Math.random(); String value = "Coding Serbia"; cache.put(key, value); key = null;