Erlang C NIF access to process struct

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Erlang C NIF access to process struct

Boshan Sun
Hi all, 

In Erlang, you can use `hipe_bifs:show_heap(self()).` to debug the process's heap.

From: 0x000000001ee5c6e0 to 0x000000001ee5c748
 |         H E A P         |
 |            Address |           Contents |
 |--------------------|--------------------|
4 | 0x000000001ee5c6e0 | 0x000000000000004f |
[] | 0x000000001ee5c6e8 | 0xfffffffffffffffb |
3 | 0x000000001ee5c6f0 | 0x000000000000003f |
[4] | 0x000000001ee5c6f8 | 0x000000001ee5c6e1 |
 |--------------------|--------------------|

However the implementation is for 32-bits machine, and the table is kind of off for a 64-bits erlang.

I want to write a C NIF to print similar heap information. What I need is the address of `process -> heap` and the heap size so I can get the heap's information.

My question is, is there a way to get a pointer to the given process via pid in C NIF?

In NIF doc there's enif_get_local_pid , how does this pid translate to the process pointer?

Thanks!

Boshan


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang C NIF access to process struct

Mikael Pettersson-5
The "off" table is due to a glitch in the output routine.  The too short "H  E A P" banner is indeed a 32-vs-64 bit bug.  I fixed both in https://github.com/erlang/otp/pull/1619.

WRT accessing the current "struct process", I haven't looked in detail, but in general the NIF interface wants to abstract away representational details and replace them function calls (actual runtime function calls, not just function-like macros).  I don't see direct accesses to "struct process" fitting into that.

On Sun, Nov 5, 2017 at 4:39 AM, Boshan Sun <[hidden email]> wrote:
Hi all, 

In Erlang, you can use `hipe_bifs:show_heap(self()).` to debug the process's heap.

From: 0x000000001ee5c6e0 to 0x000000001ee5c748
 |         H E A P         |
 |            Address |           Contents |
 |--------------------|--------------------|
4 | 0x000000001ee5c6e0 | 0x000000000000004f |
[] | 0x000000001ee5c6e8 | 0xfffffffffffffffb |
3 | 0x000000001ee5c6f0 | 0x000000000000003f |
[4] | 0x000000001ee5c6f8 | 0x000000001ee5c6e1 |
 |--------------------|--------------------|

However the implementation is for 32-bits machine, and the table is kind of off for a 64-bits erlang.

I want to write a C NIF to print similar heap information. What I need is the address of `process -> heap` and the heap size so I can get the heap's information.

My question is, is there a way to get a pointer to the given process via pid in C NIF?

In NIF doc there's enif_get_local_pid , how does this pid translate to the process pointer?

Thanks!

Boshan


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang C NIF access to process struct

Boshan Sun
Does your fix also fix the variable alignment issue as well? The variable is in the beginning of the next row now, and should be in the end of same row. Also can you fix hipe_bifs:show_estack/1, hipe_bifs:show_nstack/1, hipe_bifs:show_pcb/1? They all suffer the "off" issue.

BTW, I just read your paper A Staged Tag Scheme for Erlang and it explains Erlang's tag scheme pretty well. Thanks for that. The paper was written in 2000 for R6B/R7A, just wondering do you guys have some updated paper regarding for current state of Erlang/OTP's tag scheme?

Thanks!

2017-11-05 1:34 GMT-08:00 Mikael Pettersson <[hidden email]>:
The "off" table is due to a glitch in the output routine.  The too short "H  E A P" banner is indeed a 32-vs-64 bit bug.  I fixed both in https://github.com/erlang/otp/pull/1619.

WRT accessing the current "struct process", I haven't looked in detail, but in general the NIF interface wants to abstract away representational details and replace them function calls (actual runtime function calls, not just function-like macros).  I don't see direct accesses to "struct process" fitting into that.

On Sun, Nov 5, 2017 at 4:39 AM, Boshan Sun <[hidden email]> wrote:
Hi all, 

In Erlang, you can use `hipe_bifs:show_heap(self()).` to debug the process's heap.

From: 0x000000001ee5c6e0 to 0x000000001ee5c748
 |         H E A P         |
 |            Address |           Contents |
 |--------------------|--------------------|
4 | 0x000000001ee5c6e0 | 0x000000000000004f |
[] | 0x000000001ee5c6e8 | 0xfffffffffffffffb |
3 | 0x000000001ee5c6f0 | 0x000000000000003f |
[4] | 0x000000001ee5c6f8 | 0x000000001ee5c6e1 |
 |--------------------|--------------------|

However the implementation is for 32-bits machine, and the table is kind of off for a 64-bits erlang.

