File: manual022.html

package info (click to toggle)
ocaml-doc 2.04-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,820 kB
  • ctags: 997
  • sloc: makefile: 38; sh: 12
file content (180 lines) | stat: -rw-r--r-- 7,831 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset= ISO-8859-1">
<TITLE>
 The runtime system (ocamlrun)
</TITLE>
</HEAD>
<BODY >
<A HREF="manual021.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual023.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
<HR>

<H1>Chapter&nbsp;9:&nbsp;&nbsp; The runtime system (ocamlrun)</H1> <A NAME="c:runtime"></A>
The <TT>ocamlrun</TT> command executes bytecode files produced by the
linking phase of the <TT>ocamlc</TT> command.<BR>
<BR>

<H2>9.1&nbsp;&nbsp; Overview</H2>The <TT>ocamlrun</TT> command comprises three main parts: the bytecode
interpreter, that actually executes bytecode files; the memory
allocator and garbage collector; and a set of C functions that
implement primitive operations such as input/output.<BR>
<BR>
The usage for <TT>ocamlrun</TT> is:
<PRE>
        ocamlrun <I>options</I> <I>bytecode-executable</I> <I>arg</I><SUB><FONT SIZE=2>1</FONT></SUB> ... <I>arg</I><SUB><FONT SIZE=2><I>n</I></FONT></SUB>
</PRE>
The first non-option argument is taken to be the name of the file
containing the executable bytecode. (That file is searched in the
executable path as well as in the current directory.) The remaining
arguments are passed to the Caml Light program, in the string array
<TT>Sys.argv</TT>. Element 0 of this array is the name of the
bytecode executable file; elements 1 to <I>n</I> are the remaining
arguments <I>arg</I><SUB><FONT SIZE=2>1</FONT></SUB> to <I>arg</I><SUB><FONT SIZE=2><I>n</I></FONT></SUB>.<BR>
<BR>
As mentioned in chapter&nbsp;<A HREF="manual020.html#c:camlc">7</A>, in most cases, the bytecode
executable files produced by the <TT>ocamlc</TT> command are self-executable,
and manage to launch the <TT>ocamlrun</TT> command on themselves
automatically. That is, assuming <TT>caml.out</TT> is a bytecode executable
file,
<PRE>
        caml.out <I>arg</I><SUB><FONT SIZE=2>1</FONT></SUB> ... <I>arg</I><SUB><FONT SIZE=2><I>n</I></FONT></SUB>
</PRE>
works exactly as
<PRE>
        ocamlrun caml.out <I>arg</I><SUB><FONT SIZE=2>1</FONT></SUB> ... <I>arg</I><SUB><FONT SIZE=2><I>n</I></FONT></SUB>
</PRE>
Notice that it is not possible to pass options to <TT>ocamlrun</TT> when
invoking <TT>caml.out</TT> directly.<BR>
<BR>

<H2>9.2&nbsp;&nbsp; Options</H2>The following command-line option is recognized by <TT>ocamlrun</TT>.<BR>
<BR>
<DL COMPACT=compact>
<DT><TT>-v</TT><DD> 
When set, the memory manager prints some verbose messages on
standard error.</DL>The following environment variables are also consulted:<BR>
<BR>
<DL COMPACT=compact>
<DT>
<TT>OCAMLRUNPARAM</TT><DD> Set the garbage collection parameters.
 (If <TT>OCAMLRUNPARAM</TT> is not set, <TT>CAMLRUNPARAM</TT> will be used instead.)
 This variable must be a sequence of parameter specifications.
 A parameter specification is an option letter followed by an <TT>=</TT>
 sign, a decimal number, and an optional multiplier. There are
 seven options, the first six correspond to the fields of the
 <TT>control</TT> record documented in section&nbsp;<A HREF="manual039.html#s:Gc">17.9</A>:
 <DL COMPACT=compact>
<DT>
 s<DD> (<TT>minor</TT><TT>_</TT><TT>heap</TT><TT>_</TT><TT>size</TT>) Size of the minor heap.
 
<DT>i<DD> (<TT>major</TT><TT>_</TT><TT>heap</TT><TT>_</TT><TT>increment</TT>) Minimum size increment for the
 major heap.
 
<DT>o<DD> (<TT>space</TT><TT>_</TT><TT>overhead</TT>) The major GC speed setting.
 
<DT>O<DD> (<TT>max</TT><TT>_</TT><TT>overhead</TT>) The heap compaction trigger setting.
 
<DT>v<DD> (<TT>verbose</TT>) What GC messages to print to stderr. This
 is a sum of values selected from the following:
 <DL COMPACT=compact>
<DT>
 1<DD> Start of major GC cycle.
 
<DT>2<DD> Minor collection and major GC slice.
 
<DT>4<DD> Growing and shrinking of the heap.
 
<DT>8<DD> Resizing of stacks and memory manager tables.
 
<DT>16<DD> Heap compaction.
 
<DT>32<DD> Change of GC parameters.
 
<DT>64<DD> Computation of major GC slice size.
 </DL>
 
<DT>l<DD> (<TT>stack</TT><TT>_</TT><TT>limit</TT>) The limit (in words) of the stack size.
 
<DT>h<DD> The initial size of the major heap (in words).
 </DL>
 The multiplier is <TT>k</TT>, <TT>M</TT>, or <TT>G</TT>, for multiplication by 2<SUP><FONT SIZE=2>10</FONT></SUP>,
 2<SUP><FONT SIZE=2>20</FONT></SUP>, and 2<SUP><FONT SIZE=2>30</FONT></SUP> respectively.
 For example, on a 32-bit machine, under <TT>bash</TT> the command
<PRE>
        export OCAMLRUNPARAM='s=256k,v=1'
</PRE>
 tells a subsequent <TT>ocamlrun</TT> to set its initial minor heap size to
 1&nbsp;megabyte and to print a message at the start of each major GC cycle.<BR>
<BR>

<DT><TT>PATH</TT><DD> List of directories searched to find the bytecode
executable file.
</DL>
<H2>9.3&nbsp;&nbsp; Common errors</H2>This section describes and explains the most frequently encountered
error messages.<BR>
<BR>
<DL COMPACT=compact>
<DT><I>filename</I><TT>: no such file or directory</TT><DD>
If <I>filename</I> is the name of a self-executable bytecode file, this
means that either that file does not exist, or that it failed to run
the <TT>ocamlrun</TT> bytecode interpreter on itself. The second possibility
indicates that Objective Caml has not been properly installed on your
system.<BR>
<BR>

<DT><TT>Cannot exec camlrun</TT><DD>
(When launching a self-executable bytecode file.) The <TT>ocamlrun</TT>
 could not be found in the executable path. Check that Objective Caml
 has been properly installed on your system.<BR>
<BR>

<DT><TT>Cannot find the bytecode file</TT><DD>
The file that <TT>ocamlrun</TT> is trying to execute (e.g. the file given as
first non-option argument to <TT>ocamlrun</TT>) either does not exist, or is
not a valid executable bytecode file.<BR>
<BR>

<DT><TT>Truncated bytecode file</TT><DD>
The file that <TT>ocamlrun</TT> is trying to execute is not a valid executable
bytecode file. Probably it has been truncated or mangled since
created. Erase and rebuild it.<BR>
<BR>

<DT><TT>Uncaught exception</TT><DD>
The program being executed contains a ``stray'' exception. That is,
it raises an exception at some point, and this exception is never
caught. This causes immediate termination of the program. The name of
the exception is printed, but not its arguments.<BR>
<BR>

<DT><TT>Out of memory</TT><DD>
The program being executed requires more memory than available. Either
the program builds excessively large data structures; or the program
contains too many nested function calls, and the stack overflows. In
some cases, your program is perfectly correct, it just requires more
memory than your machine provides. In other cases, the ``out of
memory'' message reveals an error in your program: non-terminating
recursive function, allocation of an excessively large array or
string, attempts to build an infinite list or other data structure,
...<BR>
<BR>
To help you diagnose this error, run your program with the <TT>-v</TT> option
to <TT>ocamlrun</TT>. If it displays lots of ``<TT>Growing stack</TT>...''
messages, this is probably a looping recursive function. If it
displays lots of ``<TT>Growing heap</TT>...'' messages, with the heap size
growing slowly, this is probably an attempt to construct a data
structure with too many (infinitely many?) cells. If it displays few 
``<TT>Growing heap</TT>...'' messages, but with a huge increment in the
heap size, this is probably an attempt to build an excessively large
array or string.</DL>

<HR>
<A HREF="manual021.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="manual023.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A>
</BODY>
</HTML>