From de9b805eb93b4a39c03e9f7e1cda62c674c87fe3 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Sun, 9 Sep 2012 14:56:15 +0200 Subject: [PATCH] codegen: get full jnmap in patcher at compile-time, the java PC to native PC map is not complete yet. --- Mate.hs | 2 +- Mate/ClassPool.hs | 3 ++- Mate/MethodPool.hs | 8 ++++---- Mate/MethodPool.hs-boot | 2 +- Mate/X86CodeGen.hs | 5 +++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Mate.hs b/Mate.hs index e93fea4..2231a58 100644 --- a/Mate.hs +++ b/Mate.hs @@ -67,7 +67,7 @@ executeMain bclspath cls = do Just m -> do let mi = MethodInfo "main" bclspath $ methodSignature m rawmethod <- parseMethod cls "main" $ methodSignature m - entry <- compileBB rawmethod mi + entry <- compileBB mi rawmethod mi addMethodRef entry mi [bclspath] printfInfo "executing `main' now:\n" executeFuncPtr $ fst entry diff --git a/Mate/ClassPool.hs b/Mate/ClassPool.hs index baf49a3..245b1a4 100644 --- a/Mate/ClassPool.hs +++ b/Mate/ClassPool.hs @@ -275,7 +275,8 @@ loadAndInitClass path = do Just m -> do rawmethod <- parseMethod (ciFile ci) "" $ MethodSignature [] ReturnsVoid let mi = MethodInfo "" path (methodSignature m) - entry <- compileBB rawmethod mi + -- TODO(bernhard): test exception handling in static initalizer + entry <- compileBB mi rawmethod mi addMethodRef entry mi [path] printfCp $ printf "executing static initializer from %s now\n" (toString path) executeFuncPtr $ fst entry diff --git a/Mate/MethodPool.hs b/Mate/MethodPool.hs index 6eba0d4..5918a2f 100644 --- a/Mate/MethodPool.hs +++ b/Mate/MethodPool.hs @@ -77,7 +77,7 @@ getMethodEntry mi@(MethodInfo method cm sig) = do return nf' else do rawmethod <- parseMethod cls' method sig - entry <- compileBB rawmethod (MethodInfo method (thisClass cls') sig) + entry <- compileBB mi rawmethod (MethodInfo method (thisClass cls') sig) addMethodRef entry mi clsnames return entry Nothing -> error $ show method ++ " not found. abort" @@ -133,13 +133,13 @@ addMethodRef entry (MethodInfo mmname _ msig) clsnames = do setMethodMap $ mmap `M.union` newmap -compileBB :: RawMethod -> MethodInfo -> IO (NativeWord, JpcNpcMap) -compileBB rawmethod methodinfo = do +compileBB :: MethodInfo -> RawMethod -> MethodInfo -> IO (NativeWord, JpcNpcMap) +compileBB mi rawmethod methodinfo = do tmap <- getTrapMap cls <- getClassFile (methClassName methodinfo) printfJit $ printf "emit code of \"%s\" from \"%s\":\n" (toString $ methName methodinfo) (toString $ methClassName methodinfo) - let ebb = emitFromBB cls rawmethod + let ebb = emitFromBB cls mi rawmethod let cgconfig = defaultCodeGenConfig { codeBufferSize = fromIntegral $ rawCodeLength rawmethod * 32 } (jnmap, Right right) <- runCodeGenWithConfig ebb () M.empty cgconfig diff --git a/Mate/MethodPool.hs-boot b/Mate/MethodPool.hs-boot index e55aab8..6bb91c3 100644 --- a/Mate/MethodPool.hs-boot +++ b/Mate/MethodPool.hs-boot @@ -10,6 +10,6 @@ import Foreign.C.Types addMethodRef :: (NativeWord, JpcNpcMap) -> MethodInfo -> [B.ByteString] -> IO () -compileBB :: RawMethod -> MethodInfo -> IO (NativeWord, JpcNpcMap) +compileBB :: MethodInfo -> RawMethod -> MethodInfo -> IO (NativeWord, JpcNpcMap) executeFuncPtr :: NativeWord -> IO () getMethodEntry :: MethodInfo -> IO (CPtrdiff, JpcNpcMap) diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index 03333ce..79586ef 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -45,8 +45,8 @@ type BBStarts = M.Map BlockID Int type CompileInfo = (EntryPoint, Int, TrapMap) -emitFromBB :: Class Direct -> RawMethod -> CodeGen e JpcNpcMap (CompileInfo, [Instruction]) -emitFromBB cls method = do +emitFromBB :: Class Direct -> MethodInfo -> RawMethod -> CodeGen e JpcNpcMap (CompileInfo, [Instruction]) +emitFromBB cls miThis method = do let keys = M.keys hmap llmap <- mapM (newNamedLabel . (++) "bb_" . show) keys let lmap = zip keys llmap @@ -218,6 +218,7 @@ emitFromBB cls method = do emit' ATHROW = do trapaddr <- emitSigIllTrap 2 let patcher resp reip = do + (_, jnmap) <- liftIO $ getMethodEntry miThis error "no athrow for you, sorry" emitSigIllTrap 2 return reip -- 2.25.1