MethodPool: removed demo call stuff - added printGCStats instead;
[mate.git] / Mate / GarbageAlloc.hs
index 1a272fbaedbbd02265d47a3a72785ab5b755cd8e..dc806b7418a99a90ab10fe3f5f1a77baacf4ca3f 100644 (file)
@@ -1,14 +1,22 @@
 {-# LANGUAGE ForeignFunctionInterface #-}
 {-# LANGUAGE CPP #-}
 #include "debug.h"
-module Mate.GarbageAlloc where
+module Mate.GarbageAlloc(
+    mallocClassData,
+    mallocString,
+    mallocObject,
+    getHeapMemory,
+    printMemoryUsage,
+    mallocStringVM,
+    mallocObjectVM,
+    printGCStats)  where
 
 import Foreign
 import Foreign.C
 
-#ifdef DEBUG
-import Text.Printf
-#endif
+import Mate.GC.Boehm
+
+--import Text.Printf
 import Mate.Debug
 
 -- unified place for allocating Memory
@@ -17,16 +25,38 @@ 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 CUInt
-mallocObject :: Int -> IO CUInt
+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
+
+getHeapMemory :: IO Int
+getHeapMemory = getHeapSizeGC
+
+foreign export ccall printMemoryUsage :: IO ()
+printMemoryUsage :: IO ()
+printMemoryUsage = getHeapMemory >>= print
+
+foreign export ccall printGCStats :: IO ()
+printGCStats :: IO ()
+printGCStats = putStrLn "Should print GC Stats"