Trampolines: which is for what?

Hi,

Programmers of complex games for iOS know the problem of running out of trampolines.
I ran out of trampolines today again. It is of type 2.

I would like to know a bit more about the different trampolines.

For People Who don’t know about trampolines

Trampolines are used to reserve memory on AOT platforms. AOT means “Ahead Of Time”, so all the stuff is compiled before the application is started. All the stuff? No. There are some things which cannot be compiled before starting. Generic types cannot completely compiled before. So for each type passed to some gegenric class or method a new table entry is generated. On AOT platforms these tables are stored in memory which was reserved by trampolines.

PS: Please correct me if I missed something.

There are 3 types of trampolines:

  • nrgctx-trampolines
  • nimt-trampolines
  • ntrampolines

I know that one is for generics. somewhere I read once that one is for interfaces… And the third is for…?

My question is:

  • Which trampoline type is responsible for what kind of code (generics, interfaces(?), delegates(?), reflection(?), etc.)
  • The error message always tells something like “ran out of trampolines of type 2”.
    I want to know how the mapping is between the numbered type and the trampoline name… (is nimt-trampolines the type 2?)

thanks!

1 Like

There is an article somewhere that lists the different types and codes but I cannot remember where it is. Type 2 though is nimt. In the player settings there is a box where you can supply command line arguments for the compiler. You’ll want to add:

-nimt-trampolines=512

Start there and move up. The larger the number the more initial memory overhead there is so don’t just blow it up right at the start. Type 2 (nimt) I believe are the trampolines they use for generic methods (probably amongst other things).

See the last post there.

Hi Dustin,

Thanks for the reply.
I don’t see how the last post from the linked thread answers my question (my question is not how to increase the trampolines! It is about how they are related to my code and how they are mapped to the numbers in the error mesages).

I also have a third question:

  • (code relation question - see above)

  • (error type mapping - see above)

  • What means the number which I assign to the trampolines? Is it the size in bytes which is allocated for the trampolin? Or is it the number of “trampolines” (whatever this means exactly)? And is it important to have a power of 2 value here?

right, sorry, I sidetracked. :slight_smile: So I’m not 100% certain… I read a very good post on it awhile back and it was somewhere in the Xamarin forms but unfortunately I don’t recall 100% what maps to what. I believe though that Type 0 is used for generic types and Type 2 is for generic method signatures, I could be wrong on Type 0…

At any rate, Type 2 is for sure nimt. That just leaves you with Type 0 and Type 1 to map out and I’ll look again tonight to see if I can find that article but it explained how they work very well.

As to the number, that’s the number of trampolines and there is no direct correlation that can be made between the number of trampolines and the impact on memory. This is because of things like Generics, because it completely depends on how much and often those generics are used and how many different signatures there are for those types and methods. The trampolines are responsible for ‘bouncing’ out of AOT and it does some in memory voodoo to execute the generic stuff. I know this sounds very non-technical and it’s because I don’t fully understand it, just the premise of it, but basically the amount of impact it has on your memory consumption completely depends on the code, so you’d just have to play with different numbers to determine the impact.

The “ran out of trampolines” error is pretty generic and can actually occur for the other trampoline types as well. It just means there weren’t enough trampolines allotted to the application to handle whatever it is you’re doing with those trampolines (i.e. generics in the case of NIMT). These errors are fairly common.