process_info(P,current_function) and HiPE (was Re: Bugs with hibernate/3 and HiPE)
Mikael Pettersson
mikpe@REDACTED
Tue Sep 28 15:27:53 CEST 2010
Paul Guyot writes:
> > Hello,
> >
> > There are several bugs related to hibernate/3 BIF and HiPE:
> >
> > 1. erlang:hibernate/3 simply fails with badarg when called from HiPE.
> > 2. erlang:hibernate/3 simply fails with badarg when called dynamically, in a way that the compiler and the loader cannot replace with the i_hibernate beam instruction.
> > 3. There is a segfault in the garbage collector when calling erlang:hibernate/3 (from beam unless bug #1 is fixed) if the process went through HiPE. This is because erts_garbage_collect_hibernate would not clean up the hipe process state.
> >
> > These bugs are highly related: 1 and 2 are actually the same bug (hibernate/3 BIF isn't implemented, and apparently wasn't since it was introduced), and 3 causes segfaults with any reasonable test once bug #1 is fixed.
> >
> > The following patch fixes these issues:
> > http://github.com/pguyot/otp/commit/fcc005c8758d97d7f0c402bfffede0b22b8ab401
> > git fetch git://github.com/pguyot/otp.git fix-hibernate-with-hipe
>
>
> Hello,
>
> I realize I sent the e-mail above to erlang-bugs@ instead of erlang-patches@REDACTED
>
> Besides, even with this fix to hibernate, gen_server_SUITE:hibernate/1 test does not pass when OTP is configured with --enable-native-libs. This is not because the process does not hibernate or does not wake up. Instead, the test heavily relies on process_info(P, current_function) which is not updated by HiPE, while beam updates it (on context switch, I guess).
>
> What is the policy for current_function?
As far as HiPE is concerned, process_info(P, current_function) is a BEAM-only
introspection mechanism that should not be considered part of the Erlang
language. It's unfortunate that the test case relies on it.
> When started and when awoken after an hibernation, a simple gen_server with a non-native callback module with non-native gen_server and non-native proc_lib modules reports {current_function,{gen_server,loop,6}}. The same non-native callback module with native proc_lib and native gen_server reports {current_function,undefined} when started and {current_function,{erlang,hibernate,3}} when awoken after an hibernation (because erts_hibernate function sets current to the hibernate_3 BIF). Should we update HiPE to report some current_function, at least when switching mode? Or should we clear the current_function when waking up from hibernation?
Please investigate:
a) when and how BEAM updates current_function, and
b) when you're allowed to call process_info(P, current_function) on
a BEAM-mode function and what it returns; what if the target process
is currently running? does it stop or does process_info then return
stale data
c) to what extent the hibernate test relies on the above
Then maybe we can find a way to emulate the needed functionality
without hurting performance.
/Mikael
More information about the erlang-patches
mailing list