@@ -1493,25 +1493,25 @@ RB_EVENT_HOOKS_HAVE_CALLBACK_DATA ::
1493
1493
See documentation for {mkmf}[rdoc-ref:MakeMakefile].
1494
1494
= Appendix D. Generational GC
1495
1495
1496
- Ruby 2.1 introduced a generational garbage collector (called RGenGC).
1496
+ Ruby 2.1 introduced a generational garbage collector (called RGenGC).
1497
1497
RGenGC (mostly) keeps compatibility.
1498
1498
1499
- Generally, the use of the technique called write barriers is required in
1500
- extension libraries for generational GC
1501
- (http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29).
1499
+ Generally, the use of the technique called write barriers is required in
1500
+ extension libraries for generational GC
1501
+ (http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29).
1502
1502
RGenGC works fine without write barriers in extension libraries.
1503
-
1503
+
1504
1504
If your library adheres to the following tips, performance can
1505
1505
be further improved. Especially, the "Don't touch pointers directly" section is
1506
1506
important.
1507
1507
1508
1508
== Incompatibility
1509
-
1510
- You can't write RBASIC(obj)->klass field directly because it is const
1509
+
1510
+ You can't write RBASIC(obj)->klass field directly because it is const
1511
1511
value now.
1512
1512
1513
- Basically you should not write this field because MRI expects it to be
1514
- an immutable field, but if you want to do it in your extension you can
1513
+ Basically you should not write this field because MRI expects it to be
1514
+ an immutable field, but if you want to do it in your extension you can
1515
1515
use the following functions:
1516
1516
1517
1517
VALUE rb_obj_hide(VALUE obj) ::
@@ -1526,65 +1526,65 @@ VALUE rb_obj_reveal(VALUE obj, VALUE klass) ::
1526
1526
1527
1527
== Write barriers
1528
1528
1529
- RGenGC doesn't require write barriers to support generational GC.
1530
- However, caring about write barrier can improve the performance of
1529
+ RGenGC doesn't require write barriers to support generational GC.
1530
+ However, caring about write barrier can improve the performance of
1531
1531
RGenGC. Please check the following tips.
1532
-
1532
+
1533
1533
=== Don't touch pointers directly
1534
-
1535
- In MRI (include/ruby/ruby.h), some macros to acquire pointers to the
1536
- internal data structures are supported such as RARRAY_PTR(),
1534
+
1535
+ In MRI (include/ruby/ruby.h), some macros to acquire pointers to the
1536
+ internal data structures are supported such as RARRAY_PTR(),
1537
1537
RSTRUCT_PTR() and so on.
1538
1538
1539
- DO NOT USE THESE MACROS and instead use the corresponding C-APIs such as
1539
+ DO NOT USE THESE MACROS and instead use the corresponding C-APIs such as
1540
1540
rb_ary_aref(), rb_ary_store() and so on.
1541
1541
1542
1542
=== Consider whether to insert write barriers
1543
1543
1544
- You don't need to care about write barriers if you only use built-in
1544
+ You don't need to care about write barriers if you only use built-in
1545
1545
types.
1546
1546
1547
1547
If you support T_DATA objects, you may consider using write barriers.
1548
1548
1549
- Inserting write barriers into T_DATA objects only works with the
1550
- following type objects: (a) long-lived objects, (b) when a huge number
1551
- of objects are generated and (c) container-type objects that have
1552
- references to other objects. If your extension provides such a type of
1549
+ Inserting write barriers into T_DATA objects only works with the
1550
+ following type objects: (a) long-lived objects, (b) when a huge number
1551
+ of objects are generated and (c) container-type objects that have
1552
+ references to other objects. If your extension provides such a type of
1553
1553
T_DATA objects, consider inserting write barriers.
1554
1554
1555
1555
(a): short-lived objects don't become old generation objects.
1556
1556
(b): only a few oldgen objects don't have performance impact.
1557
1557
(c): only a few references don't have performance impact.
1558
-
1559
- Inserting write barriers is a very difficult hack, it is easy to
1560
- introduce critical bugs. And inserting write barriers has several areas
1561
- of overhead. Basically we don't recommend you insert write barriers.
1558
+
1559
+ Inserting write barriers is a very difficult hack, it is easy to
1560
+ introduce critical bugs. And inserting write barriers has several areas
1561
+ of overhead. Basically we don't recommend you insert write barriers.
1562
1562
Please carefully consider the risks.
1563
1563
1564
1564
=== Combine with built-in types
1565
1565
1566
- Please consider utilizing built-in types. Most built-in types support
1567
- write barrier, so you can use them to avoid manually inserting write
1566
+ Please consider utilizing built-in types. Most built-in types support
1567
+ write barrier, so you can use them to avoid manually inserting write
1568
1568
barriers.
1569
1569
1570
- For example, if your T_DATA has references to other objects, then you
1571
- can move these references to Array. A T_DATA object only has a reference
1572
- to an array object. Or you can also use a Struct object to gather a
1573
- T_DATA object (without any references) and an that Array contains
1570
+ For example, if your T_DATA has references to other objects, then you
1571
+ can move these references to Array. A T_DATA object only has a reference
1572
+ to an array object. Or you can also use a Struct object to gather a
1573
+ T_DATA object (without any references) and an that Array contains
1574
1574
references.
1575
1575
1576
- With use of such techniques, you don't need to insert write barriers
1576
+ With use of such techniques, you don't need to insert write barriers
1577
1577
anymore.
1578
1578
1579
1579
=== Insert write barriers
1580
1580
1581
- [AGAIN] Inserting write barriers is a very difficult hack, and it is
1582
- easy to introduce critical bugs. And inserting write barriers has
1583
- several areas of overhead. Basically we don't recommend you insert write
1581
+ [AGAIN] Inserting write barriers is a very difficult hack, and it is
1582
+ easy to introduce critical bugs. And inserting write barriers has
1583
+ several areas of overhead. Basically we don't recommend you insert write
1584
1584
barriers. Please carefully consider the risks.
1585
1585
1586
- Before inserting write barriers, you need to know about RGenGC algorithm
1587
- (gc.c will help you). Macros and functions to insert write barriers are
1586
+ Before inserting write barriers, you need to know about RGenGC algorithm
1587
+ (gc.c will help you). Macros and functions to insert write barriers are
1588
1588
available in in include/ruby/ruby.h. An example is available in iseq.c.
1589
1589
1590
1590
For a complete guide for RGenGC and write barriers, please refer to [...].
0 commit comments