1 /* src/native/tools/gennativetable.c - generate nativetable.h for native.c
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@cacaojvm.org
27 Authors: Christian Thalinger
31 $Id: gennativetable.c 4908 2006-05-12 16:49:50Z edwin $
45 #include "cacaoh/headers.h"
47 #include "mm/memory.h"
49 #if defined(USE_THREADS)
50 # if defined(NATIVE_THREADS)
51 # include "threads/native/threads.h"
53 # include "threads/green/threads.h"
57 #include "toolbox/chain.h"
58 #include "vm/classcache.h"
59 #include "vm/exceptions.h"
60 #include "vm/global.h"
61 #include "vm/loader.h"
62 #include "vm/options.h"
66 /* define heap sizes **********************************************************/
68 #define HEAP_MAXSIZE 4 * 1024 * 1024 /* default 4MB */
69 #define HEAP_STARTSIZE 100 * 1024 /* default 100kB */
72 /* define cacaoh options ******************************************************/
85 { "help", false, OPT_HELP },
86 { "version", false, OPT_VERSION },
87 { "verbose", false, OPT_VERBOSE },
88 { "bootclasspath", true, OPT_BOOTCLASSPATH },
93 int main(int argc, char **argv)
97 chain *nativemethod_chain;
98 classcache_name_entry *nmen;
99 classcache_class_entry *clsen;
106 bool nativelyoverloaded;
110 #if defined(DISABLE_GC)
111 nogc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
114 while ((i = get_opt(argc, argv, opts)) != OPT_DONE) {
123 case OPT_BOOTCLASSPATH:
124 bootclasspath = MNEW(char, strlen(opt_arg) + strlen("0"));
125 strcpy(bootclasspath, opt_arg);
144 /* initialize the garbage collector */
146 gc_init(HEAP_MAXSIZE, HEAP_STARTSIZE);
148 #if defined(USE_THREADS)
149 #if defined(NATIVE_THREADS)
155 /* initialize the string hashtable stuff: lock (must be done
156 _after_ threads_preinit) */
159 throw_main_exception_exit();
161 /* initialize the utf8 hashtable stuff: lock, often used utf8 strings
162 (must be done _after_ threads_preinit) */
165 throw_main_exception_exit();
167 /* initialize the classcache hashtable stuff: lock, hashtable
168 (must be done _after_ threads_preinit) */
170 if (!classcache_init())
171 throw_main_exception_exit();
173 /* initialize the loader with bootclasspath (must be done _after_
177 throw_main_exception_exit();
179 suck_add(bootclasspath);
181 /* initialize the loader subsystems (must be done _after_
184 if (!loader_init((u1 *) &dummy))
185 throw_main_exception_exit();
188 /*********************** Load JAVA classes **************************/
190 nativemethod_chain = chain_new();
191 ident_chain = chain_new();
193 /* load all classes from bootclasspath */
195 loader_load_all_classes();
197 /* link all classes */
199 for (slot = 0; slot < hashtable_classcache.size; slot++) {
200 nmen = (classcache_name_entry *) hashtable_classcache.ptr[slot];
202 for (; nmen; nmen = nmen->hashlink) {
203 /* iterate over all class entries */
205 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
211 /* find overloaded methods */
213 for (i = 0; i < c->methodscount; i++) {
214 m = &(c->methods[i]);
216 if (!(m->flags & ACC_NATIVE))
219 /* ATTENTION: We use the methodinfo's isleafmethod
220 variable as nativelyoverloaded, so we can save
221 some space during runtime. */
223 if (!m->isleafmethod) {
224 nativelyoverloaded = false;
226 for (j = i + 1; j < c->methodscount; j++) {
227 m2 = &(c->methods[j]);
229 if (!(m2->flags & ACC_NATIVE))
232 if (m->name == m2->name) {
233 m2->isleafmethod = true;
234 nativelyoverloaded = true;
238 m->isleafmethod = nativelyoverloaded;
242 for (j = 0; j < c->methodscount; j++) {
243 m = &(c->methods[j]);
245 if (m->flags & ACC_NATIVE) {
246 chain_addlast(nativemethod_chain, m);
253 /* create table of native-methods */
257 fprintf(file, "/* This file is machine generated, don't edit it! */\n\n");
259 m = chain_first(nativemethod_chain);
263 m = chain_next(nativemethod_chain);
266 fprintf(file, "static nativeref nativetable[] = {\n");
268 m = chain_first(nativemethod_chain);
271 fprintf(file, " { \"");
273 print_classname(m->class);
274 fprintf(file, "\",\n \"");
275 utf_fprint_printable_ascii(file, m->name);
276 fprintf(file, "\",\n \"");
277 utf_fprint_printable_ascii(file, m->descriptor);
278 fprintf(file, "\",\n ");
280 if (m->flags & ACC_STATIC)
281 fprintf(file, "true");
283 fprintf(file, "false");
285 fprintf(file, ",\n ");
286 fprintf(file, "(functionptr) Java_");
287 printID(m->class->name);
291 /* ATTENTION: We use the methodinfo's isleafmethod variable as
292 nativelyoverloaded, so we can save some space during
296 printOverloadPart(m->descriptor);
298 fprintf(file,"\n },\n");
300 m = chain_next(nativemethod_chain);
303 chain_free(nativemethod_chain);
305 fprintf(file, "};\n");
309 /* release all resources */
313 /* everything is ok */
320 * These are local overrides for various environment variables in Emacs.
321 * Please do not remove this and leave it at the end of the file, where
322 * Emacs will automagically detect them.
323 * ---------------------------------------------------------------------
326 * indent-tabs-mode: t