0

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!

pauliwago
  • 6,373
  • 11
  • 42
  • 52
  • 1
    Most people just make a quick, reasonable guess and if the JVM runs out of heap, add more. Then if it keeps running out of a large heap, look for memory leaks etc – Bohemian Nov 20 '12 at 23:09
  • Based on what though? I'm trying to automate the process, and I need some concrete basis for the guess – pauliwago Nov 20 '12 at 23:10
  • @Bohemian -- He appears to be asking about the size of individual objects, not the total amount of heap needed. – Hot Licks Nov 20 '12 at 23:33

2 Answers2

1

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.

zbrunson
  • 1,587
  • 1
  • 12
  • 13
  • Yep, this is essentially what Java does, only the information is embedded in the reference to the Class object that is used in the `new` operation. The object size stored in the Class object is calculated (by essentially totaling up the field sizes) when the class is "loaded". – Hot Licks Nov 20 '12 at 23:32
0

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.

Hot Licks
  • 47,103
  • 17
  • 93
  • 151