~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to erts/emulator/beam/erl_alloc_util.c

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#endif
40
40
 
41
41
#include "global.h"
 
42
#include "big.h"
 
43
#include "erl_mtrace.h"
42
44
#define GET_ERL_ALLOC_UTIL_IMPL
43
45
#include "erl_alloc_util.h"
44
46
#include "erl_mseg.h"
 
47
#include "erl_threads.h"
45
48
 
46
 
#ifdef ERTS_ALLOC_UTIL_HARD_DEBUG
 
49
#if defined(ERTS_ALLOC_UTIL_HARD_DEBUG) && defined(__GNUC__)
47
50
#warning "* * * * * * * * * *"
48
51
#warning "* * * * * * * * * *"
49
52
#warning "* * NOTE:       * *"
87
90
static Uint sys_alloc_carrier_size;
88
91
#if HAVE_ERTS_MSEG
89
92
static Uint max_mseg_carriers;
90
 
#endif
91
 
 
92
 
/* Threads ... */
93
 
 
94
 
#ifdef USE_THREADS
95
 
 
96
 
#ifdef DEBUG
97
 
#  define LOCK(M)   ASSERT(0 == erts_mutex_lock((M)))
98
 
#  define UNLOCK(M) ASSERT(0 == erts_mutex_unlock((M)))
99
 
#else
100
 
#  define LOCK(M)   ((void) erts_mutex_lock((M)))
101
 
#  define UNLOCK(M) ((void) erts_mutex_unlock((M)))
102
 
#endif
103
 
 
104
 
#else /* #ifdef USE_THREADS */
105
 
 
106
 
#define LOCK(M)
107
 
#define UNLOCK(M)
108
 
 
109
 
#endif /* #ifdef USE_THREADS */
110
 
 
111
 
#if HAVE_ERTS_MSEG
112
93
static Uint mseg_unit_size;
113
94
#endif
114
95
 
122
103
                    ? ((CC).giga_no--, (CC).no = ONE_GIGA - 1)          \
123
104
                    : (CC).no--)
124
105
 
125
 
/* mseg ... */
126
 
 
127
 
#if HAVE_ERTS_MSEG
128
 
 
129
 
#define MSEG_ALLOC(A, SP)                                               \
130
 
  (INC_CC((A)->calls.mseg_alloc),                                       \
131
 
   erts_mseg_alloc_opt((SP), &(A)->mseg_opt))
132
 
 
133
 
#define MSEG_DEALLOC(A, C, S)                                           \
134
 
  (INC_CC((A)->calls.mseg_dealloc),                                     \
135
 
   erts_mseg_dealloc_opt((void *) (C), (S), &(A)->mseg_opt))
136
 
 
137
 
#define MSEG_REALLOC(A, C, OS, SP)                                      \
138
 
  (INC_CC((A)->calls.mseg_realloc),                                     \
139
 
   erts_mseg_realloc_opt((void *) (C), (OS), (SP), &(A)->mseg_opt))
140
 
 
141
 
#endif
142
 
 
143
 
#undef  SYS_ALLOC
144
 
#undef  SYS_REALLOC
145
 
#undef  SYS_FREE
146
 
 
147
 
#define SYS_ALLOC(A,S)          (INC_CC((A)->calls.sys_alloc),          \
148
 
                                 erts_sys_alloc(0, NULL, (S)))
149
 
#define SYS_REALLOC(A,P,S)      (INC_CC((A)->calls.sys_realloc),        \
150
 
                                 erts_sys_realloc(0, NULL, (P), (S)))
151
 
#define SYS_FREE(A,P)           (INC_CC((A)->calls.sys_free),           \
152
 
                                 erts_sys_free(0, NULL, (P)))
153
 
 
154
106
/* ... */
155
107
 
156
108
/* Blocks ... */
468
420
#define DEBUG_CHECK_ALIGNMENT(P)
469
421
#endif
470
422
 
 
423
static void make_name_atoms(Allctr_t *allctr);
 
424
 
 
425
 
 
426
/* mseg ... */
 
427
 
 
428
#if HAVE_ERTS_MSEG
 
429
 
 
430
static ERTS_INLINE void *
 
431
alcu_mseg_alloc(Allctr_t *allctr, Uint *size_p)
 
432
{
 
433
    void *res;
 
434
 
 
435
    res = erts_mseg_alloc_opt(allctr->alloc_no, size_p, &allctr->mseg_opt);
 
436
    INC_CC(allctr->calls.mseg_alloc);
 
437
    return res;
 
438
}
 
439
 
 
440
static ERTS_INLINE void *
 
441
alcu_mseg_realloc(Allctr_t *allctr, void *seg, Uint old_size, Uint *new_size_p)
 
442
{
 
443
    void *res;
 
444
 
 
445
    res = erts_mseg_realloc_opt(allctr->alloc_no, seg, old_size, new_size_p,
 
446
                                &allctr->mseg_opt);
 
447
    INC_CC(allctr->calls.mseg_realloc);
 
448
    return res;
 
449
}
 
450
 
 
451
static ERTS_INLINE void
 
452
alcu_mseg_dealloc(Allctr_t *allctr, void *seg, Uint size)
 
453
{
 
454
    erts_mseg_dealloc_opt(allctr->alloc_no, seg, size, &allctr->mseg_opt);
 
455
    INC_CC(allctr->calls.mseg_dealloc);
 
456
}
 
457
 
 
458
#endif
 
459
 
 
460
static ERTS_INLINE void *
 
461
alcu_sys_alloc(Allctr_t *allctr, Uint size)
 
462
{
 
463
    void *res;
 
464
 
 
465
    res = erts_sys_alloc(0, NULL, size);
 
466
    INC_CC(allctr->calls.sys_alloc);
 
467
    if (erts_mtrace_enabled)
 
468
        erts_mtrace_crr_alloc(res, allctr->alloc_no, ERTS_ALC_A_SYSTEM, size);
 
469
    return res;
 
470
}
 
471
 
 
472
static ERTS_INLINE void *
 
473
alcu_sys_realloc(Allctr_t *allctr, void *ptr, Uint size)
 
474
{
 
475
    void *res;
 
476
 
 
477
    res = erts_sys_realloc(0, NULL, ptr, size);
 
478
    INC_CC(allctr->calls.sys_realloc);
 
479
    if (erts_mtrace_enabled)
 
480
        erts_mtrace_crr_realloc(res,
 
481
                                allctr->alloc_no,
 
482
                                ERTS_ALC_A_SYSTEM,
 
483
                                ptr,
 
484
                                size);
 
485
    return res;
 
486
}
 
487
 
 
488
static ERTS_INLINE void
 
489
alcu_sys_free(Allctr_t *allctr, void *ptr)
 
490
{
 
491
    erts_sys_free(0, NULL, ptr);
 
492
    INC_CC(allctr->calls.sys_free);
 
493
    if (erts_mtrace_enabled)
 
494
        erts_mtrace_crr_free(allctr->alloc_no, ERTS_ALC_A_SYSTEM, ptr);
 
495
}
471
496
 
472
497
static Uint
473
498
get_next_mbc_size(Allctr_t *allctr)
1053
1078
    crr_sz = MSEG_UNIT_CEILING(crr_sz);
1054
1079
    ASSERT(crr_sz % mseg_unit_size == 0);
1055
1080
 
1056
 
    crr = (Carrier_t *) MSEG_ALLOC(allctr, &crr_sz);
 
1081
    crr = (Carrier_t *) alcu_mseg_alloc(allctr, &crr_sz);
1057
1082
    if (!crr) {
1058
1083
        have_tried_mseg = 1;
1059
1084
        if (!(have_tried_sys_alloc || flags & CFLG_FORCE_MSEG))
1097
1122
              ? UNIT_CEILING(bcrr_sz)
1098
1123
              : SYS_ALLOC_CARRIER_CEILING(bcrr_sz));
1099
1124
 
1100
 
    crr = (Carrier_t *) SYS_ALLOC(allctr, crr_sz);
 
1125
    crr = (Carrier_t *) alcu_sys_alloc(allctr, crr_sz);
1101
1126
        
1102
1127
    if (!crr) {
1103
1128
        if (crr_sz > UNIT_CEILING(bcrr_sz)) {
1104
1129
            crr_sz = UNIT_CEILING(bcrr_sz);
1105
 
            crr = (Carrier_t *) SYS_ALLOC(allctr, crr_sz);
 
1130
            crr = (Carrier_t *) alcu_sys_alloc(allctr, crr_sz);
1106
1131
        }
1107
1132
        if (!crr) {
1108
1133
#if HAVE_ERTS_MSEG
1161
1186
        }
1162
1187
 
1163
1188
        link_carrier(&allctr->mbc_list, crr);
 
1189
 
 
1190
#ifdef ERTS_ALLOC_UTIL_HARD_DEBUG
 
1191
        if (sizeof(Unit_t) == sizeof(Uint))
 
1192
            crr_sz += sizeof(Uint);
 
1193
#endif
1164
1194
        CHECK_1BLK_CARRIER(allctr, 0, is_mseg, crr, crr_sz, blk, blk_sz);
 
1195
#ifdef ERTS_ALLOC_UTIL_HARD_DEBUG
 
1196
        if (sizeof(Unit_t) == sizeof(Uint))
 
1197
            crr_sz -= sizeof(Uint);
 
1198
#endif
1165
1199
        if (allctr->creating_mbc)
1166
1200
            (*allctr->creating_mbc)(allctr, crr);
1167
1201
 
1206
1240
 
1207
1241
            new_crr_sz = new_blk_sz + SBC_HDR_SZ;
1208
1242
            new_crr_sz = MSEG_UNIT_CEILING(new_crr_sz);
1209
 
            new_crr = (Carrier_t *) MSEG_REALLOC(allctr,
1210
 
                                                 old_crr,
1211
 
                                                 old_crr_sz,
1212
 
                                                 &new_crr_sz);
 
1243
            new_crr = (Carrier_t *) alcu_mseg_realloc(allctr,
 
1244
                                                      old_crr,
 
1245
                                                      old_crr_sz,
 
1246
                                                      &new_crr_sz);
1213
1247
            if (new_crr) {
1214
1248
                SET_CARRIER_SZ(new_crr, new_crr_sz);
1215
1249
                new_blk = SBC2BLK(new_crr);
1231
1265
                       (void *) BLK2UMEM(old_blk),
1232
1266
                       MIN(new_blk_sz, old_blk_sz) - ABLK_HDR_SZ);
1233
1267
            unlink_carrier(&allctr->sbc_list, old_crr);
1234
 
            MSEG_DEALLOC(allctr, old_crr, old_crr_sz);
 
1268
            alcu_mseg_dealloc(allctr, old_crr, old_crr_sz);
1235
1269
        }
1236
1270
        else {
1237
1271
            /* Old carrier unchanged; restore stat */
1248
1282
                          ? UNIT_CEILING(new_bcrr_sz)
1249
1283
                          : SYS_ALLOC_CARRIER_CEILING(new_bcrr_sz));
1250
1284
 
1251
 
            new_crr = (Carrier_t *) SYS_REALLOC(allctr,
1252
 
                                                (void *) old_crr,
1253
 
                                                new_crr_sz);
 
1285
            new_crr = (Carrier_t *) alcu_sys_realloc(allctr,
 
1286
                                                     (void *) old_crr,
 
1287
                                                     new_crr_sz);
1254
1288
            if (new_crr) {
1255
1289
            sys_realloc_success:
1256
1290
                SET_CARRIER_SZ(new_crr, new_crr_sz);
1267
1301
            else if (new_crr_sz > UNIT_CEILING(new_bcrr_sz)) {
1268
1302
                new_crr_sz = new_blk_sz + SBC_HDR_SZ;
1269
1303
                new_crr_sz = UNIT_CEILING(new_crr_sz);
1270
 
                new_crr = (Carrier_t *) SYS_REALLOC(allctr,
1271
 
                                                    (void *) old_crr,
1272
 
                                                    new_crr_sz);
 
1304
                new_crr = (Carrier_t *) alcu_sys_realloc(allctr,
 
1305
                                                         (void *) old_crr,
 
1306
                                                         new_crr_sz);
1273
1307
                if (new_crr)
1274
1308
                    goto sys_realloc_success;
1275
1309
            }
1288
1322
                       (void *) BLK2UMEM(old_blk),
1289
1323
                       MIN(new_blk_sz, old_blk_sz) - ABLK_HDR_SZ);
1290
1324
            unlink_carrier(&allctr->sbc_list, old_crr);
1291
 
            SYS_FREE(allctr, old_crr);
 
1325
            alcu_sys_free(allctr, old_crr);
1292
1326
        }
1293
1327
        else {
1294
1328
            /* Old carrier unchanged; restore... */
1367
1401
 
1368
1402
#if HAVE_ERTS_MSEG
1369
1403
    if (is_mseg) {
1370
 
        MSEG_DEALLOC(allctr, crr, crr_sz);
 
1404
        alcu_mseg_dealloc(allctr, crr, crr_sz);
1371
1405
    }
1372
1406
    else
1373
1407
#endif
1374
 
        SYS_FREE(allctr, crr);
 
1408
        alcu_sys_free(allctr, crr);
1375
1409
}
1376
1410
 
1377
1411
 
1440
1474
}
1441
1475
#define AM_INIT(AM) atom_init(&am.AM, #AM)
1442
1476
 
 
1477
static erts_mtx_t init_atoms_mtx;
 
1478
 
1443
1479
static void
1444
 
init_atoms(void)
 
1480
init_atoms(Allctr_t *allctr)
1445
1481
{
1446
 
#ifdef DEBUG
1447
 
    Eterm *atom;
1448
 
    for (atom = (Eterm *) &am; atom <= &am.end_of_atoms; atom++) {
1449
 
        *atom = THE_NON_VALUE;
1450
 
    }
1451
 
#endif
1452
 
 
1453
 
    AM_INIT(versions);
1454
 
 
1455
 
    AM_INIT(options);
1456
 
    AM_INIT(e);
1457
 
    AM_INIT(sbct);
1458
 
#if HAVE_ERTS_MSEG
1459
 
    AM_INIT(asbcst);
1460
 
    AM_INIT(rsbcst);
1461
 
#endif
1462
 
    AM_INIT(rsbcmt);
1463
 
    AM_INIT(mmbcs);
1464
 
    AM_INIT(msbclt);
1465
 
#if HAVE_ERTS_MSEG
1466
 
    AM_INIT(mmsbc);
1467
 
    AM_INIT(mmmbc);
1468
 
#endif
1469
 
    AM_INIT(lmbcs);
1470
 
    AM_INIT(smbcs);
1471
 
    AM_INIT(mbcgs);
1472
 
 
1473
 
#if HAVE_ERTS_MSEG
1474
 
    AM_INIT(mmc);
1475
 
#endif
1476
 
    AM_INIT(ycs);
1477
 
 
1478
 
    AM_INIT(mbcs);
1479
 
    AM_INIT(sbcs);
1480
 
    AM_INIT(sys_alloc_carriers_size);
1481
 
#if HAVE_ERTS_MSEG
1482
 
    AM_INIT(mseg_alloc_carriers_size);
1483
 
#endif
1484
 
    AM_INIT(carriers_size);
1485
 
    AM_INIT(sys_alloc_carriers);
1486
 
#if HAVE_ERTS_MSEG
1487
 
    AM_INIT(mseg_alloc_carriers);
1488
 
#endif
1489
 
    AM_INIT(carriers);
1490
 
    AM_INIT(blocks_size);
1491
 
    AM_INIT(blocks);
1492
 
 
1493
 
    AM_INIT(calls);
1494
 
    AM_INIT(sys_alloc);
1495
 
    AM_INIT(sys_free);
1496
 
    AM_INIT(sys_realloc);
1497
 
#if HAVE_ERTS_MSEG
1498
 
    AM_INIT(mseg_alloc);
1499
 
    AM_INIT(mseg_dealloc);
1500
 
    AM_INIT(mseg_realloc);
1501
 
#endif
1502
 
 
1503
 
#ifdef DEBUG
1504
 
    for (atom = (Eterm *) &am; atom < &am.end_of_atoms; atom++) {
1505
 
        ASSERT(*atom != THE_NON_VALUE);
1506
 
    }
1507
 
#endif
 
1482
 
 
1483
#ifdef USE_THREADS
 
1484
    if (allctr && allctr->thread_safe)
 
1485
        erts_mtx_unlock(&allctr->mutex);
 
1486
#endif
 
1487
 
 
1488
    erts_mtx_lock(&init_atoms_mtx);
 
1489
 
 
1490
    if (!atoms_initialized) {
 
1491
#ifdef DEBUG
 
1492
        Eterm *atom;
 
1493
 
 
1494
        for (atom = (Eterm *) &am; atom <= &am.end_of_atoms; atom++) {
 
1495
            *atom = THE_NON_VALUE;
 
1496
        }
 
1497
#endif
 
1498
 
 
1499
        AM_INIT(versions);
 
1500
 
 
1501
        AM_INIT(options);
 
1502
        AM_INIT(e);
 
1503
        AM_INIT(sbct);
 
1504
#if HAVE_ERTS_MSEG
 
1505
        AM_INIT(asbcst);
 
1506
        AM_INIT(rsbcst);
 
1507
#endif
 
1508
        AM_INIT(rsbcmt);
 
1509
        AM_INIT(mmbcs);
 
1510
        AM_INIT(msbclt);
 
1511
#if HAVE_ERTS_MSEG
 
1512
        AM_INIT(mmsbc);
 
1513
        AM_INIT(mmmbc);
 
1514
#endif
 
1515
        AM_INIT(lmbcs);
 
1516
        AM_INIT(smbcs);
 
1517
        AM_INIT(mbcgs);
 
1518
 
 
1519
#if HAVE_ERTS_MSEG
 
1520
        AM_INIT(mmc);
 
1521
#endif
 
1522
        AM_INIT(ycs);
 
1523
 
 
1524
        AM_INIT(mbcs);
 
1525
        AM_INIT(sbcs);
 
1526
        AM_INIT(sys_alloc_carriers_size);
 
1527
#if HAVE_ERTS_MSEG
 
1528
        AM_INIT(mseg_alloc_carriers_size);
 
1529
#endif
 
1530
        AM_INIT(carriers_size);
 
1531
        AM_INIT(sys_alloc_carriers);
 
1532
#if HAVE_ERTS_MSEG
 
1533
        AM_INIT(mseg_alloc_carriers);
 
1534
#endif
 
1535
        AM_INIT(carriers);
 
1536
        AM_INIT(blocks_size);
 
1537
        AM_INIT(blocks);
 
1538
 
 
1539
        AM_INIT(calls);
 
1540
        AM_INIT(sys_alloc);
 
1541
        AM_INIT(sys_free);
 
1542
        AM_INIT(sys_realloc);
 
1543
#if HAVE_ERTS_MSEG
 
1544
        AM_INIT(mseg_alloc);
 
1545
        AM_INIT(mseg_dealloc);
 
1546
        AM_INIT(mseg_realloc);
 
1547
#endif
 
1548
 
 
1549
#ifdef DEBUG
 
1550
        for (atom = (Eterm *) &am; atom < &am.end_of_atoms; atom++) {
 
1551
            ASSERT(*atom != THE_NON_VALUE);
 
1552
        }
 
1553
#endif
 
1554
    }
 
1555
 
 
1556
    
 
1557
    if (allctr) {
 
1558
 
 
1559
        make_name_atoms(allctr);
 
1560
 
 
1561
        (*allctr->init_atoms)();
 
1562
 
 
1563
#ifdef USE_THREADS
 
1564
        if (allctr->thread_safe)
 
1565
            erts_mtx_lock(&allctr->mutex);
 
1566
#endif
 
1567
        allctr->atoms_initialized = 1;
 
1568
    }
1508
1569
 
1509
1570
    atoms_initialized = 1;
1510
 
}
1511
 
 
 
1571
    erts_mtx_unlock(&init_atoms_mtx);
 
1572
 
 
1573
}
 
1574
 
 
1575
static ERTS_INLINE void
 
1576
ensure_atoms_initialized(Allctr_t *allctr)
 
1577
{
 
1578
    if (!allctr || !allctr->atoms_initialized)
 
1579
        init_atoms(allctr);
 
1580
}
1512
1581
 
1513
1582
#define bld_uint        erts_bld_uint
1514
1583
#define bld_cons        erts_bld_cons
1515
1584
#define bld_tuple       erts_bld_tuple
1516
1585
#define bld_string      erts_bld_string
1517
1586
 
 
1587
/*
 
1588
 * bld_unstable_uint() (instead bld_uint()) is used when values may
 
1589
 * change between size check and actual build. This because a value
 
1590
 * that would fit a small when size check is done may need to be built
 
1591
 * as a big when the actual build is performed. Caller is required to
 
1592
 * HRelease after build.
 
1593
 */
 
1594
static ERTS_INLINE Eterm
 
1595
bld_unstable_uint(Uint **hpp, Uint *szp, Uint ui)
 
