1 #ifndef _TYPECHECK_COMMON_H
2 #define _TYPECHECK_COMMON_H
10 #include "vm/jit/jit.h"
13 /****************************************************************************/
15 /****************************************************************************/
17 #ifdef TYPECHECK_DEBUG
18 #define TYPECHECK_ASSERT(cond) assert(cond)
20 #define TYPECHECK_ASSERT(cond)
23 #ifdef TYPECHECK_VERBOSE_OPT
24 extern bool opt_typecheckverbose;
25 #define DOLOG(action) do { if (opt_typecheckverbose) {action;} } while(0)
30 #ifdef TYPECHECK_VERBOSE
31 #define TYPECHECK_VERBOSE_IMPORTANT
32 #define LOGNL DOLOG(puts(""))
33 #define LOG(str) DOLOG(puts(str);)
34 #define LOG1(str,a) DOLOG(printf(str,a); LOGNL)
35 #define LOG2(str,a,b) DOLOG(printf(str,a,b); LOGNL)
36 #define LOG3(str,a,b,c) DOLOG(printf(str,a,b,c); LOGNL)
37 #define LOGIF(cond,str) DOLOG(do {if (cond) { puts(str); }} while(0))
39 #define LOGINFO(info) DOLOG(do {typeinfo_print_short(stdout,(info)); LOGNL;} while(0))
42 #define typevector_print(x,y,z)
44 #define LOGFLUSH DOLOG(fflush(stdout))
45 #define LOGSTR(str) DOLOG(printf("%s", str))
46 #define LOGSTR1(str,a) DOLOG(printf(str,a))
47 #define LOGSTR2(str,a,b) DOLOG(printf(str,a,b))
48 #define LOGSTR3(str,a,b,c) DOLOG(printf(str,a,b,c))
49 #define LOGNAME(c) DOLOG(class_classref_or_classinfo_print(c))
50 #define LOGMETHOD(str,m) DOLOG(printf("%s", str); method_println(m);)
55 #define LOG3(str,a,b,c)
56 #define LOGIF(cond,str)
61 #define LOGSTR1(str,a)
62 #define LOGSTR2(str,a,b)
63 #define LOGSTR3(str,a,b,c)
65 #define LOGMETHOD(str,m)
68 #ifdef TYPECHECK_VERBOSE_IMPORTANT
69 #define LOGimp(str) DOLOG(puts(str);LOGNL)
70 #define LOGimpSTR(str) DOLOG(puts(str))
73 #define LOGimpSTR(str)
76 #if defined(TYPECHECK_VERBOSE) || defined(TYPECHECK_VERBOSE_IMPORTANT)
78 static void typecheck_print_var(FILE *file, jitdata *jd, s4 index);
79 static void typecheck_print_vararray(FILE *file, jitdata *jd, s4 *vars, int len);
83 /****************************************************************************/
85 /****************************************************************************/
87 #ifdef TYPECHECK_DEBUG
88 /*#define TYPECHECK_STATISTICS*/
91 #ifdef TYPECHECK_STATISTICS
92 #define STAT_ITERATIONS 10
93 #define STAT_BLOCKS 10
94 #define STAT_LOCALS 16
96 static int stat_typechecked;
97 static int stat_methods_with_handlers;
98 static int stat_methods_maythrow;
99 static int stat_iterations[STAT_ITERATIONS+1];
100 static int stat_reached;
101 static int stat_copied;
102 static int stat_merged;
103 static int stat_merging_changed;
104 static int stat_blocks[STAT_BLOCKS+1];
105 static int stat_locals[STAT_LOCALS+1];
107 static int stat_ins_maythrow;
108 static int stat_ins_stack;
109 static int stat_ins_field;
110 static int stat_ins_field_unresolved;
111 static int stat_ins_field_uninitialized;
112 static int stat_ins_invoke;
113 static int stat_ins_invoke_unresolved;
114 static int stat_ins_primload;
115 static int stat_ins_aload;
116 static int stat_ins_builtin;
117 static int stat_ins_builtin_gen;
118 static int stat_ins_branch;
119 static int stat_ins_switch;
120 static int stat_ins_primitive_return;
121 static int stat_ins_areturn;
122 static int stat_ins_areturn_unresolved;
123 static int stat_ins_athrow;
124 static int stat_ins_athrow_unresolved;
125 static int stat_ins_unchecked;
126 static int stat_handlers_reached;
127 static int stat_savedstack;
129 #define TYPECHECK_MARK(var) ((var) = true)
130 #define TYPECHECK_COUNT(cnt) (cnt)++
131 #define TYPECHECK_COUNTIF(cond,cnt) do{if(cond) (cnt)++;} while(0)
132 #define TYPECHECK_COUNT_FREQ(array,val,limit) \
134 if ((val) < (limit)) (array)[val]++; \
135 else (array)[limit]++; \
140 #define TYPECHECK_COUNT(cnt)
141 #define TYPECHECK_MARK(var)
142 #define TYPECHECK_COUNTIF(cond,cnt)
143 #define TYPECHECK_COUNT_FREQ(array,val,limit)
147 /****************************************************************************/
148 /* MACROS FOR THROWING EXCEPTIONS */
149 /****************************************************************************/
151 #define TYPECHECK_VERIFYERROR_ret(m,msg,retval) \
153 exceptions_throw_verifyerror((m), (msg)); \
157 #define TYPECHECK_VERIFYERROR_main(msg) TYPECHECK_VERIFYERROR_ret(state.m,(msg),NULL)
158 #define TYPECHECK_VERIFYERROR_bool(msg) TYPECHECK_VERIFYERROR_ret(state->m,(msg),false)
161 /****************************************************************************/
162 /* VERIFIER STATE STRUCT */
163 /****************************************************************************/
165 /* verifier_state - This structure keeps the current state of the */
166 /* bytecode verifier for passing it between verifier functions. */
168 typedef struct verifier_state {
169 instruction *iptr; /* pointer to current instruction */
170 basicblock *bptr; /* pointer to current basic block */
172 methodinfo *m; /* the current method */
173 jitdata *jd; /* jitdata for current method */
174 codegendata *cd; /* codegendata for current method */
176 basicblock *basicblocks;
179 s4 numlocals; /* number of local variables */
180 s4 validlocals; /* number of Java-accessible locals */
183 typedescriptor returntype; /* return type of the current method */
186 s4 *savedinvars; /* saved invar pointer */
190 exceptiontable **handlers; /* active exception handlers */
192 bool repeat; /* if true, blocks are iterated over again */
193 bool initmethod; /* true if this is an "<init>" method */
195 #ifdef TYPECHECK_STATISTICS
196 bool stat_maythrow; /* at least one instruction may throw */
200 void typecheck_init_flags(verifier_state *state, s4 minflags);
201 void typecheck_reset_flags(verifier_state *state);
203 #endif /* _TYPECHECK_COMMON_H */
206 * These are local overrides for various environment variables in Emacs.
207 * Please do not remove this and leave it at the end of the file, where
208 * Emacs will automagically detect them.
209 * ---------------------------------------------------------------------
212 * indent-tabs-mode: t
216 * vim:noexpandtab:sw=4:ts=4: