+isInstanceOf 0 _ = return False
+isInstanceOf obj classname = do
+ obj_mtable <- peek (intPtrToPtr . fromIntegral $ obj)
+ class_mtable <- getMethodTable classname
+ ch <- readHier
+ return $ checkInstance obj_mtable class_mtable ch
+
+checkInstance :: NativeWord -> NativeWord -> HierMap -> Bool
+checkInstance obj cl_mtable ch
+ | obj == cl_mtable = True
+ | otherwise =
+ case ch M.! obj of
+ Class _ super _ -> checkInstance super cl_mtable ch
+ JavaLangObject _ -> False
+
+addClassEntry :: NativeWord -> NativeWord -> IO ()
+addClassEntry mtable 0 = do
+ ch <- readHier
+ writeHier (M.insert mtable (JavaLangObject mtable) ch)
+addClassEntry mtable super_mtable = do
+ ch <- readHier
+ when (not $ M.member super_mtable ch) $ error "classhierarchy: superclass should be in hierarchy!"
+ let cl = Class mtable super_mtable []
+ writeHier (M.insert mtable cl ch)