1 #ifndef _TYPECHECK_COMMON_H
2 #define _TYPECHECK_COMMON_H
10 #include "vm/jit/jit.h"
12 /****************************************************************************/
14 /****************************************************************************/
16 #ifdef TYPECHECK_DEBUG
17 #define TYPECHECK_ASSERT(cond) assert(cond)
19 #define TYPECHECK_ASSERT(cond)
22 #ifdef TYPECHECK_VERBOSE_OPT
23 extern bool opt_typecheckverbose;
24 #define DOLOG(action) do { if (opt_typecheckverbose) {action;} } while(0)
29 #ifdef TYPECHECK_VERBOSE
30 #define TYPECHECK_VERBOSE_IMPORTANT
31 #define LOGNL DOLOG(puts(""))
32 #define LOG(str) DOLOG(puts(str);)
33 #define LOG1(str,a) DOLOG(printf(str,a); LOGNL)
34 #define LOG2(str,a,b) DOLOG(printf(str,a,b); LOGNL)
35 #define LOG3(str,a,b,c) DOLOG(printf(str,a,b,c); LOGNL)
36 #define LOGIF(cond,str) DOLOG(do {if (cond) { puts(str); }} while(0))
38 #define LOGINFO(info) DOLOG(do {typeinfo_print_short(stdout,(info)); LOGNL;} while(0))
41 #define typevector_print(x,y,z)
43 #define LOGFLUSH DOLOG(fflush(stdout))
44 #define LOGSTR(str) DOLOG(printf("%s", str))
45 #define LOGSTR1(str,a) DOLOG(printf(str,a))
46 #define LOGSTR2(str,a,b) DOLOG(printf(str,a,b))
47 #define LOGSTR3(str,a,b,c) DOLOG(printf(str,a,b,c))
48 #define LOGNAME(c) DOLOG(class_classref_or_classinfo_print(c))
49 #define LOGMETHOD(str,m) DOLOG(printf("%s", str); method_println(m);)
54 #define LOG3(str,a,b,c)
55 #define LOGIF(cond,str)
60 #define LOGSTR1(str,a)
61 #define LOGSTR2(str,a,b)
62 #define LOGSTR3(str,a,b,c)
64 #define LOGMETHOD(str,m)
67 #ifdef TYPECHECK_VERBOSE_IMPORTANT
68 #define LOGimp(str) DOLOG(puts(str);LOGNL)
69 #define LOGimpSTR(str) DOLOG(puts(str))
72 #define LOGimpSTR(str)
75 #if defined(TYPECHECK_VERBOSE) || defined(TYPECHECK_VERBOSE_IMPORTANT)
77 static void typecheck_print_var(FILE *file, jitdata *jd, s4 index);
78 static void typecheck_print_vararray(FILE *file, jitdata *jd, s4 *vars, int len);
82 /****************************************************************************/
84 /****************************************************************************/
86 #ifdef TYPECHECK_DEBUG
87 /*#define TYPECHECK_STATISTICS*/
90 #ifdef TYPECHECK_STATISTICS
91 #define STAT_ITERATIONS 10
92 #define STAT_BLOCKS 10
93 #define STAT_LOCALS 16
95 static int stat_typechecked;
96 static int stat_methods_with_handlers;
97 static int stat_methods_maythrow;
98 static int stat_iterations[STAT_ITERATIONS+1];
99 static int stat_reached;
100 static int stat_copied;
101 static int stat_merged;
102 static int stat_merging_changed;
103 static int stat_blocks[STAT_BLOCKS+1];
104 static int stat_locals[STAT_LOCALS+1];
106 static int stat_ins_maythrow;
107 static int stat_ins_stack;
108 static int stat_ins_field;
109 static int stat_ins_field_unresolved;
110 static int stat_ins_field_uninitialized;
111 static int stat_ins_invoke;
112 static int stat_ins_invoke_unresolved;
113 static int stat_ins_primload;
114 static int stat_ins_aload;
115 static int stat_ins_builtin;
116 static int stat_ins_builtin_gen;
117 static int stat_ins_branch;
118 static int stat_ins_switch;
119 static int stat_ins_primitive_return;
120 static int stat_ins_areturn;
121 static int stat_ins_areturn_unresolved;
122 static int stat_ins_athrow;
123 static int stat_ins_athrow_unresolved;
124 static int stat_ins_unchecked;
125 static int stat_handlers_reached;
126 static int stat_savedstack;
128 #define TYPECHECK_MARK(var) ((var) = true)
129 #define TYPECHECK_COUNT(cnt) (cnt)++
130 #define TYPECHECK_COUNTIF(cond,cnt) do{if(cond) (cnt)++;} while(0)
131 #define TYPECHECK_COUNT_FREQ(array,val,limit) \
133 if ((val) < (limit)) (array)[val]++; \
134 else (array)[limit]++; \
139 #define TYPECHECK_COUNT(cnt)
140 #define TYPECHECK_MARK(var)
141 #define TYPECHECK_COUNTIF(cond,cnt)
142 #define TYPECHECK_COUNT_FREQ(array,val,limit)
146 /****************************************************************************/
147 /* MACROS FOR THROWING EXCEPTIONS */
148 /****************************************************************************/
150 #define TYPECHECK_VERIFYERROR_ret(m,msg,retval) \
152 exceptions_throw_verifyerror((m), (msg)); \
156 #define TYPECHECK_VERIFYERROR_main(msg) TYPECHECK_VERIFYERROR_ret(state.m,(msg),NULL)
157 #define TYPECHECK_VERIFYERROR_bool(msg) TYPECHECK_VERIFYERROR_ret(state->m,(msg),false)
160 /****************************************************************************/
161 /* VERIFIER STATE STRUCT */
162 /****************************************************************************/
164 /* verifier_state - This structure keeps the current state of the */
165 /* bytecode verifier for passing it between verifier functions. */
167 typedef struct verifier_state {
168 instruction *iptr; /* pointer to current instruction */
169 basicblock *bptr; /* pointer to current basic block */
171 methodinfo *m; /* the current method */
172 jitdata *jd; /* jitdata for current method */
173 codegendata *cd; /* codegendata for current method */
175 basicblock *basicblocks;
178 s4 numlocals; /* number of local variables */
179 s4 validlocals; /* number of Java-accessible locals */
182 typedescriptor returntype; /* return type of the current method */
185 s4 *savedinvars; /* saved invar pointer */
189 exceptiontable **handlers; /* active exception handlers */
191 bool repeat; /* if true, blocks are iterated over again */
192 bool initmethod; /* true if this is an "<init>" method */
194 #ifdef TYPECHECK_STATISTICS
195 bool stat_maythrow; /* at least one instruction may throw */
199 void typecheck_init_flags(verifier_state *state);
200 void typecheck_reset_flags(verifier_state *state);
202 #endif /* _TYPECHECK_COMMON_H */
205 * These are local overrides for various environment variables in Emacs.
206 * Please do not remove this and leave it at the end of the file, where
207 * Emacs will automagically detect them.
208 * ---------------------------------------------------------------------
211 * indent-tabs-mode: t
215 * vim:noexpandtab:sw=4:ts=4: