~clint-fewbar/ubuntu/precise/erlang/merge-15b

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Sergei Golovan
  • Date: 2011-12-15 19:20:10 UTC
  • mfrom: (1.1.18) (3.5.15 sid)
  • mto: (3.5.16 sid)
  • mto: This revision was merged to the branch mainline in revision 33.
  • Revision ID: package-import@ubuntu.com-20111215192010-jnxcfe3tbrpp0big
Tags: 1:15.b-dfsg-1
* New upstream release.
* Upload to experimental because this release breaks external drivers
  API along with ABI, so several applications are to be fixed.
* Removed SSL patch because the old SSL implementation is removed from
  the upstream distribution.
* Removed never used patch which added native code to erlang beam files.
* Removed the erlang-docbuilder binary package because the docbuilder
  application was dropped by upstream.
* Documented dropping ${erlang-docbuilder:Depends} substvar in
  erlang-depends(1) manpage.
* Made erlang-base and erlang-base-hipe provide virtual package
  erlang-abi-15.b (the number means the first erlang version, which
  provides current ABI).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * %CopyrightBegin%
3
3
 *
4
 
 * Copyright Ericsson AB 2000-2010. All Rights Reserved.
 
4
 * Copyright Ericsson AB 2000-2011. All Rights Reserved.
5
5
 *
6
6
 * The contents of this file are subject to the Erlang Public License,
7
7
 * Version 1.1, (the "License"); you may not use this file except in
22
22
#endif
23
23
#include "sys.h"
24
24
#include "beam_catches.h"
 
25
#include "global.h"
25
26
 
26
 
/* XXX: should use dynamic reallocation */
27
 
#define TABSIZ (16*1024)
28
 
static struct {
 
27
/* R14B04 has about 380 catches when starting erlang */
 
28
#define DEFAULT_TABSIZE (1024)
 
29
typedef struct {
29
30
    BeamInstr *cp;
30
31
    unsigned cdr;
31
 
} beam_catches[TABSIZ];
 
32
} beam_catch_t;
32
33
 
33
34
static int free_list;
34
35
static unsigned high_mark;
 
36
static unsigned tabsize;
 
37
static beam_catch_t *beam_catches;
35
38
 
36
39
void beam_catches_init(void)
37
40
{
 
41
    tabsize   = DEFAULT_TABSIZE;
38
42
    free_list = -1;
39
43
    high_mark = 0;
 
44
 
 
45
    beam_catches = erts_alloc(ERTS_ALC_T_CODE, sizeof(beam_catch_t)*DEFAULT_TABSIZE);
40
46
}
41
47
 
42
48
unsigned beam_catches_cons(BeamInstr *cp, unsigned cdr)
50
56
     * This avoids the need to initialise the free list in
51
57
     * beam_catches_init(), which would cost O(TABSIZ) time.
52
58
     */
53
 
    if( (i = free_list) >= 0 ) {
 
59
    if( free_list >= 0 ) {
 
60
        i = free_list;
54
61
        free_list = beam_catches[i].cdr;
55
 
    } else if( (i = high_mark) < TABSIZ ) {
56
 
        high_mark = i + 1;
 
62
    } else if( high_mark < tabsize ) {
 
63
        i = high_mark;
 
64
        high_mark++;
57
65
    } else {
58
 
        fprintf(stderr, "beam_catches_cons: no free slots :-(\r\n");
59
 
        exit(1);
 
66
        /* No free slots and table is full: realloc table */
 
67
        tabsize      = 2*tabsize;
 
68
        beam_catches = erts_realloc(ERTS_ALC_T_CODE, beam_catches, sizeof(beam_catch_t)*tabsize);
 
69
        i = high_mark;
 
70
        high_mark++;
60
71
    }
61
72
 
62
 
    beam_catches[i].cp = cp;
 
73
    beam_catches[i].cp  = cp;
63
74
    beam_catches[i].cdr = cdr;
64
75
 
65
76
    return i;
67
78
 
68
79
BeamInstr *beam_catches_car(unsigned i)
69
80
{
70
 
    if( i >= TABSIZ ) {
71
 
        fprintf(stderr,
72
 
                "beam_catches_car: index %#x is out of range\r\n", i);
73
 
        abort();
 
81
    if( i >= tabsize ) {
 
82
        erl_exit(1, "beam_catches_delmod: index %#x is out of range\r\n", i);
74
83
    }
75
84
    return beam_catches[i].cp;
76
85
}
80
89
    unsigned i, cdr;
81
90
 
82
91
    for(i = head; i != (unsigned)-1;) {
83
 
        if( i >= TABSIZ ) {
84
 
            fprintf(stderr,
85
 
                    "beam_catches_delmod: index %#x is out of range\r\n", i);
86
 
            abort();
 
92
        if( i >= tabsize ) {
 
93
            erl_exit(1, "beam_catches_delmod: index %#x is out of range\r\n", i);
87
94
        }
88
95
        if( (char*)beam_catches[i].cp - (char*)code >= code_bytes ) {
89
 
            fprintf(stderr,
 
96
            erl_exit(1,
90
97
                    "beam_catches_delmod: item %#x has cp %#lx which is not "
91
98
                    "in module's range [%#lx,%#lx[\r\n",
92
99
                    i, (long)beam_catches[i].cp,
93
100
                    (long)code, (long)((char*)code + code_bytes));
94
 
            abort();
95
101
        }
96
102
        beam_catches[i].cp = 0;
97
103
        cdr = beam_catches[i].cdr;