History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: FRG-295
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Stephan Zuercher
Reporter: Stephan Zuercher
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Farrago

MDR code generation does not correctly handle more than 4 long or double attributes

Created: 25/Sep/07 03:34 PM   Updated: 06/Feb/09 01:05 PM
Component/s: Catalog
Affects Version/s: None
Fix Version/s: None


 Description  « Hide
The current version of Netbeans MDR libraries has a code generation bug.

If more than 5 attributes with type Long or Double and multiplicity 1 exist in a single class (including super classes), the code generation fails because the generated method _createInstance(Object[]) does not compensate for the fact that double and long primitives take up two JVM operand stack slots a piece. With exactly 5 such attributes, the code generation fails intermittently.

Need to take the following actions:

1) Short Term: modify net.sf.farrago.catalog.codegen.FactoryGen to detect the cases that causes errors and fail with a useful error message.
2) Long Term: resurrect a buildable version of MDR and fix the bug

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Stephan Zuercher - 25/Sep/07 03:35 PM
A more detailed description of the problem.

-----Original Message-----
From: Stephan Zuercher
Sent: Tue 9/25/2007 11:14 AM
To: John Sichi
Subject: Re: createCatalogRepository
 
Okay, the reason switching to [0..1] helps is that it causes the
interfaces to use java.lang.Long vs. primitive long. A java.lang.Long
takes a single operand stack slot (it's just a reference like any
other), but primitive longs take two slots. This eats into the 6 slot
buffer and if you have enough of them in your class's hierarcy, you'll
get the VerifyError.

If I write out the byte code for FemCmdVerifyIndex's _createInstance,
assuming that super class attributes come before their child's
attributes and that attributes are ordered within a class, then I should
never see the error. However, if I scramble the order and the last
attribute is not a primitive type, then my class exceeds the max stack
by 1 slot. Basically each primitive type increases the number of
operand stack slots used by 1 (or 2 if a long or double). Each
non-primitive type increases the operand stack slots used by 1, but
temporarily uses a 2nd slot.

So, with up to 4 primitive longs or doubles there's no problem. With 5,
the error appears randomly. With 6 it should always appear.

In any event, switching my result attributes to Long[0..1] will take
care of the problem: the class will have only 3 primitive longs.

Will note this limitation on the wiki. Is there a good place to add a
check for this during catalog creation? May as well prevent the error
until we fix it for real.

Stephan

Stephan Zuercher - 25/Sep/07 03:36 PM
Work arounds:

1) Switch one or more long/double attributes to integer/float.
2) Switch multiplicity from 1 to 0..1 (causes a java.lang.Long or java.lang.Double to be used, reducing stack space requirements)
3) Anything that reduces the number of long/double attributes.

John V. Sichi - 25/Sep/07 03:46 PM
Oops...one problem with generateMetadataFactory is that it gets called after writeDTD, which is where the failure currently occurs when it does occur. So the developer will still get a bad error message, though that's better than no error message at all.

Stephan Zuercher - 25/Sep/07 09:23 PM
Since the VerifyError will appear with 6+ long/double attributes, I'll add the error message here to help anyone who runs into it.

     [java] /home/szuercher/open/farrago/build.xml:537: java.lang.VerifyError: (class: net/sf/farrago/fem/fennel/FemCmdVerifyIndexClass$Impl, method: _createInstance signature: ([Ljava/lang/Object;)Ljavax/jmi/reflect/RefObject;) Stack size too large

Stephan Zuercher - 26/Sep/07 11:01 AM
Change 9919 (on the //open/lu/dev_lcs branch) adds a test or the condition that causes the error, so the intermittent case won't slip through.

Stephan Zuercher - 20/Jun/08 01:09 PM
These limitations go away if Enki/Hibernate is in use -- it generates Java source code at build-time. So, if/when Farrago switches completely away from Netbeans (at least as the repository implementation) we can close this bug. Note that we could continue to use Netbeans XMI reader/writer implementations without issue.

Also, Enki is now handling the generation of the JMI interface classes (e.g. FemLocalSchema), so we can add a test for "too many longs or doubles" there and get ahead of the writeDTD error.

Stephan Zuercher - 06/Feb/09 01:05 PM
The Enki change to detect this condition was never made.

If it's still desirable to add it, it would go in JmiTemplateHandler's generateClassInstance method. Count long and double values with multiplicity.lower == 1 and throw GenerationError if you get to 5.