* configure.ac (AC_CHECK_HEADERS): Added sys/socket.h.
[cacao.git] / src / vmcore / options.c
1 /* src/vmcore/options.c - contains global options
2
3    Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    $Id: options.c 8123 2007-06-20 23:50:55Z michi $
26
27 */
28
29
30 #include "config.h"
31
32 #include <errno.h>
33 #include <stdint.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 #if defined(HAVE_STRING_H)
38 # include <string.h>
39 #endif
40
41 #include <limits.h>
42
43 #include "mm/memory.h"
44
45 #include "native/jni.h"
46
47 #include "vm/vm.h"
48
49 #include "vmcore/options.h"
50
51
52 /* command line option ********************************************************/
53
54 s4    opt_index = 0;            /* index of processed arguments               */
55 char *opt_arg;                  /* this one exports the option argument       */
56
57 bool opt_foo = false;           /* option for development                     */
58
59 bool opt_jar = false;
60
61 #if defined(ENABLE_JIT)
62 bool opt_jit = true;            /* JIT mode execution (default)               */
63 bool opt_intrp = false;         /* interpreter mode execution                 */
64 #else
65 bool opt_jit = false;           /* JIT mode execution                         */
66 bool opt_intrp = true;          /* interpreter mode execution (default)       */
67 #endif
68
69 bool opt_run = true;
70
71 s4   opt_heapmaxsize   = 0;     /* maximum heap size                          */
72 s4   opt_heapstartsize = 0;     /* initial heap size                          */
73 s4   opt_stacksize     = 0;     /* thread stack size                          */
74
75 bool opt_verbose = false;
76 bool opt_debugcolor = false;    /* use ANSI terminal sequences                */
77 bool compileall = false;
78
79 bool loadverbose = false;
80 bool linkverbose = false;
81 bool initverbose = false;
82
83 bool opt_verboseclass     = false;
84 bool opt_verbosegc        = false;
85 bool opt_verbosejni       = false;
86 bool opt_verbosecall      = false;      /* trace all method invocation        */
87 bool opt_verbosethreads   = false;
88
89 bool showmethods = false;
90 bool showconstantpool = false;
91 bool showutf = false;
92
93 char *opt_method = NULL;
94 char *opt_signature = NULL;
95
96 bool compileverbose =  false;           /* trace compiler actions             */
97 bool showstack = false;
98
99 bool opt_showdisassemble    = false;    /* generate disassembler listing      */
100 bool opt_shownops           = false;
101 bool opt_showddatasegment   = false;    /* generate data segment listing      */
102 bool opt_showintermediate   = false;    /* generate intermediate code listing */
103 bool opt_showexceptionstubs = false;
104 bool opt_shownativestub     = false;
105
106 bool checkbounds = true;       /* check array bounds                         */
107 bool opt_noieee = false;       /* don't implement ieee compliant floats      */
108 bool checksync = true;         /* do synchronization                         */
109 #if defined(ENABLE_LOOP)
110 bool opt_loops = false;        /* optimize array accesses in loops           */
111 #endif
112
113 bool makeinitializations = true;
114
115 #if defined(ENABLE_STATISTICS)
116 bool opt_stat    = false;
117 bool opt_getloadingtime = false;   /* to measure the runtime                 */
118 bool opt_getcompilingtime = false; /* compute compile time                   */
119 #endif
120 #if defined(ENABLE_VERIFIER)
121 bool opt_verify  = true;       /* true if classfiles should be verified      */
122 #endif
123 bool opt_eager   = false;
124
125 #if defined(ENABLE_PROFILING)
126 bool opt_prof    = false;
127 bool opt_prof_bb = false;
128 #endif
129
130
131 /* inlining options ***********************************************************/
132
133 #if defined(ENABLE_INLINING)
134 bool opt_inlining = false;
135 #if defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG)
136 s4 opt_replace_verbose = 0;
137 s4 opt_inline_debug_min_size = 0;
138 s4 opt_inline_debug_max_size = INT_MAX;
139 s4 opt_inline_debug_end_counter = INT_MAX;
140 bool opt_inline_debug_all = false;
141 #endif /* defined(ENABLE_INLINING_DEBUG) || !defined(NDEBUG) */
142 #if !defined(NDEBUG)
143 bool opt_inline_debug_log = false;
144 #endif /* !defined(NDEBUG) */
145 #endif /* defined(ENABLE_INLINING) */
146
147
148 /* optimization options *******************************************************/
149
150 #if defined(ENABLE_IFCONV)
151 bool opt_ifconv = false;
152 #endif
153
154 #if defined(ENABLE_LSRA) || defined(ENABLE_SSA)
155 bool opt_lsra = false;
156 #endif
157
158
159 /* interpreter options ********************************************************/
160
161 #if defined(ENABLE_INTRP)
162 bool opt_no_dynamic = false;            /* suppress dynamic superinstructions */
163 bool opt_no_replication = false;        /* don't use replication in intrp     */
164 bool opt_no_quicksuper = false;         /* instructions for quickening cannot be
165                                                                                    part of dynamic superinstructions */
166
167 s4   opt_static_supers = 0x7fffffff;
168 bool vm_debug = false;          /* XXX this should be called `opt_trace'      */
169 #endif
170
171 #if defined(ENABLE_DEBUG_FILTER)
172 const char *opt_filter_verbosecall_include = 0;
173 const char *opt_filter_verbosecall_exclude = 0;
174 const char *opt_filter_show_method = 0;
175 #endif
176
177
178 /* -XX options ****************************************************************/
179
180 /* NOTE: For better readability keep these alpha-sorted. */
181
182 int32_t  opt_ProfileGCMemoryUsage      = 0;
183 int32_t  opt_ProfileMemoryUsage        = 0;
184 FILE    *opt_ProfileMemoryUsageGNUPlot = NULL;
185 int32_t  opt_TraceExceptions           = 0;
186 #if defined(ENABLE_REPLACEMENT)
187 int32_t  opt_TraceReplacement          = 0;
188 #endif
189
190
191 enum {
192         OPT_ProfileGCMemoryUsage,
193         OPT_ProfileMemoryUsage,
194         OPT_ProfileMemoryUsageGNUPlot,
195         OPT_TraceExceptions,
196         OPT_TraceReplacement
197 };
198
199
200 option_t options_XX[] = {
201         { "ProfileGCMemoryUsage",      OPT_ProfileGCMemoryUsage,      "" },
202         { "ProfileMemoryUsage",        OPT_ProfileMemoryUsage,        "" },
203         { "ProfileMemoryUsageGNUPlot", OPT_ProfileMemoryUsageGNUPlot, "" },
204         { "TraceExceptions",           OPT_TraceExceptions,           "" },
205 #if defined(ENABLE_REPLACEMENT)
206         { "TraceReplacement",          OPT_TraceReplacement,          "" },
207 #endif
208 };
209
210
211 /* options_get *****************************************************************
212
213    DOCUMENT ME!!!
214
215 *******************************************************************************/
216
217 s4 options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
218 {
219         char *option;
220         s4    i;
221
222         if (opt_index >= vm_args->nOptions)
223                 return OPT_DONE;
224
225         /* get the current option */
226
227         option = vm_args->options[opt_index].optionString;
228
229         if ((option == NULL) || (option[0] != '-'))
230                 return OPT_DONE;
231
232         for (i = 0; opts[i].name; i++) {
233                 if (!opts[i].arg) {
234                         /* boolean option found */
235
236                         if (strcmp(option + 1, opts[i].name) == 0) {
237                                 opt_index++;
238                                 return opts[i].value;
239                         }
240
241                 } else {
242                         /* parameter option found */
243
244                         /* with a space between */
245
246                         if (strcmp(option + 1, opts[i].name) == 0) {
247                                 opt_index++;
248
249                                 if (opt_index < vm_args->nOptions) {
250
251 #if defined(HAVE_STRDUP)
252                                         opt_arg = strdup(vm_args->options[opt_index].optionString);
253 #else
254 # error !HAVE_STRDUP
255 #endif
256
257                                         opt_index++;
258                                         return opts[i].value;
259                                 }
260
261                                 return OPT_ERROR;
262
263                         } else {
264                                 /* parameter and option have no space between */
265
266                                 /* FIXME: this assumption is plain wrong, hits you if there is a
267                                  * parameter with no argument starting with same letter as param with argument
268                                  * but named after that one, ouch! */
269
270                                 size_t l = strlen(opts[i].name);
271
272                                 if (strlen(option + 1) > l) {
273                                         if (memcmp(option + 1, opts[i].name, l) == 0) {
274                                                 opt_index++;
275
276 #if defined(HAVE_STRDUP)
277                                                 opt_arg = strdup(option + 1 + l);
278 #else
279 # error !HAVE_STRDUP
280 #endif
281
282                                                 return opts[i].value;
283                                         }
284                                 }
285                         }
286                 }
287         }
288
289         return OPT_ERROR;
290 }
291
292
293 /* options_xx ******************************************************************
294
295    Handle -XX: options.
296
297 *******************************************************************************/
298
299 void options_xx(const char *name)
300 {
301         char    *end;
302         int32_t  length;
303         char    *value;
304         int32_t  option;
305         char    *filename;
306         FILE    *file;
307         int32_t  i;
308
309         log_println("name: %s", name);
310
311         /* Search for a ':' in the option name and get the option name
312            length and the value of the option. */
313
314         end = strchr(name, ':');
315
316         if (end == NULL) {
317                 length = strlen(name);
318                 value  = NULL;
319         }
320         else {
321                 length = end - name;
322                 value  = end + 1;
323         }
324
325         /* search the option in the option array */
326
327         option = OPT_ERROR;
328
329         for (i = 0; options_XX[i].name != NULL; i++) {
330                 if (strncmp(options_XX[i].name, name, length) == 0) {
331                         option = options_XX[i].option;
332                         break;
333                 }
334         }
335
336         /* process the option */
337
338         switch (option) {
339         case OPT_ProfileGCMemoryUsage:
340                 if (value == NULL)
341                         opt_ProfileGCMemoryUsage = 5;
342                 else
343                         opt_ProfileGCMemoryUsage = atoi(value);
344                 break;
345
346         case OPT_ProfileMemoryUsage:
347                 if (value == NULL)
348                         opt_ProfileMemoryUsage = 5;
349                 else
350                         opt_ProfileMemoryUsage = atoi(value);
351
352 # if defined(ENABLE_STATISTICS)
353                 /* we also need statistics */
354
355                 opt_stat = true;
356 # endif
357                 break;
358
359         case OPT_ProfileMemoryUsageGNUPlot:
360                 if (value == NULL)
361                         filename = "profile.dat";
362                 else
363                         filename = value;
364
365                 file = fopen(filename, "w");
366
367                 if (file == NULL)
368                         vm_abort("options_xx: fopen failed: %s", strerror(errno));
369
370                 opt_ProfileMemoryUsageGNUPlot = file;
371                 break;
372
373         case OPT_TraceExceptions:
374                 opt_TraceExceptions = true;
375                 break;
376
377 #if defined(ENABLE_REPLACEMENT)
378         case OPT_TraceReplacement:
379                 if (value == NULL)
380                         opt_TraceReplacement = 1;
381                 else
382                         opt_TraceReplacement = atoi(value);
383                 break;
384 #endif
385
386         default:
387                 printf("Unknown option: -XX:%s\n", name);
388                 break;
389         }
390 }
391
392
393 /*
394  * These are local overrides for various environment variables in Emacs.
395  * Please do not remove this and leave it at the end of the file, where
396  * Emacs will automagically detect them.
397  * ---------------------------------------------------------------------
398  * Local variables:
399  * mode: c
400  * indent-tabs-mode: t
401  * c-basic-offset: 4
402  * tab-width: 4
403  * End:
404  */