I want to write a C NIF to print similar heap information. What I need is the address of `process -> heap` and the heap size so I can get the heap's information.

My question is, is there a way to get a pointer to the given process via pid in C NIF?

In NIF doc there's enif_get_local_pid , how does this pid translate to the process pointer?

Thanks!

Boshan


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang C NIF access to process struct

Dmytro Lytovchenko

2017-11-06 4:55 GMT+01:00 Boshan Sun <[hidden email]>:
Does your fix also fix the variable alignment issue as well? The variable is in the beginning of the next row now, and should be in the end of same row. Also can you fix hipe_bifs:show_estack/1, hipe_bifs:show_nstack/1, hipe_bifs:show_pcb/1? They all suffer the "off" issue.

BTW, I just read your paper A Staged Tag Scheme for Erlang and it explains Erlang's tag scheme pretty well. Thanks for that. The paper was written in 2000 for R6B/R7A, just wondering do you guys have some updated paper regarding for current state of Erlang/OTP's tag scheme?

Thanks!

2017-11-05 1:34 GMT-08:00 Mikael Pettersson <[hidden email]>:
The "off" table is due to a glitch in the output routine.  The too short "H  E A P" banner is indeed a 32-vs-64 bit bug.  I fixed both in https://github.com/erlang/otp/pull/1619.

WRT accessing the current "struct process", I haven't looked in detail, but in general the NIF interface wants to abstract away representational details and replace them function calls (actual runtime function calls, not just function-like macros).  I don't see direct accesses to "struct process" fitting into that.

On Sun, Nov 5, 2017 at 4:39 AM, Boshan Sun <[hidden email]> wrote:
Hi all, 

In Erlang, you can use `hipe_bifs:show_heap(self()).` to debug the process's heap.

From: 0x000000001ee5c6e0 to 0x000000001ee5c748
 |         H E A P         |
 |            Address |           Contents |
 |--------------------|--------------------|
4 | 0x000000001ee5c6e0 | 0x000000000000004f |
[] | 0x000000001ee5c6e8 | 0xfffffffffffffffb |
3 | 0x000000001ee5c6f0 | 0x000000000000003f |
[4] | 0x000000001ee5c6f8 | 0x000000001ee5c6e1 |
 |--------------------|--------------------|

However the implementation is for 32-bits machine, and the table is kind of off for a 64-bits erlang.

I want to write a C NIF to print similar heap information. What I need is the address of `process -> heap` and the heap size so I can get the heap's information.

My question is, is there a way to get a pointer to the given process via pid in C NIF?

In NIF doc there's enif_get_local_pid , how does this pid translate to the process pointer?

Thanks!

Boshan


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions




_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang C NIF access to process struct

Mikael Pettersson-5
In reply to this post by Boshan Sun
My PR should fix both issues with show_heap/1.  I wasn't aware the other show_* BIFs had issues, I may take a look at them soonish.

There is no updated document for the tag scheme AFAIK, but reading erts/emulator/beam/erl_term.h should, if you can decipher all #ifdefs and macros, provide the current details.  The general principles remain the same, but new types and alternatives have appeared, and existing ones may have been reassigned.

On Mon, Nov 6, 2017 at 4:55 AM, Boshan Sun <[hidden email]> wrote:
Does your fix also fix the variable alignment issue as well? The variable is in the beginning of the next row now, and should be in the end of same row. Also can you fix hipe_bifs:show_estack/1, hipe_bifs:show_nstack/1, hipe_bifs:show_pcb/1? They all suffer the "off" issue.

BTW, I just read your paper A Staged Tag Scheme for Erlang and it explains Erlang's tag scheme pretty well. Thanks for that. The paper was written in 2000 for R6B/R7A, just wondering do you guys have some updated paper regarding for current state of Erlang/OTP's tag scheme?

Thanks!

2017-11-05 1:34 GMT-08:00 Mikael Pettersson <[hidden email]>:
The "off" table is due to a glitch in the output routine.  The too short "H  E A P" banner is indeed a 32-vs-64 bit bug.  I fixed both in https://github.com/erlang/otp/pull/1619.

WRT accessing the current "struct process", I haven't looked in detail, but in general the NIF interface wants to abstract away representational details and replace them function calls (actual runtime function calls, not just function-like macros).  I don't see direct accesses to "struct process" fitting into that.

On Sun, Nov 5, 2017 at 4:39 AM, Boshan Sun <[hidden email]> wrote:
Hi all, 

In Erlang, you can use `hipe_bifs:show_heap(self()).` to debug the process's heap.

From: 0x000000001ee5c6e0 to 0x000000001ee5c748
 |         H E A P         |
 |            Address |           Contents |
 |--------------------|--------------------|
