From af88fa2a73378fa634a8ccb51bda5c982cad6b91 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Mon, 30 Apr 2012 13:50:44 +0200 Subject: [PATCH] classpool: we want the object size 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 | 11 ++++++----- Mate/X86CodeGen.hs | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Mate/ClassPool.hs b/Mate/ClassPool.hs index 3e000df..b678f55 100644 --- a/Mate/ClassPool.hs +++ b/Mate/ClassPool.hs @@ -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 diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index d95358c..0392da5 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -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 -- 2.25.1