Bug 224590 - Make smap mapping more memory friendly.
Summary: Make smap mapping more memory friendly.
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL: http://clojure.sourceforge.net/
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2008-03-28 09:22 EDT by Christophe Grand CLA
Modified: 2010-04-12 10:58 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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....