Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Generator switches from generating Literals to Methods
EMF Generator switches from generating Literals to Methods [message #1833165] Mon, 05 October 2020 09:22 Go to next message
Thomas Kohler is currently offline Thomas KohlerFriend
Messages: 15
Registered: November 2016
Junior Member
As our xcore Model growed, the EMF Generator switched from generating the Package.Literals Interface to using Method to access EClasses and EStructuralFeatures.

It seems that this should prevent going over the 64k Limit every Java method bytecode still has. All static fields in the Literals interface will be initialized in one hidden static method which has to be smaller 64k...

We had simmilar problems when generating vertical and horizontal big enumerations and solved it by separating the declaration and initialization of the Enum Literals (internally enum literals are also static fields) by having more than one static initializer block for the initializations.

My Question to the Forum - and in special to Ed - is how EMF detects the Point where it switches to the alternate Code generation and if it would be possible to change the behaviour similar to the way we handled those big enumerations mentioned before.

An alternate would be to generate only EClasses to the Literal Interface and all EStructuralFeatures to inner interfaces named like the EClass itself. Then an access to a structural feature would be instead of

MyPackage.Literals.HAS_NAME__NAME
MyPackage.Literals.HasName.NAME

where "HasName" is the inner inner interface for the EClass in Literal.HAS_NAME which also would help to make the Literals Interface itself smaller.

Our big problem is, that the majority of our code relies on the info out of the Literal Interface in own but also with "@generated NOT" anntotated and generated EMF classes and methods. So the switch in the generator causes hundreds of unresolved points in our code :-(

Some ideas beside splitting the Model to several packages which will - of course - also be a solution?

And last but not least: Can there be a perfomance difference between the two kinds of generated code?
Re: EMF Generator switches from generating Literals to Methods [message #1833181 is a reply to message #1833165] Mon, 05 October 2020 17:03 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7103
Registered: July 2009
Senior Member
Hi

Are you sure it is actually the Literals package that exceeds 64k? It seems much more likely that it is the initializePackageContents that uses the Literals class that is the problem. If so initializePackageContents could be refactored as calls to initializePackageContents1, initializePackageContents2, ... to ensure smaller functions. A perhaps 4-fold improvement could be achieved by a simple init{supertypes,classes,features,operations refactoring. More by paging to not more than say 256 inits per paged function. If the Literals package is really the problem, it could be given explicit init1(), init2() etc paged functions to again avoid one large synthetic construction.

The initialize by loading obviously incurs non-trivial extra time to intialize, but thereafter it's probably the same.

Regards

Ed Willink
Re: EMF Generator switches from generating Literals to Methods [message #1833217 is a reply to message #1833181] Wed, 07 October 2020 06:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31842
Registered: July 2009
Senior Member
This method is a heuristic to guess when a model is likely gotten "too big":

https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenPackageImpl.java#n4796

It's used here:

https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecore/genmodel/impl/GenPackageImpl.java#n3208

Of course generated patterns can be changed. Perhaps splitting the initialization of the Literal's constants could be done in multiple separate static initialization blocks (assuming that's what's exceeding the byte code limit) so that the impact of the changes are local to a single template. Generating lots of interfaces with nested constants is more complex and has broader impact, i.e., on the generated uses of these...

And yes, I expect that there is a performance difference between a call to an interface method XyzPackage.eINSTANCE.getAbc_Def() versus accessing a static final constant XyzPackage.Literals.ABC__DEF, though whether that has a significant impact on overall application performance is not clear.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Generator switches from generating Literals to Methods [message #1833232 is a reply to message #1833217] Wed, 07 October 2020 11:51 Go to previous messageGo to next message
Thomas Kohler is currently offline Thomas KohlerFriend
Messages: 15
Registered: November 2016
Junior Member
Ed Merks wrote on Wed, 07 October 2020 06:00
This method is a heuristic to guess when a model is likely gotten "too big":


Thank you, Ed, I found the GenPackageImpl>>isBigModel() method which determines the total and assumes a too big model if classes + supers + features + operations + parameters + exceptions + enums + literals + datatypes > 500.

Is it somehow possible to overrule this (the 500) in an xcore based model?

Thanks, Tom
Re: EMF Generator switches from generating Literals to Methods [message #1833236 is a reply to message #1833232] Wed, 07 October 2020 12:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31842
Registered: July 2009
Senior Member
Yes, you can specify @GenModel(loadInitialization="true", literalsInterface="true") before the package declaration (of course choosing true/false however you wish them to be).

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Generator switches from generating Literals to Methods [message #1833243 is a reply to message #1833236] Wed, 07 October 2020 14:46 Go to previous message
Thomas Kohler is currently offline Thomas KohlerFriend
Messages: 15
Registered: November 2016
Junior Member
Ed Merks wrote on Wed, 07 October 2020 12:18
Yes, you can specify @GenModel(loadInitialization="true", literalsInterface="true") before the package declaration (of course choosing true/false however you wish them to be).


Thank you Ed, it worked! You saved my day!

I didn't know that via the @GenModel annotation it is also possible to access the GenPackage ...

Regards,
Tom
Previous Topic:Loading / deserializing non-transient derived features
Next Topic:Handling references to XML datatypes uniformly
Goto Forum:
  


Current Time: Wed Apr 21 05:58:55 GMT 2021

Powered by FUDForum. Page generated in 0.02233 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top