4 | 0x000000001ee5c6e0 | 0x000000000000004f |
[] | 0x000000001ee5c6e8 | 0xfffffffffffffffb |
3 | 0x000000001ee5c6f0 | 0x000000000000003f |
[4] | 0x000000001ee5c6f8 | 0x000000001ee5c6e1 |
 |--------------------|--------------------|

However the implementation is for 32-bits machine, and the table is kind of off for a 64-bits erlang.

I want to write a C NIF to print similar heap information. What I need is the address of `process -> heap` and the heap size so I can get the heap's information.

My question is, is there a way to get a pointer to the given process via pid in C NIF?

In NIF doc there's enif_get_local_pid , how does this pid translate to the process pointer?

Thanks!

Boshan


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions





_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Erlang C NIF access to process struct

Boshan Sun
Yes Dmytro I've also enjoy reading your BEAM Wisdom series and Erik Stenman's BEAM book. I think you guy's work are very good resource out there for explaining BEAM, along with of course, the source code.

Mikael thanks for fixing those hipe_bifs:show_* functions, that would really delight 64-bits Erlang users :)


2017-11-06 4:34 GMT-08:00 Mikael Pettersson <[hidden email]>:
My PR should fix both issues with show_heap/1.  I wasn't aware the other show_* BIFs had issues, I may take a look at them soonish.

There is no updated document for the tag scheme AFAIK, but reading erts/emulator/beam/erl_term.h should, if you can decipher all #ifdefs and macros, provide the current details.  The general principles remain the same, but new types and alternatives have appeared, and existing ones may have been reassigned.

On Mon, Nov 6, 2017 at 4:55 AM, Boshan Sun <[hidden email]> wrote:
Does your fix also fix the variable alignment issue as well? The variable is in the beginning of the next row now, and should be in the end of same row. Also can you fix hipe_bifs:show_estack/1, hipe_bifs:show_nstack/1, hipe_bifs:show_pcb/1? They all suffer the "off" issue.

BTW, I just read your paper A Staged Tag Scheme for Erlang and it explains Erlang's tag scheme pretty well. Thanks for that. The paper was written in 2000 for R6B/R7A, just wondering do you guys have some updated paper regarding for current state of Erlang/OTP's tag scheme?

Thanks!

2017-11-05 1:34 GMT-08:00 Mikael Pettersson <[hidden email]>:
The "off" table is due to a glitch in the output routine.  The too short "H  E A P" banner is indeed a 32-vs-64 bit bug.  I fixed both in https://github.com/erlang/otp/pull/1619.

WRT accessing the current "struct process", I haven't looked in detail, but in general the NIF interface wants to abstract away representational details and replace them function calls (actual runtime function calls, not just function-like macros).  I don't see direct accesses to "struct process" fitting into that.

On Sun, Nov 5, 2017 at 4:39 AM, Boshan Sun <[hidden email]> wrote:
Hi all, 

In Erlang, you can use `hipe_bifs:show_heap(self()).` to debug the process's heap.

From: 0x000000001ee5c6e0 to 0x000000001ee5c748
 |         H E A P         |
 |            Address |           Contents |
 |--------------------|--------------------|
4 | 0x000000001ee5c6e0 | 0x000000000000004f |
[] | 0x000000001ee5c6e8 | 0xfffffffffffffffb |
3 | 0x000000001ee5c6f0 | 0x000000000000003f |
[4] | 0x000000001ee5c6f8 | 0x000000001ee5c6e1 |
 |--------------------|--------------------|

However the implementation is for 32-bits machine, and the table is kind of off for a 64-bits erlang.

I want to write a C NIF to print similar heap information. What I need is the address of `process -> heap` and the heap size so I can get the heap's information.

My question is, is there a way to get a pointer to the given process via pid in C NIF?

In NIF doc there's enif_get_local_pid , how does this pid translate to the process pointer?

Thanks!

Boshan


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions






_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Job opportunities?

Richard A. O'Keefe-2
In reply to this post by Dmytro Lytovchenko
I have just heard through my lawyer that the University has definitely
decided to fire me, so now I am looking for work.  Anyone know of
anything that could be done by someone in Dunedin, New Zealand?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Job opportunities?

books

if you're asking for erlang related, may search on erlangcentral, and broaden your search with elixir as well, however most are in Europe or USA, if you'd like to move



Good luck.

On Mon, Nov 6, 2017 at 5:05 PM, Richard A. O'Keefe <[hidden email]> wrote:
I have just heard through my lawyer that the University has definitely
decided to fire me, so now I am looking for work.  Anyone know of
anything that could be done by someone in Dunedin, New Zealand?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions