@@ -55,6 +55,7 @@ import Data.Function
55
55
import Data.List
56
56
import Data.Map (Map )
57
57
import qualified Data.Map as Map
58
+ import Data.Maybe (fromMaybe )
58
59
import Data.Set (Set )
59
60
import qualified Data.Set as Set
60
61
import qualified Data.Sequence as Seq
@@ -322,6 +323,7 @@ verifyPrestate ::
322
323
verifyPrestate cc mspec globals0 =
323
324
do let sym = cc^. jccBackend
324
325
let jc = cc^. jccJVMContext
326
+ let halloc = cc^. jccHandleAllocator
325
327
let preallocs = mspec ^. MS. csPreState . MS. csAllocs
326
328
let tyenv = MS. csAllocations mspec
327
329
let nameEnv = mspec ^. MS. csPreState . MS. csVarTypeNames
@@ -338,8 +340,29 @@ verifyPrestate cc mspec globals0 =
338
340
let makeWritable gs fid = CJ. doStaticFieldWritable sym jc gs fid (W4. truePred sym)
339
341
globals0' <- liftIO $ foldM makeWritable globals0 updatedStaticFields
340
342
343
+ -- determine which arrays and instance fields need to be writable
344
+ let addUpdates pt (as, es, fs) =
345
+ case pt of
346
+ JVMPointsToField _ a fid _ -> (as, es, Map. insertWith (++) a [fid] fs)
347
+ JVMPointsToStatic {} -> (as, es, fs)
348
+ JVMPointsToElem _ a i _ -> (as, Map. insertWith (++) a [i] es, fs)
349
+ JVMPointsToArray _ a _ -> (Set. insert a as, es, fs)
350
+ let (updatedArrays, updatedElems, updatedFields) =
351
+ foldr addUpdates (Set. empty, Map. empty, Map. empty) postPointsTos
352
+
341
353
-- Allocate objects in memory for each 'jvm_alloc'
342
- (env, globals1) <- runStateT (traverse (doAlloc cc . snd ) preallocs) globals0'
354
+ let doAlloc a (_loc, alloc) =
355
+ case alloc of
356
+ AllocObject cname ->
357
+ StateT (CJ. doAllocateObject sym halloc jc cname (flip elem fids))
358
+ where fids = fromMaybe [] (Map. lookup a updatedFields)
359
+ AllocArray len ty ->
360
+ StateT (CJ. doAllocateArray sym halloc jc len ty writable)
361
+ where
362
+ writable
363
+ | Set. member a updatedArrays = const True
364
+ | otherwise = maybe (const False ) (flip elem ) (Map. lookup a updatedElems)
365
+ (env, globals1) <- runStateT (Map. traverseWithKey doAlloc preallocs) globals0'
343
366
344
367
globals2 <- setupPrePointsTos mspec cc env (mspec ^. MS. csPreState . MS. csPointsTos) globals1
345
368
cs <- setupPrestateConditions mspec cc env (mspec ^. MS. csPreState . MS. csConditions)
@@ -506,21 +529,6 @@ assertEqualVals cc v1 v2 =
506
529
507
530
--------------------------------------------------------------------------------
508
531
509
- doAlloc ::
510
- JVMCrucibleContext ->
511
- Allocation ->
512
- StateT (Crucible. SymGlobalState Sym ) IO JVMRefVal
513
- doAlloc cc alloc =
514
- case alloc of
515
- AllocObject cname -> StateT (CJ. doAllocateObject sym halloc jc cname)
516
- AllocArray len ty -> StateT (CJ. doAllocateArray sym halloc jc len ty)
517
- where
518
- sym = cc^. jccBackend
519
- halloc = cc^. jccHandleAllocator
520
- jc = cc^. jccJVMContext
521
-
522
- --------------------------------------------------------------------------------
523
-
524
532
getMethodHandle :: CJ. JVMContext -> JVMMethodId -> IO CJ. JVMHandleInfo
525
533
getMethodHandle jc (JVMMethodId mkey cname) =
526
534
case Map. lookup (cname, mkey) (CJ. methodHandles jc) of
0 commit comments