GC: first working version of boehm gc. working with: 8af66bf9d36f75558ec49e0461099d5f...
[mate.git] / Mate / GarbageAlloc.hs
index d993f93e68f2af865c3ee841e51fb0cfe21fe363..5dccda0f806332ec2e6cd7ba401d46865ea9b32d 100644 (file)
@@ -5,7 +5,10 @@ module Mate.GarbageAlloc(
     mallocClassData,
     mallocString,
     mallocObject,
-    getHeapMemory)  where
+    getHeapMemory,
+    printMemoryUsage,
+    mallocStringVM,
+    mallocObjectVM)  where
 
 import Foreign
 import Foreign.C
@@ -21,13 +24,18 @@ import Mate.Debug
 mallocClassData :: Int -> IO (Ptr a)
 mallocClassData size = do
   printfStr "mallocClassData: %d\n" size
-  mallocBytesGC size
+  mem <- mallocBytes size
+  addRootGC mem (plusPtr mem size)
+  return mem
 
 mallocString :: Int -> IO (Ptr a)
 mallocString size = do
   printfStr "mallocString: %d\n" size
   mallocBytesGC size
 
+mallocStringVM :: Int -> IO (Ptr a)
+mallocStringVM = mallocBytes
+
 foreign export ccall mallocObject :: Int -> IO CPtrdiff
 mallocObject :: Int -> IO CPtrdiff
 mallocObject size = do
@@ -35,6 +43,12 @@ mallocObject size = do
   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 ()
@@ -43,5 +57,9 @@ demoInterfaceCall val = do
   return ()
 
 getHeapMemory :: IO Int
-getHeapMemory = getHeapSize
+getHeapMemory = getHeapSizeGC
+
 
+foreign export ccall printMemoryUsage :: IO ()
+printMemoryUsage :: IO ()
+printMemoryUsage = getHeapMemory >>= print