classpool: we want the object size
authorBernhard Urban <lewurm@gmail.com>
Mon, 30 Apr 2012 11:50:44 +0000 (13:50 +0200)
committerBernhard Urban <lewurm@gmail.com>
Mon, 30 Apr 2012 12:13:24 +0000 (14:13 +0200)
i.e. the number of bytes to allocate for field members of the object.

... not the amount of (virtual) methods this object has.

what an ugly bug :-(

Mate/ClassPool.hs
Mate/X86CodeGen.hs

index 3e000dfab81c869b01c9517b0fbe5d96e05e75b3..b678f5512e815243bfaca2207f89fb45e6a923e4 100644 (file)
@@ -4,7 +4,7 @@ module Mate.ClassPool (
   getClassInfo,
   getClassFile,
   getMethodTable,
-  getMethodSize,
+  getObjectSize,
   getMethodOffset,
   getFieldOffset,
   getStaticFieldAddr
@@ -65,12 +65,13 @@ getMethodTable path = do
   ci <- getClassInfo path
   return $ ciMethodBase ci
 
-getMethodSize :: B.ByteString -> IO (Word32)
-getMethodSize path = do
+getObjectSize :: B.ByteString -> IO (Word32)
+getObjectSize path = do
   ci <- getClassInfo path
   -- TODO(bernhard): correct sizes for different types...
-  let msize = fromIntegral $ M.size $ ciMethodMap ci
-  return $ (1 + msize) * 4
+  let fsize = fromIntegral $ M.size $ ciFieldMap ci
+  -- one slot for "method-table-ptr"
+  return $ (1 + fsize) * 4
 
 foreign export ccall getStaticFieldAddr :: CUInt -> Ptr () -> IO CUInt
 getStaticFieldAddr :: CUInt -> Ptr () -> IO CUInt
index d95358c959440d0acab0d5a016b09b4fa6834f1a..0392da585ef9816e0342dcf51132ef33687901fa 100644 (file)
@@ -265,7 +265,7 @@ emitFromBB method cls hmap =  do
         push eax -- push ref again
     emit (NEW objidx) = do
         let objname = buildClassID cls objidx
-        amount <- liftIO $ getMethodSize objname
+        amount <- liftIO $ getObjectSize objname
         push (amount :: Word32)
         callMalloc
         -- TODO(bernhard): save reference somewhere for GC