* src/vm/jit/x86_64/asmpart.S (asm_abstractmethoderror): Keep stack aligned.
[cacao.git] / src / vm / suck.hpp
1 /* src/vm/suck.hpp - functions to read LE ordered types from a buffer
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
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.
12
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.
17
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
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _SUCK_HPP
27 #define _SUCK_HPP
28
29 #include "config.h"
30
31 #ifdef __cplusplus
32 #include <list>
33 #endif
34
35 #include "vm/types.h"
36
37 #include "threads/mutex.hpp"
38
39 #include "toolbox/hashtable.h"
40
41 #include "vm/class.hpp"
42 #include "vm/global.h"
43 #include "vm/loader.hpp"
44
45
46 /* list_classpath_entry *******************************************************/
47
48 enum {
49         CLASSPATH_PATH,
50         CLASSPATH_ARCHIVE
51 };
52
53 typedef struct list_classpath_entry {
54 #if defined(ENABLE_THREADS)
55         Mutex             *mutex;               /* mutex locking on zip/jar files */
56 #endif
57         s4                 type;
58         char              *path;
59         s4                 pathlen;
60 #if defined(ENABLE_ZLIB)
61         hashtable         *htclasses;
62 #endif
63 } list_classpath_entry;
64
65
66 #ifdef __cplusplus
67
68 /**
69  * Classpath entries list.
70  */
71 class SuckClasspath : protected std::list<list_classpath_entry*> {
72 public:
73         void add(char *classpath);
74         void add_from_property(const char *key);
75
76         // make iterator of std::list visible
77         using std::list<list_classpath_entry*>::iterator;
78
79         // make functions of std::list visible
80         using std::list<list_classpath_entry*>::begin;
81         using std::list<list_classpath_entry*>::end;
82 };
83
84 #endif
85
86 /* macros to read LE and BE types from a buffer ********************************
87
88    BE macros are for Java class file loading.
89    LE macros are for ZIP file loading.
90
91 *******************************************************************************/
92
93 /* LE macros (for ZIP files ) *************************************************/
94
95 #if defined(__I386__) || defined(__X86_64__)
96
97 /* we can optimize the LE access on little endian machines without alignment */
98
99 #define SUCK_LE_U1(p)    *((u1 *) (p))
100 #define SUCK_LE_U2(p)    *((u2 *) (p))
101 #define SUCK_LE_U4(p)    *((u4 *) (p))
102 #define SUCK_LE_U8(p)    *((u8 *) (p))
103
104 #else /* defined(__I386__) || defined(__X86_64__) */
105
106 #define SUCK_LE_U1(p) \
107       ((u1) (p)[0])
108
109 #define SUCK_LE_U2(p) \
110     ((((u2) (p)[1]) << 8) + \
111       ((u2) (p)[0]))
112
113 #define SUCK_LE_U4(p) \
114     ((((u4) (p)[3]) << 24) + \
115      (((u4) (p)[2]) << 16) + \
116      (((u4) (p)[1]) << 8) + \
117       ((u4) (p)[0]))
118
119 #define SUCK_LE_U8(p) \
120     ((((u8) (p)[7]) << 56) + \
121      (((u8) (p)[6]) << 48) + \
122      (((u8) (p)[5]) << 40) + \
123      (((u8) (p)[4]) << 32) + \
124      (((u8) (p)[3]) << 24) + \
125      (((u8) (p)[2]) << 16) + \
126      (((u8) (p)[1]) << 8) + \
127       ((u8) (p)[0]))
128
129 #endif /* defined(__I386__) || defined(__X86_64__) */
130
131
132 /* BE macros (for Java class files ) ******************************************/
133
134 #define SUCK_BE_U1(p) \
135       ((u1) (p)[0])
136
137 #define SUCK_BE_U2(p) \
138     ((((u2) (p)[0]) << 8) + \
139       ((u2) (p)[1]))
140
141 #define SUCK_BE_U4(p) \
142     ((((u4) (p)[0]) << 24) + \
143      (((u4) (p)[1]) << 16) + \
144      (((u4) (p)[2]) << 8) + \
145       ((u4) (p)[3]))
146
147 #define SUCK_BE_U8(p) \
148     ((((u8) (p)[0]) << 56) + \
149      (((u8) (p)[1]) << 48) + \
150      (((u8) (p)[2]) << 40) + \
151      (((u8) (p)[3]) << 32) + \
152      (((u8) (p)[4]) << 24) + \
153      (((u8) (p)[5]) << 16) + \
154      (((u8) (p)[6]) << 8) + \
155       ((u8) (p)[7]))
156
157
158 #define SUCK_BE_S1(p)    (s1) SUCK_BE_U1(p)
159 #define SUCK_BE_S2(p)    (s2) SUCK_BE_U2(p)
160 #define SUCK_BE_S4(p)    (s4) SUCK_BE_U4(p)
161 #define SUCK_BE_S8(p)    (s8) SUCK_BE_U8(p)
162
163
164 /* signed suck defines ********************************************************/
165
166 #define suck_s1(a)    (s1) suck_u1((a))
167 #define suck_s2(a)    (s2) suck_u2((a))
168 #define suck_s4(a)    (s4) suck_u4((a))
169 #define suck_s8(a)    (s8) suck_u8((a))
170
171
172 /* function prototypes ********************************************************/
173
174 #ifdef __cplusplus
175 extern "C" {
176 #endif
177
178 bool suck_check_classbuffer_size(classbuffer *cb, s4 len);
179
180 u1 suck_u1(classbuffer *cb);
181 u2 suck_u2(classbuffer *cb);
182 u4 suck_u4(classbuffer *cb);
183 u8 suck_u8(classbuffer *cb);
184
185 float suck_float(classbuffer *cb);
186 double suck_double(classbuffer *cb);
187
188 void suck_nbytes(u1 *buffer, classbuffer *cb, s4 len);
189 void suck_skip_nbytes(classbuffer *cb, s4 len);
190
191 classbuffer *suck_start(classinfo *c);
192
193 void suck_stop(classbuffer *cb);
194
195 #ifdef __cplusplus
196 }
197 #endif
198
199 #endif // _SUCK_HPP
200
201
202 /*
203  * These are local overrides for various environment variables in Emacs.
204  * Please do not remove this and leave it at the end of the file, where
205  * Emacs will automagically detect them.
206  * ---------------------------------------------------------------------
207  * Local variables:
208  * mode: c++
209  * indent-tabs-mode: t
210  * c-basic-offset: 4
211  * tab-width: 4
212  * End:
213  * vim:noexpandtab:sw=4:ts=4:
214  */