'__pin' Seem to do nothing...

G

Guest

Hi,

I am writing a mixed mode application, I have a mixed mode Assembly manipulating a managed byte[] array, to access this array in unmanaged code I '__pin' the array, As I understand, pining an object guarantee that it will not be collected by the GC ( by increasing it's refcount or so ), Taking that in mind, looking at the code generated by the compiler I can't see anything taking care of the GC refcount... following is the pinned variable with the corresponding dis-assembly section:

****************** Mixed mode C++ code line ******************
BYTE __pin *pbtArray = &btArray[0];

******************** The dis-assembly ***********************
00000019 cmp dword ptr [esi+4],0 // makes sure that NULL != &btArray[0]
0000001d ja 00000026 // if it is not NULL go three lines bellow
0000001f xor ecx,ecx
00000021 call 7227F90B // call some exception handling procedure...
00000026 lea eax,[esi+8] // get the address of &btArray[0] to eax
00000029 mov dword ptr [ebp-14h],eax // pbtArray = content of eax
********************************************************
Why there is no GC manipulation code? isn't it needed?

The original code:
********************************************************
virtual int NotArray(System::Byte btArray __gc[])
{
int i = 0;
BYTE __pin *pbtArray = &btArray[0];
for(i; i < btArray->Length; i++)
pbtArray <<= 1;
return 0;
}

Nadav
http://www.ddevel.com
 
R

Ronald Laeremans [MSFT]

Look at the IL/meta data generated. It will have a pinned modifier on the
storage location. That is sufficient for the GC to know how to handle this.

Ronald Laeremans
Visual C++ team
 
G

Guest

Hi Ronald, Thanks for your immediate responce, Taking in mind what you have said, Still there should be some code that 'tells' the GC to 'read' this meta-data, where is this code? how does the GC know to use the pinned variable meta-data? any pointers, samples or any useful information would be appriciated...

Nadav
http://www.ddevel.com

Ronald Laeremans said:
Look at the IL/meta data generated. It will have a pinned modifier on the
storage location. That is sufficient for the GC to know how to handle this.

Ronald Laeremans
Visual C++ team

Nadav said:
Hi,

I am writing a mixed mode application, I have a mixed mode Assembly
manipulating a managed byte[] array, to access this array in unmanaged
code I '__pin' the array, As I understand, pining an object guarantee that
it will not be collected by the GC ( by increasing it's refcount or so ),
Taking that in mind, looking at the code generated by the compiler I can't
see anything taking care of the GC refcount... following is the pinned
variable with the corresponding dis-assembly section:

****************** Mixed mode C++ code line ******************
BYTE __pin *pbtArray = &btArray[0];

******************** The dis-assembly ***********************
00000019 cmp dword ptr [esi+4],0 // makes sure that NULL !=
&btArray[0]
0000001d ja 00000026 // if it is not NULL go three
lines bellow
0000001f xor ecx,ecx
00000021 call 7227F90B // call some exception
handling procedure...
00000026 lea eax,[esi+8] // get the address of
&btArray[0] to eax
00000029 mov dword ptr [ebp-14h],eax // pbtArray = content of eax
********************************************************
Why there is no GC manipulation code? isn't it needed?

The original code:
********************************************************
virtual int NotArray(System::Byte btArray __gc[])
{
int i = 0;
BYTE __pin *pbtArray = &btArray[0];
for(i; i < btArray->Length; i++)
pbtArray <<= 1;
return 0;
}

Nadav
http://www.ddevel.com

 
R

Ronald Laeremans [MSFT]

It is in the runtime code for the garbage collector itself. It doesn't need
to be in the generated assembly for your program. The code to do the garbage
collection itself likewise isn't emitted as part of your program. The GC
code uses the meta data directly.

Ronald

Nadav said:
Hi Ronald, Thanks for your immediate responce, Taking in mind what you
have said, Still there should be some code that 'tells' the GC to 'read'
this meta-data, where is this code? how does the GC know to use the pinned
variable meta-data? any pointers, samples or any useful information would
be appriciated...

Nadav
http://www.ddevel.com

Ronald Laeremans said:
Look at the IL/meta data generated. It will have a pinned modifier on the
storage location. That is sufficient for the GC to know how to handle
this.

Ronald Laeremans
Visual C++ team

Nadav said:
Hi,

I am writing a mixed mode application, I have a mixed mode Assembly
manipulating a managed byte[] array, to access this array in unmanaged
code I '__pin' the array, As I understand, pining an object guarantee
that
it will not be collected by the GC ( by increasing it's refcount or
so ),
Taking that in mind, looking at the code generated by the compiler I
can't
see anything taking care of the GC refcount... following is the pinned
variable with the corresponding dis-assembly section:

****************** Mixed mode C++ code line ******************
BYTE __pin *pbtArray = &btArray[0];

******************** The dis-assembly ***********************
00000019 cmp dword ptr [esi+4],0 // makes sure that NULL !=
&btArray[0]
0000001d ja 00000026 // if it is not NULL go
three
lines bellow
0000001f xor ecx,ecx
00000021 call 7227F90B // call some exception
handling procedure...
00000026 lea eax,[esi+8] // get the address of
&btArray[0] to eax
00000029 mov dword ptr [ebp-14h],eax // pbtArray = content of
eax
********************************************************
Why there is no GC manipulation code? isn't it needed?

The original code:
********************************************************
virtual int NotArray(System::Byte btArray __gc[])
{
int i = 0;
BYTE __pin *pbtArray = &btArray[0];
for(i; i < btArray->Length; i++)
pbtArray <<= 1;
return 0;
}

Nadav
http://www.ddevel.com

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top