From: Harald Steinlechner Date: Wed, 22 Aug 2012 18:20:05 +0000 (+0200) Subject: gc: delegated mallocs in GarbageAlloc to hs-boehmgc (Mate.GC.Boehm.mallocBytes); X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mate.git;a=commitdiff_plain;h=69737e443614cbe6c2acec6c3f7f6918325d4435 gc: delegated mallocs in GarbageAlloc to hs-boehmgc (Mate.GC.Boehm.mallocBytes); tests: implemented little memory leaking example jmate: added sketch implementation of Runtime class (which should be used to query heap memory and force GCs) --- diff --git a/Mate/GarbageAlloc.hs b/Mate/GarbageAlloc.hs index e7c1cc9..d993f93 100644 --- a/Mate/GarbageAlloc.hs +++ b/Mate/GarbageAlloc.hs @@ -1,11 +1,17 @@ {-# LANGUAGE ForeignFunctionInterface #-} {-# LANGUAGE CPP #-} #include "debug.h" -module Mate.GarbageAlloc where +module Mate.GarbageAlloc( + mallocClassData, + mallocString, + mallocObject, + getHeapMemory) where import Foreign import Foreign.C +import Mate.GC.Boehm + import Text.Printf import Mate.Debug @@ -15,17 +21,17 @@ import Mate.Debug mallocClassData :: Int -> IO (Ptr a) mallocClassData size = do printfStr "mallocClassData: %d\n" size - mallocBytes size + mallocBytesGC size mallocString :: Int -> IO (Ptr a) mallocString size = do printfStr "mallocString: %d\n" size - mallocBytes size + mallocBytesGC size 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 @@ -35,3 +41,7 @@ demoInterfaceCall :: CUInt -> IO () demoInterfaceCall val = do printf "demoInterfaceCall: 0x%08x\n" (fromIntegral val :: Word32) return () + +getHeapMemory :: IO Int +getHeapMemory = getHeapSize + diff --git a/tests/Garbage1.java b/tests/Garbage1.java new file mode 100644 index 0000000..4b36d86 --- /dev/null +++ b/tests/Garbage1.java @@ -0,0 +1,31 @@ +package tests; + + +public class Garbage1 +{ + + + public Garbage1(){} + + public static void main(String args[]) + { + + Big2 big2 = new Big2(); + for(int i=0;i<0x2800;i++) + { + big2 = new Big2(); + } + System.out.println("memory: todo"); + } +} + +class Big2 +{ + private int[]arr; + + public Big2() + { + arr = new int[0x400]; + //System.out.println("foo"); + } +} diff --git a/tools/installhaskellenv.sh b/tools/installhaskellenv.sh index 893cc95..32b0190 100755 --- a/tools/installhaskellenv.sh +++ b/tools/installhaskellenv.sh @@ -28,4 +28,7 @@ cabal install disassembler $CABAL_OPT # cabal install harpy $CABAL_OPT gitinstall git://wien.tomnetworks.com/harpy.git +# cabal install hs-boehmgc $CABAL_OPT +gitinstall git://wien.tomnetworks.com/hs-boehmgc.git + echo DONE