Tue, 15 Apr 2008 10:49:32 -0700
6692301: Side effect in NumberFormat tests with -server -Xcomp
Summary: Optimization in CmpPNode::sub() removed the valid compare instruction because of false positive answer from detect_dominating_control().
Reviewed-by: jrose, sgoldman
1 /*
2 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 #include "incls/_precompiled.incl"
26 #include "incls/_compile.cpp.incl"
28 /// Support for intrinsics.
30 // Return the index at which m must be inserted (or already exists).
31 // The sort order is by the address of the ciMethod, with is_virtual as minor key.
32 int Compile::intrinsic_insertion_index(ciMethod* m, bool is_virtual) {
33 #ifdef ASSERT
34 for (int i = 1; i < _intrinsics->length(); i++) {
35 CallGenerator* cg1 = _intrinsics->at(i-1);
36 CallGenerator* cg2 = _intrinsics->at(i);
37 assert(cg1->method() != cg2->method()
38 ? cg1->method() < cg2->method()
39 : cg1->is_virtual() < cg2->is_virtual(),
40 "compiler intrinsics list must stay sorted");
41 }
42 #endif
43 // Binary search sorted list, in decreasing intervals [lo, hi].
44 int lo = 0, hi = _intrinsics->length()-1;
45 while (lo <= hi) {
46 int mid = (uint)(hi + lo) / 2;
47 ciMethod* mid_m = _intrinsics->at(mid)->method();
48 if (m < mid_m) {
49 hi = mid-1;
50 } else if (m > mid_m) {
51 lo = mid+1;
52 } else {
53 // look at minor sort key
54 bool mid_virt = _intrinsics->at(mid)->is_virtual();
55 if (is_virtual < mid_virt) {
56 hi = mid-1;
57 } else if (is_virtual > mid_virt) {
58 lo = mid+1;
59 } else {
60 return mid; // exact match
61 }
62 }
63 }
64 return lo; // inexact match
65 }
67 void Compile::register_intrinsic(CallGenerator* cg) {
68 if (_intrinsics == NULL) {
69 _intrinsics = new GrowableArray<CallGenerator*>(60);
70 }
71 // This code is stolen from ciObjectFactory::insert.
72 // Really, GrowableArray should have methods for
73 // insert_at, remove_at, and binary_search.
74 int len = _intrinsics->length();
75 int index = intrinsic_insertion_index(cg->method(), cg->is_virtual());
76 if (index == len) {
77 _intrinsics->append(cg);
78 } else {
79 #ifdef ASSERT
80 CallGenerator* oldcg = _intrinsics->at(index);
81 assert(oldcg->method() != cg->method() || oldcg->is_virtual() != cg->is_virtual(), "don't register twice");
82 #endif
83 _intrinsics->append(_intrinsics->at(len-1));
84 int pos;
85 for (pos = len-2; pos >= index; pos--) {
86 _intrinsics->at_put(pos+1,_intrinsics->at(pos));
87 }
88 _intrinsics->at_put(index, cg);
89 }
90 assert(find_intrinsic(cg->method(), cg->is_virtual()) == cg, "registration worked");
91 }
93 CallGenerator* Compile::find_intrinsic(ciMethod* m, bool is_virtual) {
94 assert(m->is_loaded(), "don't try this on unloaded methods");
95 if (_intrinsics != NULL) {
96 int index = intrinsic_insertion_index(m, is_virtual);
97 if (index < _intrinsics->length()
98 && _intrinsics->at(index)->method() == m
99 && _intrinsics->at(index)->is_virtual() == is_virtual) {
100 return _intrinsics->at(index);
101 }
102 }
103 // Lazily create intrinsics for intrinsic IDs well-known in the runtime.
104 if (m->intrinsic_id() != vmIntrinsics::_none) {
105 CallGenerator* cg = make_vm_intrinsic(m, is_virtual);
106 if (cg != NULL) {
107 // Save it for next time:
108 register_intrinsic(cg);
109 return cg;
110 } else {
111 gather_intrinsic_statistics(m->intrinsic_id(), is_virtual, _intrinsic_disabled);
112 }
113 }
114 return NULL;
115 }
117 // Compile:: register_library_intrinsics and make_vm_intrinsic are defined
118 // in library_call.cpp.
121 #ifndef PRODUCT
122 // statistics gathering...
124 juint Compile::_intrinsic_hist_count[vmIntrinsics::ID_LIMIT] = {0};
125 jubyte Compile::_intrinsic_hist_flags[vmIntrinsics::ID_LIMIT] = {0};
127 bool Compile::gather_intrinsic_statistics(vmIntrinsics::ID id, bool is_virtual, int flags) {
128 assert(id > vmIntrinsics::_none && id < vmIntrinsics::ID_LIMIT, "oob");
129 int oflags = _intrinsic_hist_flags[id];
130 assert(flags != 0, "what happened?");
131 if (is_virtual) {
132 flags |= _intrinsic_virtual;
133 }
134 bool changed = (flags != oflags);
135 if ((flags & _intrinsic_worked) != 0) {
136 juint count = (_intrinsic_hist_count[id] += 1);
137 if (count == 1) {
138 changed = true; // first time
139 }
140 // increment the overall count also:
141 _intrinsic_hist_count[vmIntrinsics::_none] += 1;
142 }
143 if (changed) {
144 if (((oflags ^ flags) & _intrinsic_virtual) != 0) {
145 // Something changed about the intrinsic's virtuality.
146 if ((flags & _intrinsic_virtual) != 0) {
147 // This is the first use of this intrinsic as a virtual call.
148 if (oflags != 0) {
149 // We already saw it as a non-virtual, so note both cases.
150 flags |= _intrinsic_both;
151 }
152 } else if ((oflags & _intrinsic_both) == 0) {
153 // This is the first use of this intrinsic as a non-virtual
154 flags |= _intrinsic_both;
155 }
156 }
157 _intrinsic_hist_flags[id] = (jubyte) (oflags | flags);
158 }
159 // update the overall flags also:
160 _intrinsic_hist_flags[vmIntrinsics::_none] |= (jubyte) flags;
161 return changed;
162 }
164 static char* format_flags(int flags, char* buf) {
165 buf[0] = 0;
166 if ((flags & Compile::_intrinsic_worked) != 0) strcat(buf, ",worked");
167 if ((flags & Compile::_intrinsic_failed) != 0) strcat(buf, ",failed");
168 if ((flags & Compile::_intrinsic_disabled) != 0) strcat(buf, ",disabled");
169 if ((flags & Compile::_intrinsic_virtual) != 0) strcat(buf, ",virtual");
170 if ((flags & Compile::_intrinsic_both) != 0) strcat(buf, ",nonvirtual");
171 if (buf[0] == 0) strcat(buf, ",");
172 assert(buf[0] == ',', "must be");
173 return &buf[1];
174 }
176 void Compile::print_intrinsic_statistics() {
177 char flagsbuf[100];
178 ttyLocker ttyl;
179 if (xtty != NULL) xtty->head("statistics type='intrinsic'");
180 tty->print_cr("Compiler intrinsic usage:");
181 juint total = _intrinsic_hist_count[vmIntrinsics::_none];
182 if (total == 0) total = 1; // avoid div0 in case of no successes
183 #define PRINT_STAT_LINE(name, c, f) \
184 tty->print_cr(" %4d (%4.1f%%) %s (%s)", (int)(c), ((c) * 100.0) / total, name, f);
185 for (int index = 1 + (int)vmIntrinsics::_none; index < (int)vmIntrinsics::ID_LIMIT; index++) {
186 vmIntrinsics::ID id = (vmIntrinsics::ID) index;
187 int flags = _intrinsic_hist_flags[id];
188 juint count = _intrinsic_hist_count[id];
189 if ((flags | count) != 0) {
190 PRINT_STAT_LINE(vmIntrinsics::name_at(id), count, format_flags(flags, flagsbuf));
191 }
192 }
193 PRINT_STAT_LINE("total", total, format_flags(_intrinsic_hist_flags[vmIntrinsics::_none], flagsbuf));
194 if (xtty != NULL) xtty->tail("statistics");
195 }
197 void Compile::print_statistics() {
198 { ttyLocker ttyl;
199 if (xtty != NULL) xtty->head("statistics type='opto'");
200 Parse::print_statistics();
201 PhaseCCP::print_statistics();
202 PhaseRegAlloc::print_statistics();
203 Scheduling::print_statistics();
204 PhasePeephole::print_statistics();
205 PhaseIdealLoop::print_statistics();
206 if (xtty != NULL) xtty->tail("statistics");
207 }
208 if (_intrinsic_hist_flags[vmIntrinsics::_none] != 0) {
209 // put this under its own <statistics> element.
210 print_intrinsic_statistics();
211 }
212 }
213 #endif //PRODUCT
215 // Support for bundling info
216 Bundle* Compile::node_bundling(const Node *n) {
217 assert(valid_bundle_info(n), "oob");
218 return &_node_bundling_base[n->_idx];
219 }
221 bool Compile::valid_bundle_info(const Node *n) {
222 return (_node_bundling_limit > n->_idx);
223 }
226 // Identify all nodes that are reachable from below, useful.
227 // Use breadth-first pass that records state in a Unique_Node_List,
228 // recursive traversal is slower.
229 void Compile::identify_useful_nodes(Unique_Node_List &useful) {
230 int estimated_worklist_size = unique();
231 useful.map( estimated_worklist_size, NULL ); // preallocate space
233 // Initialize worklist
234 if (root() != NULL) { useful.push(root()); }
235 // If 'top' is cached, declare it useful to preserve cached node
236 if( cached_top_node() ) { useful.push(cached_top_node()); }
238 // Push all useful nodes onto the list, breadthfirst
239 for( uint next = 0; next < useful.size(); ++next ) {
240 assert( next < unique(), "Unique useful nodes < total nodes");
241 Node *n = useful.at(next);
242 uint max = n->len();
243 for( uint i = 0; i < max; ++i ) {
244 Node *m = n->in(i);
245 if( m == NULL ) continue;
246 useful.push(m);
247 }
248 }
249 }
251 // Disconnect all useless nodes by disconnecting those at the boundary.
252 void Compile::remove_useless_nodes(Unique_Node_List &useful) {
253 uint next = 0;
254 while( next < useful.size() ) {
255 Node *n = useful.at(next++);
256 // Use raw traversal of out edges since this code removes out edges
257 int max = n->outcnt();
258 for (int j = 0; j < max; ++j ) {
259 Node* child = n->raw_out(j);
260 if( ! useful.member(child) ) {
261 assert( !child->is_top() || child != top(),
262 "If top is cached in Compile object it is in useful list");
263 // Only need to remove this out-edge to the useless node
264 n->raw_del_out(j);
265 --j;
266 --max;
267 }
268 }
269 if (n->outcnt() == 1 && n->has_special_unique_user()) {
270 record_for_igvn( n->unique_out() );
271 }
272 }
273 debug_only(verify_graph_edges(true/*check for no_dead_code*/);)
274 }
276 //------------------------------frame_size_in_words-----------------------------
277 // frame_slots in units of words
278 int Compile::frame_size_in_words() const {
279 // shift is 0 in LP32 and 1 in LP64
280 const int shift = (LogBytesPerWord - LogBytesPerInt);
281 int words = _frame_slots >> shift;
282 assert( words << shift == _frame_slots, "frame size must be properly aligned in LP64" );
283 return words;
284 }
286 // ============================================================================
287 //------------------------------CompileWrapper---------------------------------
288 class CompileWrapper : public StackObj {
289 Compile *const _compile;
290 public:
291 CompileWrapper(Compile* compile);
293 ~CompileWrapper();
294 };
296 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
297 // the Compile* pointer is stored in the current ciEnv:
298 ciEnv* env = compile->env();
299 assert(env == ciEnv::current(), "must already be a ciEnv active");
300 assert(env->compiler_data() == NULL, "compile already active?");
301 env->set_compiler_data(compile);
302 assert(compile == Compile::current(), "sanity");
304 compile->set_type_dict(NULL);
305 compile->set_type_hwm(NULL);
306 compile->set_type_last_size(0);
307 compile->set_last_tf(NULL, NULL);
308 compile->set_indexSet_arena(NULL);
309 compile->set_indexSet_free_block_list(NULL);
310 compile->init_type_arena();
311 Type::Initialize(compile);
312 _compile->set_scratch_buffer_blob(NULL);
313 _compile->begin_method();
314 }
315 CompileWrapper::~CompileWrapper() {
316 if (_compile->failing()) {
317 _compile->print_method("Failed");
318 }
319 _compile->end_method();
320 if (_compile->scratch_buffer_blob() != NULL)
321 BufferBlob::free(_compile->scratch_buffer_blob());
322 _compile->env()->set_compiler_data(NULL);
323 }
326 //----------------------------print_compile_messages---------------------------
327 void Compile::print_compile_messages() {
328 #ifndef PRODUCT
329 // Check if recompiling
330 if (_subsume_loads == false && PrintOpto) {
331 // Recompiling without allowing machine instructions to subsume loads
332 tty->print_cr("*********************************************************");
333 tty->print_cr("** Bailout: Recompile without subsuming loads **");
334 tty->print_cr("*********************************************************");
335 }
336 if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) {
337 // Recompiling without escape analysis
338 tty->print_cr("*********************************************************");
339 tty->print_cr("** Bailout: Recompile without escape analysis **");
340 tty->print_cr("*********************************************************");
341 }
342 if (env()->break_at_compile()) {
343 // Open the debugger when compiing this method.
344 tty->print("### Breaking when compiling: ");
345 method()->print_short_name();
346 tty->cr();
347 BREAKPOINT;
348 }
350 if( PrintOpto ) {
351 if (is_osr_compilation()) {
352 tty->print("[OSR]%3d", _compile_id);
353 } else {
354 tty->print("%3d", _compile_id);
355 }
356 }
357 #endif
358 }
361 void Compile::init_scratch_buffer_blob() {
362 if( scratch_buffer_blob() != NULL ) return;
364 // Construct a temporary CodeBuffer to have it construct a BufferBlob
365 // Cache this BufferBlob for this compile.
366 ResourceMark rm;
367 int size = (MAX_inst_size + MAX_stubs_size + MAX_const_size);
368 BufferBlob* blob = BufferBlob::create("Compile::scratch_buffer", size);
369 // Record the buffer blob for next time.
370 set_scratch_buffer_blob(blob);
371 guarantee(scratch_buffer_blob() != NULL, "Need BufferBlob for code generation");
373 // Initialize the relocation buffers
374 relocInfo* locs_buf = (relocInfo*) blob->instructions_end() - MAX_locs_size;
375 set_scratch_locs_memory(locs_buf);
376 }
379 //-----------------------scratch_emit_size-------------------------------------
380 // Helper function that computes size by emitting code
381 uint Compile::scratch_emit_size(const Node* n) {
382 // Emit into a trash buffer and count bytes emitted.
383 // This is a pretty expensive way to compute a size,
384 // but it works well enough if seldom used.
385 // All common fixed-size instructions are given a size
386 // method by the AD file.
387 // Note that the scratch buffer blob and locs memory are
388 // allocated at the beginning of the compile task, and
389 // may be shared by several calls to scratch_emit_size.
390 // The allocation of the scratch buffer blob is particularly
391 // expensive, since it has to grab the code cache lock.
392 BufferBlob* blob = this->scratch_buffer_blob();
393 assert(blob != NULL, "Initialize BufferBlob at start");
394 assert(blob->size() > MAX_inst_size, "sanity");
395 relocInfo* locs_buf = scratch_locs_memory();
396 address blob_begin = blob->instructions_begin();
397 address blob_end = (address)locs_buf;
398 assert(blob->instructions_contains(blob_end), "sanity");
399 CodeBuffer buf(blob_begin, blob_end - blob_begin);
400 buf.initialize_consts_size(MAX_const_size);
401 buf.initialize_stubs_size(MAX_stubs_size);
402 assert(locs_buf != NULL, "sanity");
403 int lsize = MAX_locs_size / 2;
404 buf.insts()->initialize_shared_locs(&locs_buf[0], lsize);
405 buf.stubs()->initialize_shared_locs(&locs_buf[lsize], lsize);
406 n->emit(buf, this->regalloc());
407 return buf.code_size();
408 }
411 // ============================================================================
412 //------------------------------Compile standard-------------------------------
413 debug_only( int Compile::_debug_idx = 100000; )
415 // Compile a method. entry_bci is -1 for normal compilations and indicates
416 // the continuation bci for on stack replacement.
419 Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr_bci, bool subsume_loads, bool do_escape_analysis )
420 : Phase(Compiler),
421 _env(ci_env),
422 _log(ci_env->log()),
423 _compile_id(ci_env->compile_id()),
424 _save_argument_registers(false),
425 _stub_name(NULL),
426 _stub_function(NULL),
427 _stub_entry_point(NULL),
428 _method(target),
429 _entry_bci(osr_bci),
430 _initial_gvn(NULL),
431 _for_igvn(NULL),
432 _warm_calls(NULL),
433 _subsume_loads(subsume_loads),
434 _do_escape_analysis(do_escape_analysis),
435 _failure_reason(NULL),
436 _code_buffer("Compile::Fill_buffer"),
437 _orig_pc_slot(0),
438 _orig_pc_slot_offset_in_bytes(0),
439 _node_bundling_limit(0),
440 _node_bundling_base(NULL),
441 #ifndef PRODUCT
442 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")),
443 _printer(IdealGraphPrinter::printer()),
444 #endif
445 _congraph(NULL) {
446 C = this;
448 CompileWrapper cw(this);
449 #ifndef PRODUCT
450 if (TimeCompiler2) {
451 tty->print(" ");
452 target->holder()->name()->print();
453 tty->print(".");
454 target->print_short_name();
455 tty->print(" ");
456 }
457 TraceTime t1("Total compilation time", &_t_totalCompilation, TimeCompiler, TimeCompiler2);
458 TraceTime t2(NULL, &_t_methodCompilation, TimeCompiler, false);
459 set_print_assembly(PrintOptoAssembly || _method->should_print_assembly());
460 #endif
462 if (ProfileTraps) {
463 // Make sure the method being compiled gets its own MDO,
464 // so we can at least track the decompile_count().
465 method()->build_method_data();
466 }
468 Init(::AliasLevel);
471 print_compile_messages();
473 if (UseOldInlining || PrintCompilation NOT_PRODUCT( || PrintOpto) )
474 _ilt = InlineTree::build_inline_tree_root();
475 else
476 _ilt = NULL;
478 // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice
479 assert(num_alias_types() >= AliasIdxRaw, "");
481 #define MINIMUM_NODE_HASH 1023
482 // Node list that Iterative GVN will start with
483 Unique_Node_List for_igvn(comp_arena());
484 set_for_igvn(&for_igvn);
486 // GVN that will be run immediately on new nodes
487 uint estimated_size = method()->code_size()*4+64;
488 estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
489 PhaseGVN gvn(node_arena(), estimated_size);
490 set_initial_gvn(&gvn);
492 { // Scope for timing the parser
493 TracePhase t3("parse", &_t_parser, true);
495 // Put top into the hash table ASAP.
496 initial_gvn()->transform_no_reclaim(top());
498 // Set up tf(), start(), and find a CallGenerator.
499 CallGenerator* cg;
500 if (is_osr_compilation()) {
501 const TypeTuple *domain = StartOSRNode::osr_domain();
502 const TypeTuple *range = TypeTuple::make_range(method()->signature());
503 init_tf(TypeFunc::make(domain, range));
504 StartNode* s = new (this, 2) StartOSRNode(root(), domain);
505 initial_gvn()->set_type_bottom(s);
506 init_start(s);
507 cg = CallGenerator::for_osr(method(), entry_bci());
508 } else {
509 // Normal case.
510 init_tf(TypeFunc::make(method()));
511 StartNode* s = new (this, 2) StartNode(root(), tf()->domain());
512 initial_gvn()->set_type_bottom(s);
513 init_start(s);
514 float past_uses = method()->interpreter_invocation_count();
515 float expected_uses = past_uses;
516 cg = CallGenerator::for_inline(method(), expected_uses);
517 }
518 if (failing()) return;
519 if (cg == NULL) {
520 record_method_not_compilable_all_tiers("cannot parse method");
521 return;
522 }
523 JVMState* jvms = build_start_state(start(), tf());
524 if ((jvms = cg->generate(jvms)) == NULL) {
525 record_method_not_compilable("method parse failed");
526 return;
527 }
528 GraphKit kit(jvms);
530 if (!kit.stopped()) {
531 // Accept return values, and transfer control we know not where.
532 // This is done by a special, unique ReturnNode bound to root.
533 return_values(kit.jvms());
534 }
536 if (kit.has_exceptions()) {
537 // Any exceptions that escape from this call must be rethrown
538 // to whatever caller is dynamically above us on the stack.
539 // This is done by a special, unique RethrowNode bound to root.
540 rethrow_exceptions(kit.transfer_exceptions_into_jvms());
541 }
543 // Remove clutter produced by parsing.
544 if (!failing()) {
545 ResourceMark rm;
546 PhaseRemoveUseless pru(initial_gvn(), &for_igvn);
547 }
548 }
550 // Note: Large methods are capped off in do_one_bytecode().
551 if (failing()) return;
553 // After parsing, node notes are no longer automagic.
554 // They must be propagated by register_new_node_with_optimizer(),
555 // clone(), or the like.
556 set_default_node_notes(NULL);
558 for (;;) {
559 int successes = Inline_Warm();
560 if (failing()) return;
561 if (successes == 0) break;
562 }
564 // Drain the list.
565 Finish_Warm();
566 #ifndef PRODUCT
567 if (_printer) {
568 _printer->print_inlining(this);
569 }
570 #endif
572 if (failing()) return;
573 NOT_PRODUCT( verify_graph_edges(); )
575 // Perform escape analysis
576 if (_do_escape_analysis)
577 _congraph = new ConnectionGraph(this);
578 if (_congraph != NULL) {
579 NOT_PRODUCT( TracePhase t2("escapeAnalysis", &_t_escapeAnalysis, TimeCompiler); )
580 _congraph->compute_escape();
581 if (failing()) return;
583 #ifndef PRODUCT
584 if (PrintEscapeAnalysis) {
585 _congraph->dump();
586 }
587 #endif
588 }
589 // Now optimize
590 Optimize();
591 if (failing()) return;
592 NOT_PRODUCT( verify_graph_edges(); )
594 #ifndef PRODUCT
595 if (PrintIdeal) {
596 ttyLocker ttyl; // keep the following output all in one block
597 // This output goes directly to the tty, not the compiler log.
598 // To enable tools to match it up with the compilation activity,
599 // be sure to tag this tty output with the compile ID.
600 if (xtty != NULL) {
601 xtty->head("ideal compile_id='%d'%s", compile_id(),
602 is_osr_compilation() ? " compile_kind='osr'" :
603 "");
604 }
605 root()->dump(9999);
606 if (xtty != NULL) {
607 xtty->tail("ideal");
608 }
609 }
610 #endif
612 // Now that we know the size of all the monitors we can add a fixed slot
613 // for the original deopt pc.
615 _orig_pc_slot = fixed_slots();
616 int next_slot = _orig_pc_slot + (sizeof(address) / VMRegImpl::stack_slot_size);
617 set_fixed_slots(next_slot);
619 // Now generate code
620 Code_Gen();
621 if (failing()) return;
623 // Check if we want to skip execution of all compiled code.
624 {
625 #ifndef PRODUCT
626 if (OptoNoExecute) {
627 record_method_not_compilable("+OptoNoExecute"); // Flag as failed
628 return;
629 }
630 TracePhase t2("install_code", &_t_registerMethod, TimeCompiler);
631 #endif
633 if (is_osr_compilation()) {
634 _code_offsets.set_value(CodeOffsets::Verified_Entry, 0);
635 _code_offsets.set_value(CodeOffsets::OSR_Entry, _first_block_size);
636 } else {
637 _code_offsets.set_value(CodeOffsets::Verified_Entry, _first_block_size);
638 _code_offsets.set_value(CodeOffsets::OSR_Entry, 0);
639 }
641 env()->register_method(_method, _entry_bci,
642 &_code_offsets,
643 _orig_pc_slot_offset_in_bytes,
644 code_buffer(),
645 frame_size_in_words(), _oop_map_set,
646 &_handler_table, &_inc_table,
647 compiler,
648 env()->comp_level(),
649 true, /*has_debug_info*/
650 has_unsafe_access()
651 );
652 }
653 }
655 //------------------------------Compile----------------------------------------
656 // Compile a runtime stub
657 Compile::Compile( ciEnv* ci_env,
658 TypeFunc_generator generator,
659 address stub_function,
660 const char *stub_name,
661 int is_fancy_jump,
662 bool pass_tls,
663 bool save_arg_registers,
664 bool return_pc )
665 : Phase(Compiler),
666 _env(ci_env),
667 _log(ci_env->log()),
668 _compile_id(-1),
669 _save_argument_registers(save_arg_registers),
670 _method(NULL),
671 _stub_name(stub_name),
672 _stub_function(stub_function),
673 _stub_entry_point(NULL),
674 _entry_bci(InvocationEntryBci),
675 _initial_gvn(NULL),
676 _for_igvn(NULL),
677 _warm_calls(NULL),
678 _orig_pc_slot(0),
679 _orig_pc_slot_offset_in_bytes(0),
680 _subsume_loads(true),
681 _do_escape_analysis(false),
682 _failure_reason(NULL),
683 _code_buffer("Compile::Fill_buffer"),
684 _node_bundling_limit(0),
685 _node_bundling_base(NULL),
686 #ifndef PRODUCT
687 _trace_opto_output(TraceOptoOutput),
688 _printer(NULL),
689 #endif
690 _congraph(NULL) {
691 C = this;
693 #ifndef PRODUCT
694 TraceTime t1(NULL, &_t_totalCompilation, TimeCompiler, false);
695 TraceTime t2(NULL, &_t_stubCompilation, TimeCompiler, false);
696 set_print_assembly(PrintFrameConverterAssembly);
697 #endif
698 CompileWrapper cw(this);
699 Init(/*AliasLevel=*/ 0);
700 init_tf((*generator)());
702 {
703 // The following is a dummy for the sake of GraphKit::gen_stub
704 Unique_Node_List for_igvn(comp_arena());
705 set_for_igvn(&for_igvn); // not used, but some GraphKit guys push on this
706 PhaseGVN gvn(Thread::current()->resource_area(),255);
707 set_initial_gvn(&gvn); // not significant, but GraphKit guys use it pervasively
708 gvn.transform_no_reclaim(top());
710 GraphKit kit;
711 kit.gen_stub(stub_function, stub_name, is_fancy_jump, pass_tls, return_pc);
712 }
714 NOT_PRODUCT( verify_graph_edges(); )
715 Code_Gen();
716 if (failing()) return;
719 // Entry point will be accessed using compile->stub_entry_point();
720 if (code_buffer() == NULL) {
721 Matcher::soft_match_failure();
722 } else {
723 if (PrintAssembly && (WizardMode || Verbose))
724 tty->print_cr("### Stub::%s", stub_name);
726 if (!failing()) {
727 assert(_fixed_slots == 0, "no fixed slots used for runtime stubs");
729 // Make the NMethod
730 // For now we mark the frame as never safe for profile stackwalking
731 RuntimeStub *rs = RuntimeStub::new_runtime_stub(stub_name,
732 code_buffer(),
733 CodeOffsets::frame_never_safe,
734 // _code_offsets.value(CodeOffsets::Frame_Complete),
735 frame_size_in_words(),
736 _oop_map_set,
737 save_arg_registers);
738 assert(rs != NULL && rs->is_runtime_stub(), "sanity check");
740 _stub_entry_point = rs->entry_point();
741 }
742 }
743 }
745 #ifndef PRODUCT
746 void print_opto_verbose_signature( const TypeFunc *j_sig, const char *stub_name ) {
747 if(PrintOpto && Verbose) {
748 tty->print("%s ", stub_name); j_sig->print_flattened(); tty->cr();
749 }
750 }
751 #endif
753 void Compile::print_codes() {
754 }
756 //------------------------------Init-------------------------------------------
757 // Prepare for a single compilation
758 void Compile::Init(int aliaslevel) {
759 _unique = 0;
760 _regalloc = NULL;
762 _tf = NULL; // filled in later
763 _top = NULL; // cached later
764 _matcher = NULL; // filled in later
765 _cfg = NULL; // filled in later
767 set_24_bit_selection_and_mode(Use24BitFP, false);
769 _node_note_array = NULL;
770 _default_node_notes = NULL;
772 _immutable_memory = NULL; // filled in at first inquiry
774 // Globally visible Nodes
775 // First set TOP to NULL to give safe behavior during creation of RootNode
776 set_cached_top_node(NULL);
777 set_root(new (this, 3) RootNode());
778 // Now that you have a Root to point to, create the real TOP
779 set_cached_top_node( new (this, 1) ConNode(Type::TOP) );
780 set_recent_alloc(NULL, NULL);
782 // Create Debug Information Recorder to record scopes, oopmaps, etc.
783 env()->set_oop_recorder(new OopRecorder(comp_arena()));
784 env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
785 env()->set_dependencies(new Dependencies(env()));
787 _fixed_slots = 0;
788 set_has_split_ifs(false);
789 set_has_loops(has_method() && method()->has_loops()); // first approximation
790 _deopt_happens = true; // start out assuming the worst
791 _trap_can_recompile = false; // no traps emitted yet
792 _major_progress = true; // start out assuming good things will happen
793 set_has_unsafe_access(false);
794 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
795 set_decompile_count(0);
797 // Compilation level related initialization
798 if (env()->comp_level() == CompLevel_fast_compile) {
799 set_num_loop_opts(Tier1LoopOptsCount);
800 set_do_inlining(Tier1Inline != 0);
801 set_max_inline_size(Tier1MaxInlineSize);
802 set_freq_inline_size(Tier1FreqInlineSize);
803 set_do_scheduling(false);
804 set_do_count_invocations(Tier1CountInvocations);
805 set_do_method_data_update(Tier1UpdateMethodData);
806 } else {
807 assert(env()->comp_level() == CompLevel_full_optimization, "unknown comp level");
808 set_num_loop_opts(LoopOptsCount);
809 set_do_inlining(Inline);
810 set_max_inline_size(MaxInlineSize);
811 set_freq_inline_size(FreqInlineSize);
812 set_do_scheduling(OptoScheduling);
813 set_do_count_invocations(false);
814 set_do_method_data_update(false);
815 }
817 if (debug_info()->recording_non_safepoints()) {
818 set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
819 (comp_arena(), 8, 0, NULL));
820 set_default_node_notes(Node_Notes::make(this));
821 }
823 // // -- Initialize types before each compile --
824 // // Update cached type information
825 // if( _method && _method->constants() )
826 // Type::update_loaded_types(_method, _method->constants());
828 // Init alias_type map.
829 if (!_do_escape_analysis && aliaslevel == 3)
830 aliaslevel = 2; // No unique types without escape analysis
831 _AliasLevel = aliaslevel;
832 const int grow_ats = 16;
833 _max_alias_types = grow_ats;
834 _alias_types = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats);
835 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, grow_ats);
836 Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats);
837 {
838 for (int i = 0; i < grow_ats; i++) _alias_types[i] = &ats[i];
839 }
840 // Initialize the first few types.
841 _alias_types[AliasIdxTop]->Init(AliasIdxTop, NULL);
842 _alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM);
843 _alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM);
844 _num_alias_types = AliasIdxRaw+1;
845 // Zero out the alias type cache.
846 Copy::zero_to_bytes(_alias_cache, sizeof(_alias_cache));
847 // A NULL adr_type hits in the cache right away. Preload the right answer.
848 probe_alias_cache(NULL)->_index = AliasIdxTop;
850 _intrinsics = NULL;
851 _macro_nodes = new GrowableArray<Node*>(comp_arena(), 8, 0, NULL);
852 register_library_intrinsics();
853 }
855 //---------------------------init_start----------------------------------------
856 // Install the StartNode on this compile object.
857 void Compile::init_start(StartNode* s) {
858 if (failing())
859 return; // already failing
860 assert(s == start(), "");
861 }
863 StartNode* Compile::start() const {
864 assert(!failing(), "");
865 for (DUIterator_Fast imax, i = root()->fast_outs(imax); i < imax; i++) {
866 Node* start = root()->fast_out(i);
867 if( start->is_Start() )
868 return start->as_Start();
869 }
870 ShouldNotReachHere();
871 return NULL;
872 }
874 //-------------------------------immutable_memory-------------------------------------
875 // Access immutable memory
876 Node* Compile::immutable_memory() {
877 if (_immutable_memory != NULL) {
878 return _immutable_memory;
879 }
880 StartNode* s = start();
881 for (DUIterator_Fast imax, i = s->fast_outs(imax); true; i++) {
882 Node *p = s->fast_out(i);
883 if (p != s && p->as_Proj()->_con == TypeFunc::Memory) {
884 _immutable_memory = p;
885 return _immutable_memory;
886 }
887 }
888 ShouldNotReachHere();
889 return NULL;
890 }
892 //----------------------set_cached_top_node------------------------------------
893 // Install the cached top node, and make sure Node::is_top works correctly.
894 void Compile::set_cached_top_node(Node* tn) {
895 if (tn != NULL) verify_top(tn);
896 Node* old_top = _top;
897 _top = tn;
898 // Calling Node::setup_is_top allows the nodes the chance to adjust
899 // their _out arrays.
900 if (_top != NULL) _top->setup_is_top();
901 if (old_top != NULL) old_top->setup_is_top();
902 assert(_top == NULL || top()->is_top(), "");
903 }
905 #ifndef PRODUCT
906 void Compile::verify_top(Node* tn) const {
907 if (tn != NULL) {
908 assert(tn->is_Con(), "top node must be a constant");
909 assert(((ConNode*)tn)->type() == Type::TOP, "top node must have correct type");
910 assert(tn->in(0) != NULL, "must have live top node");
911 }
912 }
913 #endif
916 ///-------------------Managing Per-Node Debug & Profile Info-------------------
918 void Compile::grow_node_notes(GrowableArray<Node_Notes*>* arr, int grow_by) {
919 guarantee(arr != NULL, "");
920 int num_blocks = arr->length();
921 if (grow_by < num_blocks) grow_by = num_blocks;
922 int num_notes = grow_by * _node_notes_block_size;
923 Node_Notes* notes = NEW_ARENA_ARRAY(node_arena(), Node_Notes, num_notes);
924 Copy::zero_to_bytes(notes, num_notes * sizeof(Node_Notes));
925 while (num_notes > 0) {
926 arr->append(notes);
927 notes += _node_notes_block_size;
928 num_notes -= _node_notes_block_size;
929 }
930 assert(num_notes == 0, "exact multiple, please");
931 }
933 bool Compile::copy_node_notes_to(Node* dest, Node* source) {
934 if (source == NULL || dest == NULL) return false;
936 if (dest->is_Con())
937 return false; // Do not push debug info onto constants.
939 #ifdef ASSERT
940 // Leave a bread crumb trail pointing to the original node:
941 if (dest != NULL && dest != source && dest->debug_orig() == NULL) {
942 dest->set_debug_orig(source);
943 }
944 #endif
946 if (node_note_array() == NULL)
947 return false; // Not collecting any notes now.
949 // This is a copy onto a pre-existing node, which may already have notes.
950 // If both nodes have notes, do not overwrite any pre-existing notes.
951 Node_Notes* source_notes = node_notes_at(source->_idx);
952 if (source_notes == NULL || source_notes->is_clear()) return false;
953 Node_Notes* dest_notes = node_notes_at(dest->_idx);
954 if (dest_notes == NULL || dest_notes->is_clear()) {
955 return set_node_notes_at(dest->_idx, source_notes);
956 }
958 Node_Notes merged_notes = (*source_notes);
959 // The order of operations here ensures that dest notes will win...
960 merged_notes.update_from(dest_notes);
961 return set_node_notes_at(dest->_idx, &merged_notes);
962 }
965 //--------------------------allow_range_check_smearing-------------------------
966 // Gating condition for coalescing similar range checks.
967 // Sometimes we try 'speculatively' replacing a series of a range checks by a
968 // single covering check that is at least as strong as any of them.
969 // If the optimization succeeds, the simplified (strengthened) range check
970 // will always succeed. If it fails, we will deopt, and then give up
971 // on the optimization.
972 bool Compile::allow_range_check_smearing() const {
973 // If this method has already thrown a range-check,
974 // assume it was because we already tried range smearing
975 // and it failed.
976 uint already_trapped = trap_count(Deoptimization::Reason_range_check);
977 return !already_trapped;
978 }
981 //------------------------------flatten_alias_type-----------------------------
982 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
983 int offset = tj->offset();
984 TypePtr::PTR ptr = tj->ptr();
986 // Process weird unsafe references.
987 if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
988 assert(InlineUnsafeOps, "indeterminate pointers come only from unsafe ops");
989 tj = TypeOopPtr::BOTTOM;
990 ptr = tj->ptr();
991 offset = tj->offset();
992 }
994 // Array pointers need some flattening
995 const TypeAryPtr *ta = tj->isa_aryptr();
996 if( ta && _AliasLevel >= 2 ) {
997 // For arrays indexed by constant indices, we flatten the alias
998 // space to include all of the array body. Only the header, klass
999 // and array length can be accessed un-aliased.
1000 if( offset != Type::OffsetBot ) {
1001 if( ta->const_oop() ) { // methodDataOop or methodOop
1002 offset = Type::OffsetBot; // Flatten constant access into array body
1003 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),ta->ary(),ta->klass(),false,Type::OffsetBot, ta->instance_id());
1004 } else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
1005 // range is OK as-is.
1006 tj = ta = TypeAryPtr::RANGE;
1007 } else if( offset == oopDesc::klass_offset_in_bytes() ) {
1008 tj = TypeInstPtr::KLASS; // all klass loads look alike
1009 ta = TypeAryPtr::RANGE; // generic ignored junk
1010 ptr = TypePtr::BotPTR;
1011 } else if( offset == oopDesc::mark_offset_in_bytes() ) {
1012 tj = TypeInstPtr::MARK;
1013 ta = TypeAryPtr::RANGE; // generic ignored junk
1014 ptr = TypePtr::BotPTR;
1015 } else { // Random constant offset into array body
1016 offset = Type::OffsetBot; // Flatten constant access into array body
1017 tj = ta = TypeAryPtr::make(ptr,ta->ary(),ta->klass(),false,Type::OffsetBot, ta->instance_id());
1018 }
1019 }
1020 // Arrays of fixed size alias with arrays of unknown size.
1021 if (ta->size() != TypeInt::POS) {
1022 const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);
1023 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,ta->klass(),false,offset, ta->instance_id());
1024 }
1025 // Arrays of known objects become arrays of unknown objects.
1026 if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {
1027 const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());
1028 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset, ta->instance_id());
1029 }
1030 // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
1031 // cannot be distinguished by bytecode alone.
1032 if (ta->elem() == TypeInt::BOOL) {
1033 const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());
1034 ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);
1035 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset, ta->instance_id());
1036 }
1037 // During the 2nd round of IterGVN, NotNull castings are removed.
1038 // Make sure the Bottom and NotNull variants alias the same.
1039 // Also, make sure exact and non-exact variants alias the same.
1040 if( ptr == TypePtr::NotNull || ta->klass_is_exact() ) {
1041 if (ta->const_oop()) {
1042 tj = ta = TypeAryPtr::make(TypePtr::Constant,ta->const_oop(),ta->ary(),ta->klass(),false,offset);
1043 } else {
1044 tj = ta = TypeAryPtr::make(TypePtr::BotPTR,ta->ary(),ta->klass(),false,offset);
1045 }
1046 }
1047 }
1049 // Oop pointers need some flattening
1050 const TypeInstPtr *to = tj->isa_instptr();
1051 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {
1052 if( ptr == TypePtr::Constant ) {
1053 // No constant oop pointers (such as Strings); they alias with
1054 // unknown strings.
1055 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
1056 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
1057 // During the 2nd round of IterGVN, NotNull castings are removed.
1058 // Make sure the Bottom and NotNull variants alias the same.
1059 // Also, make sure exact and non-exact variants alias the same.
1060 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset, to->instance_id());
1061 }
1062 // Canonicalize the holder of this field
1063 ciInstanceKlass *k = to->klass()->as_instance_klass();
1064 if (offset >= 0 && offset < oopDesc::header_size() * wordSize) {
1065 // First handle header references such as a LoadKlassNode, even if the
1066 // object's klass is unloaded at compile time (4965979).
1067 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset, to->instance_id());
1068 } else if (offset < 0 || offset >= k->size_helper() * wordSize) {
1069 to = NULL;
1070 tj = TypeOopPtr::BOTTOM;
1071 offset = tj->offset();
1072 } else {
1073 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset);
1074 if (!k->equals(canonical_holder) || tj->offset() != offset) {
1075 tj = to = TypeInstPtr::make(TypePtr::BotPTR, canonical_holder, false, NULL, offset, to->instance_id());
1076 }
1077 }
1078 }
1080 // Klass pointers to object array klasses need some flattening
1081 const TypeKlassPtr *tk = tj->isa_klassptr();
1082 if( tk ) {
1083 // If we are referencing a field within a Klass, we need
1084 // to assume the worst case of an Object. Both exact and
1085 // inexact types must flatten to the same alias class.
1086 // Since the flattened result for a klass is defined to be
1087 // precisely java.lang.Object, use a constant ptr.
1088 if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
1090 tj = tk = TypeKlassPtr::make(TypePtr::Constant,
1091 TypeKlassPtr::OBJECT->klass(),
1092 offset);
1093 }
1095 ciKlass* klass = tk->klass();
1096 if( klass->is_obj_array_klass() ) {
1097 ciKlass* k = TypeAryPtr::OOPS->klass();
1098 if( !k || !k->is_loaded() ) // Only fails for some -Xcomp runs
1099 k = TypeInstPtr::BOTTOM->klass();
1100 tj = tk = TypeKlassPtr::make( TypePtr::NotNull, k, offset );
1101 }
1103 // Check for precise loads from the primary supertype array and force them
1104 // to the supertype cache alias index. Check for generic array loads from
1105 // the primary supertype array and also force them to the supertype cache
1106 // alias index. Since the same load can reach both, we need to merge
1107 // these 2 disparate memories into the same alias class. Since the
1108 // primary supertype array is read-only, there's no chance of confusion
1109 // where we bypass an array load and an array store.
1110 uint off2 = offset - Klass::primary_supers_offset_in_bytes();
1111 if( offset == Type::OffsetBot ||
1112 off2 < Klass::primary_super_limit()*wordSize ) {
1113 offset = sizeof(oopDesc) +Klass::secondary_super_cache_offset_in_bytes();
1114 tj = tk = TypeKlassPtr::make( TypePtr::NotNull, tk->klass(), offset );
1115 }
1116 }
1118 // Flatten all Raw pointers together.
1119 if (tj->base() == Type::RawPtr)
1120 tj = TypeRawPtr::BOTTOM;
1122 if (tj->base() == Type::AnyPtr)
1123 tj = TypePtr::BOTTOM; // An error, which the caller must check for.
1125 // Flatten all to bottom for now
1126 switch( _AliasLevel ) {
1127 case 0:
1128 tj = TypePtr::BOTTOM;
1129 break;
1130 case 1: // Flatten to: oop, static, field or array
1131 switch (tj->base()) {
1132 //case Type::AryPtr: tj = TypeAryPtr::RANGE; break;
1133 case Type::RawPtr: tj = TypeRawPtr::BOTTOM; break;
1134 case Type::AryPtr: // do not distinguish arrays at all
1135 case Type::InstPtr: tj = TypeInstPtr::BOTTOM; break;
1136 case Type::KlassPtr: tj = TypeKlassPtr::OBJECT; break;
1137 case Type::AnyPtr: tj = TypePtr::BOTTOM; break; // caller checks it
1138 default: ShouldNotReachHere();
1139 }
1140 break;
1141 case 2: // No collasping at level 2; keep all splits
1142 case 3: // No collasping at level 3; keep all splits
1143 break;
1144 default:
1145 Unimplemented();
1146 }
1148 offset = tj->offset();
1149 assert( offset != Type::OffsetTop, "Offset has fallen from constant" );
1151 assert( (offset != Type::OffsetBot && tj->base() != Type::AryPtr) ||
1152 (offset == Type::OffsetBot && tj->base() == Type::AryPtr) ||
1153 (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) ||
1154 (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) ||
1155 (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) ||
1156 (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) ||
1157 (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr) ,
1158 "For oops, klasses, raw offset must be constant; for arrays the offset is never known" );
1159 assert( tj->ptr() != TypePtr::TopPTR &&
1160 tj->ptr() != TypePtr::AnyNull &&
1161 tj->ptr() != TypePtr::Null, "No imprecise addresses" );
1162 // assert( tj->ptr() != TypePtr::Constant ||
1163 // tj->base() == Type::RawPtr ||
1164 // tj->base() == Type::KlassPtr, "No constant oop addresses" );
1166 return tj;
1167 }
1169 void Compile::AliasType::Init(int i, const TypePtr* at) {
1170 _index = i;
1171 _adr_type = at;
1172 _field = NULL;
1173 _is_rewritable = true; // default
1174 const TypeOopPtr *atoop = (at != NULL) ? at->isa_oopptr() : NULL;
1175 if (atoop != NULL && atoop->is_instance()) {
1176 const TypeOopPtr *gt = atoop->cast_to_instance(TypeOopPtr::UNKNOWN_INSTANCE);
1177 _general_index = Compile::current()->get_alias_index(gt);
1178 } else {
1179 _general_index = 0;
1180 }
1181 }
1183 //---------------------------------print_on------------------------------------
1184 #ifndef PRODUCT
1185 void Compile::AliasType::print_on(outputStream* st) {
1186 if (index() < 10)
1187 st->print("@ <%d> ", index());
1188 else st->print("@ <%d>", index());
1189 st->print(is_rewritable() ? " " : " RO");
1190 int offset = adr_type()->offset();
1191 if (offset == Type::OffsetBot)
1192 st->print(" +any");
1193 else st->print(" +%-3d", offset);
1194 st->print(" in ");
1195 adr_type()->dump_on(st);
1196 const TypeOopPtr* tjp = adr_type()->isa_oopptr();
1197 if (field() != NULL && tjp) {
1198 if (tjp->klass() != field()->holder() ||
1199 tjp->offset() != field()->offset_in_bytes()) {
1200 st->print(" != ");
1201 field()->print();
1202 st->print(" ***");
1203 }
1204 }
1205 }
1207 void print_alias_types() {
1208 Compile* C = Compile::current();
1209 tty->print_cr("--- Alias types, AliasIdxBot .. %d", C->num_alias_types()-1);
1210 for (int idx = Compile::AliasIdxBot; idx < C->num_alias_types(); idx++) {
1211 C->alias_type(idx)->print_on(tty);
1212 tty->cr();
1213 }
1214 }
1215 #endif
1218 //----------------------------probe_alias_cache--------------------------------
1219 Compile::AliasCacheEntry* Compile::probe_alias_cache(const TypePtr* adr_type) {
1220 intptr_t key = (intptr_t) adr_type;
1221 key ^= key >> logAliasCacheSize;
1222 return &_alias_cache[key & right_n_bits(logAliasCacheSize)];
1223 }
1226 //-----------------------------grow_alias_types--------------------------------
1227 void Compile::grow_alias_types() {
1228 const int old_ats = _max_alias_types; // how many before?
1229 const int new_ats = old_ats; // how many more?
1230 const int grow_ats = old_ats+new_ats; // how many now?
1231 _max_alias_types = grow_ats;
1232 _alias_types = REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats);
1233 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats);
1234 Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);
1235 for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i];
1236 }
1239 //--------------------------------find_alias_type------------------------------
1240 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create) {
1241 if (_AliasLevel == 0)
1242 return alias_type(AliasIdxBot);
1244 AliasCacheEntry* ace = probe_alias_cache(adr_type);
1245 if (ace->_adr_type == adr_type) {
1246 return alias_type(ace->_index);
1247 }
1249 // Handle special cases.
1250 if (adr_type == NULL) return alias_type(AliasIdxTop);
1251 if (adr_type == TypePtr::BOTTOM) return alias_type(AliasIdxBot);
1253 // Do it the slow way.
1254 const TypePtr* flat = flatten_alias_type(adr_type);
1256 #ifdef ASSERT
1257 assert(flat == flatten_alias_type(flat), "idempotent");
1258 assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr");
1259 if (flat->isa_oopptr() && !flat->isa_klassptr()) {
1260 const TypeOopPtr* foop = flat->is_oopptr();
1261 const TypePtr* xoop = foop->cast_to_exactness(!foop->klass_is_exact())->is_ptr();
1262 assert(foop == flatten_alias_type(xoop), "exactness must not affect alias type");
1263 }
1264 assert(flat == flatten_alias_type(flat), "exact bit doesn't matter");
1265 #endif
1267 int idx = AliasIdxTop;
1268 for (int i = 0; i < num_alias_types(); i++) {
1269 if (alias_type(i)->adr_type() == flat) {
1270 idx = i;
1271 break;
1272 }
1273 }
1275 if (idx == AliasIdxTop) {
1276 if (no_create) return NULL;
1277 // Grow the array if necessary.
1278 if (_num_alias_types == _max_alias_types) grow_alias_types();
1279 // Add a new alias type.
1280 idx = _num_alias_types++;
1281 _alias_types[idx]->Init(idx, flat);
1282 if (flat == TypeInstPtr::KLASS) alias_type(idx)->set_rewritable(false);
1283 if (flat == TypeAryPtr::RANGE) alias_type(idx)->set_rewritable(false);
1284 if (flat->isa_instptr()) {
1285 if (flat->offset() == java_lang_Class::klass_offset_in_bytes()
1286 && flat->is_instptr()->klass() == env()->Class_klass())
1287 alias_type(idx)->set_rewritable(false);
1288 }
1289 if (flat->isa_klassptr()) {
1290 if (flat->offset() == Klass::super_check_offset_offset_in_bytes() + (int)sizeof(oopDesc))
1291 alias_type(idx)->set_rewritable(false);
1292 if (flat->offset() == Klass::modifier_flags_offset_in_bytes() + (int)sizeof(oopDesc))
1293 alias_type(idx)->set_rewritable(false);
1294 if (flat->offset() == Klass::access_flags_offset_in_bytes() + (int)sizeof(oopDesc))
1295 alias_type(idx)->set_rewritable(false);
1296 if (flat->offset() == Klass::java_mirror_offset_in_bytes() + (int)sizeof(oopDesc))
1297 alias_type(idx)->set_rewritable(false);
1298 }
1299 // %%% (We would like to finalize JavaThread::threadObj_offset(),
1300 // but the base pointer type is not distinctive enough to identify
1301 // references into JavaThread.)
1303 // Check for final instance fields.
1304 const TypeInstPtr* tinst = flat->isa_instptr();
1305 if (tinst && tinst->offset() >= oopDesc::header_size() * wordSize) {
1306 ciInstanceKlass *k = tinst->klass()->as_instance_klass();
1307 ciField* field = k->get_field_by_offset(tinst->offset(), false);
1308 // Set field() and is_rewritable() attributes.
1309 if (field != NULL) alias_type(idx)->set_field(field);
1310 }
1311 const TypeKlassPtr* tklass = flat->isa_klassptr();
1312 // Check for final static fields.
1313 if (tklass && tklass->klass()->is_instance_klass()) {
1314 ciInstanceKlass *k = tklass->klass()->as_instance_klass();
1315 ciField* field = k->get_field_by_offset(tklass->offset(), true);
1316 // Set field() and is_rewritable() attributes.
1317 if (field != NULL) alias_type(idx)->set_field(field);
1318 }
1319 }
1321 // Fill the cache for next time.
1322 ace->_adr_type = adr_type;
1323 ace->_index = idx;
1324 assert(alias_type(adr_type) == alias_type(idx), "type must be installed");
1326 // Might as well try to fill the cache for the flattened version, too.
1327 AliasCacheEntry* face = probe_alias_cache(flat);
1328 if (face->_adr_type == NULL) {
1329 face->_adr_type = flat;
1330 face->_index = idx;
1331 assert(alias_type(flat) == alias_type(idx), "flat type must work too");
1332 }
1334 return alias_type(idx);
1335 }
1338 Compile::AliasType* Compile::alias_type(ciField* field) {
1339 const TypeOopPtr* t;
1340 if (field->is_static())
1341 t = TypeKlassPtr::make(field->holder());
1342 else
1343 t = TypeOopPtr::make_from_klass_raw(field->holder());
1344 AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()));
1345 assert(field->is_final() == !atp->is_rewritable(), "must get the rewritable bits correct");
1346 return atp;
1347 }
1350 //------------------------------have_alias_type--------------------------------
1351 bool Compile::have_alias_type(const TypePtr* adr_type) {
1352 AliasCacheEntry* ace = probe_alias_cache(adr_type);
1353 if (ace->_adr_type == adr_type) {
1354 return true;
1355 }
1357 // Handle special cases.
1358 if (adr_type == NULL) return true;
1359 if (adr_type == TypePtr::BOTTOM) return true;
1361 return find_alias_type(adr_type, true) != NULL;
1362 }
1364 //-----------------------------must_alias--------------------------------------
1365 // True if all values of the given address type are in the given alias category.
1366 bool Compile::must_alias(const TypePtr* adr_type, int alias_idx) {
1367 if (alias_idx == AliasIdxBot) return true; // the universal category
1368 if (adr_type == NULL) return true; // NULL serves as TypePtr::TOP
1369 if (alias_idx == AliasIdxTop) return false; // the empty category
1370 if (adr_type->base() == Type::AnyPtr) return false; // TypePtr::BOTTOM or its twins
1372 // the only remaining possible overlap is identity
1373 int adr_idx = get_alias_index(adr_type);
1374 assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, "");
1375 assert(adr_idx == alias_idx ||
1376 (alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOM
1377 && adr_type != TypeOopPtr::BOTTOM),
1378 "should not be testing for overlap with an unsafe pointer");
1379 return adr_idx == alias_idx;
1380 }
1382 //------------------------------can_alias--------------------------------------
1383 // True if any values of the given address type are in the given alias category.
1384 bool Compile::can_alias(const TypePtr* adr_type, int alias_idx) {
1385 if (alias_idx == AliasIdxTop) return false; // the empty category
1386 if (adr_type == NULL) return false; // NULL serves as TypePtr::TOP
1387 if (alias_idx == AliasIdxBot) return true; // the universal category
1388 if (adr_type->base() == Type::AnyPtr) return true; // TypePtr::BOTTOM or its twins
1390 // the only remaining possible overlap is identity
1391 int adr_idx = get_alias_index(adr_type);
1392 assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, "");
1393 return adr_idx == alias_idx;
1394 }
1398 //---------------------------pop_warm_call-------------------------------------
1399 WarmCallInfo* Compile::pop_warm_call() {
1400 WarmCallInfo* wci = _warm_calls;
1401 if (wci != NULL) _warm_calls = wci->remove_from(wci);
1402 return wci;
1403 }
1405 //----------------------------Inline_Warm--------------------------------------
1406 int Compile::Inline_Warm() {
1407 // If there is room, try to inline some more warm call sites.
1408 // %%% Do a graph index compaction pass when we think we're out of space?
1409 if (!InlineWarmCalls) return 0;
1411 int calls_made_hot = 0;
1412 int room_to_grow = NodeCountInliningCutoff - unique();
1413 int amount_to_grow = MIN2(room_to_grow, (int)NodeCountInliningStep);
1414 int amount_grown = 0;
1415 WarmCallInfo* call;
1416 while (amount_to_grow > 0 && (call = pop_warm_call()) != NULL) {
1417 int est_size = (int)call->size();
1418 if (est_size > (room_to_grow - amount_grown)) {
1419 // This one won't fit anyway. Get rid of it.
1420 call->make_cold();
1421 continue;
1422 }
1423 call->make_hot();
1424 calls_made_hot++;
1425 amount_grown += est_size;
1426 amount_to_grow -= est_size;
1427 }
1429 if (calls_made_hot > 0) set_major_progress();
1430 return calls_made_hot;
1431 }
1434 //----------------------------Finish_Warm--------------------------------------
1435 void Compile::Finish_Warm() {
1436 if (!InlineWarmCalls) return;
1437 if (failing()) return;
1438 if (warm_calls() == NULL) return;
1440 // Clean up loose ends, if we are out of space for inlining.
1441 WarmCallInfo* call;
1442 while ((call = pop_warm_call()) != NULL) {
1443 call->make_cold();
1444 }
1445 }
1448 //------------------------------Optimize---------------------------------------
1449 // Given a graph, optimize it.
1450 void Compile::Optimize() {
1451 TracePhase t1("optimizer", &_t_optimizer, true);
1453 #ifndef PRODUCT
1454 if (env()->break_at_compile()) {
1455 BREAKPOINT;
1456 }
1458 #endif
1460 ResourceMark rm;
1461 int loop_opts_cnt;
1463 NOT_PRODUCT( verify_graph_edges(); )
1465 print_method("Start");
1467 {
1468 // Iterative Global Value Numbering, including ideal transforms
1469 // Initialize IterGVN with types and values from parse-time GVN
1470 PhaseIterGVN igvn(initial_gvn());
1471 {
1472 NOT_PRODUCT( TracePhase t2("iterGVN", &_t_iterGVN, TimeCompiler); )
1473 igvn.optimize();
1474 }
1476 print_method("Iter GVN 1", 2);
1478 if (failing()) return;
1480 // get rid of the connection graph since it's information is not
1481 // updated by optimizations
1482 _congraph = NULL;
1485 // Loop transforms on the ideal graph. Range Check Elimination,
1486 // peeling, unrolling, etc.
1488 // Set loop opts counter
1489 loop_opts_cnt = num_loop_opts();
1490 if((loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
1491 {
1492 TracePhase t2("idealLoop", &_t_idealLoop, true);
1493 PhaseIdealLoop ideal_loop( igvn, NULL, true );
1494 loop_opts_cnt--;
1495 if (major_progress()) print_method("PhaseIdealLoop 1", 2);
1496 if (failing()) return;
1497 }
1498 // Loop opts pass if partial peeling occurred in previous pass
1499 if(PartialPeelLoop && major_progress() && (loop_opts_cnt > 0)) {
1500 TracePhase t3("idealLoop", &_t_idealLoop, true);
1501 PhaseIdealLoop ideal_loop( igvn, NULL, false );
1502 loop_opts_cnt--;
1503 if (major_progress()) print_method("PhaseIdealLoop 2", 2);
1504 if (failing()) return;
1505 }
1506 // Loop opts pass for loop-unrolling before CCP
1507 if(major_progress() && (loop_opts_cnt > 0)) {
1508 TracePhase t4("idealLoop", &_t_idealLoop, true);
1509 PhaseIdealLoop ideal_loop( igvn, NULL, false );
1510 loop_opts_cnt--;
1511 if (major_progress()) print_method("PhaseIdealLoop 3", 2);
1512 }
1513 }
1514 if (failing()) return;
1516 // Conditional Constant Propagation;
1517 PhaseCCP ccp( &igvn );
1518 assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
1519 {
1520 TracePhase t2("ccp", &_t_ccp, true);
1521 ccp.do_transform();
1522 }
1523 print_method("PhaseCPP 1", 2);
1525 assert( true, "Break here to ccp.dump_old2new_map()");
1527 // Iterative Global Value Numbering, including ideal transforms
1528 {
1529 NOT_PRODUCT( TracePhase t2("iterGVN2", &_t_iterGVN2, TimeCompiler); )
1530 igvn = ccp;
1531 igvn.optimize();
1532 }
1534 print_method("Iter GVN 2", 2);
1536 if (failing()) return;
1538 // Loop transforms on the ideal graph. Range Check Elimination,
1539 // peeling, unrolling, etc.
1540 if(loop_opts_cnt > 0) {
1541 debug_only( int cnt = 0; );
1542 while(major_progress() && (loop_opts_cnt > 0)) {
1543 TracePhase t2("idealLoop", &_t_idealLoop, true);
1544 assert( cnt++ < 40, "infinite cycle in loop optimization" );
1545 PhaseIdealLoop ideal_loop( igvn, NULL, true );
1546 loop_opts_cnt--;
1547 if (major_progress()) print_method("PhaseIdealLoop iterations", 2);
1548 if (failing()) return;
1549 }
1550 }
1551 {
1552 NOT_PRODUCT( TracePhase t2("macroExpand", &_t_macroExpand, TimeCompiler); )
1553 PhaseMacroExpand mex(igvn);
1554 if (mex.expand_macro_nodes()) {
1555 assert(failing(), "must bail out w/ explicit message");
1556 return;
1557 }
1558 }
1560 } // (End scope of igvn; run destructor if necessary for asserts.)
1562 // A method with only infinite loops has no edges entering loops from root
1563 {
1564 NOT_PRODUCT( TracePhase t2("graphReshape", &_t_graphReshaping, TimeCompiler); )
1565 if (final_graph_reshaping()) {
1566 assert(failing(), "must bail out w/ explicit message");
1567 return;
1568 }
1569 }
1571 print_method("Optimize finished", 2);
1572 }
1575 //------------------------------Code_Gen---------------------------------------
1576 // Given a graph, generate code for it
1577 void Compile::Code_Gen() {
1578 if (failing()) return;
1580 // Perform instruction selection. You might think we could reclaim Matcher
1581 // memory PDQ, but actually the Matcher is used in generating spill code.
1582 // Internals of the Matcher (including some VectorSets) must remain live
1583 // for awhile - thus I cannot reclaim Matcher memory lest a VectorSet usage
1584 // set a bit in reclaimed memory.
1586 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
1587 // nodes. Mapping is only valid at the root of each matched subtree.
1588 NOT_PRODUCT( verify_graph_edges(); )
1590 Node_List proj_list;
1591 Matcher m(proj_list);
1592 _matcher = &m;
1593 {
1594 TracePhase t2("matcher", &_t_matcher, true);
1595 m.match();
1596 }
1597 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
1598 // nodes. Mapping is only valid at the root of each matched subtree.
1599 NOT_PRODUCT( verify_graph_edges(); )
1601 // If you have too many nodes, or if matching has failed, bail out
1602 check_node_count(0, "out of nodes matching instructions");
1603 if (failing()) return;
1605 // Build a proper-looking CFG
1606 PhaseCFG cfg(node_arena(), root(), m);
1607 _cfg = &cfg;
1608 {
1609 NOT_PRODUCT( TracePhase t2("scheduler", &_t_scheduler, TimeCompiler); )
1610 cfg.Dominators();
1611 if (failing()) return;
1613 NOT_PRODUCT( verify_graph_edges(); )
1615 cfg.Estimate_Block_Frequency();
1616 cfg.GlobalCodeMotion(m,unique(),proj_list);
1618 print_method("Global code motion", 2);
1620 if (failing()) return;
1621 NOT_PRODUCT( verify_graph_edges(); )
1623 debug_only( cfg.verify(); )
1624 }
1625 NOT_PRODUCT( verify_graph_edges(); )
1627 PhaseChaitin regalloc(unique(),cfg,m);
1628 _regalloc = ®alloc;
1629 {
1630 TracePhase t2("regalloc", &_t_registerAllocation, true);
1631 // Perform any platform dependent preallocation actions. This is used,
1632 // for example, to avoid taking an implicit null pointer exception
1633 // using the frame pointer on win95.
1634 _regalloc->pd_preallocate_hook();
1636 // Perform register allocation. After Chaitin, use-def chains are
1637 // no longer accurate (at spill code) and so must be ignored.
1638 // Node->LRG->reg mappings are still accurate.
1639 _regalloc->Register_Allocate();
1641 // Bail out if the allocator builds too many nodes
1642 if (failing()) return;
1643 }
1645 // Prior to register allocation we kept empty basic blocks in case the
1646 // the allocator needed a place to spill. After register allocation we
1647 // are not adding any new instructions. If any basic block is empty, we
1648 // can now safely remove it.
1649 {
1650 NOT_PRODUCT( TracePhase t2("removeEmpty", &_t_removeEmptyBlocks, TimeCompiler); )
1651 cfg.RemoveEmpty();
1652 }
1654 // Perform any platform dependent postallocation verifications.
1655 debug_only( _regalloc->pd_postallocate_verify_hook(); )
1657 // Apply peephole optimizations
1658 if( OptoPeephole ) {
1659 NOT_PRODUCT( TracePhase t2("peephole", &_t_peephole, TimeCompiler); )
1660 PhasePeephole peep( _regalloc, cfg);
1661 peep.do_transform();
1662 }
1664 // Convert Nodes to instruction bits in a buffer
1665 {
1666 // %%%% workspace merge brought two timers together for one job
1667 TracePhase t2a("output", &_t_output, true);
1668 NOT_PRODUCT( TraceTime t2b(NULL, &_t_codeGeneration, TimeCompiler, false); )
1669 Output();
1670 }
1672 print_method("End");
1674 // He's dead, Jim.
1675 _cfg = (PhaseCFG*)0xdeadbeef;
1676 _regalloc = (PhaseChaitin*)0xdeadbeef;
1677 }
1680 //------------------------------dump_asm---------------------------------------
1681 // Dump formatted assembly
1682 #ifndef PRODUCT
1683 void Compile::dump_asm(int *pcs, uint pc_limit) {
1684 bool cut_short = false;
1685 tty->print_cr("#");
1686 tty->print("# "); _tf->dump(); tty->cr();
1687 tty->print_cr("#");
1689 // For all blocks
1690 int pc = 0x0; // Program counter
1691 char starts_bundle = ' ';
1692 _regalloc->dump_frame();
1694 Node *n = NULL;
1695 for( uint i=0; i<_cfg->_num_blocks; i++ ) {
1696 if (VMThread::should_terminate()) { cut_short = true; break; }
1697 Block *b = _cfg->_blocks[i];
1698 if (b->is_connector() && !Verbose) continue;
1699 n = b->_nodes[0];
1700 if (pcs && n->_idx < pc_limit)
1701 tty->print("%3.3x ", pcs[n->_idx]);
1702 else
1703 tty->print(" ");
1704 b->dump_head( &_cfg->_bbs );
1705 if (b->is_connector()) {
1706 tty->print_cr(" # Empty connector block");
1707 } else if (b->num_preds() == 2 && b->pred(1)->is_CatchProj() && b->pred(1)->as_CatchProj()->_con == CatchProjNode::fall_through_index) {
1708 tty->print_cr(" # Block is sole successor of call");
1709 }
1711 // For all instructions
1712 Node *delay = NULL;
1713 for( uint j = 0; j<b->_nodes.size(); j++ ) {
1714 if (VMThread::should_terminate()) { cut_short = true; break; }
1715 n = b->_nodes[j];
1716 if (valid_bundle_info(n)) {
1717 Bundle *bundle = node_bundling(n);
1718 if (bundle->used_in_unconditional_delay()) {
1719 delay = n;
1720 continue;
1721 }
1722 if (bundle->starts_bundle())
1723 starts_bundle = '+';
1724 }
1726 if( !n->is_Region() && // Dont print in the Assembly
1727 !n->is_Phi() && // a few noisely useless nodes
1728 !n->is_Proj() &&
1729 !n->is_MachTemp() &&
1730 !n->is_Catch() && // Would be nice to print exception table targets
1731 !n->is_MergeMem() && // Not very interesting
1732 !n->is_top() && // Debug info table constants
1733 !(n->is_Con() && !n->is_Mach())// Debug info table constants
1734 ) {
1735 if (pcs && n->_idx < pc_limit)
1736 tty->print("%3.3x", pcs[n->_idx]);
1737 else
1738 tty->print(" ");
1739 tty->print(" %c ", starts_bundle);
1740 starts_bundle = ' ';
1741 tty->print("\t");
1742 n->format(_regalloc, tty);
1743 tty->cr();
1744 }
1746 // If we have an instruction with a delay slot, and have seen a delay,
1747 // then back up and print it
1748 if (valid_bundle_info(n) && node_bundling(n)->use_unconditional_delay()) {
1749 assert(delay != NULL, "no unconditional delay instruction");
1750 if (node_bundling(delay)->starts_bundle())
1751 starts_bundle = '+';
1752 if (pcs && n->_idx < pc_limit)
1753 tty->print("%3.3x", pcs[n->_idx]);
1754 else
1755 tty->print(" ");
1756 tty->print(" %c ", starts_bundle);
1757 starts_bundle = ' ';
1758 tty->print("\t");
1759 delay->format(_regalloc, tty);
1760 tty->print_cr("");
1761 delay = NULL;
1762 }
1764 // Dump the exception table as well
1765 if( n->is_Catch() && (Verbose || WizardMode) ) {
1766 // Print the exception table for this offset
1767 _handler_table.print_subtable_for(pc);
1768 }
1769 }
1771 if (pcs && n->_idx < pc_limit)
1772 tty->print_cr("%3.3x", pcs[n->_idx]);
1773 else
1774 tty->print_cr("");
1776 assert(cut_short || delay == NULL, "no unconditional delay branch");
1778 } // End of per-block dump
1779 tty->print_cr("");
1781 if (cut_short) tty->print_cr("*** disassembly is cut short ***");
1782 }
1783 #endif
1785 //------------------------------Final_Reshape_Counts---------------------------
1786 // This class defines counters to help identify when a method
1787 // may/must be executed using hardware with only 24-bit precision.
1788 struct Final_Reshape_Counts : public StackObj {
1789 int _call_count; // count non-inlined 'common' calls
1790 int _float_count; // count float ops requiring 24-bit precision
1791 int _double_count; // count double ops requiring more precision
1792 int _java_call_count; // count non-inlined 'java' calls
1793 VectorSet _visited; // Visitation flags
1794 Node_List _tests; // Set of IfNodes & PCTableNodes
1796 Final_Reshape_Counts() :
1797 _call_count(0), _float_count(0), _double_count(0), _java_call_count(0),
1798 _visited( Thread::current()->resource_area() ) { }
1800 void inc_call_count () { _call_count ++; }
1801 void inc_float_count () { _float_count ++; }
1802 void inc_double_count() { _double_count++; }
1803 void inc_java_call_count() { _java_call_count++; }
1805 int get_call_count () const { return _call_count ; }
1806 int get_float_count () const { return _float_count ; }
1807 int get_double_count() const { return _double_count; }
1808 int get_java_call_count() const { return _java_call_count; }
1809 };
1811 static bool oop_offset_is_sane(const TypeInstPtr* tp) {
1812 ciInstanceKlass *k = tp->klass()->as_instance_klass();
1813 // Make sure the offset goes inside the instance layout.
1814 return (uint)tp->offset() < (uint)(oopDesc::header_size() + k->nonstatic_field_size())*wordSize;
1815 // Note that OffsetBot and OffsetTop are very negative.
1816 }
1818 //------------------------------final_graph_reshaping_impl----------------------
1819 // Implement items 1-5 from final_graph_reshaping below.
1820 static void final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &fpu ) {
1822 uint nop = n->Opcode();
1824 // Check for 2-input instruction with "last use" on right input.
1825 // Swap to left input. Implements item (2).
1826 if( n->req() == 3 && // two-input instruction
1827 n->in(1)->outcnt() > 1 && // left use is NOT a last use
1828 (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
1829 n->in(2)->outcnt() == 1 &&// right use IS a last use
1830 !n->in(2)->is_Con() ) { // right use is not a constant
1831 // Check for commutative opcode
1832 switch( nop ) {
1833 case Op_AddI: case Op_AddF: case Op_AddD: case Op_AddL:
1834 case Op_MaxI: case Op_MinI:
1835 case Op_MulI: case Op_MulF: case Op_MulD: case Op_MulL:
1836 case Op_AndL: case Op_XorL: case Op_OrL:
1837 case Op_AndI: case Op_XorI: case Op_OrI: {
1838 // Move "last use" input to left by swapping inputs
1839 n->swap_edges(1, 2);
1840 break;
1841 }
1842 default:
1843 break;
1844 }
1845 }
1847 // Count FPU ops and common calls, implements item (3)
1848 switch( nop ) {
1849 // Count all float operations that may use FPU
1850 case Op_AddF:
1851 case Op_SubF:
1852 case Op_MulF:
1853 case Op_DivF:
1854 case Op_NegF:
1855 case Op_ModF:
1856 case Op_ConvI2F:
1857 case Op_ConF:
1858 case Op_CmpF:
1859 case Op_CmpF3:
1860 // case Op_ConvL2F: // longs are split into 32-bit halves
1861 fpu.inc_float_count();
1862 break;
1864 case Op_ConvF2D:
1865 case Op_ConvD2F:
1866 fpu.inc_float_count();
1867 fpu.inc_double_count();
1868 break;
1870 // Count all double operations that may use FPU
1871 case Op_AddD:
1872 case Op_SubD:
1873 case Op_MulD:
1874 case Op_DivD:
1875 case Op_NegD:
1876 case Op_ModD:
1877 case Op_ConvI2D:
1878 case Op_ConvD2I:
1879 // case Op_ConvL2D: // handled by leaf call
1880 // case Op_ConvD2L: // handled by leaf call
1881 case Op_ConD:
1882 case Op_CmpD:
1883 case Op_CmpD3:
1884 fpu.inc_double_count();
1885 break;
1886 case Op_Opaque1: // Remove Opaque Nodes before matching
1887 case Op_Opaque2: // Remove Opaque Nodes before matching
1888 n->replace_by(n->in(1));
1889 break;
1890 case Op_CallStaticJava:
1891 case Op_CallJava:
1892 case Op_CallDynamicJava:
1893 fpu.inc_java_call_count(); // Count java call site;
1894 case Op_CallRuntime:
1895 case Op_CallLeaf:
1896 case Op_CallLeafNoFP: {
1897 assert( n->is_Call(), "" );
1898 CallNode *call = n->as_Call();
1899 // Count call sites where the FP mode bit would have to be flipped.
1900 // Do not count uncommon runtime calls:
1901 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
1902 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...
1903 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) {
1904 fpu.inc_call_count(); // Count the call site
1905 } else { // See if uncommon argument is shared
1906 Node *n = call->in(TypeFunc::Parms);
1907 int nop = n->Opcode();
1908 // Clone shared simple arguments to uncommon calls, item (1).
1909 if( n->outcnt() > 1 &&
1910 !n->is_Proj() &&
1911 nop != Op_CreateEx &&
1912 nop != Op_CheckCastPP &&
1913 !n->is_Mem() ) {
1914 Node *x = n->clone();
1915 call->set_req( TypeFunc::Parms, x );
1916 }
1917 }
1918 break;
1919 }
1921 case Op_StoreD:
1922 case Op_LoadD:
1923 case Op_LoadD_unaligned:
1924 fpu.inc_double_count();
1925 goto handle_mem;
1926 case Op_StoreF:
1927 case Op_LoadF:
1928 fpu.inc_float_count();
1929 goto handle_mem;
1931 case Op_StoreB:
1932 case Op_StoreC:
1933 case Op_StoreCM:
1934 case Op_StorePConditional:
1935 case Op_StoreI:
1936 case Op_StoreL:
1937 case Op_StoreLConditional:
1938 case Op_CompareAndSwapI:
1939 case Op_CompareAndSwapL:
1940 case Op_CompareAndSwapP:
1941 case Op_StoreP:
1942 case Op_LoadB:
1943 case Op_LoadC:
1944 case Op_LoadI:
1945 case Op_LoadKlass:
1946 case Op_LoadL:
1947 case Op_LoadL_unaligned:
1948 case Op_LoadPLocked:
1949 case Op_LoadLLocked:
1950 case Op_LoadP:
1951 case Op_LoadRange:
1952 case Op_LoadS: {
1953 handle_mem:
1954 #ifdef ASSERT
1955 if( VerifyOptoOopOffsets ) {
1956 assert( n->is_Mem(), "" );
1957 MemNode *mem = (MemNode*)n;
1958 // Check to see if address types have grounded out somehow.
1959 const TypeInstPtr *tp = mem->in(MemNode::Address)->bottom_type()->isa_instptr();
1960 assert( !tp || oop_offset_is_sane(tp), "" );
1961 }
1962 #endif
1963 break;
1964 }
1965 case Op_If:
1966 case Op_CountedLoopEnd:
1967 fpu._tests.push(n); // Collect CFG split points
1968 break;
1970 case Op_AddP: { // Assert sane base pointers
1971 const Node *addp = n->in(AddPNode::Address);
1972 assert( !addp->is_AddP() ||
1973 addp->in(AddPNode::Base)->is_top() || // Top OK for allocation
1974 addp->in(AddPNode::Base) == n->in(AddPNode::Base),
1975 "Base pointers must match" );
1976 break;
1977 }
1979 case Op_ModI:
1980 if (UseDivMod) {
1981 // Check if a%b and a/b both exist
1982 Node* d = n->find_similar(Op_DivI);
1983 if (d) {
1984 // Replace them with a fused divmod if supported
1985 Compile* C = Compile::current();
1986 if (Matcher::has_match_rule(Op_DivModI)) {
1987 DivModINode* divmod = DivModINode::make(C, n);
1988 d->replace_by(divmod->div_proj());
1989 n->replace_by(divmod->mod_proj());
1990 } else {
1991 // replace a%b with a-((a/b)*b)
1992 Node* mult = new (C, 3) MulINode(d, d->in(2));
1993 Node* sub = new (C, 3) SubINode(d->in(1), mult);
1994 n->replace_by( sub );
1995 }
1996 }
1997 }
1998 break;
2000 case Op_ModL:
2001 if (UseDivMod) {
2002 // Check if a%b and a/b both exist
2003 Node* d = n->find_similar(Op_DivL);
2004 if (d) {
2005 // Replace them with a fused divmod if supported
2006 Compile* C = Compile::current();
2007 if (Matcher::has_match_rule(Op_DivModL)) {
2008 DivModLNode* divmod = DivModLNode::make(C, n);
2009 d->replace_by(divmod->div_proj());
2010 n->replace_by(divmod->mod_proj());
2011 } else {
2012 // replace a%b with a-((a/b)*b)
2013 Node* mult = new (C, 3) MulLNode(d, d->in(2));
2014 Node* sub = new (C, 3) SubLNode(d->in(1), mult);
2015 n->replace_by( sub );
2016 }
2017 }
2018 }
2019 break;
2021 case Op_Load16B:
2022 case Op_Load8B:
2023 case Op_Load4B:
2024 case Op_Load8S:
2025 case Op_Load4S:
2026 case Op_Load2S:
2027 case Op_Load8C:
2028 case Op_Load4C:
2029 case Op_Load2C:
2030 case Op_Load4I:
2031 case Op_Load2I:
2032 case Op_Load2L:
2033 case Op_Load4F:
2034 case Op_Load2F:
2035 case Op_Load2D:
2036 case Op_Store16B:
2037 case Op_Store8B:
2038 case Op_Store4B:
2039 case Op_Store8C:
2040 case Op_Store4C:
2041 case Op_Store2C:
2042 case Op_Store4I:
2043 case Op_Store2I:
2044 case Op_Store2L:
2045 case Op_Store4F:
2046 case Op_Store2F:
2047 case Op_Store2D:
2048 break;
2050 case Op_PackB:
2051 case Op_PackS:
2052 case Op_PackC:
2053 case Op_PackI:
2054 case Op_PackF:
2055 case Op_PackL:
2056 case Op_PackD:
2057 if (n->req()-1 > 2) {
2058 // Replace many operand PackNodes with a binary tree for matching
2059 PackNode* p = (PackNode*) n;
2060 Node* btp = p->binaryTreePack(Compile::current(), 1, n->req());
2061 n->replace_by(btp);
2062 }
2063 break;
2064 default:
2065 assert( !n->is_Call(), "" );
2066 assert( !n->is_Mem(), "" );
2067 if( n->is_If() || n->is_PCTable() )
2068 fpu._tests.push(n); // Collect CFG split points
2069 break;
2070 }
2071 }
2073 //------------------------------final_graph_reshaping_walk---------------------
2074 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
2075 // requires that the walk visits a node's inputs before visiting the node.
2076 static void final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &fpu ) {
2077 fpu._visited.set(root->_idx); // first, mark node as visited
2078 uint cnt = root->req();
2079 Node *n = root;
2080 uint i = 0;
2081 while (true) {
2082 if (i < cnt) {
2083 // Place all non-visited non-null inputs onto stack
2084 Node* m = n->in(i);
2085 ++i;
2086 if (m != NULL && !fpu._visited.test_set(m->_idx)) {
2087 cnt = m->req();
2088 nstack.push(n, i); // put on stack parent and next input's index
2089 n = m;
2090 i = 0;
2091 }
2092 } else {
2093 // Now do post-visit work
2094 final_graph_reshaping_impl( n, fpu );
2095 if (nstack.is_empty())
2096 break; // finished
2097 n = nstack.node(); // Get node from stack
2098 cnt = n->req();
2099 i = nstack.index();
2100 nstack.pop(); // Shift to the next node on stack
2101 }
2102 }
2103 }
2105 //------------------------------final_graph_reshaping--------------------------
2106 // Final Graph Reshaping.
2107 //
2108 // (1) Clone simple inputs to uncommon calls, so they can be scheduled late
2109 // and not commoned up and forced early. Must come after regular
2110 // optimizations to avoid GVN undoing the cloning. Clone constant
2111 // inputs to Loop Phis; these will be split by the allocator anyways.
2112 // Remove Opaque nodes.
2113 // (2) Move last-uses by commutative operations to the left input to encourage
2114 // Intel update-in-place two-address operations and better register usage
2115 // on RISCs. Must come after regular optimizations to avoid GVN Ideal
2116 // calls canonicalizing them back.
2117 // (3) Count the number of double-precision FP ops, single-precision FP ops
2118 // and call sites. On Intel, we can get correct rounding either by
2119 // forcing singles to memory (requires extra stores and loads after each
2120 // FP bytecode) or we can set a rounding mode bit (requires setting and
2121 // clearing the mode bit around call sites). The mode bit is only used
2122 // if the relative frequency of single FP ops to calls is low enough.
2123 // This is a key transform for SPEC mpeg_audio.
2124 // (4) Detect infinite loops; blobs of code reachable from above but not
2125 // below. Several of the Code_Gen algorithms fail on such code shapes,
2126 // so we simply bail out. Happens a lot in ZKM.jar, but also happens
2127 // from time to time in other codes (such as -Xcomp finalizer loops, etc).
2128 // Detection is by looking for IfNodes where only 1 projection is
2129 // reachable from below or CatchNodes missing some targets.
2130 // (5) Assert for insane oop offsets in debug mode.
2132 bool Compile::final_graph_reshaping() {
2133 // an infinite loop may have been eliminated by the optimizer,
2134 // in which case the graph will be empty.
2135 if (root()->req() == 1) {
2136 record_method_not_compilable("trivial infinite loop");
2137 return true;
2138 }
2140 Final_Reshape_Counts fpu;
2142 // Visit everybody reachable!
2143 // Allocate stack of size C->unique()/2 to avoid frequent realloc
2144 Node_Stack nstack(unique() >> 1);
2145 final_graph_reshaping_walk(nstack, root(), fpu);
2147 // Check for unreachable (from below) code (i.e., infinite loops).
2148 for( uint i = 0; i < fpu._tests.size(); i++ ) {
2149 Node *n = fpu._tests[i];
2150 assert( n->is_PCTable() || n->is_If(), "either PCTables or IfNodes" );
2151 // Get number of CFG targets; 2 for IfNodes or _size for PCTables.
2152 // Note that PCTables include exception targets after calls.
2153 uint expected_kids = n->is_PCTable() ? n->as_PCTable()->_size : 2;
2154 if (n->outcnt() != expected_kids) {
2155 // Check for a few special cases. Rethrow Nodes never take the
2156 // 'fall-thru' path, so expected kids is 1 less.
2157 if (n->is_PCTable() && n->in(0) && n->in(0)->in(0)) {
2158 if (n->in(0)->in(0)->is_Call()) {
2159 CallNode *call = n->in(0)->in(0)->as_Call();
2160 if (call->entry_point() == OptoRuntime::rethrow_stub()) {
2161 expected_kids--; // Rethrow always has 1 less kid
2162 } else if (call->req() > TypeFunc::Parms &&
2163 call->is_CallDynamicJava()) {
2164 // Check for null receiver. In such case, the optimizer has
2165 // detected that the virtual call will always result in a null
2166 // pointer exception. The fall-through projection of this CatchNode
2167 // will not be populated.
2168 Node *arg0 = call->in(TypeFunc::Parms);
2169 if (arg0->is_Type() &&
2170 arg0->as_Type()->type()->higher_equal(TypePtr::NULL_PTR)) {
2171 expected_kids--;
2172 }
2173 } else if (call->entry_point() == OptoRuntime::new_array_Java() &&
2174 call->req() > TypeFunc::Parms+1 &&
2175 call->is_CallStaticJava()) {
2176 // Check for negative array length. In such case, the optimizer has
2177 // detected that the allocation attempt will always result in an
2178 // exception. There is no fall-through projection of this CatchNode .
2179 Node *arg1 = call->in(TypeFunc::Parms+1);
2180 if (arg1->is_Type() &&
2181 arg1->as_Type()->type()->join(TypeInt::POS)->empty()) {
2182 expected_kids--;
2183 }
2184 }
2185 }
2186 }
2187 // Recheck with a better notion of 'expected_kids'
2188 if (n->outcnt() != expected_kids) {
2189 record_method_not_compilable("malformed control flow");
2190 return true; // Not all targets reachable!
2191 }
2192 }
2193 // Check that I actually visited all kids. Unreached kids
2194 // must be infinite loops.
2195 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++)
2196 if (!fpu._visited.test(n->fast_out(j)->_idx)) {
2197 record_method_not_compilable("infinite loop");
2198 return true; // Found unvisited kid; must be unreach
2199 }
2200 }
2202 // If original bytecodes contained a mixture of floats and doubles
2203 // check if the optimizer has made it homogenous, item (3).
2204 if( Use24BitFPMode && Use24BitFP &&
2205 fpu.get_float_count() > 32 &&
2206 fpu.get_double_count() == 0 &&
2207 (10 * fpu.get_call_count() < fpu.get_float_count()) ) {
2208 set_24_bit_selection_and_mode( false, true );
2209 }
2211 set_has_java_calls(fpu.get_java_call_count() > 0);
2213 // No infinite loops, no reason to bail out.
2214 return false;
2215 }
2217 //-----------------------------too_many_traps----------------------------------
2218 // Report if there are too many traps at the current method and bci.
2219 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
2220 bool Compile::too_many_traps(ciMethod* method,
2221 int bci,
2222 Deoptimization::DeoptReason reason) {
2223 ciMethodData* md = method->method_data();
2224 if (md->is_empty()) {
2225 // Assume the trap has not occurred, or that it occurred only
2226 // because of a transient condition during start-up in the interpreter.
2227 return false;
2228 }
2229 if (md->has_trap_at(bci, reason) != 0) {
2230 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
2231 // Also, if there are multiple reasons, or if there is no per-BCI record,
2232 // assume the worst.
2233 if (log())
2234 log()->elem("observe trap='%s' count='%d'",
2235 Deoptimization::trap_reason_name(reason),
2236 md->trap_count(reason));
2237 return true;
2238 } else {
2239 // Ignore method/bci and see if there have been too many globally.
2240 return too_many_traps(reason, md);
2241 }
2242 }
2244 // Less-accurate variant which does not require a method and bci.
2245 bool Compile::too_many_traps(Deoptimization::DeoptReason reason,
2246 ciMethodData* logmd) {
2247 if (trap_count(reason) >= (uint)PerMethodTrapLimit) {
2248 // Too many traps globally.
2249 // Note that we use cumulative trap_count, not just md->trap_count.
2250 if (log()) {
2251 int mcount = (logmd == NULL)? -1: (int)logmd->trap_count(reason);
2252 log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'",
2253 Deoptimization::trap_reason_name(reason),
2254 mcount, trap_count(reason));
2255 }
2256 return true;
2257 } else {
2258 // The coast is clear.
2259 return false;
2260 }
2261 }
2263 //--------------------------too_many_recompiles--------------------------------
2264 // Report if there are too many recompiles at the current method and bci.
2265 // Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff.
2266 // Is not eager to return true, since this will cause the compiler to use
2267 // Action_none for a trap point, to avoid too many recompilations.
2268 bool Compile::too_many_recompiles(ciMethod* method,
2269 int bci,
2270 Deoptimization::DeoptReason reason) {
2271 ciMethodData* md = method->method_data();
2272 if (md->is_empty()) {
2273 // Assume the trap has not occurred, or that it occurred only
2274 // because of a transient condition during start-up in the interpreter.
2275 return false;
2276 }
2277 // Pick a cutoff point well within PerBytecodeRecompilationCutoff.
2278 uint bc_cutoff = (uint) PerBytecodeRecompilationCutoff / 8;
2279 uint m_cutoff = (uint) PerMethodRecompilationCutoff / 2 + 1; // not zero
2280 Deoptimization::DeoptReason per_bc_reason
2281 = Deoptimization::reason_recorded_per_bytecode_if_any(reason);
2282 if ((per_bc_reason == Deoptimization::Reason_none
2283 || md->has_trap_at(bci, reason) != 0)
2284 // The trap frequency measure we care about is the recompile count:
2285 && md->trap_recompiled_at(bci)
2286 && md->overflow_recompile_count() >= bc_cutoff) {
2287 // Do not emit a trap here if it has already caused recompilations.
2288 // Also, if there are multiple reasons, or if there is no per-BCI record,
2289 // assume the worst.
2290 if (log())
2291 log()->elem("observe trap='%s recompiled' count='%d' recompiles2='%d'",
2292 Deoptimization::trap_reason_name(reason),
2293 md->trap_count(reason),
2294 md->overflow_recompile_count());
2295 return true;
2296 } else if (trap_count(reason) != 0
2297 && decompile_count() >= m_cutoff) {
2298 // Too many recompiles globally, and we have seen this sort of trap.
2299 // Use cumulative decompile_count, not just md->decompile_count.
2300 if (log())
2301 log()->elem("observe trap='%s' count='%d' mcount='%d' decompiles='%d' mdecompiles='%d'",
2302 Deoptimization::trap_reason_name(reason),
2303 md->trap_count(reason), trap_count(reason),
2304 md->decompile_count(), decompile_count());
2305 return true;
2306 } else {
2307 // The coast is clear.
2308 return false;
2309 }
2310 }
2313 #ifndef PRODUCT
2314 //------------------------------verify_graph_edges---------------------------
2315 // Walk the Graph and verify that there is a one-to-one correspondence
2316 // between Use-Def edges and Def-Use edges in the graph.
2317 void Compile::verify_graph_edges(bool no_dead_code) {
2318 if (VerifyGraphEdges) {
2319 ResourceArea *area = Thread::current()->resource_area();
2320 Unique_Node_List visited(area);
2321 // Call recursive graph walk to check edges
2322 _root->verify_edges(visited);
2323 if (no_dead_code) {
2324 // Now make sure that no visited node is used by an unvisited node.
2325 bool dead_nodes = 0;
2326 Unique_Node_List checked(area);
2327 while (visited.size() > 0) {
2328 Node* n = visited.pop();
2329 checked.push(n);
2330 for (uint i = 0; i < n->outcnt(); i++) {
2331 Node* use = n->raw_out(i);
2332 if (checked.member(use)) continue; // already checked
2333 if (visited.member(use)) continue; // already in the graph
2334 if (use->is_Con()) continue; // a dead ConNode is OK
2335 // At this point, we have found a dead node which is DU-reachable.
2336 if (dead_nodes++ == 0)
2337 tty->print_cr("*** Dead nodes reachable via DU edges:");
2338 use->dump(2);
2339 tty->print_cr("---");
2340 checked.push(use); // No repeats; pretend it is now checked.
2341 }
2342 }
2343 assert(dead_nodes == 0, "using nodes must be reachable from root");
2344 }
2345 }
2346 }
2347 #endif
2349 // The Compile object keeps track of failure reasons separately from the ciEnv.
2350 // This is required because there is not quite a 1-1 relation between the
2351 // ciEnv and its compilation task and the Compile object. Note that one
2352 // ciEnv might use two Compile objects, if C2Compiler::compile_method decides
2353 // to backtrack and retry without subsuming loads. Other than this backtracking
2354 // behavior, the Compile's failure reason is quietly copied up to the ciEnv
2355 // by the logic in C2Compiler.
2356 void Compile::record_failure(const char* reason) {
2357 if (log() != NULL) {
2358 log()->elem("failure reason='%s' phase='compile'", reason);
2359 }
2360 if (_failure_reason == NULL) {
2361 // Record the first failure reason.
2362 _failure_reason = reason;
2363 }
2364 _root = NULL; // flush the graph, too
2365 }
2367 Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator, bool dolog)
2368 : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false)
2369 {
2370 if (dolog) {
2371 C = Compile::current();
2372 _log = C->log();
2373 } else {
2374 C = NULL;
2375 _log = NULL;
2376 }
2377 if (_log != NULL) {
2378 _log->begin_head("phase name='%s' nodes='%d'", name, C->unique());
2379 _log->stamp();
2380 _log->end_head();
2381 }
2382 }
2384 Compile::TracePhase::~TracePhase() {
2385 if (_log != NULL) {
2386 _log->done("phase nodes='%d'", C->unique());
2387 }
2388 }