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

Dump symbols reference to their fstr in ObjectSpace.dump() (Feature #15939) #2240

Closed
wants to merge 1 commit into from
Closed

Conversation

casperisfine
Copy link
Contributor

@casperisfine casperisfine commented Jun 18, 2019

Ref: https://bugs.ruby-lang.org/issues/15939

Symbols wether they are dynamic or static do hold a reference
onto their respective string, 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:

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

Dumping a dynamic Symbol:

>> 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.

@casperisfine casperisfine changed the title Dump symbols reference to their fstr in ObjectSpace.dump() Dump symbols reference to their fstr in ObjectSpace.dump() (Feature #15939) Jun 19, 2019
@k0kubun k0kubun changed the base branch from trunk to master August 15, 2019 17:08
@k0kubun
Copy link
Member

k0kubun commented Aug 17, 2019

Now master branch has a required check "check_branch", but I couldn't update your branch to include it. Could you rebase this from master to run it?

Symbols wether they are dynamic or static do hold a reference
onto their respective string, 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:

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

Dumping a dynamic Symbol:

```
>> 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.
@casperisfine
Copy link
Contributor Author

I rebased and the check_branch status was properly triggered.

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