1 /* src/vmcore/primitivecore.c - core functions for primitive types
3 Copyright (C) 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
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
33 #include "vm/global.h"
34 #include "vm/primitive.h"
37 #include "vmcore/class.h"
38 #include "vmcore/utf8.h"
41 /* primitivetype_table *********************************************************
43 Structure for primitive classes: contains the class for wrapping
44 the primitive type, the primitive class, the name of the class for
45 wrapping, the one character type signature and the name of the
48 CAUTION: Don't change the order of the types. This table is indexed
49 by the ARRAYTYPE_ constants (except ARRAYTYPE_OBJECT).
51 *******************************************************************************/
53 primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT] = {
54 { "int" , NULL, NULL, NULL, "java/lang/Integer", 'I', "[I", NULL },
55 { "long" , NULL, NULL, NULL, "java/lang/Long", 'J', "[J", NULL },
56 { "float" , NULL, NULL, NULL, "java/lang/Float", 'F', "[F", NULL },
57 { "double" , NULL, NULL, NULL, "java/lang/Double", 'D', "[D", NULL },
58 { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
59 { "byte" , NULL, NULL, NULL, "java/lang/Byte", 'B', "[B", NULL },
60 { "char" , NULL, NULL, NULL, "java/lang/Character", 'C', "[C", NULL },
61 { "short" , NULL, NULL, NULL, "java/lang/Short", 'S', "[S", NULL },
62 { "boolean" , NULL, NULL, NULL, "java/lang/Boolean", 'Z', "[Z", NULL },
63 { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
64 #if defined(ENABLE_JAVASE)
65 { "void" , NULL, NULL, NULL, "java/lang/Void", 'V', NULL, NULL }
67 { NULL , NULL, NULL, NULL, NULL, 0 , NULL, NULL },
72 /* primitive_init **************************************************************
74 Fill the primitive type table with the primitive-type classes,
75 array-classes and wrapper classes. This is important in the VM
78 We split this primitive-type table initialization because of
79 annotations in the bootstrap classes.
81 But we may get a problem if we have annotations in:
87 Also see: loader_preinit and linker_preinit.
89 *******************************************************************************/
91 void primitive_init(void)
99 /* Load and link primitive-type classes and array-classes. */
101 for (i = 0; i < PRIMITIVETYPE_COUNT; i++) {
102 /* Skip dummy entries. */
104 if (primitivetype_table[i].cname == NULL)
107 /* create UTF-8 name */
109 name = utf_new_char(primitivetype_table[i].cname);
111 primitivetype_table[i].name = name;
113 /* create primitive class */
115 c = class_create_classinfo(name);
117 /* Primitive type classes don't have a super class. */
121 /* set flags and mark it as primitive class */
123 c->flags = ACC_PUBLIC | ACC_FINAL | ACC_ABSTRACT | ACC_CLASS_PRIMITIVE;
125 /* prevent loader from loading primitive class */
127 c->state |= CLASS_LOADED;
129 /* INFO: don't put primitive classes into the classcache */
132 vm_abort("linker_init: linking failed");
134 /* Just to be sure. */
136 assert(c->state & CLASS_LOADED);
137 assert(c->state & CLASS_LINKED);
139 primitivetype_table[i].class_primitive = c;
141 /* Create primitive array class. */
143 if (primitivetype_table[i].arrayname != NULL) {
144 u = utf_new_char(primitivetype_table[i].arrayname);
145 ac = class_create_classinfo(u);
146 ac = load_newly_created_array(ac, NULL);
149 vm_abort("primitive_init: loading failed");
151 assert(ac->state & CLASS_LOADED);
154 vm_abort("primitive_init: linking failed");
156 /* Just to be sure. */
158 assert(ac->state & CLASS_LOADED);
159 assert(ac->state & CLASS_LINKED);
161 primitivetype_table[i].arrayclass = ac;
165 /* We use two for-loops to have the array-classes already in the
166 primitive-type table (hint: annotations in wrapper-classes). */
168 for (i = 0; i < PRIMITIVETYPE_COUNT; i++) {
169 /* Skip dummy entries. */
171 if (primitivetype_table[i].cname == NULL)
174 /* Create class for wrapping the primitive type. */
176 u = utf_new_char(primitivetype_table[i].wrapname);
177 c = load_class_bootstrap(u);
180 vm_abort("primitive_init: loading failed");
183 vm_abort("primitive_init: linking failed");
185 /* Just to be sure. */
187 assert(c->state & CLASS_LOADED);
188 assert(c->state & CLASS_LINKED);
190 primitivetype_table[i].class_wrap = c;
195 /* primitive_postinit **********************************************************
197 Finish the primitive-type table initialization. In this step we
198 set the vftbl of the primitive-type classes.
200 This is necessary because java/lang/Class is loaded and linked
201 after the primitive types have been linked.
203 We have to do that in an extra function, as the primitive types are
204 not stored in the classcache.
206 *******************************************************************************/
208 void primitive_postinit(void)
213 assert(class_java_lang_Class);
214 assert(class_java_lang_Class->vftbl);
216 for (i = 0; i < PRIMITIVETYPE_COUNT; i++) {
217 /* Skip dummy entries. */
219 if (primitivetype_table[i].cname == NULL)
222 c = primitivetype_table[i].class_primitive;
224 c->object.header.vftbl = class_java_lang_Class->vftbl;
230 * These are local overrides for various environment variables in Emacs.
231 * Please do not remove this and leave it at the end of the file, where
232 * Emacs will automagically detect them.
233 * ---------------------------------------------------------------------
236 * indent-tabs-mode: t
240 * vim:noexpandtab:sw=4:ts=4: