Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize GC write barriers in the pmc's #1069

Closed
rurban opened this issue Apr 22, 2014 · 2 comments
Closed

Optimize GC write barriers in the pmc's #1069

rurban opened this issue Apr 22, 2014 · 2 comments

Comments

@rurban
Copy link
Member

rurban commented Apr 22, 2014

GSOC task 1 for ZYROz (i.e. Chirag):

Starting from branch rurban/pmc2_orig which removes the nested pmc calls to add a
PARROT_GC_WRITE_BARRIER(interp, _self); before every return from a PMC VTABLE
method call, we want to mark needed or unneeded WB ("write barriers") in each method for SELF.
A PMC write barrier adds the PMC to the root_objects list for mandatory next collecting.

When to WB SELF in pmc methods

  • if you change a PMC you didn’t create WB it.
  • any time you save a value to a new PMC in an old PMC, WB the old one.
  • see src/vtable.tbl for the :write annotation.

How to annotate WBs for VTABLE methods

  • mark a method as :manual_wb if you added a WB manually, if in the body after all SELF changes were done, or in an inlined macro or in an included function.
    Or if the last method is a vtable method on SELF, which does the WB then. We don't need to WB SELF twice per method call.

  • mark a method as :no_wb if no WB is needed. See above. Only writers need a WB.

  • check src/vtable.tbl for the :write annotation.

  • all other methods will get WB added automatically by pmc2c. pmc2c can only do that if there's no or only one return statement. Otherwise you need use a RETURN(decl variable) statement instead as with PCCMETHODs. Note that return call_function(SELF, ...); is not allowed. This must be converted to:

    retdecl ret = call_function(SELF);
    RETURN(retdecl ret);

so that pmc2c can add the WB line before the return. SELF is the pmc here that was not created by the method.

e.g. capture.pmc:
CAPTURE_array_CREATE already write barriers SELF.

VTABLE FLOATVAL pop_float() {
    PMC *array;

    CAPTURE_array_CREATE(INTERP, SELF, array);
    /* no PARROT_GC_WRITE_BARRIER, already in CAPTURE_array_CREATE */
    return VTABLE_pop_float(INTERP, array);
}

and pmc2c will not add the WB before the call. Better annotate it with :manual_wb.
If there's no such comment add the WB before the return,
if the return call does not use self.

Otherwise use an intermediate return value. But in this case it would be easier to manually add the WB. See e.g. class.pmc which already added all needed WB manually.

manually:
i.e. OrderedHashIterator_shift_string:

VTABLE STRING* shift_string() {
    PMC * const key = SELF.shift_pmc();
    return VTABLE_get_string(INTERP, key);
}

=>

VTABLE STRING* shift_string() :manual_wb {
    PMC * const key = SELF.shift_pmc();
    PARROT_GC_WRITE_BARRIER(INTERP, SELF);
    return VTABLE_get_string(INTERP, key);
}

The expected performance gain is 2-3%, see https://github.com/parrot/parrot-bench

@rurban rurban changed the title Optimize GC write barriers in the pmc Optimize GC write barriers in the pmc's Apr 22, 2014
rurban pushed a commit that referenced this issue May 23, 2014
Start of GSOC 2014 work. Task 1: improve GC write barriers.
See GH issue #1069
rurban pushed a commit that referenced this issue May 27, 2014
Start of GSOC 2014 work. Task 1: improve GC write barriers.
See GH issue #1069
rurban pushed a commit that referenced this issue May 29, 2014
Start of GSOC 2014 work. Task 1: improve GC write barriers.
See GH issue #1069
rurban pushed a commit that referenced this issue May 30, 2014
Start of GSOC 2014 work. Task 1: improve GC write barriers.
See GH issue #1069
rurban pushed a commit that referenced this issue May 30, 2014
:manual_wb on VTABLE method calls on SELF which to a WB (avoid duplicates).
See new description at #1069
rurban pushed a commit that referenced this issue May 30, 2014
:no_wb on non-writers, :manual_wb on VTABLE method calls on SELF which to a WB (avoid duplicates).
See new description at #1069
Some UNUSED missing.

Still the same 2 regressions:
t/op/gc.t                                 (Wstat: 11 Tests: 19 Failed: 0)
  Non-zero wait status: 11
  Parse errors: No plan found in TAP output
t/pmc/namespace-old.t                     (Wstat: 1024 Tests: 38 Failed: 4)
  Failed tests:  27-30
  Non-zero exit status: 4
rurban pushed a commit that referenced this issue Jun 5, 2014
Start of GSOC 2014 work. Task 1: improve GC write barriers.
See GH issue #1069
rurban pushed a commit that referenced this issue Jun 5, 2014
:manual_wb on VTABLE method calls on SELF which to a WB (avoid duplicates).
See new description at #1069
rurban pushed a commit that referenced this issue Jun 5, 2014
:no_wb on non-writers, :manual_wb on VTABLE method calls on SELF which to a WB (avoid duplicates).
See new description at #1069
Some UNUSED missing.

Still the same 2 regressions:
t/op/gc.t                                 (Wstat: 11 Tests: 19 Failed: 0)
  Non-zero wait status: 11
  Parse errors: No plan found in TAP output
t/pmc/namespace-old.t                     (Wstat: 1024 Tests: 38 Failed: 4)
  Failed tests:  27-30
  Non-zero exit status: 4
rurban pushed a commit that referenced this issue Jun 9, 2014
Start of GSOC 2014 work. Task 1: improve GC write barriers.
See GH issue #1069
rurban pushed a commit that referenced this issue Jun 9, 2014
:manual_wb on VTABLE method calls on SELF which to a WB (avoid duplicates).
See new description at #1069
rurban pushed a commit that referenced this issue Jun 9, 2014
:no_wb on non-writers, :manual_wb on VTABLE method calls on SELF which to a WB (avoid duplicates).
See new description at #1069
Some UNUSED missing.

Still the same 2 regressions:
t/op/gc.t                                 (Wstat: 11 Tests: 19 Failed: 0)
  Non-zero wait status: 11
  Parse errors: No plan found in TAP output
t/pmc/namespace-old.t                     (Wstat: 1024 Tests: 38 Failed: 4)
  Failed tests:  27-30
  Non-zero exit status: 4
@rurban
Copy link
Member Author

rurban commented Jun 11, 2014

Merged with
commit ce9cc55
Merge: 4e2fadb 662c7d9
Author: Reini Urban rurban@cpanel.net
Date: Wed Jun 11 15:52:07 2014 -0500

Merge branch 'rurban/pmc2c_orig2-gh1069'

This is the first project of Chirag's GSOC 2014.
Optimize handling write barriers in VTABLE methods.
The performance gain is 2.5-4%.

@rurban rurban closed this as completed Jun 11, 2014
@rurban
Copy link
Member Author

rurban commented Jun 11, 2014

rakudo and nqp tested fine. For nqp I've pushed an optimized version to nqp branch pmc2c_orig which takes advantage of the new pmc2c and is about 4.5% faster for the nqp testsuite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant