Restore 'caml_unregister_frametable' in OCaml 5#12789
Conversation
|
Hi @gasche, Here is a tentative to restore Regards, |
c5ac415 to
da5499b
Compare
| for (int i = 0; i < array->ntables; i++) | ||
| new_frametables = cons((intnat*)array->table[i], new_frametables); | ||
|
|
||
| clean_frame_descriptors(¤t_frame_descrs); |
There was a problem hiding this comment.
I would find it more natural/predictable/future-proof to clean at the next STW of some sort, instead of waiting an indefinite amount of time to do the cleanup.
There was a problem hiding this comment.
One place where to do this would be in major_gc.c, right before or after the call to caml_code_fragment_cleanup_from_stw_single within stw_cycle_all_domains.
There was a problem hiding this comment.
I guess that we may want to do the cleanup here (in register_frametables) and there (in the major GC), instead of doing in just one place. If we did it only in the GC, we avoid unbounded delays but then the addition logic in register_frametables may still encounter stale entries.
There was a problem hiding this comment.
There was a problem hiding this comment.
You are the C expert, can we get away with a extern void clean_frame_descriptors(void); declaration somewhere in major_gc.c, without changing the linking order?
There was a problem hiding this comment.
Well, actually, it is not an issue with the declaration (we can include frame_descriptors.h without any issue) but I think it is about the order in which we feed the object file .o to the compiler.
A possible workaround would be to expose a register_cleanup_callback in the GC, so the latter code can register cleanup routine without being a link dependency (it would also avoid the issue that the function is a "native only function" while the GC code is common with bytecode too).
Note: I did not check if there is not already this kind of hook.
There was a problem hiding this comment.
Hi @gasche, I get a simple workaround that will not deeply modify the Makefile but I do not know if it fits the coding standard of the project.
The idea is to simply (conditionally) import the frame_descriptors.c file into major_gc.c file.
Do you think it is ok ?
There was a problem hiding this comment.
This sounds like unwanted complexity to me. I propose to just drop my suggestion and keep things as you wrote them initially, where the removal is only forced when adding more frametables later.
There was a problem hiding this comment.
Ok, so should I drop the commit 6bc2386 ?
There was a problem hiding this comment.
I guess so. Sorry for the trouble.
| /* The unregistered frametables can still be in use after calling | ||
| this function. Thus, you should not free their memory. | ||
| Note: it may reorder the content of the array 'tables' */ | ||
| void caml_copy_and_register_frametables(void **table, int *sizes, int ntables); |
There was a problem hiding this comment.
a newline before the prototype would be nice to avoid confusions around: which comments documents what.
There was a problem hiding this comment.
I added a space / reorder the declaration in 6965188
f0e36ae to
ba09794
Compare
gasche
left a comment
There was a problem hiding this comment.
I did another round of looking at the code (and comparing with the 4.x implementation), and I agree that this is fine, but I would like to see slightly more documentation of the synchronization mechanisms for removal.
(Someone should be able to understand the code and make the right design decision to evolve it from the code comments alone, without trying to go back to read the PR discussions.)
| /* cell and the (appended) frametable copy. This way, we do not have */ | ||
| /* to change the code that unregister the frametable since calling free */ | ||
| /* on the cons cell will automatically free the frametable copy at the */ | ||
| /* same time. */ |
There was a problem hiding this comment.
Nitpick: the house style is to use block comments for the whole block, not once per line (except in the license header). Could you move to that?
Sounds good, plus hopefully some more comments as suggested in my review and a minor style change. Yes, I think this would be ready to merge afterwards. The changes entry should go in the "Working version" section: this is a new feature so it will not be backported in the upcoming 5.2 release, it will be included in 5.3. |
|
Thank you, I will try to address the few changes this week and ping you again. |
|
@gasche Just a small word to tell you I do not forget this one but I was quite busy lately and will address your points the next week. |
6bc2386 to
42f58f6
Compare
|
Hi @gasche, I finally took the time to rebase the branch and update the comments as requested. |
|
Hi @gasche, do you have any insight on this? |
3dc8958 to
d37ad5c
Compare
|
Hi @gasche, I rebased the branch yesterday, everything seems to be ok. |
gasche
left a comment
There was a problem hiding this comment.
Apologies for the delay. This looks good! Approved. (See comment for minor grammatical nitpick.)
d37ad5c to
1a97d0b
Compare
1a97d0b to
5f9b696
Compare
|
Merged! Thanks for the tenacious contribution. |
|
Thank you :) |
|
Hi @recoules, I came across caml_unregister_frametable while reviewing locks in the runtime, and I have a couple of questions if you don't mind helping me reviewing it:
|
|
Hi @gadmm,
All operations but
It am not sure to understand everything but, in your proposition, the code will call Regards, |
|
Thanks @recoules! If |
This PR is a "fork" of the PR #12756. It focuses only on restoring the function
caml_unregister_frametablein OCaml 5.In order to be able to use
caml_unregister_frametableat any moment (even in acustomblock finaliser), I use a pending list of frames to remove. The frames will only be removed the next time we want to register a new frame (STW event).A mutex protects the shared table to concurent call to
caml_unregister_frametable.This PR also introduces a new mechanism to register a frametable (
caml_copy_and_register_frametables). The copy is attached to thecaml_frametable_listelement and will be automatically released with the unregister process.