X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=Mate%2FGarbageAlloc.hs;h=5dccda0f806332ec2e6cd7ba401d46865ea9b32d;hb=3573020fca0413c6d7823e2a1d70108f25766db0;hp=56bb8f17a80cde7cfa65808258fdecaa74a907be;hpb=13cf9f65321881050edb99776f29eea8580ec457;p=mate.git diff --git a/Mate/GarbageAlloc.hs b/Mate/GarbageAlloc.hs index 56bb8f1..5dccda0 100644 --- a/Mate/GarbageAlloc.hs +++ b/Mate/GarbageAlloc.hs @@ -1,14 +1,21 @@ {-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE CPP #-} #include "debug.h" -module Mate.GarbageAlloc where +module Mate.GarbageAlloc( + mallocClassData, + mallocString, + mallocObject, + getHeapMemory, + printMemoryUsage, + mallocStringVM, + mallocObjectVM) where import Foreign import Foreign.C -#ifdef DEBUG +import Mate.GC.Boehm + import Text.Printf -#endif import Mate.Debug -- unified place for allocating Memory @@ -17,16 +24,42 @@ import Mate.Debug mallocClassData :: Int -> IO (Ptr a) mallocClassData size = do printfStr "mallocClassData: %d\n" size - mallocBytes size + mem <- mallocBytes size + addRootGC mem (plusPtr mem size) + return mem mallocString :: Int -> IO (Ptr a) mallocString size = do printfStr "mallocString: %d\n" size - mallocBytes size + mallocBytesGC size + +mallocStringVM :: Int -> IO (Ptr a) +mallocStringVM = mallocBytes foreign export ccall mallocObject :: Int -> IO CPtrdiff mallocObject :: Int -> IO CPtrdiff mallocObject size = do - ptr <- mallocBytes size + ptr <- mallocBytesGC size printfStr "mallocObject: %d\n" size return $ fromIntegral $ ptrToIntPtr ptr + +mallocObjectVM :: Int -> IO CPtrdiff +mallocObjectVM size = do + ptr <- mallocBytes size + printfStr "mallocObject VM: %d\n" size + return $ fromIntegral $ ptrToIntPtr ptr + +-- TODO: delete me +foreign export ccall demoInterfaceCall :: CUInt -> IO () +demoInterfaceCall :: CUInt -> IO () +demoInterfaceCall val = do + printf "demoInterfaceCall: 0x%08x\n" (fromIntegral val :: Word32) + return () + +getHeapMemory :: IO Int +getHeapMemory = getHeapSizeGC + + +foreign export ccall printMemoryUsage :: IO () +printMemoryUsage :: IO () +printMemoryUsage = getHeapMemory >>= print