7 #include <vm/jit/show.h>
8 #include <typecheck-common.h>
10 /****************************************************************************/
12 /****************************************************************************/
14 #ifdef TYPECHECK_VERBOSE_OPT
15 bool opt_typecheckverbose = false;
18 #if defined(TYPECHECK_VERBOSE) || defined(TYPECHECK_VERBOSE_IMPORTANT)
20 void typecheck_print_var(FILE *file, jitdata *jd, s4 index)
24 assert(index >= 0 && index < jd->varcount);
26 typeinfo_print_type(file, var->type, &(var->typeinfo));
29 void typecheck_print_vararray(FILE *file, jitdata *jd, s4 *vars, int len)
33 for (i=0; i<len; ++i) {
36 typecheck_print_var(file, jd, *vars++);
40 #endif /* defined(TYPECHECK_VERBOSE) || defined(TYPECHECK_VERBOSE_IMPORTANT) */
43 /****************************************************************************/
45 /****************************************************************************/
47 #if defined(TYPECHECK_STATISTICS)
48 int stat_typechecked = 0;
49 int stat_methods_with_handlers = 0;
50 int stat_methods_maythrow = 0;
51 int stat_iterations[STAT_ITERATIONS+1] = { 0 };
55 int stat_merging_changed = 0;
56 int stat_blocks[STAT_BLOCKS+1] = { 0 };
57 int stat_locals[STAT_LOCALS+1] = { 0 };
59 int stat_ins_maythrow = 0;
60 int stat_ins_stack = 0;
61 int stat_ins_field = 0;
62 int stat_ins_field_unresolved = 0;
63 int stat_ins_field_uninitialized = 0;
64 int stat_ins_invoke = 0;
65 int stat_ins_invoke_unresolved = 0;
66 int stat_ins_primload = 0;
67 int stat_ins_aload = 0;
68 int stat_ins_builtin = 0;
69 int stat_ins_builtin_gen = 0;
70 int stat_ins_branch = 0;
71 int stat_ins_switch = 0;
72 int stat_ins_primitive_return = 0;
73 int stat_ins_areturn = 0;
74 int stat_ins_areturn_unresolved = 0;
75 int stat_ins_athrow = 0;
76 int stat_ins_athrow_unresolved = 0;
77 int stat_ins_unchecked = 0;
78 int stat_handlers_reached = 0;
79 int stat_savedstack = 0;
81 static void print_freq(FILE *file,int *array,int limit)
84 for (i=0; i<limit; ++i)
85 fprintf(file," %3d: %8d\n",i,array[i]);
86 fprintf(file," >=%3d: %8d\n",limit,array[limit]);
89 void typecheck_print_statistics(FILE *file) {
90 fprintf(file,"typechecked methods: %8d\n",stat_typechecked);
91 fprintf(file," with handler(s): %8d\n",stat_methods_with_handlers);
92 fprintf(file," with throw(s) : %8d\n",stat_methods_maythrow);
93 fprintf(file,"reached blocks : %8d\n",stat_reached);
94 fprintf(file,"copied states : %8d\n",stat_copied);
95 fprintf(file,"merged states : %8d\n",stat_merged);
96 fprintf(file,"merging changed : %8d\n",stat_merging_changed);
97 fprintf(file,"handlers reached : %8d\n",stat_handlers_reached);
98 fprintf(file,"saved stack (times): %8d\n",stat_savedstack);
99 fprintf(file,"instructions : %8d\n",stat_ins);
100 fprintf(file," stack : %8d\n",stat_ins_stack);
101 fprintf(file," field access : %8d\n",stat_ins_field);
102 fprintf(file," (unresolved) : %8d\n",stat_ins_field_unresolved);
103 fprintf(file," (uninit.) : %8d\n",stat_ins_field_uninitialized);
104 fprintf(file," invocations : %8d\n",stat_ins_invoke);
105 fprintf(file," (unresolved) : %8d\n",stat_ins_invoke_unresolved);
106 fprintf(file," load primitive : (currently not counted) %8d\n",stat_ins_primload);
107 fprintf(file," load address : %8d\n",stat_ins_aload);
108 fprintf(file," builtins : %8d\n",stat_ins_builtin);
109 fprintf(file," generic : %8d\n",stat_ins_builtin_gen);
110 fprintf(file," branches : %8d\n",stat_ins_branch);
111 fprintf(file," switches : %8d\n",stat_ins_switch);
112 fprintf(file," prim. return : %8d\n",stat_ins_primitive_return);
113 fprintf(file," areturn : %8d\n",stat_ins_areturn);
114 fprintf(file," (unresolved) : %8d\n",stat_ins_areturn_unresolved);
115 fprintf(file," athrow : %8d\n",stat_ins_athrow);
116 fprintf(file," (unresolved) : %8d\n",stat_ins_athrow_unresolved);
117 fprintf(file," unchecked : %8d\n",stat_ins_unchecked);
118 fprintf(file," maythrow : %8d\n",stat_ins_maythrow);
119 fprintf(file,"iterations used:\n");
120 print_freq(file,stat_iterations,STAT_ITERATIONS);
121 fprintf(file,"basic blocks per method / 10:\n");
122 print_freq(file,stat_blocks,STAT_BLOCKS);
123 fprintf(file,"locals:\n");
124 print_freq(file,stat_locals,STAT_LOCALS);
126 #endif /* defined(TYPECHECK_STATISTICS) */
129 /* typecheck_init_flags ********************************************************
131 Initialize the basic block flags for the following CFG traversal.
134 state............the current state of the verifier
135 minflags.........minimum flags value of blocks that should be
138 *******************************************************************************/
140 void typecheck_init_flags(verifier_state *state, s4 minflags)
145 /* set all BBFINISHED blocks to BBTYPECHECK_UNDEF. */
147 i = state->basicblockcount;
148 for (block = state->basicblocks; block; block = block->next) {
150 #ifdef TYPECHECK_DEBUG
151 /* check for invalid flags */
152 if (block->flags != BBFINISHED && block->flags != BBDELETED && block->flags != BBUNDEF)
154 LOGSTR1("block flags: %d\n",block->flags); LOGFLUSH;
155 TYPECHECK_ASSERT(false);
159 if (block->flags >= minflags) {
160 block->flags = BBTYPECHECK_UNDEF;
164 /* the first block is always reached */
166 if (state->basicblockcount && state->basicblocks[0].flags == BBTYPECHECK_UNDEF)
167 state->basicblocks[0].flags = BBTYPECHECK_REACHED;
171 /* typecheck_reset_flags *******************************************************
173 Reset the flags of basic blocks we have not reached.
176 state............the current state of the verifier
178 *******************************************************************************/
180 void typecheck_reset_flags(verifier_state *state)
184 /* check for invalid flags at exit */
186 #ifdef TYPECHECK_DEBUG
187 for (block = state->basicblocks; block; block = block->next) {
188 if (block->flags != BBDELETED
189 && block->flags != BBUNDEF
190 && block->flags != BBFINISHED
191 && block->flags != BBTYPECHECK_UNDEF) /* typecheck may never reach
192 * some exception handlers,
195 LOG2("block L%03d has invalid flags after typecheck: %d",
196 block->nr,block->flags);
197 TYPECHECK_ASSERT(false);
202 /* Delete blocks we never reached */
204 for (block = state->basicblocks; block; block = block->next) {
205 if (block->flags == BBTYPECHECK_UNDEF)
206 block->flags = BBDELETED;
212 * These are local overrides for various environment variables in Emacs.
213 * Please do not remove this and leave it at the end of the file, where
214 * Emacs will automagically detect them.
215 * ---------------------------------------------------------------------
218 * indent-tabs-mode: t
222 * vim:noexpandtab:sw=4:ts=4: