You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Yuri Kashnikoff <yu...@gmail.com> on 2008/01/24 11:36:13 UTC

[drlvm][gc] Question about references and fields.

Hi!

I need to get the name of some reference field (e.g. for String.value
- value).  Using iterating functions (like
object_ref_iterator_get(int* iterator, Partial_Reveal_Object *obj)) we
could get all REF* 's for Partial_Reveal_Object* obj. And is there any
methods to recognize the name(field name) of this reference field?

Thank, You!

-- 
Yuri S. Kashnikov
Novosibirsk State University, Russia
2 Pirogova street
630090, Novosibirsk-90
yuri.kashnikoff@gmail.com

Re: [drlvm][gc] Question about references and fields.

Posted by Yuri Kashnikoff <yu...@gmail.com>.
On Jan 24, 2008 6:31 PM, Pavel Pervov <pm...@gmail.com> wrote:
> Hm...
>
> Yuri, it looks like I've overegged the pudding.
>
> For (1) - you can lookup the field offset once and then cache it
> somewhere - no need for lookup it on each 'get'.
>
> Pavel.
>
>
Thank You, Pavel!

Your hint is exactly what I need!

> On 1/24/08, Pavel Pervov <pm...@gmail.com> wrote:
> > Yuri,
> >
> > 1) Use the Xiao-Feng's proposal to find "next" field in each object of
> > your list.
> > 2) From that field retrieve its offset.
> > 3) Use offset to find the value of 'next' field. Smth like this:
> >
> > Partial_Reveal_Object* next_obj =
> > (Partial_Reveal_Object*)((char*)this_obj + next_field_offset);
> >
> > WBR,
> > Pavel.
> >
> > On 1/24/08, Yuri Kashnikoff <yu...@gmail.com> wrote:
> > > On Jan 24, 2008 5:47 PM, Xiao-Feng Li <xi...@gmail.com> wrote:
> > > > Yuri, to get reference field you need different approach. Object field
> > > > meta info are kept in its class structure. From an object, you can get
> > > > it's vtable pointer (VTable*), from vtable pointer you can get its
> > > > class structure (Class* or Class_Handle). Assuming you have the
> > > > Class_Handle of a class _clss, then you can iterate its fields by
> > > > following routine:
> > > >
> > > >   unsigned int nfields = class_number_fields(_clss);
> > > >   unsigned int i;
> > > >
> > > >   for(i=0; i<nfields; i++){
> > > >     Field_Handle field = class_get_field(_clss, i);
> > > >     char* field_name = field_get_name(field);
> > > >   }
> > > >
> > > > Please play around to be familiar with the APIs.
> > > Xiao-Feng, first of all thank You for your answer!
> > >
> > > Sorry may be I was incorrect. I know how to iterate fields with such
> > > method as You have mentioned above. Imagine that there is a list
> > > implementation and 'next' field is typically 'next' field of list
> > > implementation ('next' refers to the next element of the list).
> > > How to get the address of the object on which it('next') refers?
> > >
> > > --
> > > Yuri S. Kashnikov
> > > Novosibirsk State University, Russia
> > > 2 Pirogova street
> > > 630090, Novosibirsk-90
> > > yuri.kashnikoff@gmail.com
> > >
> >
>
>
> --
> Pavel Pervov,
> Intel Enterprise Solutions Software Division
>



-- 
Yuri S. Kashnikov
Novosibirsk State University, Russia
2 Pirogova street
630090, Novosibirsk-90
yuri.kashnikoff@gmail.com

Re: [drlvm][gc] Question about references and fields.

Posted by Pavel Pervov <pm...@gmail.com>.
Hm...

Yuri, it looks like I've overegged the pudding.

For (1) - you can lookup the field offset once and then cache it
somewhere - no need for lookup it on each 'get'.

Pavel.

On 1/24/08, Pavel Pervov <pm...@gmail.com> wrote:
> Yuri,
>
> 1) Use the Xiao-Feng's proposal to find "next" field in each object of
> your list.
> 2) From that field retrieve its offset.
> 3) Use offset to find the value of 'next' field. Smth like this:
>
> Partial_Reveal_Object* next_obj =
> (Partial_Reveal_Object*)((char*)this_obj + next_field_offset);
>
> WBR,
> Pavel.
>
> On 1/24/08, Yuri Kashnikoff <yu...@gmail.com> wrote:
> > On Jan 24, 2008 5:47 PM, Xiao-Feng Li <xi...@gmail.com> wrote:
> > > Yuri, to get reference field you need different approach. Object field
> > > meta info are kept in its class structure. From an object, you can get
> > > it's vtable pointer (VTable*), from vtable pointer you can get its
> > > class structure (Class* or Class_Handle). Assuming you have the
> > > Class_Handle of a class _clss, then you can iterate its fields by
> > > following routine:
> > >
> > >   unsigned int nfields = class_number_fields(_clss);
> > >   unsigned int i;
> > >
> > >   for(i=0; i<nfields; i++){
> > >     Field_Handle field = class_get_field(_clss, i);
> > >     char* field_name = field_get_name(field);
> > >   }
> > >
> > > Please play around to be familiar with the APIs.
> > Xiao-Feng, first of all thank You for your answer!
> >
> > Sorry may be I was incorrect. I know how to iterate fields with such
> > method as You have mentioned above. Imagine that there is a list
> > implementation and 'next' field is typically 'next' field of list
> > implementation ('next' refers to the next element of the list).
> > How to get the address of the object on which it('next') refers?
> >
> > --
> > Yuri S. Kashnikov
> > Novosibirsk State University, Russia
> > 2 Pirogova street
> > 630090, Novosibirsk-90
> > yuri.kashnikoff@gmail.com
> >
>


