#include "debug.h"
module Mate.GarbageAlloc(
mallocClassData,
- mallocString,
- mallocObject,
+ mallocStringGC,
+ mallocObjectGC,
getHeapMemory,
printMemoryUsage,
- mallocStringVM,
- mallocObjectVM,
- printGCStats) where
+ printGCStats,
+ mallocObjectUnmanaged,
+ mallocStringUnmanaged) where
import Foreign
import Foreign.C
addRootGC mem (plusPtr mem size)
return mem
-mallocString :: Int -> IO (Ptr a)
-mallocString size = do
+mallocStringGC :: Int -> IO (Ptr a)
+mallocStringGC 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
+foreign export ccall mallocObjectGC :: Int -> IO CPtrdiff
+mallocObjectGC :: Int -> IO CPtrdiff
+mallocObjectGC size = do
ptr <- mallocBytesGC size
printfStr "mallocObject: %d\n" size
return $ fromIntegral $ ptrToIntPtr ptr
-mallocObjectVM :: Int -> IO CPtrdiff
-mallocObjectVM size = do
+mallocObjectUnmanaged :: Int -> IO CPtrdiff
+mallocObjectUnmanaged size = do
ptr <- mallocBytes size
- printfStr "mallocObject VM: %d\n" size
+ printfStr "mallocObjectUnmanged: %d\n" size
return $ fromIntegral $ ptrToIntPtr ptr
+mallocStringUnmanaged :: Int -> IO (Ptr a)
+mallocStringUnmanaged size = do
+ printfStr "mallocStringUnamaged: %d\n" size
+ mallocBytes size
+
+
getHeapMemory :: IO Int
getHeapMemory = getHeapSizeGC
-- build object layout
fsize <- getObjectSize "java/lang/String"
printfStr "string: fsize: %d (should be 4 * 5)\n" fsize
- tblptr <- mallocObjectVM $ fromIntegral fsize
+ tblptr <- mallocObjectUnmanaged $ fromIntegral fsize
let ptr = intPtrToPtr (fromIntegral tblptr) :: Ptr CPtrdiff
mtbl <- getMethodTable "java/lang/String"
poke ptr $ fromIntegral mtbl
-- build array layout
let strlen = fromIntegral $ B.length str
-- (+1) for \0, (+4) for length
- newstr <- mallocStringVM (strlen + 5)
+ newstr <- mallocStringUnmanaged (strlen + 5) --[TODO hs,bernhard: should be managed right?]
BI.memset newstr 0 (fromIntegral $ strlen + 5)
arr <- newArray ((map fromIntegral $ B.unpack str) :: [Word8])
copyBytes (plusPtr newstr 4) arr strlen