Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] stack overflow from simple script
[ATL] stack overflow from simple script [message #105690] Wed, 27 May 2009 10:38 Go to next message
Henrik Rentz-Reichert is currently offline Henrik Rentz-ReichertFriend
Messages: 261
Registered: July 2009
Senior Member
Hi all,

I have a simple script (see below) that for each object in the source
model loops over all attributes and produces some output.

This lead to an ArrayOutOfBoundsException in
org.eclipse.m2m.atl.engine.emfvm.ASMOperation

since every result of a println() operation seems to be appended to the
array
final Object[] stack = new Object[MAX_STACK];

For a still small model the frame pointer fp hit the MAX_STACK value of
100. When I increased that to 1000 everything went fine.

I don't know details about the VM implementation but I assume it is a
principle flaw if a nested loop is sort of expanded to a stack?

Can you give me a hint which kind of constructs I have to avoid for not
falling into this kind of pit?

Regards,
Henrik

-------------------------- xrefs_simple.atl ----------------------------

module xrefs_simple;

create OUT : TestSequence from IN : TestInterface;

helper def: xrefs : Map(String, TestInterface!EObject) = Map{};

entrypoint rule createMapAndRoot() {
to
t: TestSequence!PortSequence
do {
'started creating xrefs'.println();
for (e in TestInterface!EObject.allInstancesFrom('IN')) {
'checking object of class: '.concat(e.eClass().getName()).println();
--e.debug('--');
for (a in e.eClass().getEAllAttributes()) {
--a.debug(' attribute ');
' attribute: '.concat(a.getName()).println();
if (a.getName() = 'Typ') {
' got a match'.println();
' value of Typ is: '.concat(e.eGet(a)).println();
thisModule.xrefs <- thisModule.xrefs.including(e.eGet(a), e);
}
}
}
'finished creating xrefs'.println();
}
}
Re: [ATL] stack overflow from simple script [message #106333 is a reply to message #105690] Tue, 09 June 2009 12:07 Go to previous messageGo to next message
William Piers is currently offline William PiersFriend
Messages: 301
Registered: July 2009
Senior Member
Hello,

I don't see what you can do here to avoid that error. "do" sections are
sometimes quite unstable due to the stack size issue, as you mentioned.

There is an existing bug about that, could you please attach your
example to it?
https://bugs.eclipse.org/bugs/show_bug.cgi?id=245891

Thanks in advance,

William

Henrik Rentz-Reichert a écrit :
> Hi all,
>
> I have a simple script (see below) that for each object in the source
> model loops over all attributes and produces some output.
>
> This lead to an ArrayOutOfBoundsException in
> org.eclipse.m2m.atl.engine.emfvm.ASMOperation
>
> since every result of a println() operation seems to be appended to the
> array
> final Object[] stack = new Object[MAX_STACK];
>
> For a still small model the frame pointer fp hit the MAX_STACK value of
> 100. When I increased that to 1000 everything went fine.
>
> I don't know details about the VM implementation but I assume it is a
> principle flaw if a nested loop is sort of expanded to a stack?
>
> Can you give me a hint which kind of constructs I have to avoid for not
> falling into this kind of pit?
>
> Regards,
> Henrik
>
> -------------------------- xrefs_simple.atl ----------------------------
>
> module xrefs_simple;
>
> create OUT : TestSequence from IN : TestInterface;
>
> helper def: xrefs : Map(String, TestInterface!EObject) = Map{};
>
> entrypoint rule createMapAndRoot() {
> to
> t: TestSequence!PortSequence
> do {
> 'started creating xrefs'.println();
> for (e in TestInterface!EObject.allInstancesFrom('IN')) {
> 'checking object of class: '.concat(e.eClass().getName()).println();
> --e.debug('--');
> for (a in e.eClass().getEAllAttributes()) {
> --a.debug(' attribute ');
> ' attribute: '.concat(a.getName()).println();
> if (a.getName() = 'Typ') {
> ' got a match'.println();
> ' value of Typ is: '.concat(e.eGet(a)).println();
> thisModule.xrefs <- thisModule.xrefs.including(e.eGet(a), e);
> }
> }
> }
> 'finished creating xrefs'.println();
> }
> }
Re: [ATL] stack overflow from simple script [message #106372 is a reply to message #106333] Tue, 09 June 2009 14:50 Go to previous messageGo to next message
Henrik Rentz-Reichert is currently offline Henrik Rentz-ReichertFriend
Messages: 261
Registered: July 2009
Senior Member
I've attached my example to the bug

William Piers wrote:
> Hello,
>
> I don't see what you can do here to avoid that error. "do" sections are
> sometimes quite unstable due to the stack size issue, as you mentioned.
>
> There is an existing bug about that, could you please attach your
> example to it?
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=245891
>
> Thanks in advance,
>
> William
>
> Henrik Rentz-Reichert a écrit :
>> Hi all,
>>
>> I have a simple script (see below) that for each object in the source
>> model loops over all attributes and produces some output.
>>
>> This lead to an ArrayOutOfBoundsException in
>> org.eclipse.m2m.atl.engine.emfvm.ASMOperation
>>
>> since every result of a println() operation seems to be appended to the
>> array
>> final Object[] stack = new Object[MAX_STACK];
>>
>> For a still small model the frame pointer fp hit the MAX_STACK value of
>> 100. When I increased that to 1000 everything went fine.
>>
>> I don't know details about the VM implementation but I assume it is a
>> principle flaw if a nested loop is sort of expanded to a stack?
>>
>> Can you give me a hint which kind of constructs I have to avoid for not
>> falling into this kind of pit?
>>
>> Regards,
>> Henrik
>>
>> -------------------------- xrefs_simple.atl ----------------------------
>>
>> module xrefs_simple;
>>
>> create OUT : TestSequence from IN : TestInterface;
>>
>> helper def: xrefs : Map(String, TestInterface!EObject) = Map{};
>>
>> entrypoint rule createMapAndRoot() {
>> to
>> t: TestSequence!PortSequence
>> do {
>> 'started creating xrefs'.println();
>> for (e in TestInterface!EObject.allInstancesFrom('IN')) {
>> 'checking object of class:
>> '.concat(e.eClass().getName()).println();
>> --e.debug('--');
>> for (a in e.eClass().getEAllAttributes()) {
>> --a.debug(' attribute ');
>> ' attribute: '.concat(a.getName()).println();
>> if (a.getName() = 'Typ') {
>> ' got a match'.println();
>> ' value of Typ is: '.concat(e.eGet(a)).println();
>> thisModule.xrefs <-
>> thisModule.xrefs.including(e.eGet(a), e);
>> }
>> }
>> }
>> 'finished creating xrefs'.println();
>> }
>> }
Re: [ATL] stack overflow from simple script [message #108577 is a reply to message #106372] Thu, 23 July 2009 08:16 Go to previous message
Sebastien Revol is currently offline Sebastien RevolFriend
Messages: 15
Registered: July 2009
Junior Member
Hi all,
I encountered the same problem and had a look at the executed bytecode to
understand what happened.
Indeed, in imperative blocks, any imperative statement which is not an
variable assignement (such as 'toto'.println(); or src.debug();, or even
called rules) pushes its result on the stack. The problem is that this
result is then never used by any other following statement, and the
accumulation of such results progressively leads to a stack overflow.

A workaround to avoid the overflow is to artificially "consume" the result
of such statements, using for instance a sink local variable:


rule model2model {
from src: UML!Model
using {
sinkVar: OclAny = OclUndefined;
}
to dst: UML!Model(
name <- src.name
)
do {
for (t in src.packagedElement->select(elem|
elem.oclIsKindOf(UML!Class)){
for (attr in t.ownedAttribute){
sinkVar<-'--'.println();
sinkVar<- attr.name.debug('attribute name');
}
}
}
}

It permitted me to fix my problem, I should also work for you!

Best regards,

Sebastien
Previous Topic:problem with rule
Next Topic:[ATL] Problems with allInstancesFrom()
Goto Forum:
  


Current Time: Thu Sep 19 08:50:26 GMT 2024

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

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

Back to the top