1596
{
 
1597
    Eterm res = THE_NON_VALUE;
 
1598
    if (szp)
 
1599
        szp += BIG_UINT_HEAP_SIZE;
 
1600
    if (hpp) {
 
1601
        if (IS_USMALL(0, ui))
 
1602
            res = make_small(ui);
 
1603
        else {
 
1604
            res = uint_to_big(ui, *hpp);
 
1605
            *hpp += BIG_UINT_HEAP_SIZE;
 
1606
        }
 
1607
    }
 
1608
    return res;
 
1609
}
 
1610
 
1518
1611
static ERTS_INLINE void
1519
1612
add_2tup(Uint **hpp, Uint *szp, Eterm *lp, Eterm el1, Eterm el2)
1520
1613
{
1539
1632
info_carriers(Allctr_t *allctr,
1540
1633
              CarriersStats_t *cs,
1541
1634
              char *prefix,
1542
 
              CIO *ciop,
 
1635
              int *print_to_p,
 
1636
              void *print_to_arg,
1543
1637
              Uint **hpp,
1544
1638
              Uint *szp)
1545
1639
{
1547
1641
    Uint curr_no   = cs->curr_mseg.no   + cs->curr_sys_alloc.no;
1548
1642
    Uint curr_size = cs->curr_mseg.size + cs->curr_sys_alloc.size;
1549
1643
 
1550
 
    if (ciop) {
1551
 
        CIO to = *ciop;
1552
 
        erl_printf(to,
1553
 
                   "%sblocks: %lu %lu %lu\n",
 
1644
    if (print_to_p) {
 
1645
        int to = *print_to_p;
 
1646
        void *arg = print_to_arg;
 
1647
        erts_print(to,
 
1648
                   arg,
 
1649
                   "%sblocks: %bpu %bpu %bpu\n",
1554
1650
                   prefix,
1555
1651
                   cs->blocks.curr.no,
1556
1652
                   cs->blocks.max.no,
1557
1653
                   cs->blocks.max_ever.no);
1558
 
        erl_printf(to,
1559
 
                   "%sblocks size: %lu %lu %lu\n",
 
1654
        erts_print(to,
 
1655
                   arg,
 
1656
                   "%sblocks size: %bpu %bpu %bpu\n",
1560
1657
                   prefix,
1561
1658
                   cs->blocks.curr.size,
1562
1659
                   cs->blocks.max.size,
1563
1660
                   cs->blocks.max_ever.size);
1564
 
        erl_printf(to,
1565
 
                   "%scarriers: %lu %lu %lu\n",
 
1661
        erts_print(to,
 
1662
                   arg,
 
1663
                   "%scarriers: %bpu %bpu %bpu\n",
1566
1664
                   prefix,
1567
1665
                   curr_no,
1568
1666
                   cs->max.no,
1569
1667
                   cs->max_ever.no);
1570
1668
#if HAVE_ERTS_MSEG
1571
 
        erl_printf(to,
1572
 
                   "%smseg carriers: %lu\n",
 
1669
        erts_print(to,
 
1670
                   arg,
 
1671
                   "%smseg carriers: %bpu\n",
1573
1672
                   prefix,
1574
1673
                   cs->curr_mseg.no);
1575
1674
#endif
1576
 
        erl_printf(to,
1577
 
                   "%ssys_alloc carriers: %lu\n",
 
1675
        erts_print(to,
 
1676
                   arg,
 
1677
                   "%ssys_alloc carriers: %bpu\n",
1578
1678
                   prefix,
1579
1679
                   cs->curr_sys_alloc.no);
1580
 
        erl_printf(to,
1581
 
                   "%scarriers size: %lu %lu %lu\n",
 
1680
        erts_print(to,
 
1681
                   arg,
 
1682
                   "%scarriers size: %bpu %bpu %bpu\n",
1582
1683
                   prefix,
1583
1684
                   curr_size,
1584
1685
                   cs->max.size,
1585
1686
                   cs->max_ever.size);
1586
1687
#if HAVE_ERTS_MSEG
1587
 
        erl_printf(to,
1588
 
                   "%smseg carriers size: %lu\n",
 
1688
        erts_print(to,
 
1689
                   arg,
 
1690
                   "%smseg carriers size: %bpu\n",
1589
1691
                   prefix,
1590
1692
                   cs->curr_mseg.size);
1591
1693
#endif
1592
 
        erl_printf(to,
1593
 
                   "%ssys_alloc carriers size: %lu\n",
 
1694
        erts_print(to,
 
1695
                   arg,
 
1696
                   "%ssys_alloc carriers size: %bpu\n",
1594
1697
                   prefix,
1595
1698
                   cs->curr_sys_alloc.size);
1596
1699
    }
1599
1702
        res = NIL;
1600
1703
        add_2tup(hpp, szp, &res,
1601
1704
                 am.sys_alloc_carriers_size,
1602
 
                 bld_uint(hpp, szp, cs->curr_sys_alloc.size));
 
1705
                 bld_unstable_uint(hpp, szp, cs->curr_sys_alloc.size));
1603
1706
#if HAVE_ERTS_MSEG
1604
1707
        add_2tup(hpp, szp, &res,
1605
1708
                 am.mseg_alloc_carriers_size,
1606
 
                 bld_uint(hpp, szp, cs->curr_mseg.size));
 
1709
                 bld_unstable_uint(hpp, szp, cs->curr_mseg.size));
1607
1710
#endif
1608
1711
        add_4tup(hpp, szp, &res,
1609
1712
                 am.carriers_size,
1610
 
                 bld_uint(hpp, szp, curr_size),
1611
 
                 bld_uint(hpp, szp, cs->max.size),
1612
 
                 bld_uint(hpp, szp, cs->max_ever.size));
 
1713
                 bld_unstable_uint(hpp, szp, curr_size),
 
1714
                 bld_unstable_uint(hpp, szp, cs->max.size),
 
1715
                 bld_unstable_uint(hpp, szp, cs->max_ever.size));
1613
1716
        add_2tup(hpp, szp, &res,
1614
1717
                 am.sys_alloc_carriers,
1615
 
                 bld_uint(hpp, szp, cs->curr_sys_alloc.no));
 
1718
                 bld_unstable_uint(hpp, szp, cs->curr_sys_alloc.no));
1616
1719
#if HAVE_ERTS_MSEG
1617
1720
        add_2tup(hpp, szp, &res,
1618
1721
                 am.mseg_alloc_carriers,
1619
 
                 bld_uint(hpp, szp, cs->curr_mseg.no));
 
1722
                 bld_unstable_uint(hpp, szp, cs->curr_mseg.no));
1620
1723
#endif
1621
1724
        add_4tup(hpp, szp, &res,
1622
1725
                 am.carriers,
1623
 
                 bld_uint(hpp, szp, curr_no),
1624
 
                 bld_uint(hpp, szp, cs->max.no),
1625
 
                 bld_uint(hpp, szp, cs->max_ever.no));
 
1726
                 bld_unstable_uint(hpp, szp, curr_no),
 
1727
                 bld_unstable_uint(hpp, szp, cs->max.no),
 
1728
                 bld_unstable_uint(hpp, szp, cs->max_ever.no));
1626
1729
        add_4tup(hpp, szp, &res,
1627
1730
                 am.blocks_size,
1628
 
                 bld_uint(hpp, szp, cs->blocks.curr.size),
1629
 
                 bld_uint(hpp, szp, cs->blocks.max.size),
1630
 
                 bld_uint(hpp, szp, cs->blocks.max_ever.size));
 
1731
                 bld_unstable_uint(hpp, szp, cs->blocks.curr.size),
 
1732
                 bld_unstable_uint(hpp, szp, cs->blocks.max.size),
 
1733
                 bld_unstable_uint(hpp, szp, cs->blocks.max_ever.size));
1631
1734
        add_4tup(hpp, szp, &res,
1632
1735
                 am.blocks,
1633
 
                 bld_uint(hpp, szp, cs->blocks.curr.no),
1634
 
                 bld_uint(hpp, szp, cs->blocks.max.no),
1635
 
                 bld_uint(hpp, szp, cs->blocks.max_ever.no));
 
1736
                 bld_unstable_uint(hpp, szp, cs->blocks.curr.no),
 
1737
                 bld_unstable_uint(hpp, szp, cs->blocks.max.no),
 
1738
                 bld_unstable_uint(hpp, szp, cs->blocks.max_ever.no));
1636
1739
    }
1637
1740
 
1638
1741
    return res;
1665
1768
 
1666
1769
static Eterm
1667
1770
info_calls(Allctr_t *allctr,
1668
 
           CIO *ciop,
 
1771
           int *print_to_p,
 
1772
           void *print_to_arg,
1669
1773
           Uint **hpp,
1670
1774
           Uint *szp)
1671
1775
{
1672
1776
    Eterm res = THE_NON_VALUE;
1673
1777
 
1674
1778
 
1675
 
    if (ciop) {
1676
 
 
1677
 
#define PRINT_CC_3(TO, NAME, CC)                                        \
1678
 
    if ((CC).giga_no == 0)                                              \
1679
 
        erl_printf(TO, "%s calls: %lu\n", NAME, CC.no);                 \
1680
 
    else                                                                \
1681
 
        erl_printf(TO, "%s calls: %lu%09lu\n", NAME, CC.giga_no, CC.no)
1682
 
 
1683
 
#define PRINT_CC_4(TO, PRFX, NAME, CC)                                  \
1684
 
    if ((CC).giga_no == 0)                                              \
1685
 
        erl_printf(TO,"%s%s calls: %lu\n",PRFX,NAME,CC.no);             \
1686
 
    else                                                                \
1687
 
        erl_printf(TO,"%s%s calls: %lu%09lu\n",PRFX,NAME,CC.giga_no,CC.no)
 
1779
    if (print_to_p) {
 
1780
 
 
1781
#define PRINT_CC_4(TO, TOA, NAME, CC)                                   \
 
1782
    if ((CC).giga_no == 0)                                              \
 
1783
        erts_print(TO, TOA, "%s calls: %bpu\n", NAME, CC.no);           \
 
1784
    else                                                                \
 
1785
        erts_print(TO, TOA, "%s calls: %bpu%09lu\n", NAME, CC.giga_no, CC.no)
 
1786
 
 
1787
#define PRINT_CC_5(TO, TOA, PRFX, NAME, CC)                             \
 
1788
    if ((CC).giga_no == 0)                                              \
 
1789
        erts_print(TO, TOA, "%s%s calls: %bpu\n",PRFX,NAME,CC.no);      \
 
1790
    else                                                                \
 
1791
        erts_print(TO, TOA, "%s%s calls: %bpu%09lu\n",PRFX,NAME,CC.giga_no,CC.no)
1688
1792
 
1689
1793
        char *prefix = allctr->name_prefix;
1690
 
        CIO to = *ciop;
 
1794
        int to = *print_to_p;
 
1795
        void *arg = print_to_arg;
1691
1796
 
1692
 
        PRINT_CC_4(to, prefix, "alloc",        allctr->calls.this_alloc);
1693
 
        PRINT_CC_4(to, prefix, "free",         allctr->calls.this_free);
1694
 
        PRINT_CC_4(to, prefix, "realloc",      allctr->calls.this_realloc);
 
1797
        PRINT_CC_5(to, arg, prefix, "alloc",        allctr->calls.this_alloc);
 
1798
        PRINT_CC_5(to, arg, prefix, "free",         allctr->calls.this_free);
 
1799
        PRINT_CC_5(to, arg, prefix, "realloc",      allctr->calls.this_realloc);
1695
1800
 
1696
1801
#if HAVE_ERTS_MSEG
1697
 
        PRINT_CC_3(to,         "mseg_alloc",   allctr->calls.mseg_alloc);
1698
 
        PRINT_CC_3(to,         "mseg_dealloc", allctr->calls.mseg_dealloc);
1699
 
        PRINT_CC_3(to,         "mseg_realloc", allctr->calls.mseg_realloc);
 
1802
        PRINT_CC_4(to, arg,         "mseg_alloc",   allctr->calls.mseg_alloc);
 
1803
        PRINT_CC_4(to, arg,         "mseg_dealloc", allctr->calls.mseg_dealloc);
 
1804
        PRINT_CC_4(to, arg,         "mseg_realloc", allctr->calls.mseg_realloc);
1700
1805
#endif
1701
1806
 
1702
 
        PRINT_CC_3(to,         "sys_alloc",    allctr->calls.sys_alloc);
1703
 
        PRINT_CC_3(to,         "sys_free",     allctr->calls.sys_free);
1704
 
        PRINT_CC_3(to,         "sys_realloc",  allctr->calls.sys_realloc);
 
1807
        PRINT_CC_4(to, arg,         "sys_alloc",    allctr->calls.sys_alloc);
 
1808
        PRINT_CC_4(to, arg,         "sys_free",     allctr->calls.sys_free);
 
1809
        PRINT_CC_4(to, arg,         "sys_realloc",  allctr->calls.sys_realloc);
1705
1810
 
1706
 
#undef PRINT_CC_3
1707
1811
#undef PRINT_CC_4
 
1812
#undef PRINT_CC_5
1708
1813
 
1709
1814
    }
1710
1815
 
1711
1816
 
1712
1817
    if (hpp || szp) {
1713
 
        if (allctr->name.alloc == THE_NON_VALUE)
1714
 
            make_name_atoms(allctr);
1715
1818
 
1716
1819
        ASSERT(allctr->name.alloc   != THE_NON_VALUE);
1717
1820
        ASSERT(allctr->name.realloc != THE_NON_VALUE);
1721
1824
 
1722
1825
        add_3tup(hpp, szp, &res,
1723
1826
                 am.sys_realloc,
1724
 
                 bld_uint(hpp, szp, allctr->calls.sys_realloc.giga_no),
1725
 
                 bld_uint(hpp, szp, allctr->calls.sys_realloc.no));
 
1827
                 bld_unstable_uint(hpp, szp, allctr->calls.sys_realloc.giga_no),
 
1828
                 bld_unstable_uint(hpp, szp, allctr->calls.sys_realloc.no));
1726
1829
        add_3tup(hpp, szp, &res,
1727
1830
                 am.sys_free,
1728
 
                 bld_uint(hpp, szp, allctr->calls.sys_free.giga_no),
1729
 
                 bld_uint(hpp, szp, allctr->calls.sys_free.no));
 
1831
                 bld_unstable_uint(hpp, szp, allctr->calls.sys_free.giga_no),
 
1832
                 bld_unstable_uint(hpp, szp, allctr->calls.sys_free.no));
1730
1833
        add_3tup(hpp, szp, &res,
1731
1834
                 am.sys_alloc,
1732
 
                 bld_uint(hpp, szp, allctr->calls.sys_alloc.giga_no),
1733
 
                 bld_uint(hpp, szp, allctr->calls.sys_alloc.no));
 
1835
                 bld_unstable_uint(hpp, szp, allctr->calls.sys_alloc.giga_no),
 
1836
                 bld_unstable_uint(hpp, szp, allctr->calls.sys_alloc.no));
1734
1837
#if HAVE_ERTS_MSEG
1735
1838
        add_3tup(hpp, szp, &res,
1736
1839
                 am.mseg_realloc,
1737
 
                 bld_uint(hpp, szp, allctr->calls.mseg_realloc.giga_no),
1738
 
                 bld_uint(hpp, szp, allctr->calls.mseg_realloc.no));
 
1840
                 bld_unstable_uint(hpp, szp, allctr->calls.mseg_realloc.giga_no),
 
1841
                 bld_unstable_uint(hpp, szp, allctr->calls.mseg_realloc.no));
1739
1842
        add_3tup(hpp, szp, &res,
1740
1843
                 am.mseg_dealloc,
1741
 
                 bld_uint(hpp, szp, allctr->calls.mseg_dealloc.giga_no),
1742
 
                 bld_uint(hpp, szp, allctr->calls.mseg_dealloc.no));
 
1844
                 bld_unstable_uint(hpp, szp, allctr->calls.mseg_dealloc.giga_no),
 
1845
                 bld_unstable_uint(hpp, szp, allctr->calls.mseg_dealloc.no));
