1 /* src/vmcore/primitivecore.c - core functions for primitive types
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 #include "vm/global.h"
32 #include "vm/primitive.hpp"
35 #include "vmcore/class.h"
36 #include "vmcore/options.h"
37 #include "vmcore/utf8.h"
40 /* primitivetype_table *********************************************************
42 Structure for primitive classes: contains the class for wrapping
43 the primitive type, the primitive class, the name of the class for
44 wrapping, the one character type signature and the name of the
47 CAUTION: Don't change the order of the types. This table is indexed
48 by the ARRAYTYPE_ constants (except ARRAYTYPE_OBJECT).
50 *******************************************************************************/
52 primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT] = {
53 { "int" , NULL, NULL, NULL, "java/lang/Integer", 'I', "[I", NULL },
54 { "long" , NULL, NULL, NULL, "java/lang/Long", 'J', "[J", NULL },
55 { "float" , NULL, NULL, NULL, "java/lang/Float", 'F', "[F", NULL },
56 { "double" , NULL, NULL, NULL, "java/lang/Double", 'D', "[D", NULL },
57 { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
58 { "byte" , NULL, NULL, NULL, "java/lang/Byte", 'B', "[B", NULL },
59 { "char" , NULL, NULL, NULL, "java/lang/Character", 'C', "[C", NULL },
60 { "short" , NULL, NULL, NULL, "java/lang/Short", 'S', "[S", NULL },
61 { "boolean" , NULL, NULL, NULL, "java/lang/Boolean", 'Z', "[Z", NULL },
62 { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
63 #if defined(ENABLE_JAVASE)
64 { "void" , NULL, NULL, NULL, "java/lang/Void", 'V', NULL, NULL }
66 { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
71 /* primitive_init **************************************************************
73 Fill the primitive type table with the primitive-type classes,
74 array-classes and wrapper classes. This is important in the VM
77 We split this primitive-type table initialization because of
78 annotations in the bootstrap classes.
80 But we may get a problem if we have annotations in:
86 Also see: loader_preinit and linker_preinit.
88 *******************************************************************************/
90 void primitive_init(void)
98 TRACESUBSYSTEMINITIALIZATION("primitive_init");
100 /* Load and link primitive-type classes and array-classes. */
102 for (i = 0; i < PRIMITIVETYPE_COUNT; i++) {
103 /* Skip dummy entries. */
105 if (primitivetype_table[i].cname == NULL)
108 /* create UTF-8 name */
110 name = utf_new_char(primitivetype_table[i].cname);
112 primitivetype_table[i].name = name;
114 /* create primitive class */
116 c = class_create_classinfo(name);
118 /* Primitive type classes don't have a super class. */
122 /* set flags and mark it as primitive class */
124 c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT | ACC_CLASS_PRIMITIVE;
126 /* prevent loader from loading primitive class */
128 c->state |= CLASS_LOADED;
130 /* INFO: don't put primitive classes into the classcache */
133 vm_abort("linker_init: linking failed");
135 /* Just to be sure. */
137 assert(c->state & CLASS_LOADED);
138 assert(c->state & CLASS_LINKED);
140 primitivetype_table[i].class_primitive = c;
142 /* Create primitive array class. */
144 if (primitivetype_table[i].arrayname != NULL) {
145 u = utf_new_char(primitivetype_table[i].arrayname);
146 ac = class_create_classinfo(u);
147 ac = load_newly_created_array(ac, NULL);
150 vm_abort("primitive_init: loading failed");
152 assert(ac->state & CLASS_LOADED);
155 vm_abort("primitive_init: linking failed");
157 /* Just to be sure. */
159 assert(ac->state & CLASS_LOADED);
160 assert(ac->state & CLASS_LINKED);
162 primitivetype_table[i].arrayclass = ac;
166 /* We use two for-loops to have the array-classes already in the
167 primitive-type table (hint: annotations in wrapper-classes). */
169 for (i = 0; i < PRIMITIVETYPE_COUNT; i++) {
170 /* Skip dummy entries. */
172 if (primitivetype_table[i].cname == NULL)
175 /* Create class for wrapping the primitive type. */
177 u = utf_new_char(primitivetype_table[i].wrapname);
178 c = load_class_bootstrap(u);
181 vm_abort("primitive_init: loading failed");
184 vm_abort("primitive_init: linking failed");
186 /* Just to be sure. */
188 assert(c->state & CLASS_LOADED);
189 assert(c->state & CLASS_LINKED);
191 primitivetype_table[i].class_wrap = c;
196 /* primitive_postinit **********************************************************
198 Finish the primitive-type table initialization. In this step we
199 set the vftbl of the primitive-type classes.
201 This is necessary because java/lang/Class is loaded and linked
202 after the primitive types have been linked.
204 We have to do that in an extra function, as the primitive types are
205 not stored in the classcache.
207 *******************************************************************************/
209 void primitive_postinit(void)
214 TRACESUBSYSTEMINITIALIZATION("primitive_postinit");
216 assert(class_java_lang_Class);
217 assert(class_java_lang_Class->vftbl);
219 for (i = 0; i < PRIMITIVETYPE_COUNT; i++) {
220 /* Skip dummy entries. */
222 if (primitivetype_table[i].cname == NULL)
225 c = primitivetype_table[i].class_primitive;
227 c->object.header.vftbl = class_java_lang_Class->vftbl;
233 * These are local overrides for various environment variables in Emacs.
234 * Please do not remove this and leave it at the end of the file, where
235 * Emacs will automagically detect them.
236 * ---------------------------------------------------------------------
239 * indent-tabs-mode: t
243 * vim:noexpandtab:sw=4:ts=4: