Project

General

Profile

Actions

Feature #15939

open

Dump symbols reference to their fstr in ObjectSpace.dump()

Added by byroot (Jean Boussier) over 5 years ago. Updated about 5 years ago.

Status:
Assigned
Target version:
-
[ruby-core:93246]

Description

Patch: https://github.com/ruby/ruby/pull/2240

Symbols wether they are dynamic or static do hold a reference onto their respective fstring, so it's important to dump these references so that it's possible to see that a String isn't garbage collected because it has an associated Symbol.

Dumping a static Symbol (before):

>> puts ObjectSpace.dump(:foobar)
{"type":"SYMBOL", "value":"foobar"}

after:

>> puts ObjectSpace.dump(:foobar)
{"address":"0x7a210c", "type":"SYMBOL", "value":"foobar", "references":["0x7f8dd482c7d8"], "dynamic": false}

Dumping a dynamic Symbol (before):

>> puts ObjectSpace.dump("foobar".to_sym)
{"address":"0x7fcdf7042eb0", "type":"SYMBOL", "class":"0x7fcdf70c8628", "frozen":true, "bytesize":6, "value":"foobar", "memsize":40, "flags":{"wb_protected":true}}

After:

>> puts ObjectSpace.dump("foobar".to_sym)
{"address":"0x7fcdf7042eb0", "type":"SYMBOL", "class":"0x7fcdf70c8628", "frozen":true, "bytesize":6, "value":"foobar", "dynamic":true, "references":["0x7fcdf7042ed8"], "memsize":40, "flags":{"wb_protected":true}}

Limitations:

ObjectSpace.dump_all rely on rb_objspace_reachable_objects_from to list an object's references.
Because of this static symbol "references" are not followed, and as such are invisible in ObjectSpace.dump_all.

I'd like to correct it but it's quite more complicated because rb_objspace_reachable_objects_from is used by the GC, so I'd need to duplicate that function for objspace_dump usage.

So I wouldn't mind some opinion on that before attempting it.

Updated by mame (Yusuke Endoh) over 5 years ago

  • Status changed from Open to Assigned
  • Assignee set to ko1 (Koichi Sasada)

ko1 will handle this.

Updated by ko1 (Koichi Sasada) over 5 years ago

>> puts ObjectSpace.dump(:foobar)
{"address":"0x7a210c", "type":"SYMBOL", "value":"foobar", "references":["0x7f8dd482c7d8"], "dynamic": false}

address should be pointer to RVALUE, so it is not acceptable.

ObjectSpace.dump_all rely on rb_objspace_reachable_objects_from to list an object's references. Because of this static symbol "references" are not followed, and as such are invisible in ObjectSpace.dump_all.

Static symbol (immediate value) does not reach any objects, so reachable_objects doesn't make sense for me.

If we need to provide such feature (getting related String or some objects from static symbol object), new method is preferable.

Could you give us your usage?

Updated by byroot (Jean Boussier) over 5 years ago

Static symbol (immediate value) does not reach any objects

Yeah, I learned more about static symbols since I wrote this patch, I wouldn't include that part anymore. I'd still maintain the dynamic part though.

Could you give us your usage?

Sure. The usage is to rebuild the graph of objects "offline" as to visualise opportunities for retained memory reduction.

So in this context, it can happen that some strings appear as "dangling", i.e. not referenced anymore, but they still appear in the dump. Or at least appearing as having less backreference than they actually have. Sometime it's because they are backing a dynamic symbol.

Here's the tool I use: https://github.com/csfrancis/harb

Updated by ko1 (Koichi Sasada) about 5 years ago

Do you need a list of String objects referenced from static symbols?

Updated by byroot (Jean Boussier) about 5 years ago

Do you need a list of String objects referenced from static symbols?

It would be useful yes. Because otherwise you might see strings with only one reference and thing that you could reclaim there by removing that reference, but in reality you can't because they are backing a static symbol.

That being said, it's a fairly unlikely case, so not the end of the world if it's not supported.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0