Memory Leak Profiling with NetBeans and HotSpot

25
1

Transcript of Memory Leak Profiling with NetBeans and HotSpot

Page 1: Memory Leak Profiling with NetBeans and HotSpot

1

Page 2: Memory Leak Profiling with NetBeans and HotSpot

<Insert Picture Here>

Memory Leak Profiling with NetBeans and HotSpot

Clarence J M Tauro

Senior Curriculum Developer, Oracle ST Java Curriculum

Page 3: Memory Leak Profiling with NetBeans and HotSpot

3

<Insert Picture Here>

Session Agenda

• About the Speaker

• Different aspects of Performance

• Memory leaks and profiling

• Demo

Page 4: Memory Leak Profiling with NetBeans and HotSpot

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

Page 5: Memory Leak Profiling with NetBeans and HotSpot

5

Different Aspects of Performance

Performance Aspects

Memory footprint

Scalability

Responsiveness

Throughput

In this talk we will look at memory profiling

Page 6: Memory Leak Profiling with NetBeans and HotSpot

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

Page 7: Memory Leak Profiling with NetBeans and HotSpot

7

Garbage Collection – An Overview

Page 8: Memory Leak Profiling with NetBeans and HotSpot

8

Garbage Collection – An Overview

Page 9: Memory Leak Profiling with NetBeans and HotSpot

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.

Page 10: Memory Leak Profiling with NetBeans and HotSpot

10

DEMO – A Servlet with a JavaScript Error

Page 11: Memory Leak Profiling with NetBeans and HotSpot

11

DEMO – Main Class

Page 12: Memory Leak Profiling with NetBeans and HotSpot

12

DEMO – NetBeans Profiler Configuration

I am interested in Garbage collection

statistics too

Choosing this option has a lot of additional

overhead

Page 13: Memory Leak Profiling with NetBeans and HotSpot

13

DEMO – Telemetry Overview

Page 14: Memory Leak Profiling with NetBeans and HotSpot

14

DEMO – Live Profiling Results

Page 15: Memory Leak Profiling with NetBeans and HotSpot

15

DEMO – Snapshot of String Class

Page 16: Memory Leak Profiling with NetBeans and HotSpot

16

DEMO – Stack Trace

Page 17: Memory Leak Profiling with NetBeans and HotSpot

17

DEMO – Source of handleScriptException

Page 18: Memory Leak Profiling with NetBeans and HotSpot

18

DEMO – Find Usaged on _errorMessages

Page 19: Memory Leak Profiling with NetBeans and HotSpot

19

DEMO – Source of ____________JavaScript.clearErrorMessages()

Page 20: Memory Leak Profiling with NetBeans and HotSpot

20

DEMO – Find Usages on -------------------------------------------------------------JavaScript.clearErrorMessages()

So, who calls the JavaScriptEngineFactory.clearErrorMessages()??

Page 21: Memory Leak Profiling with NetBeans and HotSpot

21

So, who calls the HttpUnitOptions.clearScriptErrorMessages()??

DEMO – Find Usages on JavaScriptEngineFactory.clearErrorMessages(

)

Page 22: Memory Leak Profiling with NetBeans and HotSpot

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.

Page 23: Memory Leak Profiling with NetBeans and HotSpot

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

Page 24: Memory Leak Profiling with NetBeans and HotSpot

24

• Java Performance Tuning and Optimization Course from

Oracle University

• Java Performance - Charlie Hunt (Author), Binu John (Author) (Expected

August 2011)

Where to go?

Page 25: Memory Leak Profiling with NetBeans and HotSpot

25