Bug 145746 - [1.5][compiler] Enum synthetic methods should be improved
Summary: [1.5][compiler] Enum synthetic methods should be improved
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2.1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-07 08:00 EDT by Philipe Mulet CLA
Modified: 2006-09-11 10:51 EDT (History)
3 users (show)

See Also:


Attachments
Proposed patch (33.44 KB, patch)
2006-06-07 10:01 EDT, Philipe Mulet CLA
no flags Details | Diff
Complement to the first patch (10.76 KB, patch)
2006-06-08 11:18 EDT, Olivier Thomann CLA
no flags Details | Diff
New patch (11.25 KB, patch)
2006-06-08 11:35 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2006-06-07 08:00:00 EDT
Build 3.2RC7

An enum type is generated 2 methods: #values() and #valueOf(String).
These should be reworked to do:
1. #values() use array clone
2. #valueOf(String) reuse Enum#valueOf(String,Class) which internally is map based and thus much more efficient in large cases.
Comment 1 Philipe Mulet CLA 2006-06-07 08:00:51 EDT
Actually, arraycopy for (1) is debattable.
Comment 2 Philipe Mulet CLA 2006-06-07 08:01:19 EDT
Note that (2) will take care of addressing bug 145732
Comment 3 Tim Ellison CLA 2006-06-07 09:29:08 EDT
re: (2) I wonder how common it is to have such a large number of enum constants?  I would expect an easily JIT-optimized for-loop with known limits would be more efficient in the most common cases.  However, if you dispatch to the Enum type then it becomes their problem<g>.
Comment 4 Philipe Mulet CLA 2006-06-07 09:52:40 EDT
It also makes the classfile more compact, since using one indirection.
I wonder about scenarii where #valueOf(...) would be extensively used, as opposed to direct reference to enum constants. Feels like reflecting upon the enum.
Comment 5 Philipe Mulet CLA 2006-06-07 10:01:43 EDT
Created attachment 43713 [details]
Proposed patch
Comment 6 Philipe Mulet CLA 2006-06-07 10:02:11 EDT
Olivier - pls double check
Comment 7 Philipe Mulet CLA 2006-06-07 11:31:18 EDT
Releasing for 3.2.1 since it will impact other bug 145732, which matters for Harmony
Comment 8 Olivier Thomann CLA 2006-06-08 11:18:09 EDT
Created attachment 43866 [details]
Complement to the first patch

Fix comments + remove unused field and methods from the CodeStream/StackMapCodeStream and ConstantPool.
Comment 9 Olivier Thomann CLA 2006-06-08 11:35:44 EDT
Created attachment 43872 [details]
New patch

Forgot one change in the StackMapCodeStream
Comment 10 Philipe Mulet CLA 2006-06-09 11:18:00 EDT
Fix also released for 3.3M1
Comment 11 Frederic Fusier CLA 2006-06-12 06:26:32 EDT
Released for 3.2.1
Released for 3.3 M1
Comment 12 Frederic Fusier CLA 2006-08-08 07:46:33 EDT
Verified for 3.3 M1 using build I20060807-2000.
Comment 13 David Audel CLA 2006-09-11 10:51:13 EDT
Verified for 3.2.1 using build M20060908-1655