1743
1846
        add_3tup(hpp, szp, &res,
1744
1847
                 am.mseg_alloc,
1745
 
                 bld_uint(hpp, szp, allctr->calls.mseg_alloc.giga_no),
1746
 
                 bld_uint(hpp, szp, allctr->calls.mseg_alloc.no));
 
1848
                 bld_unstable_uint(hpp, szp, allctr->calls.mseg_alloc.giga_no),
 
1849
                 bld_unstable_uint(hpp, szp, allctr->calls.mseg_alloc.no));
1747
1850
#endif
1748
1851
        add_3tup(hpp, szp, &res,
1749
1852
                 allctr->name.realloc,
1750
 
                 bld_uint(hpp, szp, allctr->calls.this_realloc.giga_no),
1751
 
                 bld_uint(hpp, szp, allctr->calls.this_realloc.no));
 
1853
                 bld_unstable_uint(hpp, szp, allctr->calls.this_realloc.giga_no),
 
1854
                 bld_unstable_uint(hpp, szp, allctr->calls.this_realloc.no));
1752
1855
        add_3tup(hpp, szp, &res,
1753
1856
                 allctr->name.free,
1754
 
                 bld_uint(hpp, szp, allctr->calls.this_free.giga_no),
1755
 
                 bld_uint(hpp, szp, allctr->calls.this_free.no));
 
