Ticket #895 (closed experimental: done)

Opened 5 years ago

Last modified 4 years ago

Towards automatic allocation and deallocation of PMC attributes

Reported by: NotFound Owned by: NotFound
Priority: normal Milestone:
Component: none Version: 1.4.0
Severity: medium Keywords:
Cc: Language:
Patch status: Platform:

Description

Currently all PMC that use attributes must allocate and deallocate the struct that contains them during init and destroy. This is boring and error prone, and disallows or makes difficult using SUPER inside init.

I've thinked a way to avoid this: by storing the size of the struct inside the vtable, pmc_new and friends can allocate it before calling init, and will be easy to deallocate it during garbage collection when all PMC gets checked against minimal problems.

I've done some tests and looks promising.

To make easier that change, and as general cleaning, several PMC need some changes in his initialization/destruction and attribute usage. I'll refer to this ticket in the changes related to that.

Attachments

TT_895_1.patch Download (12.9 KB) - added by NotFound 5 years ago.
TT_895_3.patch Download (26.4 KB) - added by NotFound 5 years ago.
auto_attrs.patch Download (59.7 KB) - added by NotFound 5 years ago.
diff between trunk and auto_attrs branch at r40501

Change History

Changed 5 years ago by NotFound

  • status changed from new to assigned
  • owner set to NotFound

Changed 5 years ago by whiteknight

On a related note, in r40368 I added some experimental functions to the GC to manage attribute structures. Using the new functions decreases calls to malloc/free, and should speed Parrot up a little bit. The functions probably need some good testing before use. I will see if I can get some tests for it working soon.

Changed 5 years ago by NotFound

Changed 5 years ago by NotFound

The last patch is the current attempt: it introduces a new flag for the PMC declaration, auto_attrs, that declares that the PMC wants automatic allocation of the attributes struct, and deallocation if it has not been cleared during destroy.

The effect of the flag is to store in the vtable the size of the structure, this value is checked by the pmc allocation functions.

The patch also includes his usage in several PMC.

Changed 5 years ago by NotFound

Changed 5 years ago by NotFound

Attached more recent version which uses the new fixed size allocator and does more PMCs.

Changed 5 years ago by NotFound

Following discussion in yesterday's #ps, created the branch auto_attrs with the changes in the last patch and some more.

Changed 5 years ago by NotFound

Some results of the auto_attrs branch:

* The attr_size field is located at the end of the vtable struct, to avoid possible problems with someone depending on his binary format.

* The value is set in the vtable update functions. A heuristic is used to solve problems with PMC inheriting from the ones that had been converted to auto_attrs: if the PMC has not the auto_attrs flag, the size value is set to zero only if it defines the init or the init_pmc vtable functions, otherwise it let unchanged the value from his parent.

* With a bunch of PMC converted parrot pass all tests and I've been able to build and test rakudo and partcl.

I think the results are positive and the feature can be introduced in trunk with none or minimal impact on languages.

Changed 5 years ago by NotFound

diff between trunk and auto_attrs branch at r40501

Changed 5 years ago by NotFound

Last attachment is a svn diff between trunk and the branch at r40501, stripped of irrelevant mergeinfo properties.

The changes in pmc files are for setting the auto_attrs flag on then and the fixes to work with it. Also a destroy vtable function that does nothing is added to the Default PMC, this is to help with some flag changes, it can be deleted after transition to auto_attrs get completed or a careful fixing of flag changes, but maybe the code will be simpler by letting it in place.

The key changes are in src/gc/api.c, src/pmc.c, lib/Parrot/Vtable.pm and lib/Parrot/Pmc2c/PMCEmitter.pm

There are some #if'ed code to select the usage of the fixed size allocator or plain mem_sys

Changed 5 years ago by NotFound

I've posted a summary of the changes in the branch and his goals in:  http://notfound.posterous.com/autoattrs-branch

The plan is to merge the branch into trunk after the 1.5 release.

Changed 5 years ago by NotFound

  • status changed from assigned to closed
  • resolution set to done

Branch has been merged to trunk and deleted. For any problems related to the changes please open new tickets, not reopen this one.

Changed 5 years ago by coke

  • status changed from closed to reopened
  • resolution done deleted
  • type changed from feature to experimental

re-opening for placeholder tracking of experimental status.

Changed 4 years ago by NotFound

  • status changed from reopened to closed
  • resolution set to done

The tracking and planning of the evolution of this feature is now in TT #1506, closing this ticket to avoid duplication.

Note: See TracTickets for help on using tickets.