Slide 1

Slide 1 text

1

Slide 2

Slide 2 text

Memory Leak Profiling with NetBeans and HotSpot Clarence J M Tauro Senior Curriculum Developer, Oracle ST Java Curriculum

Slide 3

Slide 3 text

3 Session Agenda • About the Speaker • Different aspects of Performance • Memory leaks and profiling • Demo

Slide 4

Slide 4 text

4 About the Speaker • Clarence J M Tauro – [email protected] • Senior Curriculum Developer, Java Curriculum (Oracle ST Curriculum) • ~7 Years Professional Teaching and Instructional Design Experience • Masters of Science in Information Technology • Masters of Technology in Computer Science • Masters of Philosophy in Computer Science • Doctor of Philosophy in Computer Science [expected to graduate by August 2012] • Guest faculty to various Colleges and Universities

Slide 5

Slide 5 text

5 Different Aspects of Performance Performance Aspects Memory footprint Scalability Responsiveness Throughput In this talk we will look at memory profiling

Slide 6

Slide 6 text

6 Memory Leak Profiling: Why and When • Memory leaks are situations where a reference to allocated objects remains unintentionally reachable and as a result cannot be garbage collected. – Leads to poor application performance – Can lead to application failure – Can be hard to diagnose

Slide 7

Slide 7 text

7 Garbage Collection – An Overview

Slide 8

Slide 8 text

8 Garbage Collection – An Overview

Slide 9

Slide 9 text

9 Profiling • An act of collecting or observing performance data from an operating or running application. • Usually more intrusive than monitoring. • Usually a narrower focus than monitoring.

Slide 10

Slide 10 text

10 DEMO – A Servlet with a JavaScript Error

Slide 11

Slide 11 text

11 DEMO – Main Class

Slide 12

Slide 12 text

12 DEMO – NetBeans Profiler Configuration I am interested in Garbage collection statistics too Choosing this option has a lot of additional overhead

Slide 13

Slide 13 text

13 DEMO – Telemetry Overview

Slide 14

Slide 14 text

14 DEMO – Live Profiling Results

Slide 15

Slide 15 text

15 DEMO – Snapshot of String Class

Slide 16

Slide 16 text

16 DEMO – Stack Trace

Slide 17

Slide 17 text

17 DEMO – Source of handleScriptException

Slide 18

Slide 18 text

18 DEMO – Find Usaged on _errorMessages

Slide 19

Slide 19 text

19 DEMO – Source of ____________JavaScript.clearErrorMessages()

Slide 20

Slide 20 text

20 DEMO – Find Usages on ----------------------------------------- --------------------JavaScript.clearErrorMessages() So, who calls the JavaScriptEngineFactory.clearErrorMessages()??

Slide 21

Slide 21 text

21 So, who calls the HttpUnitOptions.clearScriptErrorMessages()?? DEMO – Find Usages on JavaScriptEngineFactory.clearErrorMessages( )

Slide 22

Slide 22 text

22 DEMO – Find Usages on HttpUnitOptions.clearScriptErrorMessages() Ahh.. Haa.. You just found the root cause of the memory leak. The _errorMessages ArrayList is NEVER cleared.. It has only elements added to it.

Slide 23

Slide 23 text

23 Farewell to the memory leak! So, to fix this memory leak, the ArrayList needs to be explicitly cleared. This is a task for the authors of HttpUnit

Slide 24

Slide 24 text

24 • Java Performance Tuning and Optimization Course from Oracle University • Java Performance - Charlie Hunt (Author), Binu John (Author) (Expected August 2011) Where to go?

Slide 25

Slide 25 text

25