Bug 224590

Summary: Make smap mapping more memory friendly.
Product: [Eclipse Project] JDT Reporter: Christophe Grand <christophe>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3 CC: christophe, Michael_Rennie
Version: 3.3.1Keywords: performance
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
URL: http://clojure.sourceforge.net/
Whiteboard:

Description Christophe Grand CLA 2008-03-28 09:22:07 EDT
I ran in OutOf Memory errors while trying to set breakpoints in classes compiled by the Clojure language. These errors are caused by 
org.eclipse.jdi.internal.ReferenceTypeImpl.Stratum and org.eclipse.jdi.internal.ReferenceTypeImpl.FileInfo allocating *several megabytes per class* when parsing the smap string (and not releasing them).
(The NetBeans debugger is reported to handle them fine.)

Background:
org.eclipse.jdi.internal.ReferenceTypeImpl.Stratum and org.eclipse.jdi.internal.ReferenceTypeImpl.FileInfo store the mapping between inputline and outputline in a map (Integer -> List of int[2]) 

... and Clojure emits a canned line section (1#1,10000:1) in each class which causes eclipse to allocate (twice) what the following code allocates:
Map smap = new HashMap();
for(int i = 1;i <=10000; i++) {
  ArrayList list = new ArrayList(); // by default creating an Object[10]...
  list.add(new int[] { i, 1 });
  smap.put(i, list);
} 

I know that it's bad form from Clojure to emit such canned line sections (the developers have been notified) but I think this code use too much memory to represent line mapping while JSR045 smap are so compact. With the growing number of non-Java languages on the JVM, this memory overhead may become harmful.

At the very least, the memory usage can be nearly cut by a factor of 10 in most cases by creating the lists with new ArrayList(1) instead of new ArrayList() in FileInfo.addLineInfo and Stratum.addLineInfoToMap.

The memory usage could also be reduced by staying closer to JSR045 and not building an explicit mapping.

Thanks.
Comment 1 Michael Rennie CLA 2008-03-28 09:33:56 EDT
interesting find, from the looks of things we could definatley improve our memory use....