X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=Mate%2FStrings.hs;h=254adb2283628f8e65d255d0f605350c5cc3dd7e;hb=d52e9acb9411a9d8386ec95aa9952edb950c65b2;hp=e5f0fd99f21de81003b2f91b5bd43368f11e4f19;hpb=3573020fca0413c6d7823e2a1d70108f25766db0;p=mate.git diff --git a/Mate/Strings.hs b/Mate/Strings.hs index e5f0fd9..254adb2 100644 --- a/Mate/Strings.hs +++ b/Mate/Strings.hs @@ -1,6 +1,4 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -#include "debug.h" module Mate.Strings ( getUniqueStringAddr ) where @@ -9,9 +7,6 @@ import Data.Word import qualified Data.Map as M import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Internal as BI -#ifdef DEBUG -import Text.Printf -#endif import JVM.ClassFile @@ -42,11 +37,11 @@ allocateJavaString str = do - this -+ - | - v - - +-------------+-------+-------+----------------+--------+ - - | MethodTable | value | count | cachedhashcode | offset | - - +-------------+-------+-------+----------------+--------+ - - | | - - | +------------+ + - +-------------+---------+-------+-------+----------------+--------+ + - | MethodTable | GC Data | value | count | cachedhashcode | offset | + - +-------------+---------+-------+-------+----------------+--------+ + - | | + - | +--+ - v v - java/lang/String +--------+--------+--------+-----+------------------+ - | length | str[0] | str[1] | ... | str [length - 1] | @@ -56,8 +51,8 @@ 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 + printfStr $ printf "string: fsize: %d (should be 4 * 6)\n" fsize + tblptr <- mallocObjectUnmanaged $ fromIntegral fsize let ptr = intPtrToPtr (fromIntegral tblptr) :: Ptr CPtrdiff mtbl <- getMethodTable "java/lang/String" poke ptr $ fromIntegral mtbl @@ -65,22 +60,24 @@ 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 - printfStr "new str ptr: (%s)@%d\n" (toString str) strlen + printfStr $ printf "new str ptr: (%s)@%d\n" (toString str) strlen let newstr_length = castPtr newstr :: Ptr CPtrdiff poke newstr_length $ fromIntegral strlen + -- set GC Data (TODO) + poke (plusPtr ptr 0x4) (0 :: CPtrdiff) -- set value pointer - poke (plusPtr ptr 4) (fromIntegral (ptrToIntPtr newstr) :: CPtrdiff) + poke (plusPtr ptr 0x8) (fromIntegral (ptrToIntPtr newstr) :: CPtrdiff) -- set count field - poke (plusPtr ptr 8) (fromIntegral strlen :: CPtrdiff) + poke (plusPtr ptr 0xc) (fromIntegral strlen :: CPtrdiff) -- set hash code (TODO) - poke (plusPtr ptr 12) (0 :: CPtrdiff) + poke (plusPtr ptr 0x10) (0 :: CPtrdiff) -- set offset - poke (plusPtr ptr 16) (0 :: CPtrdiff) + poke (plusPtr ptr 0x14) (0 :: CPtrdiff) return $ fromIntegral tblptr