-- 
Pavel Pervov,
Intel Enterprise Solutions Software Division

Re: [drlvm][gc] Question about references and fields.

Posted by Pavel Pervov <pm...@gmail.com>.
Yuri,

1) Use the Xiao-Feng's proposal to find "next" field in each object of
your list.
2) From that field retrieve its offset.
3) Use offset to find the value of 'next' field. Smth like this:

Partial_Reveal_Object* next_obj =
(Partial_Reveal_Object*)((char*)this_obj + next_field_offset);

WBR,
Pavel.

On 1/24/08, Yuri Kashnikoff <yu...@gmail.com> wrote:
> On Jan 24, 2008 5:47 PM, Xiao-Feng Li <xi...@gmail.com> wrote:
> > Yuri, to get reference field you need different approach. Object field
> > meta info are kept in its class structure. From an object, you can get
> > it's vtable pointer (VTable*), from vtable pointer you can get its
> > class structure (Class* or Class_Handle). Assuming you have the
> > Class_Handle of a class _clss, then you can iterate its fields by
> > following routine:
> >
> >   unsigned int nfields = class_number_fields(_clss);
> >   unsigned int i;
> >
> >   for(i=0; i<nfields; i++){
> >     Field_Handle field = class_get_field(_clss, i);
> >     char* field_name = field_get_name(field);
> >   }
> >
> > Please play around to be familiar with the APIs.
> Xiao-Feng, first of all thank You for your answer!
>
> Sorry may be I was incorrect. I know how to iterate fields with such
> method as You have mentioned above. Imagine that there is a list
> implementation and 'next' field is typically 'next' field of list
> implementation ('next' refers to the next element of the list).
> How to get the address of the object on which it('next') refers?
>
> --
> Yuri S. Kashnikov
> Novosibirsk State University, Russia
> 2 Pirogova street
> 630090, Novosibirsk-90
> yuri.kashnikoff@gmail.com
>

Re: [drlvm][gc] Question about references and fields.

Posted by Yuri Kashnikoff <yu...@gmail.com>.
On Jan 24, 2008 5:47 PM, Xiao-Feng Li <xi...@gmail.com> wrote:
> Yuri, to get reference field you need different approach. Object field
> meta info are kept in its class structure. From an object, you can get
> it's vtable pointer (VTable*), from vtable pointer you can get its
> class structure (Class* or Class_Handle). Assuming you have the
> Class_Handle of a class _clss, then you can iterate its fields by
> following routine:
>
>   unsigned int nfields = class_number_fields(_clss);
>   unsigned int i;
>
>   for(i=0; i<nfields; i++){
>     Field_Handle field = class_get_field(_clss, i);
>     char* field_name = field_get_name(field);
>   }
>
> Please play around to be familiar with the APIs.
Xiao-Feng, first of all thank You for your answer!

Sorry may be I was incorrect. I know how to iterate fields with such
method as You have mentioned above. Imagine that there is a list
implementation and 'next' field is typically 'next' field of list
implementation ('next' refers to the next element of the list).
How to get the address of the object on which it('next') refers?

-- 
Yuri S. Kashnikov
Novosibirsk State University, Russia
2 Pirogova street
630090, Novosibirsk-90
yuri.kashnikoff@gmail.com

Re: [drlvm][gc] Question about references and fields.

Posted by Xiao-Feng Li <xi...@gmail.com>.
Yuri, to get reference field you need different approach. Object field
meta info are kept in its class structure. From an object, you can get
it's vtable pointer (VTable*), from vtable pointer you can get its
class structure (Class* or Class_Handle). Assuming you have the
Class_Handle of a class _clss, then you can iterate its fields by
following routine:

  unsigned int nfields = class_number_fields(_clss);
  unsigned int i;

  for(i=0; i<nfields; i++){
    Field_Handle field = class_get_field(_clss, i);
    char* field_name = field_get_name(field);
  }

Please play around to be familiar with the APIs.

Thanks,
xiaofeng

On Jan 24, 2008 6:36 PM, Yuri Kashnikoff <yu...@gmail.com> wrote:
> Hi!
>
> I need to get the name of some reference field (e.g. for String.value
> - value).  Using iterating functions (like
> object_ref_iterator_get(int* iterator, Partial_Reveal_Object *obj)) we
> could get all REF* 's for Partial_Reveal_Object* obj. And is there any
> methods to recognize the name(field name) of this reference field?
>
> Thank, You!
>
> --
> Yuri S. Kashnikov
> Novosibirsk State University, Russia
> 2 Pirogova street
> 630090, Novosibirsk-90
> yuri.kashnikoff@gmail.com
>



-- 
http://xiao-feng.blogspot.com