Changes between Version 1 and Version 2 of MakeEveryPMCAnObject

Show
Ignore:
Timestamp:
10/28/09 18:11:05 (5 years ago)
Author:
jessevdam
Comment:

make up

Legend:

Unmodified
Added
Removed
Modified
  • MakeEveryPMCAnObject

    v1 v2  
    1 This page is a direct copy/paste of jessevdam's proposal from TT #1020. 
     1This page is a direct copy/paste of proposal of jesse van dam from TT #1020. 
    22 
    33---- 
    4 The status as it is on 28 okt 2009. See branch tt_1020 for more details.  
    5 (broken at the moment will be fixed tomorrow I hope,small svn problem) 
    6  
    7 This will give some extra detail on the plan and will give a view on the current status. 
    8 Any comments are welcome.  
    9  
     4The status as it is on 28 okt 2009. See branch tt_1020 for more details. [[BR]] 
     5(broken at the moment will be fixed tomorrow I hope,small svn problem) [[BR]] 
     6[[BR]] 
     7This will give some extra detail on the plan and will give a view on the current status. [[BR]] 
     8Any comments are welcome. [[BR]] 
     9[[BR]] 
    1010The functionality in object.pmc will move to default.pmc. With this action everything will 
    11 become an object. (default.pmc will get renamed back to object.pmc).  
    12 The C pmc can keep using there C structures as they did before. But with a few restrictions. 
    13 All field must be one off the following types. 
    14 (AT_POINTER)     void* (to some C structure/data) 
    15 (AT_PMC_POINTER) pmc* (pointer to a pmc) 
    16 (AT_STRING)      STRING* (pointer to a String) 
    17 (AT_INTEGER)     INTVAL (integer) 
    18 (AT_FLOAT)       FLOATVAL (float value) 
    19 The usage of attributes as an array is no longer allowed. (ATTR INTVAL vals[4] = no long allowed) 
     11become an object. (default.pmc will get renamed back to object.pmc). [[BR]] 
     12The C pmc can keep using there C structures as they did before. But with a few restrictions. [[BR]] 
     13All field must be one off the following types. [[BR]] 
     14(AT_POINTER)     void* (to some C structure/data) [[BR]] 
     15(AT_PMC_POINTER) pmc* (pointer to a pmc) [[BR]] 
     16(AT_STRING)      STRING* (pointer to a String) [[BR]] 
     17(AT_INTEGER)     INTVAL (integer) [[BR]] 
     18(AT_FLOAT)       FLOATVAL (float value) [[BR]] 
     19The usage of attributes as an array is no longer allowed. (ATTR INTVAL vals[4] = no long allowed) [[BR]] 
    2020The following thing has been done to make the set/get attributes function also work for the attributes accessed via the 
    21 C structure. The attributes array (DPOINTER **) array has been mapped over this C structure (union).  
     21C structure. The attributes array (DPOINTER **) array has been mapped over this C structure (union). [[BR]] 
    2222The "get_attr_str","get_attr_keyed","set_attr_str","set_attr_keyed" use this array to access these attributes. 
    2323This array has element size off 32 bits. Using a 32 bits I386 machine as base. Pointers and Integers are 32 bits.  
    2424But Float (=double) are 64 bit. So they take 2 entries of this attributes array. To keep track of this sizes the  
    25 following attributes in the class.pmc are used. 
    26 -attrib_index2type  
    27 Tells which type of value can be found at each index. If it is index halfway of double value then it is a invalid value. 
    28 That is a small gap. 
    29 -attrib_markwalk 
    30 Array with the indexes to the items which has to marked. 
    31 -attrib_indexes  
    32 Array with the indexes to all items. 
    33  
    34 For exmaple when using the following attributes. 
    35 attr Context * ctx; 
    36 attr PMC * some_pmc; 
    37 attr INTVAL myval; 
    38 attr FLOAT myfloat; 
    39 attr STRING * mystring; 
    40 Then these attributes will look like: 
    41 attrib_index2type = [AT_POINTER,AT_PMC_POINTER,AT_INTEGER,AT_FLOAT,invalid,AT_STRING] 
    42 attrib_mark_walk = [1,5] 
    43 attrib_indexes = [0,1,2,3,5] 
    44  
     25following attributes in the class.pmc are used. [[BR]] 
     26-attrib_index2type [[BR]] 
     27Tells which type of value can be found at each index. If it is index halfway of double value then it is a invalid value.  
     28That is a small gap. [[BR]] 
     29-attrib_markwalk [[BR]] 
     30Array with the indexes to the items which has to marked. [[BR]] 
     31-attrib_indexes [[BR]] 
     32Array with the indexes to all items. [[BR]] 
     33[[BR]] 
     34For exmaple when using the following attributes. [[BR]] 
     35attr Context * ctx; [[BR]] 
     36attr PMC * some_pmc; [[BR]] 
     37attr INTVAL myval; [[BR]] 
     38attr FLOAT myfloat; [[BR]] 
     39attr STRING * mystring; [[BR]] 
     40Then these attributes will look like: [[BR]]  
     41attrib_index2type = [AT_POINTER,AT_PMC_POINTER,AT_INTEGER,AT_FLOAT,invalid,AT_STRING] [[BR]] 
     42attrib_mark_walk = [1,5] [[BR]] 
     43attrib_indexes = [0,1,2,3,5] [[BR]] 
     44[[BR]] 
    4545The sizeof(void*), INTVAL and FLOAT are determined by a config script and placed in the  
    4646core_pmcs.c->attrib_type2index_size function. Note that I placed some restriction on the this, see config/gen/core_pmcs.pm. 
    47 See code oo.c "get_attrib_type_from_desc", "cache_class_attribs","build_attrib_index" for extra detail. 
    48  
     47See code oo.c "get_attrib_type_from_desc", "cache_class_attribs","build_attrib_index" for extra detail. [[BR]] 
     48[[BR]] 
    4949All core pmcs get a full describing pmcclass object as a  
    50 pir created class does have, instead of the vtable struct information. See the code in lib/Parrot/Pmc2c. 
    51  
     50pir created class does have, instead of the vtable struct information. See the code in lib/Parrot/Pmc2c.[[BR]] 
     51[[BR]] 
    5252A extra load pass had been added. These are the attributes of the class.pmc which the load pass 
    53 at which they are loaded. 
    54   
    55 0    ATTR INTVAL id;             /* The type number of the PMC. [deprecated: See RT #48024] */ 
    56 0    ATTR STRING *name;          /* The name of the class. */ 
    57 0    ATTR STRING *fullname;      /* The name of the class. */ 
    58 2    ATTR PMC *_namespace;       /* The namespace it's linked to, if any. */ 
    59 -    ATTR INTVAL instantiated;   /* Any instantiations since last modification? */ 
    60 1    ATTR PMC *parents;          /* Immediate parent classes. */ 
    61 2    ATTR PMC *all_parents;      /* Cached list of ourself and all parents, in MRO order. */ 
    62 2    ATTR PMC *roles;            /* An array of roles. */ 
    63 2    ATTR PMC *methods;          /* Hash of method names to methods in this class. */ 
    64 -    ATTR PMC *vtable_overrides; /* Hash of Parrot v-table methods we override. */ 
    65 2    ATTR PMC *attrib_metadata;  /* Hash of attributes in this class to hashes of metadata. */ 
    66 2    ATTR PMC *attrib_index;     /* Lookup table for attributes in this and parents. */ 
    67 2    ATTR PMC *attrib_cache;     /* Cache of visible attrib names to indexes. */ 
    68 -    ATTR PMC *resolve_method;   /* List of method names the class provides to resolve 
    69                                  * conflicts with methods from roles. */ 
    70 -    ATTR PMC *parent_overrides; 
     53at which they are loaded.[[BR]] 
     54[[BR]] 
     550    ATTR INTVAL id;             /* The type number of the PMC. [deprecated: See RT #48024] */ [[BR]] 
     560    ATTR STRING *name;          /* The name of the class. */ [[BR]] 
     570    ATTR STRING *fullname;      /* The name of the class. */ [[BR]] 
     582    ATTR PMC *_namespace;       /* The namespace it's linked to, if any. */ [[BR]] 
     59-    ATTR INTVAL instantiated;   /* Any instantiations since last modification? */ [[BR]] 
     601    ATTR PMC *parents;          /* Immediate parent classes. */ [[BR]] 
     612    ATTR PMC *all_parents;      /* Cached list of ourself and all parents, in MRO order. */ [[BR]] 
     622    ATTR PMC *roles;            /* An array of roles. */ [[BR]] 
     632    ATTR PMC *methods;          /* Hash of method names to methods in this class. */ [[BR]] 
     64-    ATTR PMC *vtable_overrides; /* Hash of Parrot v-table methods we override. */ [[BR]] 
     652    ATTR PMC *attrib_metadata;  /* Hash of attributes in this class to hashes of metadata. */ [[BR]] 
     662    ATTR PMC *attrib_index;     /* Lookup table for attributes in this and parents. */ [[BR]] 
     672    ATTR PMC *attrib_cache;     /* Cache of visible attrib names to indexes. */ [[BR]] 
     68-    ATTR PMC *resolve_method;   /* List of method names the class provides to resolve [[BR]] 
     69                                    conflicts with methods from roles. */ [[BR]] 
     70-    ATTR PMC *parent_overrides; [[BR]] 
    71710    ATTR INTVAL attrib_count;   /* Number of attributes in attrib object store of the 
    7272                                   object of this type 
    73                                    Field could be saved by combining it with instantiated */ 
    74  
    75 0    ATTR VTABLE *vtable;        /* The vtable function of this class */ 
    76 0    ATTR VTABLE *ro_vtable; 
    77  
     73                                   Field could be saved by combining it with instantiated */ [[BR]] 
     740    ATTR VTABLE *vtable;        /* The vtable function of this class */ [[BR]] 
     750    ATTR VTABLE *ro_vtable; [[BR]] 
     76[[BR]]  
    7877The roles field uses a temporary function which create a "empty" role.pmc object. 
    7978In the future someone could implement something, which makes it possible to define a role as  
    80 in the same way a pmc is now. 
    81  
    82 The namespace is created when the class is loaded. 
    83  
     79in the same way a pmc is now. [[BR]] 
     80[[BR]] 
     81The namespace is created when the class is loaded.[[BR]] 
     82[[BR]] 
    8483The attrib_metadata is created, the "type" field is now used to describe the type of the 
    85 attributes. Which can be one of the following items "String","Void*","Integer","Float","PMC". 
    86  
     84attributes. Which can be one of the following items "String","Void*","Integer","Float","PMC". [[BR]] 
     85[[BR]] 
    8786Since all pmc will become an object, there is will be a field pointing to the pmcclass. 
    8887The pmcclass object will contain the full describtion of the pmc/object.  
    8988The pointer to the vtable struct will get removed since all information is stored in the 
    90 pmcclass object. The interp->vtables[] array get replaced with the interp->classes[] array. 
    91 This last step has already been completed. 
    92  
     89pmcclass object. The interp->vtables[] array get replaced with the interp->classes[] array. [[BR]] 
     90This last step has already been completed. [[BR]] 
     91[[BR]] 
    9392The vtable fields and initianlization of "base_type","attribute_defs","whoami","provides_str", 
    94 "isa_hash","_namespace",*"mro",*"attr_size",*"pmc_class" will become reduntant. 
    95 * are already removed 
    96  
    97 So after completion of this change the vtable struct will only hold pointers to the vtable functions. 
    98 The pmc will have no more pointer to the vtable struct, all needed information is stored in the pmcclass object. 
    99  
     93"isa_hash","_namespace",*"mro",*"attr_size",*"pmc_class" will become reduntant. [[BR]] 
     94* are already removed [[BR]] 
     95[[BR]] 
     96So after completion of this change the vtable struct will only hold pointers to the vtable functions.  
     97The pmc will have no more pointer to the vtable struct, all needed information is stored in the pmcclass object. [[BR]] 
     98[[BR]] 
    10099Because a pmcclass object, which describes a class has got a more central role and the information is used 
    101100for the removal of an object, are they stored in a seperate gc small object arena. Class object will 
     
    104103These can ofcourse be fixed in the future, but this "problem" has also been 
    105104for a while in the jvm, so I think it will not be a big problem. Once the gc system get finalized, the pmcclass object 
    106 which describes the class itself will get removed as the last one. See code src/gc/*.c.  
    107  
     105which describes the class itself will get removed as the last one. See code src/gc/*.c. [[BR]] 
     106[[BR]] 
    108107The "get_attr_str","get_attr_keyed","set_attr_str","set_attr_keyed" are the function which are 
    109108used by pir code to access the attributes. These function do lookup via a hash, as it was before 
    110 this change.  
    111 When a INTVAL,FLOAT or STRING is stored it will get unbox and stored. 
    112 When rertrieving them they will get boxed again. 
    113 Attributes of type void* can not be accessed, they are "private". 
    114 Note that the code in the core pmc's just keep using the c structure. 
     109this change. [[BR]] 
     110When a INTVAL,FLOAT or STRING is stored it will get unbox and stored. [[BR]] 
     111When rertrieving them they will get boxed again. [[BR]] 
     112Attributes of type void* can not be accessed, they are "private". [[BR]] 
     113Note that the code in the core pmc's just keep using the c structure. [[BR]] 
    115114The difference is there will be no more proxy object so setting an attribute in an extended core pmc object 
    116115will actually set the attribute values. This will make the following test succeed. 
     
    133132}}} 
    134133 
    135 The following work has already been doen. 
    136  
    137 -Replace interp->vtables[] by interp->classes[] 
    138 -Added needed extra fields in class.pmc 
    139 -Make bootstrap/load code in lib/Parrot/pmc2c/ for loading the full class information of the core pmcs 
    140 -Addapt the class registration code, (some changes still be done) 
    141 -Creation of the new attribute indexing system   
    142 -Store pmcclass object into seperate gc pool. 
     134The following work has already been done. [[BR]] 
     135[[BR]] 
     136-Replace interp->vtables[] by interp->classes[] [[BR]] 
     137-Added needed extra fields in class.pmc [[BR]]  
     138-Make bootstrap/load code in lib/Parrot/pmc2c/ for loading the full class information of the core pmcs [[BR]] 
     139-Addapt the class registration code, (some changes still be done) [[BR]] 
     140-Creation of the new attribute indexing system [[BR]] 
     141-Store pmcclass object into seperate gc pool. [[BR]] 
    143142-Because of the restriction of the c structure some attributes of some pmc had to wrapped in a struct 
    144 or pointer. This work has been completed.  
     143or pointer. This work has been completed. [[BR]] 
    145144-All pmc has become an object, this resulted in the removal of the auto_attr fields. All changes 
    146145needed for that has been completed. See for example the context.pmc. The pointer to the context has 
    147 become an attribute instead of being directly stored in the pmc->data field. 
    148 -Move the functionality of the object.pmc to default.pmc partly done 
    149 --The mark,clone,thaw,freeze,visit and finishthaw has still to be done. 
    150  
    151 Work to do and thing not yet build 
    152  
    153 This is the work that has still to be done, to complete this change.  
    154  
    155 -mark,clone,freeze,thaw,visit,finishthaw functions 
    156 Pir code can extends a core pmcs class and extra attributes to it. These extra attributes also needs to get handled. 
    157 This applies to the following function. 
    158 Marking -> mark 
    159 Cloning -> clone 
    160 Freeze/thaw -> freeze,thaw,visit,finishthaw 
     146become an attribute instead of being directly stored in the pmc->data field. [[BR]] 
     147-Move the functionality of the object.pmc to default.pmc partly done [[BR]] 
     148--The mark,clone,thaw,freeze,visit and finishthaw has still to be done. [[BR]] 
     149[[BR]] 
     150Work to do and thing not yet build[[BR]] 
     151[[BR]] 
     152This is the work that has still to be done, to complete this change. [[BR]] 
     153[[BR]] 
     154-mark,clone,freeze,thaw,visit,finishthaw functions [[BR]] 
     155Pir code can extends a core pmcs class and extra attributes to it. These extra attributes also needs to get handled. [[BR]] 
     156This applies to the following function. [[BR]] 
     157Marking -> mark [[BR]] 
     158Cloning -> clone [[BR]] 
     159Freeze/thaw -> freeze,thaw,visit,finishthaw [[BR]] 
    161160These function are currently implemented in the pmc files, but they should the "'object.pmc'" also to handle 
    162161the optionally added extra attributes. But since all attributes of type of PMC,STRING,INVTAL and FLOAT can be handled 
    163162by this "'object.pmc'" basic code, they do not need to be done by the specific pmcs code itself, except there is 
    164163something special to them. Attributes of type Void* has to be handled by the pmcs class itself. 
    165 The pmc´s has to changed in such a way the optionally added extra attributes get also handled. 
    166  
    167 -freeze/thaw system 
     164The pmc´s has to changed in such a way the optionally added extra attributes get also handled. [[BR]] 
     165[[BR]] 
     166-freeze/thaw system [[BR]] 
    168167The freeze/thaw system, make use of the imformation stored in the pmcclass objects. These need special handling in 
    169168the freeze/thaw system. First needs the classes get thawed before the object, because the information in the classpmc 
    170 object is needed for the thawing.  
     169object is needed for the thawing. [[BR]] 
    171170The current completed changed code stores the class information in the object freeze/thaw data,  
    172 but that cost extra space, which is not needed. 
    173  
    174 -get/set attr overrides 
    175 "get_attr_keyed","set_attr_keyed" are free and not implemented by any core pmc 
    176 "get_attr_str","set_attr_str" implemented in callsignature, exception,task,eventhandler 
    177  
    178 -kill pmcproxy.pmc 
    179 --make sure the init and init_pmc vtable function still get called in rigth order 
    180 --step by step removal of pmcproxy functions 
    181 --switch over to class.pmc initialize function 
    182 --kill pmcproxy.pmc file  
    183  
    184 -kill old object.pmc file 
    185 -rename default.pmc to object.pmc 
    186  
    187 -clean up 
    188 --step by step of vtable struct fields, which are no longer used 
    189 --remove vtable field from pmc struct  
    190 --remove old no longer used code 
    191 --fixup broken tests 
    192 ---threads.t and interpreter cloning may need some extra time 
    193 --fixup coding standaard 
    194  
    195 -fixup the documentation 
    196  
    197  
    198 - 
    199  
    200 Discussion on Performance  
     171but that cost extra space, which is not needed. [[BR]] 
     172[[BR]] 
     173-get/set attr overrides [[BR]] 
     174"get_attr_keyed","set_attr_keyed" are free and not implemented by any core pmc [[BR]] 
     175"get_attr_str","set_attr_str" implemented in callsignature, exception,task,eventhandler [[BR]] 
     176[[BR]] 
     177-kill pmcproxy.pmc [[BR]] 
     178--make sure the init and init_pmc vtable function still get called in rigth order [[BR]] 
     179--step by step removal of pmcproxy functions [[BR]] 
     180--switch over to class.pmc initialize function [[BR]] 
     181--kill pmcproxy.pmc file [[BR]] 
     182[[BR]] 
     183-kill old object.pmc file [[BR]] 
     184-rename default.pmc to object.pmc [[BR]] 
     185[[BR]] 
     186-clean up [[BR]] 
     187--step by step of vtable struct fields, which are no longer used [[BR]] 
     188--remove vtable field from pmc struct [[BR]] 
     189--remove old no longer used code [[BR]] 
     190--fixup broken tests [[BR]] 
     191---threads.t and interpreter cloning may need some extra time [[BR]] 
     192--fixup coding standaard [[BR]] 
     193[[BR]] 
     194-fixup the documentation [[BR]] 
     195[[BR]] 
     196Discussion on Performance [[BR]] 
    201197Take in mind that the above described int_subclass_test test is not working at the moment and fixing that is going to cost 
    202 some performance. 
    203  
    204 +no more pmc proxy object  
    205  = gaining speed (no more looking up needed) 
    206  = use less memory in case of extending core pmc (lots less memory) 
    207 -vtable function acces pmc->class->vtable->function instead of pmc->vtable->function 
    208 -some non allowed attribute types are wrapped up 
    209 -auto_attr is gone, see for example context.pmc. If there are no attributes then no mem is allocated. 
    210 -call to vtable get/set attribute functions must do extra index 2 type action 
    211 -call to vtable get/set attribute functions do unbox and boxing, but only in case of accessing 
    212 a core pmc attribute, so this one does not count :) 
    213 +allowing later on patch for vtable override function, which does the following thing: 
     198some performance.[[BR]] 
     199[[BR]] 
     200+no more pmc proxy object [[BR]] 
     201 = gaining speed (no more looking up needed) [[BR]] 
     202 = use less memory in case of extending core pmc (lots less memory) [[BR]] 
     203-vtable function acces pmc->class->vtable->function instead of pmc->vtable->function [[BR]] 
     204-some non allowed attribute types are wrapped up [[BR]] 
     205-auto_attr is gone, see for example context.pmc. If there are no attributes then no mem is allocated. [[BR]] 
     206-call to vtable get/set attribute functions must do extra index 2 type action [[BR]] 
     207-call to vtable get/set attribute functions do unbox and boxing, but only in case of accessing [[BR]] 
     208a core pmc attribute, so this one does not count :) [[BR]] 
     209+allowing later on patch for vtable override function, which does the following thing: [[BR]] 
    214210When there is a vtable override the vtable function pointer will get replaced by pointer 
    215211pointing to a lookup function which search in the vtable overrides code. Instead of having 
    216 to do a lookup search all the time. Gaining lots of speed. 
    217 +no more special code inplace for handling core pmcs 
    218 -the class.pmc needs some more initialization.  
    219 +- the mark,clone,freeze and thaw function will change 
    220 - mark function must only walk the pmc* and String* attributes 
    221 - clone function must take care of the different attribute types 
    222  
    223 +the already nice parrot code will get better smoothed out, gaining dev time (important one for me :))  
    224  
    225  
     212to do a lookup search all the time. Gaining lots of speed. [[BR]] 
     213+no more special code inplace for handling core pmcs [[BR]] 
     214-the class.pmc needs some more initialization.  [[BR]] 
     215+- the mark,clone,freeze and thaw function will change [[BR]] 
     216- mark function must only walk the pmc* and String* attributes [[BR]] 
     217- clone function must take care of the different attribute types [[BR]] 
     218[[BR]] 
     219+the already nice parrot code will get better smoothed out, gaining dev time (important one for me :))  [[BR]] 
     220[[BR]] 
     221[[BR]] 
    226222I hope have mentioned every thing and did not forget stuff.