* src/vm/options.h, src/vm/options.c (getloadingtime): Renamed to
[cacao.git] / src / vm / options.c
1 /* src/vm/options.c - contains global options
2
3    Copyright (C) 1996-2005, 2006 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    Contact: cacao@cacaojvm.org
26
27    Authors: Christian Thalinger
28
29    Changes:
30
31    $Id: options.c 4834 2006-04-25 12:25:43Z edwin $
32
33 */
34
35
36 #include "config.h"
37
38 #include <string.h>
39
40 #include "vm/types.h"
41
42 #include "mm/memory.h"
43 #include "native/jni.h"
44 #include "vm/options.h"
45
46
47 /* command line option ********************************************************/
48
49 s4    opt_index = 0;            /* index of processed arguments               */
50 char *opt_arg;                  /* this one exports the option argument       */
51
52 bool opt_jar = false;
53
54 #if defined(ENABLE_JIT)
55 bool opt_jit = true;            /* JIT mode execution (default)               */
56 bool opt_intrp = false;         /* interpreter mode execution                 */
57 #else
58 bool opt_jit = false;           /* JIT mode execution                         */
59 bool opt_intrp = true;          /* interpreter mode execution (default)       */
60 #endif
61
62 bool opt_run = true;
63
64 s4   opt_stacksize = 0;         /* thread stack size                          */
65
66 bool opt_verbose = false;
67 bool compileall = false;
68
69 bool loadverbose = false;
70 bool linkverbose = false;
71 bool initverbose = false;
72
73 bool opt_verboseclass     = false;
74 bool opt_verbosegc        = false;
75 bool opt_verbosejni       = false;
76 bool opt_verbosecall      = false;      /* trace all method invocation        */
77 bool opt_verboseexception = false;
78
79 bool showmethods = false;
80 bool showconstantpool = false;
81 bool showutf = false;
82
83 char *opt_method = NULL;
84 char *opt_signature = NULL;
85
86 bool compileverbose =  false;           /* trace compiler actions             */
87 bool showstack = false;
88 bool opt_showdisassemble = false;       /* generate disassembler listing      */
89 bool opt_showddatasegment = false;      /* generate data segment listing      */
90 bool opt_showintermediate = false;      /* generate intermediate code listing */
91 bool opt_showexceptionstubs = false;
92 bool opt_shownativestub = false;
93
94 bool useinlining = false;      /* use method inlining                        */
95 bool inlinevirtuals = false;   /* inline unique virtual methods              */
96 bool inlineexceptions = false; /* inline methods, that contain excptions     */
97 bool inlineparamopt = false;   /* optimize parameter passing to inlined methods */
98 bool inlineoutsiders = false;  /* inline methods, that are not member of the invoker's class */
99
100 bool checkbounds = true;       /* check array bounds                         */
101 bool checknull = true;         /* check null pointers                        */
102 bool opt_noieee = false;       /* don't implement ieee compliant floats      */
103 bool checksync = true;         /* do synchronization                         */
104 #if defined(ENABLE_LOOP)
105 bool opt_loops = false;        /* optimize array accesses in loops           */
106 #endif
107
108 bool makeinitializations = true;
109
110 #if defined(ENABLE_STATISTICS)
111 bool opt_stat    = false;
112 bool opt_getloadingtime = false;   /* to measure the runtime                 */
113 bool opt_getcompilingtime = false; /* compute compile time                   */
114 #endif
115 #if defined(ENABLE_VERIFIER)
116 bool opt_verify  = true;       /* true if classfiles should be verified      */
117 #endif
118 bool opt_eager   = false;
119
120 bool opt_prof    = false;
121 bool opt_prof_bb = false;
122
123
124 /* optimization options *******************************************************/
125
126 #if defined(ENABLE_IFCONV)
127 bool opt_ifconv = false;
128 #endif
129
130 #if defined(ENABLE_LSRA)
131 bool opt_lsra = false;
132 #endif
133
134
135 /* interpreter options ********************************************************/
136
137 #if defined(ENABLE_INTRP)
138 bool opt_no_dynamic = false;            /* suppress dynamic superinstructions */
139 bool opt_no_replication = false;        /* don't use replication in intrp     */
140 bool opt_no_quicksuper = false;         /* instructions for quickening cannot be
141                                                                                    part of dynamic superinstructions */
142
143 s4   opt_static_supers = 0x7fffffff;
144 bool vm_debug = false;          /* XXX this should be called `opt_trace'      */
145 #endif
146
147
148 /* options_get *****************************************************************
149
150    DOCUMENT ME!!!
151
152 *******************************************************************************/
153
154 s4 options_get(opt_struct *opts, JavaVMInitArgs *vm_args)
155 {
156         char *option;
157         s4    i;
158
159         if (opt_index >= vm_args->nOptions)
160                 return OPT_DONE;
161
162         /* get the current option */
163
164         option = vm_args->options[opt_index].optionString;
165
166         if ((option == NULL) || (option[0] != '-'))
167                 return OPT_DONE;
168
169         for (i = 0; opts[i].name; i++) {
170                 if (!opts[i].arg) {
171                         /* boolean option found */
172
173                         if (strcmp(option + 1, opts[i].name) == 0) {
174                                 opt_index++;
175                                 return opts[i].value;
176                         }
177
178                 } else {
179                         /* parameter option found */
180
181                         /* with a space between */
182
183                         if (strcmp(option + 1, opts[i].name) == 0) {
184                                 opt_index++;
185
186                                 if (opt_index < vm_args->nOptions) {
187                                         opt_arg = strdup(vm_args->options[opt_index].optionString);
188                                         opt_index++;
189                                         return opts[i].value;
190                                 }
191
192                                 return OPT_ERROR;
193
194                         } else {
195                                 /* parameter and option have no space between */
196
197                                 size_t l = strlen(opts[i].name);
198
199                                 if (strlen(option + 1) > l) {
200                                         if (memcmp(option + 1, opts[i].name, l) == 0) {
201                                                 opt_index++;
202                                                 opt_arg = strdup(option + 1 + l);
203                                                 return opts[i].value;
204                                         }
205                                 }
206                         }
207                 }
208         }
209
210         return OPT_ERROR;
211 }
212
213
214 /* options_prepare *************************************************************
215
216    Prepare the JavaVMInitArgs.
217
218 *******************************************************************************/
219
220 JavaVMInitArgs *options_prepare(int argc, char **argv)
221 {
222         JavaVMInitArgs *vm_args;
223         s4              i;
224
225         vm_args = NEW(JavaVMInitArgs);
226
227         vm_args->version            = JNI_VERSION_1_2;
228         vm_args->nOptions           = argc - 1;
229         vm_args->options            = MNEW(JavaVMOption, argc);
230         vm_args->ignoreUnrecognized = JNI_FALSE;
231
232         for (i = 1; i < argc; i++)
233                 vm_args->options[i - 1].optionString = argv[i];
234
235         return vm_args;
236 }
237
238
239 /*
240  * These are local overrides for various environment variables in Emacs.
241  * Please do not remove this and leave it at the end of the file, where
242  * Emacs will automagically detect them.
243  * ---------------------------------------------------------------------
244  * Local variables:
245  * mode: c
246  * indent-tabs-mode: t
247  * c-basic-offset: 4
248  * tab-width: 4
249  * End:
250  */