Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccurate GHCStats size for 32 bit arch #6

Closed
mitchellwrosen opened this issue Jul 8, 2016 · 3 comments
Closed

Inaccurate GHCStats size for 32 bit arch #6

mitchellwrosen opened this issue Jul 8, 2016 · 3 comments

Comments

@mitchellwrosen
Copy link
Contributor

mitchellwrosen commented Jul 8, 2016

I see some hard-coded 8s in Weigh.GHCStats that assume a 64 bit architecture. I can think of two ways to fix this:

  • Replace 8 with SIZEOF_HSWORD
  • Replace the generic traversal with something like:
-- Get the size of an arbitrary closure
sizeOf :: a -> Int64                                                                                                       
sizeOf x =                                                                                                                 
  case unpackClosure# x of                                                                                                 
    (# _, xs, ys #) ->                                                                                                    
      case SIZEOF_HSWORD of                                                                                                
        I# wordSize ->                                                                                                     
          I64# (wordSize +# (wordSize *# (sizeofArray# xs)) +# sizeofByteArray# ys)

ghcStatsSizeInBytes :: Int64
ghcStatsSizeInBytes = $([| sizeOf $! GCStats 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |])
@mitchellwrosen
Copy link
Contributor Author

Random aside: is there any way to get GHC to calculate a top-level thing like ghcStatsSizeInBytes at compile time w/o $([| x |])? Would inline + -O2 work?

@chrisdone
Copy link
Contributor

What's the reliability of sizeOf?

Replace 8 with SIZEOF_HSWORD

Sounds good.

@mitchellwrosen
Copy link
Contributor Author

I'm not sure what the reliability of sizeOf is, I modified it from an old Simon Marlow snippet: https://ghcmutterings.wordpress.com/2009/02/12/53/

I do understand how it works but I don't know how often the semantics of e.g. sizeofByteArray will change, or if unpackClosure will be around forever, etc.

But if you meant how likely is it to work on Haskell things, I assume it is accurate for all closures (data constructors, functions, and thunks).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants