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 4357 2006-01-22 23:33:38Z twisti $
43 #include "cacaoh/headers.h"
45 #include "mm/memory.h"
47 #if defined(USE_THREADS)
48 # if defined(NATIVE_THREADS)
49 # include "threads/native/threads.h"
51 # include "threads/green/threads.h"
55 #include "toolbox/chain.h"
56 #include "vm/classcache.h"
57 #include "vm/exceptions.h"
58 #include "vm/global.h"
59 #include "vm/loader.h"
60 #include "vm/tables.h"
63 int main(int argc, char **argv)
68 classcache_name_entry *nmen;
69 classcache_class_entry *clsen;
76 bool nativelyoverloaded;
78 u4 heapmaxsize = 4 * 1024 * 1024;
79 u4 heapstartsize = 100 * 1024;
82 /* set the bootclasspath */
84 cp = getenv("BOOTCLASSPATH");
86 bootclasspath = MNEW(char, strlen(cp) + 1);
87 strcpy(bootclasspath, cp);
90 /* initialize the garbage collector */
91 gc_init(heapmaxsize, heapstartsize);
95 suck_init(bootclasspath);
97 #if defined(USE_THREADS)
98 #if defined(NATIVE_THREADS)
104 /* initialize some cacao subsystems */
107 loader_init((u1 *) &dummy);
110 /*********************** Load JAVA classes **************************/
112 nativemethod_chain = chain_new();
113 ident_chain = chain_new();
115 /* load all classes from bootclasspath */
117 loader_load_all_classes();
119 /* link all classes */
121 for (slot = 0; slot < classcache_hash.size; slot++) {
122 nmen = (classcache_name_entry *) classcache_hash.ptr[slot];
124 for (; nmen; nmen = nmen->hashlink) {
125 /* iterate over all class entries */
127 for (clsen = nmen->classes; clsen; clsen = clsen->next) {
133 /* exceptions are catched with new_exception call */
136 (void) link_class(c);
138 /* find overloaded methods */
140 for (i = 0; i < c->methodscount; i++) {
141 m = &(c->methods[i]);
143 if (!(m->flags & ACC_NATIVE))
146 if (!m->nativelyoverloaded) {
147 nativelyoverloaded = false;
149 for (j = i + 1; j < c->methodscount; j++) {
150 m2 = &(c->methods[j]);
152 if (!(m2->flags & ACC_NATIVE))
155 if (m->name == m2->name) {
156 m2->nativelyoverloaded = true;
157 nativelyoverloaded = true;
161 m->nativelyoverloaded = nativelyoverloaded;
165 for (j = 0; j < c->methodscount; j++) {
166 m = &(c->methods[j]);
168 if (m->flags & ACC_NATIVE) {
169 chain_addlast(nativemethod_chain, m);
176 /* create table of native-methods */
180 fprintf(file, "/* This file is machine generated, don't edit it! */\n\n");
182 m = chain_first(nativemethod_chain);
186 m = chain_next(nativemethod_chain);
189 fprintf(file, "static nativeref nativetable[] = {\n");
191 m = chain_first(nativemethod_chain);
194 fprintf(file, " { \"");
196 print_classname(m->class);
197 fprintf(file, "\",\n \"");
198 utf_fprint(file, m->name);
199 fprintf(file, "\",\n \"");
200 utf_fprint(file, m->descriptor);
201 fprintf(file, "\",\n ");
203 if (m->flags & ACC_STATIC)
204 fprintf(file, "true");
206 fprintf(file, "false");
208 fprintf(file, ",\n ");
209 fprintf(file, "(functionptr) Java_");
210 printID(m->class->name);
214 if (m->nativelyoverloaded)
215 printOverloadPart(m->descriptor);
217 fprintf(file,"\n },\n");
219 m = chain_next(nativemethod_chain);
222 chain_free(nativemethod_chain);
223 chain_free(ident_chain);
225 fprintf(file, "};\n");
229 /* release all resources */
233 /* everything is ok */
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 * ---------------------------------------------------------------------
246 * indent-tabs-mode: t