1857
                 bld_unstable_uint(hpp, szp, allctr->calls.this_free.giga_no),
 
1858
                 bld_unstable_uint(hpp, szp, allctr->calls.this_free.no));
1756
1859
        add_3tup(hpp, szp, &res,
1757
1860
                 allctr->name.alloc,
1758
 
                 bld_uint(hpp, szp, allctr->calls.this_alloc.giga_no),
1759
 
                 bld_uint(hpp, szp, allctr->calls.this_alloc.no));
 
1861
                 bld_unstable_uint(hpp, szp, allctr->calls.this_alloc.giga_no),
 
1862
                 bld_unstable_uint(hpp, szp, allctr->calls.this_alloc.no));
1760
1863
    }
1761
1864
 
1762
1865
    return res;
1764
1867
 
1765
1868
static Eterm
1766
1869
info_options(Allctr_t *allctr,
1767
 
             CIO *ciop,
 
1870
             int *print_to_p,
 
1871
             void *print_to_arg,
1768
1872
             Uint **hpp,
1769
1873
             Uint *szp)
1770
1874
{
1771
1875
    Eterm res = THE_NON_VALUE;
1772
1876
 
1773
1877
    if (!allctr) {
1774
 
        if (ciop)
1775
 
            erl_printf(*ciop, "option e: false\n");
 
1878
        if (print_to_p)
 
1879
            erts_print(*print_to_p, print_to_arg, "option e: false\n");
1776
1880
        if (hpp || szp) {
1777
1881
            res = NIL;
1778
1882
            add_2tup(hpp, szp, &res, am.e, am_false);
1780
1884
        return res;
1781
1885
    }
1782
1886
 
1783
 
    if (ciop) {
1784
 
            erl_printf(*ciop,
 
1887
    if (print_to_p) {
 
1888
            erts_print(*print_to_p,
 
1889
                       print_to_arg,
1785
1890
                       "option e: true\n"
1786
 
                       "option sbct: %lu\n"
1787
 
#if HAVE_ERTS_MSEG
1788
 
                       "option asbcst: %lu\n"
1789
 
                       "option rsbcst: %lu\n"
1790
 
#endif
1791
 
                       "option rsbcmt: %lu\n"
1792
 
                       "option mmbcs: %lu\n"
1793
 
#if HAVE_ERTS_MSEG
1794
 
                       "option mmsbc: %lu\n"
1795
 
                       "option mmmbc: %lu\n"
1796
 
#endif
1797
 
                       "option lmbcs: %lu\n"
1798
 
                       "option smbcs: %lu\n"
1799
 
                       "option mbcgs: %lu\n",
 
1891
                       "option sbct: %bpu\n"
 
1892
#if HAVE_ERTS_MSEG
 
1893
                       "option asbcst: %bpu\n"
 
1894
                       "option rsbcst: %bpu\n"
 
1895
#endif
 
1896
                       "option rsbcmt: %bpu\n"
 
1897
                       "option mmbcs: %bpu\n"
 
1898
#if HAVE_ERTS_MSEG
 
1899
                       "option mmsbc: %bpu\n"
 
1900
                       "option mmmbc: %bpu\n"
 
1901
#endif
 
1902
                       "option lmbcs: %bpu\n"
 
1903
                       "option smbcs: %bpu\n"
 
1904
                       "option mbcgs: %bpu\n",
1800
1905
                       allctr->sbc_threshold,
1801
1906
#if HAVE_ERTS_MSEG
1802
1907
                       allctr->mseg_opt.abs_shrink_th,
1813
1918
                       allctr->mbc_growth_stages);
1814
1919
    }
1815
1920
 
1816
 
    res = (*allctr->info_options)(allctr, "option ", ciop, hpp, szp);
 
1921
    res = (*allctr->info_options)(allctr, "option ", print_to_p, print_to_arg,
 
1922
                                  hpp, szp);
1817
1923
 
1818
1924
    if (hpp || szp) {
1819
1925
        add_2tup(hpp, szp, &res,
1885
1991
\*                                                                         */
1886
1992
 
1887
1993
Eterm
1888
 
erts_alcu_au_info_options(CIO *ciop, Uint **hpp, Uint *szp)
 
1994
erts_alcu_au_info_options(int *print_to_p, void *print_to_arg,
 
1995
                          Uint **hpp, Uint *szp)
1889
1996
{
1890
 
    Eterm res = THE_NON_VALUE;
1891
 
 
1892
 
    if (hpp || szp) {
1893
 
        if (!atoms_initialized)
1894
 
            init_atoms();
1895
 
    }
1896
 
    
1897
 
 
1898
 
    if (ciop) {
1899
 
 
1900
 
        erl_printf(*ciop,
 
1997
    Eterm res = THE_NON_VALUE;    
 
1998
 
 
1999
    if (print_to_p) {
 
2000
 
 
2001
        erts_print(*print_to_p,
 
2002
                   print_to_arg,
1901
2003
#if HAVE_ERTS_MSEG
1902
 
                   "option mmc: %lu\n"
 
2004
                   "option mmc: %bpu\n"
1903
2005
#endif
1904
 
                   "option ycs: %lu\n",
 
2006
                   "option ycs: %bpu\n",
1905
2007
#if HAVE_ERTS_MSEG
1906
2008
                   max_mseg_carriers,
1907
2009
#endif
1910
2012
 
1911
2013
    if (hpp || szp) {
1912
2014
        res = NIL;
 
2015
        ensure_atoms_initialized(NULL);
1913
2016
        add_2tup(hpp, szp, &res,
1914
2017
                 am.ycs,
1915
2018
                 bld_uint(hpp, szp, sys_alloc_carrier_size));
1926
2029
 
1927
2030
Eterm
1928
2031
erts_alcu_info_options(Allctr_t *allctr,
1929
 
                       CIO *ciop,
 
2032
                       int *print_to_p,
 
2033
                       void *print_to_arg,
1930
2034
                       Uint **hpp,
1931
2035
                       Uint *szp)
1932
2036
{
1933
2037
    Eterm res;
1934
2038
 
1935
 
    if (hpp || szp) {
1936
 
        if (!atoms_initialized)
1937
 
            init_atoms();
1938
 
    }
1939
 
    
1940
 
    if (!allctr)
1941
 
        return info_options(allctr, ciop, hpp, szp);
1942
 
 
1943
 
#ifdef USE_THREADS
1944
 
    if (allctr->thread_safe)
1945
 
        LOCK(allctr->mutex);
1946
 
#endif
1947
 
 
1948
 
    res = info_options(allctr, ciop, hpp, szp);
1949
 
 
1950
 
#ifdef USE_THREADS
1951
 
    if (allctr->thread_safe)
1952
 
        UNLOCK(allctr->mutex);
1953
 
#endif
1954
 
 
 
2039
 
 
2040
#ifdef USE_THREADS
 
2041
    if (allctr->thread_safe)
 
2042
        erts_mtx_lock(&allctr->mutex);
 
2043
#endif
 
2044
    if (hpp || szp)
 
2045
        ensure_atoms_initialized(allctr);
 
2046
    res = info_options(allctr, print_to_p, print_to_arg, hpp, szp);
 
2047
#ifdef USE_THREADS
 
2048
    if (allctr->thread_safe)
 
2049
        erts_mtx_unlock(&allctr->mutex);
 
2050
#endif
1955
2051
    return res;
1956
2052
}
1957
2053
 
1960
2056
Eterm
1961
2057
erts_alcu_info(Allctr_t *allctr,
1962
2058
               int begin_max_period,
1963
 
               CIO *ciop,
 
2059
               int *print_to_p,
 
2060
               void *print_to_arg,
1964
2061
               Uint **hpp,
1965
2062
               Uint *szp)
1966
2063
{
1969
2066
    res  = THE_NON_VALUE;
1970
2067
 
1971
2068
    if (!allctr) {
1972
 
        if (ciop)
1973
 
            erl_printf(*ciop, "false\n");
 
2069
        if (print_to_p)
 
2070
            erts_print(*print_to_p, print_to_arg, "false\n");
1974
2071
        if (szp)
1975
2072
            *szp = 0;
1976
2073
        return am_false;
1977
2074
    }
1978
2075
 
1979
2076
#ifdef USE_THREADS
1980
 
    if (allctr->thread_safe && !erts_writing_erl_crash_dump)
1981
 
        LOCK(allctr->mutex);
 
2077
    if (allctr->thread_safe)
 
2078
        erts_mtx_lock(&allctr->mutex);
1982
2079
#endif
1983
2080
 
 
2081
    if (hpp || szp)
 
2082
        ensure_atoms_initialized(allctr);
 
2083
 
1984
2084
    /* Update sbc values not continously updated */
1985
2085
    allctr->sbcs.blocks.curr.no
1986
2086
        = allctr->sbcs.curr_mseg.no + allctr->sbcs.curr_sys_alloc.no;
1989
2089
    update_max_ever_values(&allctr->mbcs);
1990
2090
    update_max_ever_values(&allctr->sbcs);
1991
2091
 
1992
 
    if (ciop) {
1993
 
        erl_printf(*ciop,
 
2092
    if (print_to_p) {
 
2093
        erts_print(*print_to_p,
 
2094
                   print_to_arg,
1994
2095
                   "versions: %s %s\n",
1995
2096
                   allctr->vsn_str,
1996
2097
                   ERTS_ALCU_VSN_STR);
1997
2098
    }
1998
2099
 
1999
 
    sett  = info_options(allctr, ciop, hpp, szp);
2000
 
    mbcs  = info_carriers(allctr, &allctr->mbcs, "mbcs ", ciop, hpp, szp);
2001
 
    sbcs  = info_carriers(allctr, &allctr->sbcs, "sbcs ", ciop, hpp, szp);
2002
 
    calls = info_calls(allctr, ciop, hpp, szp);
 
2100
    sett  = info_options(allctr, print_to_p, print_to_arg, hpp, szp);
 
2101
    mbcs  = info_carriers(allctr, &allctr->mbcs, "mbcs ", print_to_p,
 
2102
                          print_to_arg, hpp, szp);
 
2103
    sbcs  = info_carriers(allctr, &allctr->sbcs, "sbcs ", print_to_p,
 
2104
                          print_to_arg, hpp, szp);
 
2105
    calls = info_calls(allctr, print_to_p, print_to_arg, hpp, szp);
2003
2106
 
2004
2107
    if (hpp || szp) {
2005
2108
        res = NIL;
2006
2109
 
2007
 
        if (!atoms_initialized)
2008
 
            init_atoms();
2009
 
 
2010
2110
        add_2tup(hpp, szp, &res, am.calls, calls);
2011
2111
        add_2tup(hpp, szp, &res, am.sbcs, sbcs);
2012
2112
        add_2tup(hpp, szp, &res, am.mbcs, mbcs);
2024
2124
 
2025
2125
 
2026
2126
#ifdef USE_THREADS
2027
 
    if (allctr->thread_safe && !erts_writing_erl_crash_dump)
2028
 
        UNLOCK(allctr->mutex);
 
2127
    if (allctr->thread_safe)
 
2128
        erts_mtx_unlock(&allctr->mutex);
2029
2129
#endif
2030
2130
 
2031
2131
    return res;
2075
2175
{
2076
2176
    Allctr_t *allctr = (Allctr_t *) extra;
2077
2177
    void *res;
2078
 
    LOCK(allctr->mutex);
 
2178
    erts_mtx_lock(&allctr->mutex);
2079
2179
    res = do_erts_alcu_alloc(type, extra, size);
2080
 
    UNLOCK(allctr->mutex);
 
2180
    erts_mtx_unlock(&allctr->mutex);
2081
2181
    return res;
2082
2182
}
2083
2183
 
 
2184
#ifdef ERTS_ALC_THR_SPEC_ALLOCS
 
2185
void *
 
2186
erts_alcu_alloc_thr_spec(ErtsAlcType_t type, void *unused, Uint size)
 
2187
{
 
2188
    void *vallctr = erts_tsd_get(erts_allctr_thr_spec[ERTS_ALC_T2A(T)].key);
 
2189
 
 
2190
    if (!vallctr) {
 
2191
        vallctr = (*erts_allctr_thr_spec[ERTS_ALC_T2A(type)].start_default)();
 
2192
        if (!vallctr)
 
2193
            return NULL;
 
2194
    }
 
2195
 
 
2196
    return do_erts_alcu_alloc(type, vallctr, size);
 
2197
}
 
2198
#endif
 
2199
 
2084
2200
#endif
2085
2201
 
2086
2202
/* ------------------------------------------------------------------------- */
2117
2233
erts_alcu_free_ts(ErtsAlcType_t type, void *extra, void *p)
2118
2234
{
2119
2235
    Allctr_t *allctr = (Allctr_t *) extra;
2120
 
    LOCK(allctr->mutex);
 
2236
    erts_mtx_lock(&allctr->mutex);
2121
2237
    do_erts_alcu_free(type, extra, p);
2122
 
    UNLOCK(allctr->mutex);
2123
 
}
 
2238
    erts_mtx_unlock(&allctr->mutex);
 
2239
}
 
2240
 
 
2241
#ifdef ERTS_ALC_THR_SPEC_ALLOCS
 
2242
void
 
2243
erts_alcu_free_thr_spec(ErtsAlcType_t type, void *unused, void *p)
 
2244
{
 
2245
    void *vallctr = erts_tsd_get(erts_allctr_thr_spec[ERTS_ALC_T2A(type)].key);
 
2246
    ASSERT(vallctr);
 
2247
    do_erts_alcu_free(type, vallctr, p);
 
2248
}
 
2249
#endif
2124
2250
 
2125
2251
#endif
2126
2252
 
2227
2353
{
2228
2354
    Allctr_t *allctr = (Allctr_t *) extra;
2229
2355
    void *res;
2230
 
    LOCK(allctr->mutex);
 
2356
    erts_mtx_lock(&allctr->mutex);
2231
2357
    res = do_erts_alcu_realloc(type, extra, ptr, size);
2232
 
    UNLOCK(allctr->mutex);
 
2358
    erts_mtx_unlock(&allctr->mutex);
2233
2359
    return res;
2234
2360
}
2235
2361
 
 
2362
#ifdef ERTS_ALC_THR_SPEC_ALLOCS
 
2363
void *
 
2364
erts_alcu_realloc_thr_spec(ErtsAlcType_t type, void *unused,
 
2365
                           void *ptr, Uint size)
 
2366
{
 
2367
    void *vallctr = erts_tsd_get(erts_allctr_thr_spec[ERTS_ALC_T2A(T)].key);
 
2368
 
 
2369
    if (!vallctr) {
 
2370
        vallctr = (*erts_allctr_thr_spec[ERTS_ALC_T2A(type)].start_default)();
 
2371
        if (!vallctr)
 
2372
            return NULL;
 
2373
    }
 
2374
 
 
2375
    return do_erts_alcu_realloc(type, vallctr, ptr, size);
 
2376
}
 
2377
#endif
 
2378
 
2236
2379
#endif
2237
2380
 
2238
2381
/* ------------------------------------------------------------------------- */
2259
2402
    if (!allctr->name_prefix)
2260
2403
        goto error;
2261
2404
 
 
2405
    allctr->alloc_no                    = init->alloc_no;
 
2406
    if (allctr->alloc_no < ERTS_ALC_A_MIN
 
2407
        || ERTS_ALC_A_MAX < allctr->alloc_no)
 
2408
        allctr->alloc_no = ERTS_ALC_A_INVALID;
 
2409
 
2262
2410
    if (!allctr->vsn_str)
2263
2411
        goto error;
2264
2412
 
2265
 
#ifdef USE_THREADS
2266
 
    allctr->sys_mutex_no                = init->smn;
2267
 
#endif
2268
 
 
2269
2413
    allctr->name.alloc                  = THE_NON_VALUE;
2270
2414
    allctr->name.realloc                = THE_NON_VALUE;
2271
2415
    allctr->name.free                   = THE_NON_VALUE;
2299
2443
#ifdef USE_THREADS
2300
2444
    if (init->ts) {
2301
2445
        allctr->thread_safe = 1;
2302
 
        if (allctr->sys_mutex_no >= 0)
2303
 
            allctr->mutex = erts_mutex_sys(allctr->sys_mutex_no);
2304
 
        else
2305
 
            allctr->mutex = erts_mutex_create();
2306
 
        if (!allctr->mutex || erts_mutex_set_default_atfork(allctr->mutex))
2307
 
            goto error;
 
2446
        erts_mtx_init_x(&allctr->mutex,
 
2447
                        "alcu_allocator",
 
2448
                        make_small(allctr->alloc_no));
 
2449
        erts_mtx_set_forksafe(&allctr->mutex);
2308
2450
    }
2309
2451
#endif
2310
2452
 
2347
2489
 error:
2348
2490
 
2349
2491
#ifdef USE_THREADS
2350
 
    if (allctr->mutex) {
2351
 
        if (allctr->sys_mutex_no >= 0)
2352
 
            erts_mutex_unset_default_atfork(allctr->mutex);
2353
 
        else
2354
 
            erts_mutex_destroy(allctr->mutex);
2355
 
    }
 
2492
    if (allctr->thread_safe)
 
2493
        erts_mtx_destroy(&allctr->mutex);
2356
2494
#endif
2357
2495
 
2358
2496
    return 0;
2372
2510
        destroy_carrier(allctr, MBC2FBLK(allctr, allctr->mbc_list.first));
2373
2511
 
2374
2512
#ifdef USE_THREADS
2375
 
    if (allctr->thread_safe) {
2376
 
        ASSERT(allctr->mutex);
2377
 
        if (allctr->sys_mutex_no >= 0)
2378
 
            erts_mutex_unset_default_atfork(allctr->mutex);
2379
 
        else
2380
 
            erts_mutex_destroy(allctr->mutex);
2381
 
    }
 
2513
    if (allctr->thread_safe)
 
2514
        erts_mtx_destroy(&allctr->mutex);
2382
2515
#endif
2383
2516
 
2384
2517
}
2409
2542
    carrier_alignment = sizeof(Unit_t);
2410
2543
#endif
2411
2544
 
 
2545
    erts_mtx_init(&init_atoms_mtx, "alcu_init_atoms");
 
2546
 
2412
2547
    atoms_initialized = 0;
2413
2548
    initialized = 1;
2414
2549
}