From ccc1ff2921984cfd36595e935e3634842fa2cb7d Mon Sep 17 00:00:00 2001 From: Harald Steinlechner Date: Fri, 24 Aug 2012 15:03:27 +0200 Subject: [PATCH] GarbageAlloc: little refactoring - all GC allocate methods should have GC suffix; all non GC methods on the other hand should suffix Unmanaged; --- Mate/GarbageAlloc.hs | 35 +++++++++++++++++++---------------- Mate/Strings.hs | 4 ++-- Mate/X86CodeGen.hs | 2 +- tools/installBoehm.sh | 8 ++++++++ 4 files changed, 30 insertions(+), 19 deletions(-) create mode 100755 tools/installBoehm.sh diff --git a/Mate/GarbageAlloc.hs b/Mate/GarbageAlloc.hs index dc806b7..c2b622c 100644 --- a/Mate/GarbageAlloc.hs +++ b/Mate/GarbageAlloc.hs @@ -3,13 +3,13 @@ #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 @@ -29,27 +29,30 @@ mallocClassData size = do 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 diff --git a/Mate/Strings.hs b/Mate/Strings.hs index e5f0fd9..2f7504a 100644 --- a/Mate/Strings.hs +++ b/Mate/Strings.hs @@ -57,7 +57,7 @@ allocateJavaString str = do -- 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 @@ -65,7 +65,7 @@ allocateJavaString str = do -- 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 diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index 68cc70e..40b8262 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -35,7 +35,7 @@ import Text.Printf #endif -foreign import ccall "&mallocObject" +foreign import ccall "&mallocObjectGC" mallocObjectAddr :: FunPtr (Int -> IO CPtrdiff) type EntryPoint = Ptr Word8 diff --git a/tools/installBoehm.sh b/tools/installBoehm.sh new file mode 100755 index 0000000..9e3fedc --- /dev/null +++ b/tools/installBoehm.sh @@ -0,0 +1,8 @@ +#!/bin/bash -x +git clone git://wien.tomnetworks.com/hs-boehmgc.git hs-boehmgc +cd hs-boehmgc +runhaskell Setup.hs configure --user $CABAL_OPT +runhaskell Setup.hs build +runhaskell Setup.hs install +cd .. +echo DONE -- 2.25.1