* Fixed typo
[cacao.git] / src / vm / tables.h
1 /* src/vm/tables.h - 
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Reinhard Grafl
28
29    Changes: Christian Thalinger
30
31    $Id: tables.h 2665 2005-06-13 14:22:44Z twisti $
32
33 */
34
35
36 #ifndef _TABLES_H
37 #define _TABLES_H
38
39 #include <stdio.h>
40
41
42 /* forward typedefs ***********************************************************/
43
44 typedef struct hashtable hashtable;
45
46
47 #include "types.h"
48 #include "vm/utf8.h"
49
50
51 /* data structures for hashtables ********************************************
52
53    All utf-symbols, javastrings and classes are stored in global
54    hashtables, so every symbol exists only once. Equal symbols have
55    identical pointers.  The functions for adding hashtable elements
56    search the table for the element with the specified name/text and
57    return it on success. Otherwise a new hashtable element is created.
58
59    The hashtables use external linking for handling collisions. The
60    hashtable structure contains a pointer <ptr> to the array of
61    hashtable slots. The number of hashtable slots and therefore the
62    size of this array is specified by the element <size> of hashtable
63    structure. <entries> contains the number of all hashtable elements
64    stored in the table, including those in the external chains.  The
65    hashtable element structures (utf, literalstring, classinfo)
66    contain both a pointer to the next hashtable element as a link for
67    the external hash chain and the key of the element. The key is
68    computed from the text of the string or the classname by using up
69    to 8 characters.
70         
71    If the number of entries in the hashtable exceeds twice the size of
72    the hashtableslot-array it is supposed that the average length of
73    the external chains has reached a value beyond 2. Therefore the
74    functions for adding hashtable elements (utf_new, class_new,
75    literalstring_new) double the hashtableslot-array. In this
76    restructuring process all elements have to be inserted into the new
77    hashtable and new external chains must be built.
78
79    Example for the layout of a hashtable:
80
81 hashtable.ptr-->+-------------------+
82                 |                   |
83                          ...
84                 |                   |
85                 +-------------------+   +-------------------+   +-------------------+
86                 | hashtable element |-->| hashtable element |-->| hashtable element |-->NULL
87                 +-------------------+   +-------------------+   +-------------------+
88                 | hashtable element |
89                 +-------------------+   +-------------------+   
90                 | hashtable element |-->| hashtable element |-->NULL
91                 +-------------------+   +-------------------+   
92                 | hashtable element |-->NULL
93                 +-------------------+
94                 |                   |
95                          ...
96                 |                   |
97                 +-------------------+
98
99 */
100
101
102 /* hashtable ******************************************************************/
103
104 struct hashtable {            
105         u4     size;
106         u4     entries;                     /* number of entries in the table     */
107         void **ptr;                         /* pointer to hashtable               */
108 };
109
110
111 #define CLASS(name)     (unicode_getclasslink(unicode_new_char(name)))
112
113 extern hashtable utf_hash;     /* hashtable for utf8-symbols */
114 extern hashtable string_hash;  /* hashtable for javastrings  */
115
116
117 /* function prototypes ********************************************************/
118
119 /* creates hashtables for symboltables */
120 void tables_init(void);
121
122 /* free memory for hashtables */ 
123 void tables_close(void);
124
125 /* get javatype according to a typedescriptor */
126 u2 desc_to_type(utf *descriptor);
127
128 /* get length of a datatype */
129 u2 desc_typesize(utf *descriptor);
130
131 /* create hashtable */
132 void init_hashtable(hashtable *hash, u4 size);
133
134 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
135 void tables_lock(void);
136 void tables_unlock(void);
137 #endif
138
139 #endif /* _TABLES_H */
140
141
142 /*
143  * These are local overrides for various environment variables in Emacs.
144  * Please do not remove this and leave it at the end of the file, where
145  * Emacs will automagically detect them.
146  * ---------------------------------------------------------------------
147  * Local variables:
148  * mode: c
149  * indent-tabs-mode: t
150  * c-basic-offset: 4
151  * tab-width: 4
152  * End:
153  */