Tue, 09 Oct 2012 10:09:34 -0700
7197424: update copyright year to match last edit in jdk8 hotspot repository
Summary: Update copyright year to 2012 for relevant files
Reviewed-by: dholmes, coleenp
duke@435 | 1 | /* |
mikael@4153 | 2 | * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "c1/c1_CFGPrinter.hpp" |
stefank@2314 | 27 | #include "c1/c1_IR.hpp" |
stefank@2314 | 28 | #include "c1/c1_InstructionPrinter.hpp" |
stefank@2314 | 29 | #include "c1/c1_LIR.hpp" |
stefank@2314 | 30 | #include "c1/c1_LinearScan.hpp" |
stefank@2314 | 31 | #include "c1/c1_ValueStack.hpp" |
duke@435 | 32 | |
duke@435 | 33 | #ifndef PRODUCT |
duke@435 | 34 | |
duke@435 | 35 | |
zgu@3900 | 36 | class CFGPrinterOutput : public CHeapObj<mtCompiler> { |
duke@435 | 37 | private: |
duke@435 | 38 | outputStream* _output; |
duke@435 | 39 | |
duke@435 | 40 | Compilation* _compilation; |
duke@435 | 41 | bool _do_print_HIR; |
duke@435 | 42 | bool _do_print_LIR; |
duke@435 | 43 | |
duke@435 | 44 | class PrintBlockClosure: public BlockClosure { |
duke@435 | 45 | void block_do(BlockBegin* block) { if (block != NULL) CFGPrinter::output()->print_block(block); } |
duke@435 | 46 | }; |
duke@435 | 47 | |
duke@435 | 48 | |
duke@435 | 49 | outputStream* output() { assert(_output != NULL, ""); return _output; } |
duke@435 | 50 | |
duke@435 | 51 | void inc_indent(); |
duke@435 | 52 | void dec_indent(); |
duke@435 | 53 | void print(const char* format, ...); |
duke@435 | 54 | void print_begin(const char* tag); |
duke@435 | 55 | void print_end(const char* tag); |
duke@435 | 56 | |
duke@435 | 57 | char* method_name(ciMethod* method, bool short_name = false); |
duke@435 | 58 | |
duke@435 | 59 | public: |
duke@435 | 60 | CFGPrinterOutput(); |
duke@435 | 61 | |
duke@435 | 62 | void set_compilation(Compilation* compilation) { _compilation = compilation; } |
duke@435 | 63 | void set_print_flags(bool do_print_HIR, bool do_print_LIR) { _do_print_HIR = do_print_HIR; _do_print_LIR = do_print_LIR; } |
duke@435 | 64 | |
duke@435 | 65 | void print_compilation(); |
duke@435 | 66 | void print_intervals(IntervalList* intervals, const char* name); |
duke@435 | 67 | |
duke@435 | 68 | void print_state(BlockBegin* block); |
duke@435 | 69 | void print_operand(Value instr); |
duke@435 | 70 | void print_HIR(Value instr); |
duke@435 | 71 | void print_HIR(BlockBegin* block); |
duke@435 | 72 | void print_LIR(BlockBegin* block); |
duke@435 | 73 | void print_block(BlockBegin* block); |
duke@435 | 74 | void print_cfg(BlockList* blocks, const char* name); |
duke@435 | 75 | void print_cfg(IR* blocks, const char* name); |
duke@435 | 76 | }; |
duke@435 | 77 | |
duke@435 | 78 | CFGPrinterOutput* CFGPrinter::_output = NULL; |
duke@435 | 79 | |
duke@435 | 80 | |
duke@435 | 81 | |
duke@435 | 82 | |
duke@435 | 83 | void CFGPrinter::print_compilation(Compilation* compilation) { |
duke@435 | 84 | if (_output == NULL) { |
duke@435 | 85 | _output = new CFGPrinterOutput(); |
duke@435 | 86 | } |
duke@435 | 87 | output()->set_compilation(compilation); |
duke@435 | 88 | output()->print_compilation(); |
duke@435 | 89 | } |
duke@435 | 90 | |
duke@435 | 91 | void CFGPrinter::print_cfg(BlockList* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) { |
duke@435 | 92 | output()->set_print_flags(do_print_HIR, do_print_LIR); |
duke@435 | 93 | output()->print_cfg(blocks, name); |
duke@435 | 94 | } |
duke@435 | 95 | |
duke@435 | 96 | void CFGPrinter::print_cfg(IR* blocks, const char* name, bool do_print_HIR, bool do_print_LIR) { |
duke@435 | 97 | output()->set_print_flags(do_print_HIR, do_print_LIR); |
duke@435 | 98 | output()->print_cfg(blocks, name); |
duke@435 | 99 | } |
duke@435 | 100 | |
duke@435 | 101 | |
duke@435 | 102 | void CFGPrinter::print_intervals(IntervalList* intervals, const char* name) { |
duke@435 | 103 | output()->print_intervals(intervals, name); |
duke@435 | 104 | } |
duke@435 | 105 | |
duke@435 | 106 | |
duke@435 | 107 | |
duke@435 | 108 | CFGPrinterOutput::CFGPrinterOutput() |
zgu@3900 | 109 | : _output(new(ResourceObj::C_HEAP, mtCompiler) fileStream("output.cfg")) |
duke@435 | 110 | { |
duke@435 | 111 | } |
duke@435 | 112 | |
duke@435 | 113 | |
duke@435 | 114 | |
duke@435 | 115 | void CFGPrinterOutput::inc_indent() { |
duke@435 | 116 | output()->inc(); |
duke@435 | 117 | output()->inc(); |
duke@435 | 118 | } |
duke@435 | 119 | |
duke@435 | 120 | void CFGPrinterOutput::dec_indent() { |
duke@435 | 121 | output()->dec(); |
duke@435 | 122 | output()->dec(); |
duke@435 | 123 | } |
duke@435 | 124 | |
duke@435 | 125 | void CFGPrinterOutput::print(const char* format, ...) { |
duke@435 | 126 | output()->indent(); |
duke@435 | 127 | |
duke@435 | 128 | va_list ap; |
duke@435 | 129 | va_start(ap, format); |
duke@435 | 130 | output()->vprint_cr(format, ap); |
duke@435 | 131 | va_end(ap); |
duke@435 | 132 | } |
duke@435 | 133 | |
duke@435 | 134 | void CFGPrinterOutput::print_begin(const char* tag) { |
duke@435 | 135 | output()->indent(); |
duke@435 | 136 | output()->print_cr("begin_%s", tag); |
duke@435 | 137 | inc_indent(); |
duke@435 | 138 | } |
duke@435 | 139 | |
duke@435 | 140 | void CFGPrinterOutput::print_end(const char* tag) { |
duke@435 | 141 | dec_indent(); |
duke@435 | 142 | output()->indent(); |
duke@435 | 143 | output()->print_cr("end_%s", tag); |
duke@435 | 144 | } |
duke@435 | 145 | |
duke@435 | 146 | |
duke@435 | 147 | char* CFGPrinterOutput::method_name(ciMethod* method, bool short_name) { |
duke@435 | 148 | stringStream name; |
duke@435 | 149 | if (short_name) { |
duke@435 | 150 | method->print_short_name(&name); |
duke@435 | 151 | } else { |
duke@435 | 152 | method->print_name(&name); |
duke@435 | 153 | } |
duke@435 | 154 | return name.as_string(); |
duke@435 | 155 | |
duke@435 | 156 | } |
duke@435 | 157 | |
duke@435 | 158 | |
duke@435 | 159 | void CFGPrinterOutput::print_compilation() { |
duke@435 | 160 | print_begin("compilation"); |
duke@435 | 161 | |
duke@435 | 162 | print("name \"%s\"", method_name(_compilation->method(), true)); |
duke@435 | 163 | print("method \"%s\"", method_name(_compilation->method())); |
duke@435 | 164 | print("date "INT64_FORMAT, os::javaTimeMillis()); |
duke@435 | 165 | |
duke@435 | 166 | print_end("compilation"); |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | |
duke@435 | 170 | |
duke@435 | 171 | |
duke@435 | 172 | |
duke@435 | 173 | void CFGPrinterOutput::print_state(BlockBegin* block) { |
duke@435 | 174 | print_begin("states"); |
duke@435 | 175 | |
duke@435 | 176 | InstructionPrinter ip(true, output()); |
duke@435 | 177 | |
duke@435 | 178 | ValueStack* state = block->state(); |
duke@435 | 179 | int index; |
duke@435 | 180 | Value value; |
duke@435 | 181 | |
duke@435 | 182 | for_each_state(state) { |
duke@435 | 183 | print_begin("locals"); |
duke@435 | 184 | print("size %d", state->locals_size()); |
duke@435 | 185 | print("method \"%s\"", method_name(state->scope()->method())); |
duke@435 | 186 | |
duke@435 | 187 | for_each_local_value(state, index, value) { |
duke@435 | 188 | ip.print_phi(index, value, block); |
duke@435 | 189 | print_operand(value); |
duke@435 | 190 | output()->cr(); |
duke@435 | 191 | } |
duke@435 | 192 | print_end("locals"); |
roland@2174 | 193 | |
roland@2174 | 194 | if (state->stack_size() > 0) { |
roland@2174 | 195 | print_begin("stack"); |
roland@2174 | 196 | print("size %d", state->stack_size()); |
roland@2174 | 197 | print("method \"%s\"", method_name(state->scope()->method())); |
roland@2174 | 198 | |
roland@2174 | 199 | for_each_stack_value(state, index, value) { |
roland@2174 | 200 | ip.print_phi(index, value, block); |
roland@2174 | 201 | print_operand(value); |
roland@2174 | 202 | output()->cr(); |
roland@2174 | 203 | } |
roland@2174 | 204 | |
roland@2174 | 205 | print_end("stack"); |
roland@2174 | 206 | } |
roland@2174 | 207 | |
roland@2174 | 208 | if (state->locks_size() > 0) { |
roland@2174 | 209 | print_begin("locks"); |
roland@2174 | 210 | print("size %d", state->locks_size()); |
roland@2174 | 211 | print("method \"%s\"", method_name(state->scope()->method())); |
roland@2174 | 212 | |
roland@2174 | 213 | for_each_lock_value(state, index, value) { |
roland@2174 | 214 | ip.print_phi(index, value, block); |
roland@2174 | 215 | print_operand(value); |
roland@2174 | 216 | output()->cr(); |
roland@2174 | 217 | } |
roland@2174 | 218 | print_end("locks"); |
roland@2174 | 219 | } |
duke@435 | 220 | } |
duke@435 | 221 | |
duke@435 | 222 | print_end("states"); |
duke@435 | 223 | } |
duke@435 | 224 | |
duke@435 | 225 | |
duke@435 | 226 | void CFGPrinterOutput::print_operand(Value instr) { |
duke@435 | 227 | if (instr->operand()->is_virtual()) { |
duke@435 | 228 | output()->print(" \""); |
duke@435 | 229 | instr->operand()->print(output()); |
duke@435 | 230 | output()->print("\" "); |
duke@435 | 231 | } |
duke@435 | 232 | } |
duke@435 | 233 | |
duke@435 | 234 | void CFGPrinterOutput::print_HIR(Value instr) { |
duke@435 | 235 | InstructionPrinter ip(true, output()); |
duke@435 | 236 | |
duke@435 | 237 | if (instr->is_pinned()) { |
duke@435 | 238 | output()->put('.'); |
duke@435 | 239 | } |
roland@2174 | 240 | |
roland@2174 | 241 | output()->print("%d %d ", instr->printable_bci(), instr->use_count()); |
duke@435 | 242 | |
duke@435 | 243 | print_operand(instr); |
duke@435 | 244 | |
duke@435 | 245 | ip.print_temp(instr); |
duke@435 | 246 | output()->print(" "); |
duke@435 | 247 | ip.print_instr(instr); |
duke@435 | 248 | |
duke@435 | 249 | output()->print_cr(" <|@"); |
duke@435 | 250 | } |
duke@435 | 251 | |
duke@435 | 252 | void CFGPrinterOutput::print_HIR(BlockBegin* block) { |
duke@435 | 253 | print_begin("HIR"); |
duke@435 | 254 | |
duke@435 | 255 | Value cur = block->next(); |
duke@435 | 256 | while (cur != NULL) { |
duke@435 | 257 | print_HIR(cur); |
duke@435 | 258 | cur = cur->next(); |
duke@435 | 259 | } |
duke@435 | 260 | |
duke@435 | 261 | print_end("HIR"); |
duke@435 | 262 | } |
duke@435 | 263 | |
duke@435 | 264 | void CFGPrinterOutput::print_LIR(BlockBegin* block) { |
duke@435 | 265 | print_begin("LIR"); |
duke@435 | 266 | |
duke@435 | 267 | for (int i = 0; i < block->lir()->length(); i++) { |
duke@435 | 268 | block->lir()->at(i)->print_on(output()); |
duke@435 | 269 | output()->print_cr(" <|@ "); |
duke@435 | 270 | } |
duke@435 | 271 | |
duke@435 | 272 | print_end("LIR"); |
duke@435 | 273 | } |
duke@435 | 274 | |
duke@435 | 275 | |
duke@435 | 276 | void CFGPrinterOutput::print_block(BlockBegin* block) { |
duke@435 | 277 | print_begin("block"); |
duke@435 | 278 | |
duke@435 | 279 | print("name \"B%d\"", block->block_id()); |
duke@435 | 280 | |
duke@435 | 281 | print("from_bci %d", block->bci()); |
roland@2174 | 282 | print("to_bci %d", (block->end() == NULL ? -1 : block->end()->printable_bci())); |
duke@435 | 283 | |
duke@435 | 284 | output()->indent(); |
duke@435 | 285 | output()->print("predecessors "); |
duke@435 | 286 | int i; |
duke@435 | 287 | for (i = 0; i < block->number_of_preds(); i++) { |
duke@435 | 288 | output()->print("\"B%d\" ", block->pred_at(i)->block_id()); |
duke@435 | 289 | } |
duke@435 | 290 | output()->cr(); |
duke@435 | 291 | |
duke@435 | 292 | output()->indent(); |
duke@435 | 293 | output()->print("successors "); |
duke@435 | 294 | for (i = 0; i < block->number_of_sux(); i++) { |
duke@435 | 295 | output()->print("\"B%d\" ", block->sux_at(i)->block_id()); |
duke@435 | 296 | } |
duke@435 | 297 | output()->cr(); |
duke@435 | 298 | |
duke@435 | 299 | output()->indent(); |
duke@435 | 300 | output()->print("xhandlers"); |
duke@435 | 301 | for (i = 0; i < block->number_of_exception_handlers(); i++) { |
duke@435 | 302 | output()->print("\"B%d\" ", block->exception_handler_at(i)->block_id()); |
duke@435 | 303 | } |
duke@435 | 304 | output()->cr(); |
duke@435 | 305 | |
duke@435 | 306 | output()->indent(); |
duke@435 | 307 | output()->print("flags "); |
duke@435 | 308 | if (block->is_set(BlockBegin::std_entry_flag)) output()->print("\"std\" "); |
duke@435 | 309 | if (block->is_set(BlockBegin::osr_entry_flag)) output()->print("\"osr\" "); |
duke@435 | 310 | if (block->is_set(BlockBegin::exception_entry_flag)) output()->print("\"ex\" "); |
duke@435 | 311 | if (block->is_set(BlockBegin::subroutine_entry_flag)) output()->print("\"sr\" "); |
duke@435 | 312 | if (block->is_set(BlockBegin::backward_branch_target_flag)) output()->print("\"bb\" "); |
duke@435 | 313 | if (block->is_set(BlockBegin::parser_loop_header_flag)) output()->print("\"plh\" "); |
duke@435 | 314 | if (block->is_set(BlockBegin::critical_edge_split_flag)) output()->print("\"ces\" "); |
duke@435 | 315 | if (block->is_set(BlockBegin::linear_scan_loop_header_flag)) output()->print("\"llh\" "); |
duke@435 | 316 | if (block->is_set(BlockBegin::linear_scan_loop_end_flag)) output()->print("\"lle\" "); |
duke@435 | 317 | output()->cr(); |
duke@435 | 318 | |
duke@435 | 319 | if (block->dominator() != NULL) { |
duke@435 | 320 | print("dominator \"B%d\"", block->dominator()->block_id()); |
duke@435 | 321 | } |
duke@435 | 322 | if (block->loop_index() != -1) { |
duke@435 | 323 | print("loop_index %d", block->loop_index()); |
duke@435 | 324 | print("loop_depth %d", block->loop_depth()); |
duke@435 | 325 | } |
duke@435 | 326 | |
duke@435 | 327 | if (block->first_lir_instruction_id() != -1) { |
duke@435 | 328 | print("first_lir_id %d", block->first_lir_instruction_id()); |
duke@435 | 329 | print("last_lir_id %d", block->last_lir_instruction_id()); |
duke@435 | 330 | } |
duke@435 | 331 | |
duke@435 | 332 | if (_do_print_HIR) { |
duke@435 | 333 | print_state(block); |
duke@435 | 334 | print_HIR(block); |
duke@435 | 335 | } |
duke@435 | 336 | |
duke@435 | 337 | if (_do_print_LIR) { |
duke@435 | 338 | print_LIR(block); |
duke@435 | 339 | } |
duke@435 | 340 | |
duke@435 | 341 | print_end("block"); |
duke@435 | 342 | } |
duke@435 | 343 | |
duke@435 | 344 | |
duke@435 | 345 | |
duke@435 | 346 | void CFGPrinterOutput::print_cfg(BlockList* blocks, const char* name) { |
duke@435 | 347 | print_begin("cfg"); |
duke@435 | 348 | print("name \"%s\"", name); |
duke@435 | 349 | |
duke@435 | 350 | PrintBlockClosure print_block; |
duke@435 | 351 | blocks->iterate_forward(&print_block); |
duke@435 | 352 | |
duke@435 | 353 | print_end("cfg"); |
duke@435 | 354 | output()->flush(); |
duke@435 | 355 | } |
duke@435 | 356 | |
duke@435 | 357 | void CFGPrinterOutput::print_cfg(IR* blocks, const char* name) { |
duke@435 | 358 | print_begin("cfg"); |
duke@435 | 359 | print("name \"%s\"", name); |
duke@435 | 360 | |
duke@435 | 361 | PrintBlockClosure print_block; |
duke@435 | 362 | blocks->iterate_preorder(&print_block); |
duke@435 | 363 | |
duke@435 | 364 | print_end("cfg"); |
duke@435 | 365 | output()->flush(); |
duke@435 | 366 | } |
duke@435 | 367 | |
duke@435 | 368 | |
duke@435 | 369 | |
duke@435 | 370 | |
duke@435 | 371 | void CFGPrinterOutput::print_intervals(IntervalList* intervals, const char* name) { |
duke@435 | 372 | print_begin("intervals"); |
duke@435 | 373 | print("name \"%s\"", name); |
duke@435 | 374 | |
duke@435 | 375 | for (int i = 0; i < intervals->length(); i++) { |
duke@435 | 376 | if (intervals->at(i) != NULL) { |
duke@435 | 377 | intervals->at(i)->print(output()); |
duke@435 | 378 | } |
duke@435 | 379 | } |
duke@435 | 380 | |
duke@435 | 381 | print_end("intervals"); |
duke@435 | 382 | output()->flush(); |
duke@435 | 383 | } |
duke@435 | 384 | |
duke@435 | 385 | |
duke@435 | 386 | #endif |