MethodPool: removed demo call stuff - added printGCStats instead;
[mate.git] / Mate / GarbageAlloc.hs
1 {-# LANGUAGE ForeignFunctionInterface #-}
2 {-# LANGUAGE CPP #-}
3 #include "debug.h"
4 module Mate.GarbageAlloc(
5     mallocClassData,
6     mallocString,
7     mallocObject,
8     getHeapMemory,
9     printMemoryUsage,
10     mallocStringVM,
11     mallocObjectVM,
12     printGCStats)  where
13
14 import Foreign
15 import Foreign.C
16
17 import Mate.GC.Boehm
18
19 --import Text.Printf
20 import Mate.Debug
21
22 -- unified place for allocating Memory
23 -- TODO: implement GC stuff ;-)
24
25 mallocClassData :: Int -> IO (Ptr a)
26 mallocClassData size = do
27   printfStr "mallocClassData: %d\n" size
28   mem <- mallocBytes size
29   addRootGC mem (plusPtr mem size)
30   return mem
31
32 mallocString :: Int -> IO (Ptr a)
33 mallocString size = do
34   printfStr "mallocString: %d\n" size
35   mallocBytesGC size
36
37 mallocStringVM :: Int -> IO (Ptr a)
38 mallocStringVM = mallocBytes
39
40 foreign export ccall mallocObject :: Int -> IO CPtrdiff
41 mallocObject :: Int -> IO CPtrdiff
42 mallocObject size = do
43   ptr <- mallocBytesGC size
44   printfStr "mallocObject: %d\n" size
45   return $ fromIntegral $ ptrToIntPtr ptr
46
47 mallocObjectVM :: Int -> IO CPtrdiff
48 mallocObjectVM size = do
49   ptr <- mallocBytes size
50   printfStr "mallocObject VM: %d\n" size
51   return $ fromIntegral $ ptrToIntPtr ptr
52
53 getHeapMemory :: IO Int
54 getHeapMemory = getHeapSizeGC
55
56 foreign export ccall printMemoryUsage :: IO ()
57 printMemoryUsage :: IO ()
58 printMemoryUsage = getHeapMemory >>= print
59
60 foreign export ccall printGCStats :: IO ()
61 printGCStats :: IO ()
62 printGCStats = putStrLn "Should print GC Stats"