Search code examples
javacompiler-constructionintermediate-languageintermediate-code

How do we know how big to set the Heap?


I'm trying to convert Java to an intermediate language and am in the process of figuring out how the intermediate language works.

I have the original Java code: http://cs.ucla.edu/classes/spring11/cs132/cs132/mj/Factorial.java

And I have the Intermediate Code representation (VAPOR): http://cs.ucla.edu/classes/spring11/cs132/kannan/vapor-examples/Factorial.vapor

Here's another set: in Java: http://cs.ucla.edu/classes/spring11/cs132/cs132/mj/BubbleSort.java

In VAPOR: http://cs.ucla.edu/classes/spring11/cs132/kannan/vapor-examples/BubbleSort.vapor

My question is, all of the VAPOR code has t.0 = HeapAllocZ(x) (where x is an int). I'm wondering how the converter determines the heap size needs to be size x. In Factorial.vapor, it's set to 4. In BubbleSort.vapor, it's set to 12.

Thanks!


Solution

  • It looks like the HeapAlloc is based on the size of the structure you are creating (assuming 4 and 12 are byte values). I would think that looking at the variables your data structure uses, and counting the number of bytes those variables sum to would give you the number being allocated.