Question

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!

Was it helpful?

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.

OTHER TIPS

If you notice, the Java version of Factorial has no data members. The Java version of BubbleSort has two 4-byte ints (8 bytes total).

Presumably the "overhead" of an object is 4 bytes (the size of a pointer to the class object).

So Factorial has an object size of 4 and BubbleSort has an object size of 12.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top