annotate src/share/vm/opto/compile.cpp @ 6009:45467c53f178

Merge
author kvn
date Tue, 28 Jan 2014 12:28:17 -0800
parents abec000618bf 17ec2d5c43e8
children cd5d10655495
rev   line source
duke@0 1 /*
sla@4802 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
twisti@3883 26 #include "asm/macroAssembler.hpp"
twisti@3883 27 #include "asm/macroAssembler.inline.hpp"
kvn@5784 28 #include "ci/ciReplay.hpp"
stefank@1879 29 #include "classfile/systemDictionary.hpp"
stefank@1879 30 #include "code/exceptionHandlerTable.hpp"
stefank@1879 31 #include "code/nmethod.hpp"
stefank@1879 32 #include "compiler/compileLog.hpp"
twisti@3883 33 #include "compiler/disassembler.hpp"
stefank@1879 34 #include "compiler/oopMap.hpp"
stefank@1879 35 #include "opto/addnode.hpp"
stefank@1879 36 #include "opto/block.hpp"
stefank@1879 37 #include "opto/c2compiler.hpp"
stefank@1879 38 #include "opto/callGenerator.hpp"
stefank@1879 39 #include "opto/callnode.hpp"
stefank@1879 40 #include "opto/cfgnode.hpp"
stefank@1879 41 #include "opto/chaitin.hpp"
stefank@1879 42 #include "opto/compile.hpp"
stefank@1879 43 #include "opto/connode.hpp"
stefank@1879 44 #include "opto/divnode.hpp"
stefank@1879 45 #include "opto/escape.hpp"
stefank@1879 46 #include "opto/idealGraphPrinter.hpp"
stefank@1879 47 #include "opto/loopnode.hpp"
stefank@1879 48 #include "opto/machnode.hpp"
stefank@1879 49 #include "opto/macro.hpp"
stefank@1879 50 #include "opto/matcher.hpp"
rbackman@5492 51 #include "opto/mathexactnode.hpp"
stefank@1879 52 #include "opto/memnode.hpp"
stefank@1879 53 #include "opto/mulnode.hpp"
stefank@1879 54 #include "opto/node.hpp"
stefank@1879 55 #include "opto/opcodes.hpp"
stefank@1879 56 #include "opto/output.hpp"
stefank@1879 57 #include "opto/parse.hpp"
stefank@1879 58 #include "opto/phaseX.hpp"
stefank@1879 59 #include "opto/rootnode.hpp"
stefank@1879 60 #include "opto/runtime.hpp"
stefank@1879 61 #include "opto/stringopts.hpp"
stefank@1879 62 #include "opto/type.hpp"
stefank@1879 63 #include "opto/vectornode.hpp"
stefank@1879 64 #include "runtime/arguments.hpp"
stefank@1879 65 #include "runtime/signature.hpp"
stefank@1879 66 #include "runtime/stubRoutines.hpp"
stefank@1879 67 #include "runtime/timer.hpp"
sla@4802 68 #include "trace/tracing.hpp"
stefank@1879 69 #include "utilities/copy.hpp"
stefank@1879 70 #ifdef TARGET_ARCH_MODEL_x86_32
stefank@1879 71 # include "adfiles/ad_x86_32.hpp"
stefank@1879 72 #endif
stefank@1879 73 #ifdef TARGET_ARCH_MODEL_x86_64
stefank@1879 74 # include "adfiles/ad_x86_64.hpp"
stefank@1879 75 #endif
stefank@1879 76 #ifdef TARGET_ARCH_MODEL_sparc
stefank@1879 77 # include "adfiles/ad_sparc.hpp"
stefank@1879 78 #endif
stefank@1879 79 #ifdef TARGET_ARCH_MODEL_zero
stefank@1879 80 # include "adfiles/ad_zero.hpp"
stefank@1879 81 #endif
bobv@2073 82 #ifdef TARGET_ARCH_MODEL_arm
bobv@2073 83 # include "adfiles/ad_arm.hpp"
bobv@2073 84 #endif
goetz@5943 85 #ifdef TARGET_ARCH_MODEL_ppc_32
goetz@5943 86 # include "adfiles/ad_ppc_32.hpp"
goetz@5943 87 #endif
goetz@5943 88 #ifdef TARGET_ARCH_MODEL_ppc_64
goetz@5943 89 # include "adfiles/ad_ppc_64.hpp"
bobv@2073 90 #endif
duke@0 91
twisti@1915 92
twisti@1915 93 // -------------------- Compile::mach_constant_base_node -----------------------
twisti@1915 94 // Constant table base node singleton.
twisti@1915 95 MachConstantBaseNode* Compile::mach_constant_base_node() {
twisti@1915 96 if (_mach_constant_base_node == NULL) {
twisti@1915 97 _mach_constant_base_node = new (C) MachConstantBaseNode();
twisti@1915 98 _mach_constant_base_node->add_req(C->root());
twisti@1915 99 }
twisti@1915 100 return _mach_constant_base_node;
twisti@1915 101 }
twisti@1915 102
twisti@1915 103
duke@0 104 /// Support for intrinsics.
duke@0 105
duke@0 106 // Return the index at which m must be inserted (or already exists).
duke@0 107 // The sort order is by the address of the ciMethod, with is_virtual as minor key.
duke@0 108 int Compile::intrinsic_insertion_index(ciMethod* m, bool is_virtual) {
duke@0 109 #ifdef ASSERT
duke@0 110 for (int i = 1; i < _intrinsics->length(); i++) {
duke@0 111 CallGenerator* cg1 = _intrinsics->at(i-1);
duke@0 112 CallGenerator* cg2 = _intrinsics->at(i);
duke@0 113 assert(cg1->method() != cg2->method()
duke@0 114 ? cg1->method() < cg2->method()
duke@0 115 : cg1->is_virtual() < cg2->is_virtual(),
duke@0 116 "compiler intrinsics list must stay sorted");
duke@0 117 }
duke@0 118 #endif
duke@0 119 // Binary search sorted list, in decreasing intervals [lo, hi].
duke@0 120 int lo = 0, hi = _intrinsics->length()-1;
duke@0 121 while (lo <= hi) {
duke@0 122 int mid = (uint)(hi + lo) / 2;
duke@0 123 ciMethod* mid_m = _intrinsics->at(mid)->method();
duke@0 124 if (m < mid_m) {
duke@0 125 hi = mid-1;
duke@0 126 } else if (m > mid_m) {
duke@0 127 lo = mid+1;
duke@0 128 } else {
duke@0 129 // look at minor sort key
duke@0 130 bool mid_virt = _intrinsics->at(mid)->is_virtual();
duke@0 131 if (is_virtual < mid_virt) {
duke@0 132 hi = mid-1;
duke@0 133 } else if (is_virtual > mid_virt) {
duke@0 134 lo = mid+1;
duke@0 135 } else {
duke@0 136 return mid; // exact match
duke@0 137 }
duke@0 138 }
duke@0 139 }
duke@0 140 return lo; // inexact match
duke@0 141 }
duke@0 142
duke@0 143 void Compile::register_intrinsic(CallGenerator* cg) {
duke@0 144 if (_intrinsics == NULL) {
roland@3974 145 _intrinsics = new (comp_arena())GrowableArray<CallGenerator*>(comp_arena(), 60, 0, NULL);
duke@0 146 }
duke@0 147 // This code is stolen from ciObjectFactory::insert.
duke@0 148 // Really, GrowableArray should have methods for
duke@0 149 // insert_at, remove_at, and binary_search.
duke@0 150 int len = _intrinsics->length();
duke@0 151 int index = intrinsic_insertion_index(cg->method(), cg->is_virtual());
duke@0 152 if (index == len) {
duke@0 153 _intrinsics->append(cg);
duke@0 154 } else {
duke@0 155 #ifdef ASSERT
duke@0 156 CallGenerator* oldcg = _intrinsics->at(index);
duke@0 157 assert(oldcg->method() != cg->method() || oldcg->is_virtual() != cg->is_virtual(), "don't register twice");
duke@0 158 #endif
duke@0 159 _intrinsics->append(_intrinsics->at(len-1));
duke@0 160 int pos;
duke@0 161 for (pos = len-2; pos >= index; pos--) {
duke@0 162 _intrinsics->at_put(pos+1,_intrinsics->at(pos));
duke@0 163 }
duke@0 164 _intrinsics->at_put(index, cg);
duke@0 165 }
duke@0 166 assert(find_intrinsic(cg->method(), cg->is_virtual()) == cg, "registration worked");
duke@0 167 }
duke@0 168
duke@0 169 CallGenerator* Compile::find_intrinsic(ciMethod* m, bool is_virtual) {
duke@0 170 assert(m->is_loaded(), "don't try this on unloaded methods");
duke@0 171 if (_intrinsics != NULL) {
duke@0 172 int index = intrinsic_insertion_index(m, is_virtual);
duke@0 173 if (index < _intrinsics->length()
duke@0 174 && _intrinsics->at(index)->method() == m
duke@0 175 && _intrinsics->at(index)->is_virtual() == is_virtual) {
duke@0 176 return _intrinsics->at(index);
duke@0 177 }
duke@0 178 }
duke@0 179 // Lazily create intrinsics for intrinsic IDs well-known in the runtime.
jrose@856 180 if (m->intrinsic_id() != vmIntrinsics::_none &&
jrose@856 181 m->intrinsic_id() <= vmIntrinsics::LAST_COMPILER_INLINE) {
duke@0 182 CallGenerator* cg = make_vm_intrinsic(m, is_virtual);
duke@0 183 if (cg != NULL) {
duke@0 184 // Save it for next time:
duke@0 185 register_intrinsic(cg);
duke@0 186 return cg;
duke@0 187 } else {
duke@0 188 gather_intrinsic_statistics(m->intrinsic_id(), is_virtual, _intrinsic_disabled);
duke@0 189 }
duke@0 190 }
duke@0 191 return NULL;
duke@0 192 }
duke@0 193
duke@0 194 // Compile:: register_library_intrinsics and make_vm_intrinsic are defined
duke@0 195 // in library_call.cpp.
duke@0 196
duke@0 197
duke@0 198 #ifndef PRODUCT
duke@0 199 // statistics gathering...
duke@0 200
duke@0 201 juint Compile::_intrinsic_hist_count[vmIntrinsics::ID_LIMIT] = {0};
duke@0 202 jubyte Compile::_intrinsic_hist_flags[vmIntrinsics::ID_LIMIT] = {0};
duke@0 203
duke@0 204 bool Compile::gather_intrinsic_statistics(vmIntrinsics::ID id, bool is_virtual, int flags) {
duke@0 205 assert(id > vmIntrinsics::_none && id < vmIntrinsics::ID_LIMIT, "oob");
duke@0 206 int oflags = _intrinsic_hist_flags[id];
duke@0 207 assert(flags != 0, "what happened?");
duke@0 208 if (is_virtual) {
duke@0 209 flags |= _intrinsic_virtual;
duke@0 210 }
duke@0 211 bool changed = (flags != oflags);
duke@0 212 if ((flags & _intrinsic_worked) != 0) {
duke@0 213 juint count = (_intrinsic_hist_count[id] += 1);
duke@0 214 if (count == 1) {
duke@0 215 changed = true; // first time
duke@0 216 }
duke@0 217 // increment the overall count also:
duke@0 218 _intrinsic_hist_count[vmIntrinsics::_none] += 1;
duke@0 219 }
duke@0 220 if (changed) {
duke@0 221 if (((oflags ^ flags) & _intrinsic_virtual) != 0) {
duke@0 222 // Something changed about the intrinsic's virtuality.
duke@0 223 if ((flags & _intrinsic_virtual) != 0) {
duke@0 224 // This is the first use of this intrinsic as a virtual call.
duke@0 225 if (oflags != 0) {
duke@0 226 // We already saw it as a non-virtual, so note both cases.
duke@0 227 flags |= _intrinsic_both;
duke@0 228 }
duke@0 229 } else if ((oflags & _intrinsic_both) == 0) {
duke@0 230 // This is the first use of this intrinsic as a non-virtual
duke@0 231 flags |= _intrinsic_both;
duke@0 232 }
duke@0 233 }
duke@0 234 _intrinsic_hist_flags[id] = (jubyte) (oflags | flags);
duke@0 235 }
duke@0 236 // update the overall flags also:
duke@0 237 _intrinsic_hist_flags[vmIntrinsics::_none] |= (jubyte) flags;
duke@0 238 return changed;
duke@0 239 }
duke@0 240
duke@0 241 static char* format_flags(int flags, char* buf) {
duke@0 242 buf[0] = 0;
duke@0 243 if ((flags & Compile::_intrinsic_worked) != 0) strcat(buf, ",worked");
duke@0 244 if ((flags & Compile::_intrinsic_failed) != 0) strcat(buf, ",failed");
duke@0 245 if ((flags & Compile::_intrinsic_disabled) != 0) strcat(buf, ",disabled");
duke@0 246 if ((flags & Compile::_intrinsic_virtual) != 0) strcat(buf, ",virtual");
duke@0 247 if ((flags & Compile::_intrinsic_both) != 0) strcat(buf, ",nonvirtual");
duke@0 248 if (buf[0] == 0) strcat(buf, ",");
duke@0 249 assert(buf[0] == ',', "must be");
duke@0 250 return &buf[1];
duke@0 251 }
duke@0 252
duke@0 253 void Compile::print_intrinsic_statistics() {
duke@0 254 char flagsbuf[100];
duke@0 255 ttyLocker ttyl;
duke@0 256 if (xtty != NULL) xtty->head("statistics type='intrinsic'");
duke@0 257 tty->print_cr("Compiler intrinsic usage:");
duke@0 258 juint total = _intrinsic_hist_count[vmIntrinsics::_none];
duke@0 259 if (total == 0) total = 1; // avoid div0 in case of no successes
duke@0 260 #define PRINT_STAT_LINE(name, c, f) \
duke@0 261 tty->print_cr(" %4d (%4.1f%%) %s (%s)", (int)(c), ((c) * 100.0) / total, name, f);
duke@0 262 for (int index = 1 + (int)vmIntrinsics::_none; index < (int)vmIntrinsics::ID_LIMIT; index++) {
duke@0 263 vmIntrinsics::ID id = (vmIntrinsics::ID) index;
duke@0 264 int flags = _intrinsic_hist_flags[id];
duke@0 265 juint count = _intrinsic_hist_count[id];
duke@0 266 if ((flags | count) != 0) {
duke@0 267 PRINT_STAT_LINE(vmIntrinsics::name_at(id), count, format_flags(flags, flagsbuf));
duke@0 268 }
duke@0 269 }
duke@0 270 PRINT_STAT_LINE("total", total, format_flags(_intrinsic_hist_flags[vmIntrinsics::_none], flagsbuf));
duke@0 271 if (xtty != NULL) xtty->tail("statistics");
duke@0 272 }
duke@0 273
duke@0 274 void Compile::print_statistics() {
duke@0 275 { ttyLocker ttyl;
duke@0 276 if (xtty != NULL) xtty->head("statistics type='opto'");
duke@0 277 Parse::print_statistics();
duke@0 278 PhaseCCP::print_statistics();
duke@0 279 PhaseRegAlloc::print_statistics();
duke@0 280 Scheduling::print_statistics();
duke@0 281 PhasePeephole::print_statistics();
duke@0 282 PhaseIdealLoop::print_statistics();
duke@0 283 if (xtty != NULL) xtty->tail("statistics");
duke@0 284 }
duke@0 285 if (_intrinsic_hist_flags[vmIntrinsics::_none] != 0) {
duke@0 286 // put this under its own <statistics> element.
duke@0 287 print_intrinsic_statistics();
duke@0 288 }
duke@0 289 }
duke@0 290 #endif //PRODUCT
duke@0 291
duke@0 292 // Support for bundling info
duke@0 293 Bundle* Compile::node_bundling(const Node *n) {
duke@0 294 assert(valid_bundle_info(n), "oob");
duke@0 295 return &_node_bundling_base[n->_idx];
duke@0 296 }
duke@0 297
duke@0 298 bool Compile::valid_bundle_info(const Node *n) {
duke@0 299 return (_node_bundling_limit > n->_idx);
duke@0 300 }
duke@0 301
duke@0 302
never@1080 303 void Compile::gvn_replace_by(Node* n, Node* nn) {
never@1080 304 for (DUIterator_Last imin, i = n->last_outs(imin); i >= imin; ) {
never@1080 305 Node* use = n->last_out(i);
never@1080 306 bool is_in_table = initial_gvn()->hash_delete(use);
never@1080 307 uint uses_found = 0;
never@1080 308 for (uint j = 0; j < use->len(); j++) {
never@1080 309 if (use->in(j) == n) {
never@1080 310 if (j < use->req())
never@1080 311 use->set_req(j, nn);
never@1080 312 else
never@1080 313 use->set_prec(j, nn);
never@1080 314 uses_found++;
never@1080 315 }
never@1080 316 }
never@1080 317 if (is_in_table) {
never@1080 318 // reinsert into table
never@1080 319 initial_gvn()->hash_find_insert(use);
never@1080 320 }
never@1080 321 record_for_igvn(use);
never@1080 322 i -= uses_found; // we deleted 1 or more copies of this edge
never@1080 323 }
never@1080 324 }
never@1080 325
never@1080 326
bharadwaj@3880 327 static inline bool not_a_node(const Node* n) {
bharadwaj@3880 328 if (n == NULL) return true;
bharadwaj@3880 329 if (((intptr_t)n & 1) != 0) return true; // uninitialized, etc.
bharadwaj@3880 330 if (*(address*)n == badAddress) return true; // kill by Node::destruct
bharadwaj@3880 331 return false;
bharadwaj@3880 332 }
never@1080 333
duke@0 334 // Identify all nodes that are reachable from below, useful.
duke@0 335 // Use breadth-first pass that records state in a Unique_Node_List,
duke@0 336 // recursive traversal is slower.
duke@0 337 void Compile::identify_useful_nodes(Unique_Node_List &useful) {
duke@0 338 int estimated_worklist_size = unique();
duke@0 339 useful.map( estimated_worklist_size, NULL ); // preallocate space
duke@0 340
duke@0 341 // Initialize worklist
duke@0 342 if (root() != NULL) { useful.push(root()); }
duke@0 343 // If 'top' is cached, declare it useful to preserve cached node
duke@0 344 if( cached_top_node() ) { useful.push(cached_top_node()); }
duke@0 345
duke@0 346 // Push all useful nodes onto the list, breadthfirst
duke@0 347 for( uint next = 0; next < useful.size(); ++next ) {
duke@0 348 assert( next < unique(), "Unique useful nodes < total nodes");
duke@0 349 Node *n = useful.at(next);
duke@0 350 uint max = n->len();
duke@0 351 for( uint i = 0; i < max; ++i ) {
duke@0 352 Node *m = n->in(i);
bharadwaj@3880 353 if (not_a_node(m)) continue;
duke@0 354 useful.push(m);
duke@0 355 }
duke@0 356 }
duke@0 357 }
duke@0 358
bharadwaj@3880 359 // Update dead_node_list with any missing dead nodes using useful
bharadwaj@3880 360 // list. Consider all non-useful nodes to be useless i.e., dead nodes.
bharadwaj@3880 361 void Compile::update_dead_node_list(Unique_Node_List &useful) {
bharadwaj@3880 362 uint max_idx = unique();
bharadwaj@3880 363 VectorSet& useful_node_set = useful.member_set();
bharadwaj@3880 364
bharadwaj@3880 365 for (uint node_idx = 0; node_idx < max_idx; node_idx++) {
bharadwaj@3880 366 // If node with index node_idx is not in useful set,
bharadwaj@3880 367 // mark it as dead in dead node list.
bharadwaj@3880 368 if (! useful_node_set.test(node_idx) ) {
bharadwaj@3880 369 record_dead_node(node_idx);
bharadwaj@3880 370 }
bharadwaj@3880 371 }
bharadwaj@3880 372 }
bharadwaj@3880 373
roland@3974 374 void Compile::remove_useless_late_inlines(GrowableArray<CallGenerator*>* inlines, Unique_Node_List &useful) {
roland@3974 375 int shift = 0;
roland@3974 376 for (int i = 0; i < inlines->length(); i++) {
roland@3974 377 CallGenerator* cg = inlines->at(i);
roland@3974 378 CallNode* call = cg->call_node();
roland@3974 379 if (shift > 0) {
roland@3974 380 inlines->at_put(i-shift, cg);
roland@3974 381 }
roland@3974 382 if (!useful.member(call)) {
roland@3974 383 shift++;
roland@3974 384 }
roland@3974 385 }
roland@3974 386 inlines->trunc_to(inlines->length()-shift);
roland@3974 387 }
roland@3974 388
duke@0 389 // Disconnect all useless nodes by disconnecting those at the boundary.
duke@0 390 void Compile::remove_useless_nodes(Unique_Node_List &useful) {
duke@0 391 uint next = 0;
kvn@2825 392 while (next < useful.size()) {
duke@0 393 Node *n = useful.at(next++);
duke@0 394 // Use raw traversal of out edges since this code removes out edges
duke@0 395 int max = n->outcnt();
kvn@2825 396 for (int j = 0; j < max; ++j) {
duke@0 397 Node* child = n->raw_out(j);
kvn@2825 398 if (! useful.member(child)) {
kvn@2825 399 assert(!child->is_top() || child != top(),
kvn@2825 400 "If top is cached in Compile object it is in useful list");
duke@0 401 // Only need to remove this out-edge to the useless node
duke@0 402 n->raw_del_out(j);
duke@0 403 --j;
duke@0 404 --max;
duke@0 405 }
duke@0 406 }
duke@0 407 if (n->outcnt() == 1 && n->has_special_unique_user()) {
kvn@2825 408 record_for_igvn(n->unique_out());
kvn@2825 409 }
kvn@2825 410 }
kvn@2825 411 // Remove useless macro and predicate opaq nodes
kvn@2825 412 for (int i = C->macro_count()-1; i >= 0; i--) {
kvn@2825 413 Node* n = C->macro_node(i);
kvn@2825 414 if (!useful.member(n)) {
kvn@2825 415 remove_macro_node(n);
duke@0 416 }
duke@0 417 }
roland@4154 418 // Remove useless expensive node
roland@4154 419 for (int i = C->expensive_count()-1; i >= 0; i--) {
roland@4154 420 Node* n = C->expensive_node(i);
roland@4154 421 if (!useful.member(n)) {
roland@4154 422 remove_expensive_node(n);
roland@4154 423 }
roland@4154 424 }
roland@3974 425 // clean up the late inline lists
roland@3974 426 remove_useless_late_inlines(&_string_late_inlines, useful);
kvn@4675 427 remove_useless_late_inlines(&_boxing_late_inlines, useful);
roland@3974 428 remove_useless_late_inlines(&_late_inlines, useful);
duke@0 429 debug_only(verify_graph_edges(true/*check for no_dead_code*/);)
duke@0 430 }
duke@0 431
duke@0 432 //------------------------------frame_size_in_words-----------------------------
duke@0 433 // frame_slots in units of words
duke@0 434 int Compile::frame_size_in_words() const {
duke@0 435 // shift is 0 in LP32 and 1 in LP64
duke@0 436 const int shift = (LogBytesPerWord - LogBytesPerInt);
duke@0 437 int words = _frame_slots >> shift;
duke@0 438 assert( words << shift == _frame_slots, "frame size must be properly aligned in LP64" );
duke@0 439 return words;
duke@0 440 }
duke@0 441
duke@0 442 // ============================================================================
duke@0 443 //------------------------------CompileWrapper---------------------------------
duke@0 444 class CompileWrapper : public StackObj {
duke@0 445 Compile *const _compile;
duke@0 446 public:
duke@0 447 CompileWrapper(Compile* compile);
duke@0 448
duke@0 449 ~CompileWrapper();
duke@0 450 };
duke@0 451
duke@0 452 CompileWrapper::CompileWrapper(Compile* compile) : _compile(compile) {
duke@0 453 // the Compile* pointer is stored in the current ciEnv:
duke@0 454 ciEnv* env = compile->env();
duke@0 455 assert(env == ciEnv::current(), "must already be a ciEnv active");
duke@0 456 assert(env->compiler_data() == NULL, "compile already active?");
duke@0 457 env->set_compiler_data(compile);
duke@0 458 assert(compile == Compile::current(), "sanity");
duke@0 459
duke@0 460 compile->set_type_dict(NULL);
duke@0 461 compile->set_type_hwm(NULL);
duke@0 462 compile->set_type_last_size(0);
duke@0 463 compile->set_last_tf(NULL, NULL);
duke@0 464 compile->set_indexSet_arena(NULL);
duke@0 465 compile->set_indexSet_free_block_list(NULL);
duke@0 466 compile->init_type_arena();
duke@0 467 Type::Initialize(compile);
duke@0 468 _compile->set_scratch_buffer_blob(NULL);
duke@0 469 _compile->begin_method();
duke@0 470 }
duke@0 471 CompileWrapper::~CompileWrapper() {
duke@0 472 _compile->end_method();
duke@0 473 if (_compile->scratch_buffer_blob() != NULL)
duke@0 474 BufferBlob::free(_compile->scratch_buffer_blob());
duke@0 475 _compile->env()->set_compiler_data(NULL);
duke@0 476 }
duke@0 477
duke@0 478
duke@0 479 //----------------------------print_compile_messages---------------------------
duke@0 480 void Compile::print_compile_messages() {
duke@0 481 #ifndef PRODUCT
duke@0 482 // Check if recompiling
duke@0 483 if (_subsume_loads == false && PrintOpto) {
duke@0 484 // Recompiling without allowing machine instructions to subsume loads
duke@0 485 tty->print_cr("*********************************************************");
duke@0 486 tty->print_cr("** Bailout: Recompile without subsuming loads **");
duke@0 487 tty->print_cr("*********************************************************");
duke@0 488 }
kvn@38 489 if (_do_escape_analysis != DoEscapeAnalysis && PrintOpto) {
kvn@38 490 // Recompiling without escape analysis
kvn@38 491 tty->print_cr("*********************************************************");
kvn@38 492 tty->print_cr("** Bailout: Recompile without escape analysis **");
kvn@38 493 tty->print_cr("*********************************************************");
kvn@38 494 }
kvn@4675 495 if (_eliminate_boxing != EliminateAutoBox && PrintOpto) {
kvn@4675 496 // Recompiling without boxing elimination
kvn@4675 497 tty->print_cr("*********************************************************");
kvn@4675 498 tty->print_cr("** Bailout: Recompile without boxing elimination **");
kvn@4675 499 tty->print_cr("*********************************************************");
kvn@4675 500 }
duke@0 501 if (env()->break_at_compile()) {
twisti@605 502 // Open the debugger when compiling this method.
duke@0 503 tty->print("### Breaking when compiling: ");
duke@0 504 method()->print_short_name();
duke@0 505 tty->cr();
duke@0 506 BREAKPOINT;
duke@0 507 }
duke@0 508
duke@0 509 if( PrintOpto ) {
duke@0 510 if (is_osr_compilation()) {
duke@0 511 tty->print("[OSR]%3d", _compile_id);
duke@0 512 } else {
duke@0 513 tty->print("%3d", _compile_id);
duke@0 514 }
duke@0 515 }
duke@0 516 #endif
duke@0 517 }
duke@0 518
duke@0 519
kvn@1979 520 //-----------------------init_scratch_buffer_blob------------------------------
kvn@1979 521 // Construct a temporary BufferBlob and cache it for this compile.
twisti@1915 522 void Compile::init_scratch_buffer_blob(int const_size) {
kvn@1979 523 // If there is already a scratch buffer blob allocated and the
kvn@1979 524 // constant section is big enough, use it. Otherwise free the
kvn@1979 525 // current and allocate a new one.
kvn@1979 526 BufferBlob* blob = scratch_buffer_blob();
kvn@1979 527 if ((blob != NULL) && (const_size <= _scratch_const_size)) {
kvn@1979 528 // Use the current blob.
kvn@1979 529 } else {
kvn@1979 530 if (blob != NULL) {
kvn@1979 531 BufferBlob::free(blob);
kvn@1979 532 }
duke@0 533
kvn@1979 534 ResourceMark rm;
kvn@1979 535 _scratch_const_size = const_size;
kvn@1979 536 int size = (MAX_inst_size + MAX_stubs_size + _scratch_const_size);
kvn@1979 537 blob = BufferBlob::create("Compile::scratch_buffer", size);
kvn@1979 538 // Record the buffer blob for next time.
kvn@1979 539 set_scratch_buffer_blob(blob);
kvn@1979 540 // Have we run out of code space?
kvn@1979 541 if (scratch_buffer_blob() == NULL) {
kvn@1979 542 // Let CompilerBroker disable further compilations.
kvn@1979 543 record_failure("Not enough space for scratch buffer in CodeCache");
kvn@1979 544 return;
kvn@1979 545 }
kvn@163 546 }
duke@0 547
duke@0 548 // Initialize the relocation buffers
twisti@1668 549 relocInfo* locs_buf = (relocInfo*) blob->content_end() - MAX_locs_size;
duke@0 550 set_scratch_locs_memory(locs_buf);
duke@0 551 }
duke@0 552
duke@0 553
duke@0 554 //-----------------------scratch_emit_size-------------------------------------
duke@0 555 // Helper function that computes size by emitting code
duke@0 556 uint Compile::scratch_emit_size(const Node* n) {
twisti@1915 557 // Start scratch_emit_size section.
twisti@1915 558 set_in_scratch_emit_size(true);
twisti@1915 559
duke@0 560 // Emit into a trash buffer and count bytes emitted.
duke@0 561 // This is a pretty expensive way to compute a size,
duke@0 562 // but it works well enough if seldom used.
duke@0 563 // All common fixed-size instructions are given a size
duke@0 564 // method by the AD file.
duke@0 565 // Note that the scratch buffer blob and locs memory are
duke@0 566 // allocated at the beginning of the compile task, and
duke@0 567 // may be shared by several calls to scratch_emit_size.
duke@0 568 // The allocation of the scratch buffer blob is particularly
duke@0 569 // expensive, since it has to grab the code cache lock.
duke@0 570 BufferBlob* blob = this->scratch_buffer_blob();
duke@0 571 assert(blob != NULL, "Initialize BufferBlob at start");
duke@0 572 assert(blob->size() > MAX_inst_size, "sanity");
duke@0 573 relocInfo* locs_buf = scratch_locs_memory();
twisti@1668 574 address blob_begin = blob->content_begin();
duke@0 575 address blob_end = (address)locs_buf;
twisti@1668 576 assert(blob->content_contains(blob_end), "sanity");
duke@0 577 CodeBuffer buf(blob_begin, blob_end - blob_begin);
twisti@1915 578 buf.initialize_consts_size(_scratch_const_size);
duke@0 579 buf.initialize_stubs_size(MAX_stubs_size);
duke@0 580 assert(locs_buf != NULL, "sanity");
twisti@1915 581 int lsize = MAX_locs_size / 3;
twisti@1915 582 buf.consts()->initialize_shared_locs(&locs_buf[lsize * 0], lsize);
twisti@1915 583 buf.insts()->initialize_shared_locs( &locs_buf[lsize * 1], lsize);
twisti@1915 584 buf.stubs()->initialize_shared_locs( &locs_buf[lsize * 2], lsize);
twisti@1915 585
twisti@1915 586 // Do the emission.
kvn@2602 587
kvn@2602 588 Label fakeL; // Fake label for branch instructions.
kvn@2616 589 Label* saveL = NULL;
kvn@2616 590 uint save_bnum = 0;
kvn@2616 591 bool is_branch = n->is_MachBranch();
kvn@2602 592 if (is_branch) {
kvn@2602 593 MacroAssembler masm(&buf);
kvn@2602 594 masm.bind(fakeL);
kvn@2616 595 n->as_MachBranch()->save_label(&saveL, &save_bnum);
kvn@2616 596 n->as_MachBranch()->label_set(&fakeL, 0);
kvn@2602 597 }
duke@0 598 n->emit(buf, this->regalloc());
kvn@2616 599 if (is_branch) // Restore label.
kvn@2616 600 n->as_MachBranch()->label_set(saveL, save_bnum);
twisti@1915 601
twisti@1915 602 // End scratch_emit_size section.
twisti@1915 603 set_in_scratch_emit_size(false);
twisti@1915 604
twisti@1668 605 return buf.insts_size();
duke@0 606 }
duke@0 607
duke@0 608
duke@0 609 // ============================================================================
duke@0 610 //------------------------------Compile standard-------------------------------
duke@0 611 debug_only( int Compile::_debug_idx = 100000; )
duke@0 612
duke@0 613 // Compile a method. entry_bci is -1 for normal compilations and indicates
duke@0 614 // the continuation bci for on stack replacement.
duke@0 615
duke@0 616
kvn@4675 617 Compile::Compile( ciEnv* ci_env, C2Compiler* compiler, ciMethod* target, int osr_bci,
kvn@4675 618 bool subsume_loads, bool do_escape_analysis, bool eliminate_boxing )
duke@0 619 : Phase(Compiler),
duke@0 620 _env(ci_env),
duke@0 621 _log(ci_env->log()),
duke@0 622 _compile_id(ci_env->compile_id()),
duke@0 623 _save_argument_registers(false),
duke@0 624 _stub_name(NULL),
duke@0 625 _stub_function(NULL),
duke@0 626 _stub_entry_point(NULL),
duke@0 627 _method(target),
duke@0 628 _entry_bci(osr_bci),
duke@0 629 _initial_gvn(NULL),
duke@0 630 _for_igvn(NULL),
duke@0 631 _warm_calls(NULL),
duke@0 632 _subsume_loads(subsume_loads),
kvn@38 633 _do_escape_analysis(do_escape_analysis),
kvn@4675 634 _eliminate_boxing(eliminate_boxing),
duke@0 635 _failure_reason(NULL),
duke@0 636 _code_buffer("Compile::Fill_buffer"),
duke@0 637 _orig_pc_slot(0),
duke@0 638 _orig_pc_slot_offset_in_bytes(0),
twisti@1265 639 _has_method_handle_invokes(false),
twisti@1915 640 _mach_constant_base_node(NULL),
duke@0 641 _node_bundling_limit(0),
duke@0 642 _node_bundling_base(NULL),
kvn@859 643 _java_calls(0),
kvn@859 644 _inner_loops(0),
twisti@1915 645 _scratch_const_size(-1),
twisti@1915 646 _in_scratch_emit_size(false),
bharadwaj@3880 647 _dead_node_list(comp_arena()),
bharadwaj@3880 648 _dead_node_count(0),
duke@0 649 #ifndef PRODUCT
duke@0 650 _trace_opto_output(TraceOptoOutput || method()->has_option("TraceOptoOutput")),
goetz@5990 651 _in_dump_cnt(0),
duke@0 652 _printer(IdealGraphPrinter::printer()),
duke@0 653 #endif
roland@3922 654 _congraph(NULL),
kvn@5784 655 _replay_inline_data(NULL),
roland@3974 656 _late_inlines(comp_arena(), 2, 0, NULL),
roland@3974 657 _string_late_inlines(comp_arena(), 2, 0, NULL),
kvn@4675 658 _boxing_late_inlines(comp_arena(), 2, 0, NULL),
roland@3974 659 _late_inlines_pos(0),
roland@3974 660 _number_of_mh_late_inlines(0),
roland@3974 661 _inlining_progress(false),
roland@3974 662 _inlining_incrementally(false),
roland@3922 663 _print_inlining_list(NULL),
roland@5546 664 _print_inlining_idx(0),
roland@5546 665 _preserve_jvm_state(0) {
duke@0 666 C = this;
duke@0 667
duke@0 668 CompileWrapper cw(this);
duke@0 669 #ifndef PRODUCT
duke@0 670 if (TimeCompiler2) {
duke@0 671 tty->print(" ");
duke@0 672 target->holder()->name()->print();
duke@0 673 tty->print(".");
duke@0 674 target->print_short_name();
duke@0 675 tty->print(" ");
duke@0 676 }
duke@0 677 TraceTime t1("Total compilation time", &_t_totalCompilation, TimeCompiler, TimeCompiler2);
duke@0 678 TraceTime t2(NULL, &_t_methodCompilation, TimeCompiler, false);
jrose@100 679 bool print_opto_assembly = PrintOptoAssembly || _method->has_option("PrintOptoAssembly");
jrose@100 680 if (!print_opto_assembly) {
jrose@100 681 bool print_assembly = (PrintAssembly || _method->should_print_assembly());
jrose@100 682 if (print_assembly && !Disassembler::can_decode()) {
jrose@100 683 tty->print_cr("PrintAssembly request changed to PrintOptoAssembly");
jrose@100 684 print_opto_assembly = true;
jrose@100 685 }
jrose@100 686 }
jrose@100 687 set_print_assembly(print_opto_assembly);
never@367 688 set_parsed_irreducible_loop(false);
kvn@5784 689
kvn@5784 690 if (method()->has_option("ReplayInline")) {
kvn@5784 691 _replay_inline_data = ciReplay::load_inline_data(method(), entry_bci(), ci_env->comp_level());
kvn@5784 692 }
duke@0 693 #endif
kvn@5328 694 set_print_inlining(PrintInlining || method()->has_option("PrintInlining") NOT_PRODUCT( || PrintOptoInlining));
kvn@5328 695 set_print_intrinsics(PrintIntrinsics || method()->has_option("PrintIntrinsics"));
duke@0 696
duke@0 697 if (ProfileTraps) {
duke@0 698 // Make sure the method being compiled gets its own MDO,
duke@0 699 // so we can at least track the decompile_count().
iveresov@1914 700 method()->ensure_method_data();
duke@0 701 }
duke@0 702
duke@0 703 Init(::AliasLevel);
duke@0 704
duke@0 705
duke@0 706 print_compile_messages();
duke@0 707
shade@5936 708 _ilt = InlineTree::build_inline_tree_root();
duke@0 709
duke@0 710 // Even if NO memory addresses are used, MergeMem nodes must have at least 1 slice
duke@0 711 assert(num_alias_types() >= AliasIdxRaw, "");
duke@0 712
duke@0 713 #define MINIMUM_NODE_HASH 1023
duke@0 714 // Node list that Iterative GVN will start with
duke@0 715 Unique_Node_List for_igvn(comp_arena());
duke@0 716 set_for_igvn(&for_igvn);
duke@0 717
duke@0 718 // GVN that will be run immediately on new nodes
duke@0 719 uint estimated_size = method()->code_size()*4+64;
duke@0 720 estimated_size = (estimated_size < MINIMUM_NODE_HASH ? MINIMUM_NODE_HASH : estimated_size);
duke@0 721 PhaseGVN gvn(node_arena(), estimated_size);
duke@0 722 set_initial_gvn(&gvn);
duke@0 723
kvn@5328 724 if (print_inlining() || print_intrinsics()) {
roland@3922 725 _print_inlining_list = new (comp_arena())GrowableArray<PrintInliningBuffer>(comp_arena(), 1, 1, PrintInliningBuffer());
roland@3922 726 }
duke@0 727 { // Scope for timing the parser
duke@0 728 TracePhase t3("parse", &_t_parser, true);
duke@0 729
duke@0 730 // Put top into the hash table ASAP.
duke@0 731 initial_gvn()->transform_no_reclaim(top());
duke@0 732
duke@0 733 // Set up tf(), start(), and find a CallGenerator.
johnc@2346 734 CallGenerator* cg = NULL;
duke@0 735 if (is_osr_compilation()) {
duke@0 736 const TypeTuple *domain = StartOSRNode::osr_domain();
duke@0 737 const TypeTuple *range = TypeTuple::make_range(method()->signature());
duke@0 738 init_tf(TypeFunc::make(domain, range));
kvn@3680 739 StartNode* s = new (this) StartOSRNode(root(), domain);
duke@0 740 initial_gvn()->set_type_bottom(s);
duke@0 741 init_start(s);
duke@0 742 cg = CallGenerator::for_osr(method(), entry_bci());
duke@0 743 } else {
duke@0 744 // Normal case.
duke@0 745 init_tf(TypeFunc::make(method()));
kvn@3680 746 StartNode* s = new (this) StartNode(root(), tf()->domain());
duke@0 747 initial_gvn()->set_type_bottom(s);
duke@0 748 init_start(s);
johnc@2346 749 if (method()->intrinsic_id() == vmIntrinsics::_Reference_get && UseG1GC) {
johnc@2346 750 // With java.lang.ref.reference.get() we must go through the
johnc@2346 751 // intrinsic when G1 is enabled - even when get() is the root
johnc@2346 752 // method of the compile - so that, if necessary, the value in
johnc@2346 753 // the referent field of the reference object gets recorded by
johnc@2346 754 // the pre-barrier code.
johnc@2346 755 // Specifically, if G1 is enabled, the value in the referent
johnc@2346 756 // field is recorded by the G1 SATB pre barrier. This will
johnc@2346 757 // result in the referent being marked live and the reference
johnc@2346 758 // object removed from the list of discovered references during
johnc@2346 759 // reference processing.
johnc@2346 760 cg = find_intrinsic(method(), false);
johnc@2346 761 }
johnc@2346 762 if (cg == NULL) {
johnc@2346 763 float past_uses = method()->interpreter_invocation_count();
johnc@2346 764 float expected_uses = past_uses;
johnc@2346 765 cg = CallGenerator::for_inline(method(), expected_uses);
johnc@2346 766 }
duke@0 767 }
duke@0 768 if (failing()) return;
duke@0 769 if (cg == NULL) {
duke@0 770 record_method_not_compilable_all_tiers("cannot parse method");
duke@0 771 return;
duke@0 772 }
duke@0 773 JVMState* jvms = build_start_state(start(), tf());
roland@5546 774 if ((jvms = cg->generate(jvms, NULL)) == NULL) {
duke@0 775 record_method_not_compilable("method parse failed");
duke@0 776 return;
duke@0 777 }
duke@0 778 GraphKit kit(jvms);
duke@0 779
duke@0 780 if (!kit.stopped()) {
duke@0 781 // Accept return values, and transfer control we know not where.
duke@0 782 // This is done by a special, unique ReturnNode bound to root.
duke@0 783 return_values(kit.jvms());
duke@0 784 }
duke@0 785
duke@0 786 if (kit.has_exceptions()) {
duke@0 787 // Any exceptions that escape from this call must be rethrown
duke@0 788 // to whatever caller is dynamically above us on the stack.
duke@0 789 // This is done by a special, unique RethrowNode bound to root.
duke@0 790 rethrow_exceptions(kit.transfer_exceptions_into_jvms());
duke@0 791 }
duke@0 792
roland@3974 793 assert(IncrementalInline || (_late_inlines.length() == 0 && !has_mh_late_inlines()), "incremental inlining is off");
roland@3974 794
roland@3974 795 if (_late_inlines.length() == 0 && !has_mh_late_inlines() && !failing() && has_stringbuilder()) {
roland@3974 796 inline_string_calls(true);
never@1080 797 }
roland@3974 798
roland@3974 799 if (failing()) return;
never@1080 800
sla@4802 801 print_method(PHASE_BEFORE_REMOVEUSELESS, 3);
never@367 802
duke@0 803 // Remove clutter produced by parsing.
duke@0 804 if (!failing()) {
duke@0 805 ResourceMark rm;
duke@0 806 PhaseRemoveUseless pru(initial_gvn(), &for_igvn);
duke@0 807 }
duke@0 808 }
duke@0 809
duke@0 810 // Note: Large methods are capped off in do_one_bytecode().
duke@0 811 if (failing()) return;
duke@0 812
duke@0 813 // After parsing, node notes are no longer automagic.
duke@0 814 // They must be propagated by register_new_node_with_optimizer(),
duke@0 815 // clone(), or the like.
duke@0 816 set_default_node_notes(NULL);
duke@0 817
duke@0 818 for (;;) {
duke@0 819 int successes = Inline_Warm();
duke@0 820 if (failing()) return;
duke@0 821 if (successes == 0) break;
duke@0 822 }
duke@0 823
duke@0 824 // Drain the list.
duke@0 825 Finish_Warm();
duke@0 826 #ifndef PRODUCT
duke@0 827 if (_printer) {
duke@0 828 _printer->print_inlining(this);
duke@0 829 }
duke@0 830 #endif
duke@0 831
duke@0 832 if (failing()) return;
duke@0 833 NOT_PRODUCT( verify_graph_edges(); )
duke@0 834
duke@0 835 // Now optimize
duke@0 836 Optimize();
duke@0 837 if (failing()) return;
duke@0 838 NOT_PRODUCT( verify_graph_edges(); )
duke@0 839
duke@0 840 #ifndef PRODUCT
duke@0 841 if (PrintIdeal) {
duke@0 842 ttyLocker ttyl; // keep the following output all in one block
duke@0 843 // This output goes directly to the tty, not the compiler log.
duke@0 844 // To enable tools to match it up with the compilation activity,
duke@0 845 // be sure to tag this tty output with the compile ID.
duke@0 846 if (xtty != NULL) {
duke@0 847 xtty->head("ideal compile_id='%d'%s", compile_id(),
duke@0 848 is_osr_compilation() ? " compile_kind='osr'" :
duke@0 849 "");
duke@0 850 }
duke@0 851 root()->dump(9999);
duke@0 852 if (xtty != NULL) {
duke@0 853 xtty->tail("ideal");
duke@0 854 }
duke@0 855 }
duke@0 856 #endif
duke@0 857
iveresov@5635 858 NOT_PRODUCT( verify_barriers(); )
kvn@5784 859
kvn@5784 860 // Dump compilation data to replay it.
kvn@5784 861 if (method()->has_option("DumpReplay")) {
kvn@5784 862 env()->dump_replay_data(_compile_id);
kvn@5784 863 }
kvn@5784 864 if (method()->has_option("DumpInline") && (ilt() != NULL)) {
kvn@5784 865 env()->dump_inline_data(_compile_id);
kvn@5784 866 }
kvn@5784 867
duke@0 868 // Now that we know the size of all the monitors we can add a fixed slot
duke@0 869 // for the original deopt pc.
duke@0 870
duke@0 871 _orig_pc_slot = fixed_slots();
duke@0 872 int next_slot = _orig_pc_slot + (sizeof(address) / VMRegImpl::stack_slot_size);
duke@0 873 set_fixed_slots(next_slot);
duke@0 874
goetz@5992 875 // Compute when to use implicit null checks. Used by matching trap based
goetz@5992 876 // nodes and NullCheck optimization.
goetz@5992 877 set_allowed_deopt_reasons();
goetz@5992 878
duke@0 879 // Now generate code
duke@0 880 Code_Gen();
duke@0 881 if (failing()) return;
duke@0 882
duke@0 883 // Check if we want to skip execution of all compiled code.
duke@0 884 {
duke@0 885 #ifndef PRODUCT
duke@0 886 if (OptoNoExecute) {
duke@0 887 record_method_not_compilable("+OptoNoExecute"); // Flag as failed
duke@0 888 return;
duke@0 889 }
duke@0 890 TracePhase t2("install_code", &_t_registerMethod, TimeCompiler);
duke@0 891 #endif
duke@0 892
duke@0 893 if (is_osr_compilation()) {
duke@0 894 _code_offsets.set_value(CodeOffsets::Verified_Entry, 0);
duke@0 895 _code_offsets.set_value(CodeOffsets::OSR_Entry, _first_block_size);
duke@0 896 } else {
duke@0 897 _code_offsets.set_value(CodeOffsets::Verified_Entry, _first_block_size);
duke@0 898 _code_offsets.set_value(CodeOffsets::OSR_Entry, 0);
duke@0 899 }
duke@0 900
duke@0 901 env()->register_method(_method, _entry_bci,
duke@0 902 &_code_offsets,
duke@0 903 _orig_pc_slot_offset_in_bytes,
duke@0 904 code_buffer(),
duke@0 905 frame_size_in_words(), _oop_map_set,
duke@0 906 &_handler_table, &_inc_table,
duke@0 907 compiler,
duke@0 908 env()->comp_level(),
kvn@3668 909 has_unsafe_access(),
kvn@3668 910 SharedRuntime::is_wide_vector(max_vector_size())
duke@0 911 );
vlivanov@3719 912
vlivanov@3719 913 if (log() != NULL) // Print code cache state into compiler log
vlivanov@3719 914 log()->code_cache_state();
duke@0 915 }
duke@0 916 }
duke@0 917
duke@0 918 //------------------------------Compile----------------------------------------
duke@0 919 // Compile a runtime stub
duke@0 920 Compile::Compile( ciEnv* ci_env,
duke@0 921 TypeFunc_generator generator,
duke@0 922 address stub_function,
duke@0 923 const char *stub_name,
duke@0 924 int is_fancy_jump,
duke@0 925 bool pass_tls,
duke@0 926 bool save_arg_registers,
duke@0 927 bool return_pc )
duke@0 928 : Phase(Compiler),
duke@0 929 _env(ci_env),
duke@0 930 _log(ci_env->log()),
neliasso@4295 931 _compile_id(0),
duke@0 932 _save_argument_registers(save_arg_registers),
duke@0 933 _method(NULL),
duke@0 934 _stub_name(stub_name),
duke@0 935 _stub_function(stub_function),
duke@0 936 _stub_entry_point(NULL),
duke@0 937 _entry_bci(InvocationEntryBci),
duke@0 938 _initial_gvn(NULL),
duke@0 939 _for_igvn(NULL),
duke@0 940 _warm_calls(NULL),
duke@0 941 _orig_pc_slot(0),
duke@0 942 _orig_pc_slot_offset_in_bytes(0),
duke@0 943 _subsume_loads(true),
kvn@38 944 _do_escape_analysis(false),
kvn@4675 945 _eliminate_boxing(false),
duke@0 946 _failure_reason(NULL),
duke@0 947 _code_buffer("Compile::Fill_buffer"),
twisti@1265 948 _has_method_handle_invokes(false),
twisti@1915 949 _mach_constant_base_node(NULL),
duke@0 950 _node_bundling_limit(0),
duke@0 951 _node_bundling_base(NULL),
kvn@859 952 _java_calls(0),
kvn@859 953 _inner_loops(0),
duke@0 954 #ifndef PRODUCT
duke@0 955 _trace_opto_output(TraceOptoOutput),
goetz@5990 956 _in_dump_cnt(0),
duke@0 957 _printer(NULL),
duke@0 958 #endif
bharadwaj@3880 959 _dead_node_list(comp_arena()),
bharadwaj@3880 960 _dead_node_count(0),
roland@3922 961 _congraph(NULL),
kvn@5784 962 _replay_inline_data(NULL),
roland@3974 963 _number_of_mh_late_inlines(0),
roland@3974 964 _inlining_progress(false),
roland@3974 965 _inlining_incrementally(false),
roland@3922 966 _print_inlining_list(NULL),
roland@5546 967 _print_inlining_idx(0),
goetz@5992 968 _preserve_jvm_state(0),
goetz@5992 969 _allowed_reasons(0) {
duke@0 970 C = this;
duke@0 971
duke@0 972 #ifndef PRODUCT
duke@0 973 TraceTime t1(NULL, &_t_totalCompilation, TimeCompiler, false);
duke@0 974 TraceTime t2(NULL, &_t_stubCompilation, TimeCompiler, false);
duke@0 975 set_print_assembly(PrintFrameConverterAssembly);
never@367 976 set_parsed_irreducible_loop(false);
duke@0 977 #endif
duke@0 978 CompileWrapper cw(this);
duke@0 979 Init(/*AliasLevel=*/ 0);
duke@0 980 init_tf((*generator)());
duke@0 981
duke@0 982 {
duke@0 983 // The following is a dummy for the sake of GraphKit::gen_stub
duke@0 984 Unique_Node_List for_igvn(comp_arena());
duke@0 985 set_for_igvn(&for_igvn); // not used, but some GraphKit guys push on this
duke@0 986 PhaseGVN gvn(Thread::current()->resource_area(),255);
duke@0 987 set_initial_gvn(&gvn); // not significant, but GraphKit guys use it pervasively
duke@0 988 gvn.transform_no_reclaim(top());
duke@0 989
duke@0 990 GraphKit kit;
duke@0 991 kit.gen_stub(stub_function, stub_name, is_fancy_jump, pass_tls, return_pc);
duke@0 992 }
duke@0 993
duke@0 994 NOT_PRODUCT( verify_graph_edges(); )
duke@0 995 Code_Gen();
duke@0 996 if (failing()) return;
duke@0 997
duke@0 998
duke@0 999 // Entry point will be accessed using compile->stub_entry_point();
duke@0 1000 if (code_buffer() == NULL) {
duke@0 1001 Matcher::soft_match_failure();
duke@0 1002 } else {
duke@0 1003 if (PrintAssembly && (WizardMode || Verbose))
duke@0 1004 tty->print_cr("### Stub::%s", stub_name);
duke@0 1005
duke@0 1006 if (!failing()) {
duke@0 1007 assert(_fixed_slots == 0, "no fixed slots used for runtime stubs");
duke@0 1008
duke@0 1009 // Make the NMethod
duke@0 1010 // For now we mark the frame as never safe for profile stackwalking
duke@0 1011 RuntimeStub *rs = RuntimeStub::new_runtime_stub(stub_name,
duke@0 1012 code_buffer(),
duke@0 1013 CodeOffsets::frame_never_safe,
duke@0 1014 // _code_offsets.value(CodeOffsets::Frame_Complete),
duke@0 1015 frame_size_in_words(),
duke@0 1016 _oop_map_set,
duke@0 1017 save_arg_registers);
duke@0 1018 assert(rs != NULL && rs->is_runtime_stub(), "sanity check");
duke@0 1019
duke@0 1020 _stub_entry_point = rs->entry_point();
duke@0 1021 }
duke@0 1022 }
duke@0 1023 }
duke@0 1024
duke@0 1025 //------------------------------Init-------------------------------------------
duke@0 1026 // Prepare for a single compilation
duke@0 1027 void Compile::Init(int aliaslevel) {
duke@0 1028 _unique = 0;
duke@0 1029 _regalloc = NULL;
duke@0 1030
duke@0 1031 _tf = NULL; // filled in later
duke@0 1032 _top = NULL; // cached later
duke@0 1033 _matcher = NULL; // filled in later
duke@0 1034 _cfg = NULL; // filled in later
duke@0 1035
duke@0 1036 set_24_bit_selection_and_mode(Use24BitFP, false);
duke@0 1037
duke@0 1038 _node_note_array = NULL;
duke@0 1039 _default_node_notes = NULL;
duke@0 1040
duke@0 1041 _immutable_memory = NULL; // filled in at first inquiry
duke@0 1042
duke@0 1043 // Globally visible Nodes
duke@0 1044 // First set TOP to NULL to give safe behavior during creation of RootNode
duke@0 1045 set_cached_top_node(NULL);
kvn@3680 1046 set_root(new (this) RootNode());
duke@0 1047 // Now that you have a Root to point to, create the real TOP
kvn@3680 1048 set_cached_top_node( new (this) ConNode(Type::TOP) );
duke@0 1049 set_recent_alloc(NULL, NULL);
duke@0 1050
duke@0 1051 // Create Debug Information Recorder to record scopes, oopmaps, etc.
coleenp@3602 1052 env()->set_oop_recorder(new OopRecorder(env()->arena()));
duke@0 1053 env()->set_debug_info(new DebugInformationRecorder(env()->oop_recorder()));
duke@0 1054 env()->set_dependencies(new Dependencies(env()));
duke@0 1055
duke@0 1056 _fixed_slots = 0;
duke@0 1057 set_has_split_ifs(false);
duke@0 1058 set_has_loops(has_method() && method()->has_loops()); // first approximation
never@1080 1059 set_has_stringbuilder(false);
kvn@4675 1060 set_has_boxed_value(false);
duke@0 1061 _trap_can_recompile = false; // no traps emitted yet
duke@0 1062 _major_progress = true; // start out assuming good things will happen
duke@0 1063 set_has_unsafe_access(false);
kvn@3668 1064 set_max_vector_size(0);
duke@0 1065 Copy::zero_to_bytes(_trap_hist, sizeof(_trap_hist));
duke@0 1066 set_decompile_count(0);
duke@0 1067
rasbold@418 1068 set_do_freq_based_layout(BlockLayoutByFrequency || method_has_option("BlockLayoutByFrequency"));
iveresov@1703 1069 set_num_loop_opts(LoopOptsCount);
iveresov@1703 1070 set_do_inlining(Inline);
iveresov@1703 1071 set_max_inline_size(MaxInlineSize);
iveresov@1703 1072 set_freq_inline_size(FreqInlineSize);
iveresov@1703 1073 set_do_scheduling(OptoScheduling);
iveresov@1703 1074 set_do_count_invocations(false);
iveresov@1703 1075 set_do_method_data_update(false);
duke@0 1076
duke@0 1077 if (debug_info()->recording_non_safepoints()) {
duke@0 1078 set_node_note_array(new(comp_arena()) GrowableArray<Node_Notes*>
duke@0 1079 (comp_arena(), 8, 0, NULL));
duke@0 1080 set_default_node_notes(Node_Notes::make(this));
duke@0 1081 }
duke@0 1082
duke@0 1083 // // -- Initialize types before each compile --
duke@0 1084 // // Update cached type information
duke@0 1085 // if( _method && _method->constants() )
duke@0 1086 // Type::update_loaded_types(_method, _method->constants());
duke@0 1087
duke@0 1088 // Init alias_type map.
kvn@38 1089 if (!_do_escape_analysis && aliaslevel == 3)
duke@0 1090 aliaslevel = 2; // No unique types without escape analysis
duke@0 1091 _AliasLevel = aliaslevel;
duke@0 1092 const int grow_ats = 16;
duke@0 1093 _max_alias_types = grow_ats;
duke@0 1094 _alias_types = NEW_ARENA_ARRAY(comp_arena(), AliasType*, grow_ats);
duke@0 1095 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, grow_ats);
duke@0 1096 Copy::zero_to_bytes(ats, sizeof(AliasType)*grow_ats);
duke@0 1097 {
duke@0 1098 for (int i = 0; i < grow_ats; i++) _alias_types[i] = &ats[i];
duke@0 1099 }
duke@0 1100 // Initialize the first few types.
duke@0 1101 _alias_types[AliasIdxTop]->Init(AliasIdxTop, NULL);
duke@0 1102 _alias_types[AliasIdxBot]->Init(AliasIdxBot, TypePtr::BOTTOM);
duke@0 1103 _alias_types[AliasIdxRaw]->Init(AliasIdxRaw, TypeRawPtr::BOTTOM);
duke@0 1104 _num_alias_types = AliasIdxRaw+1;
duke@0 1105 // Zero out the alias type cache.
duke@0 1106 Copy::zero_to_bytes(_alias_cache, sizeof(_alias_cache));
duke@0 1107 // A NULL adr_type hits in the cache right away. Preload the right answer.
duke@0 1108 probe_alias_cache(NULL)->_index = AliasIdxTop;
duke@0 1109
duke@0 1110 _intrinsics = NULL;
kvn@1605 1111 _macro_nodes = new(comp_arena()) GrowableArray<Node*>(comp_arena(), 8, 0, NULL);
kvn@1605 1112 _predicate_opaqs = new(comp_arena()) GrowableArray<Node*>(comp_arena(), 8, 0, NULL);
roland@4154 1113 _expensive_nodes = new(comp_arena()) GrowableArray<Node*>(comp_arena(), 8, 0, NULL);
duke@0 1114 register_library_intrinsics();
duke@0 1115 }
duke@0 1116
duke@0 1117 //---------------------------init_start----------------------------------------
duke@0 1118 // Install the StartNode on this compile object.
duke@0 1119 void Compile::init_start(StartNode* s) {
duke@0 1120 if (failing())
duke@0 1121 return; // already failing
duke@0 1122 assert(s == start(), "");
duke@0 1123 }
duke@0 1124
duke@0 1125 StartNode* Compile::start() const {
duke@0 1126 assert(!failing(), "");
duke@0 1127 for (DUIterator_Fast imax, i = root()->fast_outs(imax); i < imax; i++) {
duke@0 1128 Node* start = root()->fast_out(i);
duke@0 1129 if( start->is_Start() )
duke@0 1130 return start->as_Start();
duke@0 1131 }
duke@0 1132 ShouldNotReachHere();
duke@0 1133 return NULL;
duke@0 1134 }
duke@0 1135
duke@0 1136 //-------------------------------immutable_memory-------------------------------------
duke@0 1137 // Access immutable memory
duke@0 1138 Node* Compile::immutable_memory() {
duke@0 1139 if (_immutable_memory != NULL) {
duke@0 1140 return _immutable_memory;
duke@0 1141 }
duke@0 1142 StartNode* s = start();
duke@0 1143 for (DUIterator_Fast imax, i = s->fast_outs(imax); true; i++) {
duke@0 1144 Node *p = s->fast_out(i);
duke@0 1145 if (p != s && p->as_Proj()->_con == TypeFunc::Memory) {
duke@0 1146 _immutable_memory = p;
duke@0 1147 return _immutable_memory;
duke@0 1148 }
duke@0 1149 }
duke@0 1150 ShouldNotReachHere();
duke@0 1151 return NULL;
duke@0 1152 }
duke@0 1153
duke@0 1154 //----------------------set_cached_top_node------------------------------------
duke@0 1155 // Install the cached top node, and make sure Node::is_top works correctly.
duke@0 1156 void Compile::set_cached_top_node(Node* tn) {
duke@0 1157 if (tn != NULL) verify_top(tn);
duke@0 1158 Node* old_top = _top;
duke@0 1159 _top = tn;
duke@0 1160 // Calling Node::setup_is_top allows the nodes the chance to adjust
duke@0 1161 // their _out arrays.
duke@0 1162 if (_top != NULL) _top->setup_is_top();
duke@0 1163 if (old_top != NULL) old_top->setup_is_top();
duke@0 1164 assert(_top == NULL || top()->is_top(), "");
duke@0 1165 }
duke@0 1166
bharadwaj@3880 1167 #ifdef ASSERT
bharadwaj@3880 1168 uint Compile::count_live_nodes_by_graph_walk() {
bharadwaj@3880 1169 Unique_Node_List useful(comp_arena());
bharadwaj@3880 1170 // Get useful node list by walking the graph.
bharadwaj@3880 1171 identify_useful_nodes(useful);
bharadwaj@3880 1172 return useful.size();
bharadwaj@3880 1173 }
bharadwaj@3880 1174
bharadwaj@3880 1175 void Compile::print_missing_nodes() {
bharadwaj@3880 1176
bharadwaj@3880 1177 // Return if CompileLog is NULL and PrintIdealNodeCount is false.
bharadwaj@3880 1178 if ((_log == NULL) && (! PrintIdealNodeCount)) {
bharadwaj@3880 1179 return;
bharadwaj@3880 1180 }
bharadwaj@3880 1181
bharadwaj@3880 1182 // This is an expensive function. It is executed only when the user
bharadwaj@3880 1183 // specifies VerifyIdealNodeCount option or otherwise knows the
bharadwaj@3880 1184 // additional work that needs to be done to identify reachable nodes
bharadwaj@3880 1185 // by walking the flow graph and find the missing ones using
bharadwaj@3880 1186 // _dead_node_list.
bharadwaj@3880 1187
bharadwaj@3880 1188 Unique_Node_List useful(comp_arena());
bharadwaj@3880 1189 // Get useful node list by walking the graph.
bharadwaj@3880 1190 identify_useful_nodes(useful);
bharadwaj@3880 1191
bharadwaj@3880 1192 uint l_nodes = C->live_nodes();
bharadwaj@3880 1193 uint l_nodes_by_walk = useful.size();
bharadwaj@3880 1194
bharadwaj@3880 1195 if (l_nodes != l_nodes_by_walk) {
bharadwaj@3880 1196 if (_log != NULL) {
bharadwaj@3880 1197 _log->begin_head("mismatched_nodes count='%d'", abs((int) (l_nodes - l_nodes_by_walk)));
bharadwaj@3880 1198 _log->stamp();
bharadwaj@3880 1199 _log->end_head();
bharadwaj@3880 1200 }
bharadwaj@3880 1201 VectorSet& useful_member_set = useful.member_set();
bharadwaj@3880 1202 int last_idx = l_nodes_by_walk;
bharadwaj@3880 1203 for (int i = 0; i < last_idx; i++) {
bharadwaj@3880 1204 if (useful_member_set.test(i)) {
bharadwaj@3880 1205 if (_dead_node_list.test(i)) {
bharadwaj@3880 1206 if (_log != NULL) {
bharadwaj@3880 1207 _log->elem("mismatched_node_info node_idx='%d' type='both live and dead'", i);
bharadwaj@3880 1208 }
bharadwaj@3880 1209 if (PrintIdealNodeCount) {
bharadwaj@3880 1210 // Print the log message to tty
bharadwaj@3880 1211 tty->print_cr("mismatched_node idx='%d' both live and dead'", i);
bharadwaj@3880 1212 useful.at(i)->dump();
bharadwaj@3880 1213 }
bharadwaj@3880 1214 }
bharadwaj@3880 1215 }
bharadwaj@3880 1216 else if (! _dead_node_list.test(i)) {
bharadwaj@3880 1217 if (_log != NULL) {
bharadwaj@3880 1218 _log->elem("mismatched_node_info node_idx='%d' type='neither live nor dead'", i);
bharadwaj@3880 1219 }
bharadwaj@3880 1220 if (PrintIdealNodeCount) {
bharadwaj@3880 1221 // Print the log message to tty
bharadwaj@3880 1222 tty->print_cr("mismatched_node idx='%d' type='neither live nor dead'", i);
bharadwaj@3880 1223 }
bharadwaj@3880 1224 }
bharadwaj@3880 1225 }
bharadwaj@3880 1226 if (_log != NULL) {
bharadwaj@3880 1227 _log->tail("mismatched_nodes");
bharadwaj@3880 1228 }
bharadwaj@3880 1229 }
bharadwaj@3880 1230 }
bharadwaj@3880 1231 #endif
bharadwaj@3880 1232
duke@0 1233 #ifndef PRODUCT
duke@0 1234 void Compile::verify_top(Node* tn) const {
duke@0 1235 if (tn != NULL) {
duke@0 1236 assert(tn->is_Con(), "top node must be a constant");
duke@0 1237 assert(((ConNode*)tn)->type() == Type::TOP, "top node must have correct type");
duke@0 1238 assert(tn->in(0) != NULL, "must have live top node");
duke@0 1239 }
duke@0 1240 }
duke@0 1241 #endif
duke@0 1242
duke@0 1243
duke@0 1244 ///-------------------Managing Per-Node Debug & Profile Info-------------------
duke@0 1245
duke@0 1246 void Compile::grow_node_notes(GrowableArray<Node_Notes*>* arr, int grow_by) {
duke@0 1247 guarantee(arr != NULL, "");
duke@0 1248 int num_blocks = arr->length();
duke@0 1249 if (grow_by < num_blocks) grow_by = num_blocks;
duke@0 1250 int num_notes = grow_by * _node_notes_block_size;
duke@0 1251 Node_Notes* notes = NEW_ARENA_ARRAY(node_arena(), Node_Notes, num_notes);
duke@0 1252 Copy::zero_to_bytes(notes, num_notes * sizeof(Node_Notes));
duke@0 1253 while (num_notes > 0) {
duke@0 1254 arr->append(notes);
duke@0 1255 notes += _node_notes_block_size;
duke@0 1256 num_notes -= _node_notes_block_size;
duke@0 1257 }
duke@0 1258 assert(num_notes == 0, "exact multiple, please");
duke@0 1259 }
duke@0 1260
duke@0 1261 bool Compile::copy_node_notes_to(Node* dest, Node* source) {
duke@0 1262 if (source == NULL || dest == NULL) return false;
duke@0 1263
duke@0 1264 if (dest->is_Con())
duke@0 1265 return false; // Do not push debug info onto constants.
duke@0 1266
duke@0 1267 #ifdef ASSERT
duke@0 1268 // Leave a bread crumb trail pointing to the original node:
duke@0 1269 if (dest != NULL && dest != source && dest->debug_orig() == NULL) {
duke@0 1270 dest->set_debug_orig(source);
duke@0 1271 }
duke@0 1272 #endif
duke@0 1273
duke@0 1274 if (node_note_array() == NULL)
duke@0 1275 return false; // Not collecting any notes now.
duke@0 1276
duke@0 1277 // This is a copy onto a pre-existing node, which may already have notes.
duke@0 1278 // If both nodes have notes, do not overwrite any pre-existing notes.
duke@0 1279 Node_Notes* source_notes = node_notes_at(source->_idx);
duke@0 1280 if (source_notes == NULL || source_notes->is_clear()) return false;
duke@0 1281 Node_Notes* dest_notes = node_notes_at(dest->_idx);
duke@0 1282 if (dest_notes == NULL || dest_notes->is_clear()) {
duke@0 1283 return set_node_notes_at(dest->_idx, source_notes);
duke@0 1284 }
duke@0 1285
duke@0 1286 Node_Notes merged_notes = (*source_notes);
duke@0 1287 // The order of operations here ensures that dest notes will win...
duke@0 1288 merged_notes.update_from(dest_notes);
duke@0 1289 return set_node_notes_at(dest->_idx, &merged_notes);
duke@0 1290 }
duke@0 1291
duke@0 1292
duke@0 1293 //--------------------------allow_range_check_smearing-------------------------
duke@0 1294 // Gating condition for coalescing similar range checks.
duke@0 1295 // Sometimes we try 'speculatively' replacing a series of a range checks by a
duke@0 1296 // single covering check that is at least as strong as any of them.
duke@0 1297 // If the optimization succeeds, the simplified (strengthened) range check
duke@0 1298 // will always succeed. If it fails, we will deopt, and then give up
duke@0 1299 // on the optimization.
duke@0 1300 bool Compile::allow_range_check_smearing() const {
duke@0 1301 // If this method has already thrown a range-check,
duke@0 1302 // assume it was because we already tried range smearing
duke@0 1303 // and it failed.
duke@0 1304 uint already_trapped = trap_count(Deoptimization::Reason_range_check);
duke@0 1305 return !already_trapped;
duke@0 1306 }
duke@0 1307
duke@0 1308
duke@0 1309 //------------------------------flatten_alias_type-----------------------------
duke@0 1310 const TypePtr *Compile::flatten_alias_type( const TypePtr *tj ) const {
duke@0 1311 int offset = tj->offset();
duke@0 1312 TypePtr::PTR ptr = tj->ptr();
duke@0 1313
kvn@247 1314 // Known instance (scalarizable allocation) alias only with itself.
kvn@247 1315 bool is_known_inst = tj->isa_oopptr() != NULL &&
kvn@247 1316 tj->is_oopptr()->is_known_instance();
kvn@247 1317
duke@0 1318 // Process weird unsafe references.
duke@0 1319 if (offset == Type::OffsetBot && (tj->isa_instptr() /*|| tj->isa_klassptr()*/)) {
duke@0 1320 assert(InlineUnsafeOps, "indeterminate pointers come only from unsafe ops");
kvn@247 1321 assert(!is_known_inst, "scalarizable allocation should not have unsafe references");
duke@0 1322 tj = TypeOopPtr::BOTTOM;
duke@0 1323 ptr = tj->ptr();
duke@0 1324 offset = tj->offset();
duke@0 1325 }
duke@0 1326
duke@0 1327 // Array pointers need some flattening
duke@0 1328 const TypeAryPtr *ta = tj->isa_aryptr();
vlivanov@5223 1329 if (ta && ta->is_stable()) {
vlivanov@5223 1330 // Erase stability property for alias analysis.
vlivanov@5223 1331 tj = ta = ta->cast_to_stable(false);
vlivanov@5223 1332 }
kvn@247 1333 if( ta && is_known_inst ) {
kvn@247 1334 if ( offset != Type::OffsetBot &&
kvn@247 1335 offset > arrayOopDesc::length_offset_in_bytes() ) {
kvn@247 1336 offset = Type::OffsetBot; // Flatten constant access into array body only
kvn@247 1337 tj = ta = TypeAryPtr::make(ptr, ta->ary(), ta->klass(), true, offset, ta->instance_id());
kvn@247 1338 }
kvn@247 1339 } else if( ta && _AliasLevel >= 2 ) {
duke@0 1340 // For arrays indexed by constant indices, we flatten the alias
duke@0 1341 // space to include all of the array body. Only the header, klass
duke@0 1342 // and array length can be accessed un-aliased.
duke@0 1343 if( offset != Type::OffsetBot ) {
coleenp@3602 1344 if( ta->const_oop() ) { // MethodData* or Method*
duke@0 1345 offset = Type::OffsetBot; // Flatten constant access into array body
kvn@247 1346 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),ta->ary(),ta->klass(),false,offset);
duke@0 1347 } else if( offset == arrayOopDesc::length_offset_in_bytes() ) {
duke@0 1348 // range is OK as-is.
duke@0 1349 tj = ta = TypeAryPtr::RANGE;
duke@0 1350 } else if( offset == oopDesc::klass_offset_in_bytes() ) {
duke@0 1351 tj = TypeInstPtr::KLASS; // all klass loads look alike
duke@0 1352 ta = TypeAryPtr::RANGE; // generic ignored junk
duke@0 1353 ptr = TypePtr::BotPTR;
duke@0 1354 } else if( offset == oopDesc::mark_offset_in_bytes() ) {
duke@0 1355 tj = TypeInstPtr::MARK;
duke@0 1356 ta = TypeAryPtr::RANGE; // generic ignored junk
duke@0 1357 ptr = TypePtr::BotPTR;
duke@0 1358 } else { // Random constant offset into array body
duke@0 1359 offset = Type::OffsetBot; // Flatten constant access into array body
kvn@247 1360 tj = ta = TypeAryPtr::make(ptr,ta->ary(),ta->klass(),false,offset);
duke@0 1361 }
duke@0 1362 }
duke@0 1363 // Arrays of fixed size alias with arrays of unknown size.
duke@0 1364 if (ta->size() != TypeInt::POS) {
duke@0 1365 const TypeAry *tary = TypeAry::make(ta->elem(), TypeInt::POS);
kvn@247 1366 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,ta->klass(),false,offset);
duke@0 1367 }
duke@0 1368 // Arrays of known objects become arrays of unknown objects.
coleenp@113 1369 if (ta->elem()->isa_narrowoop() && ta->elem() != TypeNarrowOop::BOTTOM) {
coleenp@113 1370 const TypeAry *tary = TypeAry::make(TypeNarrowOop::BOTTOM, ta->size());
kvn@247 1371 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset);
coleenp@113 1372 }
duke@0 1373 if (ta->elem()->isa_oopptr() && ta->elem() != TypeInstPtr::BOTTOM) {
duke@0 1374 const TypeAry *tary = TypeAry::make(TypeInstPtr::BOTTOM, ta->size());
kvn@247 1375 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,NULL,false,offset);
duke@0 1376 }
duke@0 1377 // Arrays of bytes and of booleans both use 'bastore' and 'baload' so
duke@0 1378 // cannot be distinguished by bytecode alone.
duke@0 1379 if (ta->elem() == TypeInt::BOOL) {
duke@0 1380 const TypeAry *tary = TypeAry::make(TypeInt::BYTE, ta->size());
duke@0 1381 ciKlass* aklass = ciTypeArrayKlass::make(T_BYTE);
kvn@247 1382 tj = ta = TypeAryPtr::make(ptr,ta->const_oop(),tary,aklass,false,offset);
duke@0 1383 }
duke@0 1384 // During the 2nd round of IterGVN, NotNull castings are removed.
duke@0 1385 // Make sure the Bottom and NotNull variants alias the same.
duke@0 1386 // Also, make sure exact and non-exact variants alias the same.
roland@5556 1387 if (ptr == TypePtr::NotNull || ta->klass_is_exact() || ta->speculative() != NULL) {
kvn@2551 1388 tj = ta = TypeAryPtr::make(TypePtr::BotPTR,ta->ary(),ta->klass(),false,offset);
duke@0 1389 }
duke@0 1390 }
duke@0 1391
duke@0 1392 // Oop pointers need some flattening
duke@0 1393 const TypeInstPtr *to = tj->isa_instptr();
duke@0 1394 if( to && _AliasLevel >= 2 && to != TypeOopPtr::BOTTOM ) {
never@2223 1395 ciInstanceKlass *k = to->klass()->as_instance_klass();
duke@0 1396 if( ptr == TypePtr::Constant ) {
never@2223 1397 if (to->klass() != ciEnv::current()->Class_klass() ||
never@2223 1398 offset < k->size_helper() * wordSize) {
never@2223 1399 // No constant oop pointers (such as Strings); they alias with
never@2223 1400 // unknown strings.
never@2223 1401 assert(!is_known_inst, "not scalarizable allocation");
never@2223 1402 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
never@2223 1403 }
kvn@247 1404 } else if( is_known_inst ) {
kvn@163 1405 tj = to; // Keep NotNull and klass_is_exact for instance type
duke@0 1406 } else if( ptr == TypePtr::NotNull || to->klass_is_exact() ) {
duke@0 1407 // During the 2nd round of IterGVN, NotNull castings are removed.
duke@0 1408 // Make sure the Bottom and NotNull variants alias the same.
duke@0 1409 // Also, make sure exact and non-exact variants alias the same.
kvn@247 1410 tj = to = TypeInstPtr::make(TypePtr::BotPTR,to->klass(),false,0,offset);
duke@0 1411 }
roland@5556 1412 if (to->speculative() != NULL) {
roland@5556 1413 tj = to = TypeInstPtr::make(to->ptr(),to->klass(),to->klass_is_exact(),to->const_oop(),to->offset(), to->instance_id());
roland@5556 1414 }
duke@0 1415 // Canonicalize the holder of this field
coleenp@113 1416 if (offset >= 0 && offset < instanceOopDesc::base_offset_in_bytes()) {
duke@0 1417 // First handle header references such as a LoadKlassNode, even if the
duke@0 1418 // object's klass is unloaded at compile time (4965979).
kvn@247 1419 if (!is_known_inst) { // Do it only for non-instance types
kvn@247 1420 tj = to = TypeInstPtr::make(TypePtr::BotPTR, env()->Object_klass(), false, NULL, offset);
kvn@247 1421 }
duke@0 1422 } else if (offset < 0 || offset >= k->size_helper() * wordSize) {
never@2223 1423 // Static fields are in the space above the normal instance
never@2223 1424 // fields in the java.lang.Class instance.
never@2223 1425 if (to->klass() != ciEnv::current()->Class_klass()) {
never@2223 1426 to = NULL;
never@2223 1427 tj = TypeOopPtr::BOTTOM;
never@2223 1428 offset = tj->offset();
never@2223 1429 }
duke@0 1430 } else {
duke@0 1431 ciInstanceKlass *canonical_holder = k->get_canonical_holder(offset);
duke@0 1432 if (!k->equals(canonical_holder) || tj->offset() != offset) {
kvn@247 1433 if( is_known_inst ) {
kvn@247 1434 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, true, NULL, offset, to->instance_id());
kvn@247 1435 } else {
kvn@247 1436 tj = to = TypeInstPtr::make(to->ptr(), canonical_holder, false, NULL, offset);
kvn@247 1437 }
duke@0 1438 }
duke@0 1439 }
duke@0 1440 }
duke@0 1441
duke@0 1442 // Klass pointers to object array klasses need some flattening
duke@0 1443 const TypeKlassPtr *tk = tj->isa_klassptr();
duke@0 1444 if( tk ) {
duke@0 1445 // If we are referencing a field within a Klass, we need
duke@0 1446 // to assume the worst case of an Object. Both exact and
never@2954 1447 // inexact types must flatten to the same alias class so
never@2954 1448 // use NotNull as the PTR.
duke@0 1449 if ( offset == Type::OffsetBot || (offset >= 0 && (size_t)offset < sizeof(Klass)) ) {
duke@0 1450
never@2954 1451 tj = tk = TypeKlassPtr::make(TypePtr::NotNull,
duke@0 1452 TypeKlassPtr::OBJECT->klass(),
duke@0 1453 offset);
duke@0 1454 }
duke@0 1455
duke@0 1456 ciKlass* klass = tk->klass();
duke@0 1457 if( klass->is_obj_array_klass() ) {
duke@0 1458 ciKlass* k = TypeAryPtr::OOPS->klass();
duke@0 1459 if( !k || !k->is_loaded() ) // Only fails for some -Xcomp runs
duke@0 1460 k = TypeInstPtr::BOTTOM->klass();
duke@0 1461 tj = tk = TypeKlassPtr::make( TypePtr::NotNull, k, offset );
duke@0 1462 }
duke@0 1463
duke@0 1464 // Check for precise loads from the primary supertype array and force them
duke@0 1465 // to the supertype cache alias index. Check for generic array loads from
duke@0 1466 // the primary supertype array and also force them to the supertype cache
duke@0 1467 // alias index. Since the same load can reach both, we need to merge
duke@0 1468 // these 2 disparate memories into the same alias class. Since the
duke@0 1469 // primary supertype array is read-only, there's no chance of confusion
duke@0 1470 // where we bypass an array load and an array store.
stefank@2956 1471 int primary_supers_offset = in_bytes(Klass::primary_supers_offset());
never@2954 1472 if (offset == Type::OffsetBot ||
never@2954 1473 (offset >= primary_supers_offset &&
never@2954 1474 offset < (int)(primary_supers_offset + Klass::primary_super_limit() * wordSize)) ||
stefank@2956 1475 offset == (int)in_bytes(Klass::secondary_super_cache_offset())) {
stefank@2956 1476 offset = in_bytes(Klass::secondary_super_cache_offset());
duke@0 1477 tj = tk = TypeKlassPtr::make( TypePtr::NotNull, tk->klass(), offset );
duke@0 1478 }
duke@0 1479 }
duke@0 1480
duke@0 1481 // Flatten all Raw pointers together.
duke@0 1482 if (tj->base() == Type::RawPtr)
duke@0 1483 tj = TypeRawPtr::BOTTOM;
duke@0 1484
duke@0 1485 if (tj->base() == Type::AnyPtr)
duke@0 1486 tj = TypePtr::BOTTOM; // An error, which the caller must check for.
duke@0 1487
duke@0 1488 // Flatten all to bottom for now
duke@0 1489 switch( _AliasLevel ) {
duke@0 1490 case 0:
duke@0 1491 tj = TypePtr::BOTTOM;
duke@0 1492 break;
duke@0 1493 case 1: // Flatten to: oop, static, field or array
duke@0 1494 switch (tj->base()) {
duke@0 1495 //case Type::AryPtr: tj = TypeAryPtr::RANGE; break;
duke@0 1496 case Type::RawPtr: tj = TypeRawPtr::BOTTOM; break;
duke@0 1497 case Type::AryPtr: // do not distinguish arrays at all
duke@0 1498 case Type::InstPtr: tj = TypeInstPtr::BOTTOM; break;
duke@0 1499 case Type::KlassPtr: tj = TypeKlassPtr::OBJECT; break;
duke@0 1500 case Type::AnyPtr: tj = TypePtr::BOTTOM; break; // caller checks it
duke@0 1501 default: ShouldNotReachHere();
duke@0 1502 }
duke@0 1503 break;
twisti@605 1504 case 2: // No collapsing at level 2; keep all splits
twisti@605 1505 case 3: // No collapsing at level 3; keep all splits
duke@0 1506 break;
duke@0 1507 default:
duke@0 1508 Unimplemented();
duke@0 1509 }
duke@0 1510
duke@0 1511 offset = tj->offset();
duke@0 1512 assert( offset != Type::OffsetTop, "Offset has fallen from constant" );
duke@0 1513
duke@0 1514 assert( (offset != Type::OffsetBot && tj->base() != Type::AryPtr) ||
duke@0 1515 (offset == Type::OffsetBot && tj->base() == Type::AryPtr) ||
duke@0 1516 (offset == Type::OffsetBot && tj == TypeOopPtr::BOTTOM) ||
duke@0 1517 (offset == Type::OffsetBot && tj == TypePtr::BOTTOM) ||
duke@0 1518 (offset == oopDesc::mark_offset_in_bytes() && tj->base() == Type::AryPtr) ||
duke@0 1519 (offset == oopDesc::klass_offset_in_bytes() && tj->base() == Type::AryPtr) ||
duke@0 1520 (offset == arrayOopDesc::length_offset_in_bytes() && tj->base() == Type::AryPtr) ,
duke@0 1521 "For oops, klasses, raw offset must be constant; for arrays the offset is never known" );
duke@0 1522 assert( tj->ptr() != TypePtr::TopPTR &&
duke@0 1523 tj->ptr() != TypePtr::AnyNull &&
duke@0 1524 tj->ptr() != TypePtr::Null, "No imprecise addresses" );
duke@0 1525 // assert( tj->ptr() != TypePtr::Constant ||
duke@0 1526 // tj->base() == Type::RawPtr ||
duke@0 1527 // tj->base() == Type::KlassPtr, "No constant oop addresses" );
duke@0 1528
duke@0 1529 return tj;
duke@0 1530 }
duke@0 1531
duke@0 1532 void Compile::AliasType::Init(int i, const TypePtr* at) {
duke@0 1533 _index = i;
duke@0 1534 _adr_type = at;
duke@0 1535 _field = NULL;
vlivanov@5223 1536 _element = NULL;
duke@0 1537 _is_rewritable = true; // default
duke@0 1538 const TypeOopPtr *atoop = (at != NULL) ? at->isa_oopptr() : NULL;
kvn@223 1539 if (atoop != NULL && atoop->is_known_instance()) {
kvn@223 1540 const TypeOopPtr *gt = atoop->cast_to_instance_id(TypeOopPtr::InstanceBot);
duke@0 1541 _general_index = Compile::current()->get_alias_index(gt);
duke@0 1542 } else {
duke@0 1543 _general_index = 0;
duke@0 1544 }
duke@0 1545 }
duke@0 1546
duke@0 1547 //---------------------------------print_on------------------------------------
duke@0 1548 #ifndef PRODUCT
duke@0 1549 void Compile::AliasType::print_on(outputStream* st) {
duke@0 1550 if (index() < 10)
duke@0 1551 st->print("@ <%d> ", index());
duke@0 1552 else st->print("@ <%d>", index());
duke@0 1553 st->print(is_rewritable() ? " " : " RO");
duke@0 1554 int offset = adr_type()->offset();
duke@0 1555 if (offset == Type::OffsetBot)
duke@0 1556 st->print(" +any");
duke@0 1557 else st->print(" +%-3d", offset);
duke@0 1558 st->print(" in ");
duke@0 1559 adr_type()->dump_on(st);
duke@0 1560 const TypeOopPtr* tjp = adr_type()->isa_oopptr();
duke@0 1561 if (field() != NULL && tjp) {
duke@0 1562 if (tjp->klass() != field()->holder() ||
duke@0 1563 tjp->offset() != field()->offset_in_bytes()) {
duke@0 1564 st->print(" != ");
duke@0 1565 field()->print();
duke@0 1566 st->print(" ***");
duke@0 1567 }
duke@0 1568 }
duke@0 1569 }
duke@0 1570
duke@0 1571 void print_alias_types() {
duke@0 1572 Compile* C = Compile::current();
duke@0 1573 tty->print_cr("--- Alias types, AliasIdxBot .. %d", C->num_alias_types()-1);
duke@0 1574 for (int idx = Compile::AliasIdxBot; idx < C->num_alias_types(); idx++) {
duke@0 1575 C->alias_type(idx)->print_on(tty);
duke@0 1576 tty->cr();
duke@0 1577 }
duke@0 1578 }
duke@0 1579 #endif
duke@0 1580
duke@0 1581
duke@0 1582 //----------------------------probe_alias_cache--------------------------------
duke@0 1583 Compile::AliasCacheEntry* Compile::probe_alias_cache(const TypePtr* adr_type) {
duke@0 1584 intptr_t key = (intptr_t) adr_type;
duke@0 1585 key ^= key >> logAliasCacheSize;
duke@0 1586 return &_alias_cache[key & right_n_bits(logAliasCacheSize)];
duke@0 1587 }
duke@0 1588
duke@0 1589
duke@0 1590 //-----------------------------grow_alias_types--------------------------------
duke@0 1591 void Compile::grow_alias_types() {
duke@0 1592 const int old_ats = _max_alias_types; // how many before?
duke@0 1593 const int new_ats = old_ats; // how many more?
duke@0 1594 const int grow_ats = old_ats+new_ats; // how many now?
duke@0 1595 _max_alias_types = grow_ats;
duke@0 1596 _alias_types = REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats);
duke@0 1597 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats);
duke@0 1598 Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);
duke@0 1599 for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i];
duke@0 1600 }
duke@0 1601
duke@0 1602
duke@0 1603 //--------------------------------find_alias_type------------------------------
never@2223 1604 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field) {
duke@0 1605 if (_AliasLevel == 0)
duke@0 1606 return alias_type(AliasIdxBot);
duke@0 1607
duke@0 1608 AliasCacheEntry* ace = probe_alias_cache(adr_type);
duke@0 1609 if (ace->_adr_type == adr_type) {
duke@0 1610 return alias_type(ace->_index);
duke@0 1611 }
duke@0 1612
duke@0 1613 // Handle special cases.
duke@0 1614 if (adr_type == NULL) return alias_type(AliasIdxTop);
duke@0 1615 if (adr_type == TypePtr::BOTTOM) return alias_type(AliasIdxBot);
duke@0 1616
duke@0 1617 // Do it the slow way.
duke@0 1618 const TypePtr* flat = flatten_alias_type(adr_type);
duke@0 1619
duke@0 1620 #ifdef ASSERT
duke@0 1621 assert(flat == flatten_alias_type(flat), "idempotent");
duke@0 1622 assert(flat != TypePtr::BOTTOM, "cannot alias-analyze an untyped ptr");
duke@0 1623 if (flat->isa_oopptr() && !flat->isa_klassptr()) {
duke@0 1624 const TypeOopPtr* foop = flat->is_oopptr();
kvn@247 1625 // Scalarizable allocations have exact klass always.
kvn@247 1626 bool exact = !foop->klass_is_exact() || foop->is_known_instance();
kvn@247 1627 const TypePtr* xoop = foop->cast_to_exactness(exact)->is_ptr();
duke@0 1628 assert(foop == flatten_alias_type(xoop), "exactness must not affect alias type");
duke@0 1629 }
duke@0 1630 assert(flat == flatten_alias_type(flat), "exact bit doesn't matter");
duke@0 1631 #endif
duke@0 1632
duke@0 1633 int idx = AliasIdxTop;
duke@0 1634 for (int i = 0; i < num_alias_types(); i++) {
duke@0 1635 if (alias_type(i)->adr_type() == flat) {
duke@0 1636 idx = i;
duke@0 1637 break;
duke@0 1638 }
duke@0 1639 }
duke@0 1640
duke@0 1641 if (idx == AliasIdxTop) {
duke@0 1642 if (no_create) return NULL;
duke@0 1643 // Grow the array if necessary.
duke@0 1644 if (_num_alias_types == _max_alias_types) grow_alias_types();
duke@0 1645 // Add a new alias type.
duke@0 1646 idx = _num_alias_types++;
duke@0 1647 _alias_types[idx]->Init(idx, flat);
duke@0 1648 if (flat == TypeInstPtr::KLASS) alias_type(idx)->set_rewritable(false);
duke@0 1649 if (flat == TypeAryPtr::RANGE) alias_type(idx)->set_rewritable(false);
duke@0 1650 if (flat->isa_instptr()) {
duke@0 1651 if (flat->offset() == java_lang_Class::klass_offset_in_bytes()
duke@0 1652 && flat->is_instptr()->klass() == env()->Class_klass())
duke@0 1653 alias_type(idx)->set_rewritable(false);
duke@0 1654 }
vlivanov@5223 1655 if (flat->isa_aryptr()) {
vlivanov@5223 1656 #ifdef ASSERT
vlivanov@5223 1657 const int header_size_min = arrayOopDesc::base_offset_in_bytes(T_BYTE);
vlivanov@5223 1658 // (T_BYTE has the weakest alignment and size restrictions...)
vlivanov@5223 1659 assert(flat->offset() < header_size_min, "array body reference must be OffsetBot");
vlivanov@5223 1660 #endif
vlivanov@5223 1661 if (flat->offset() == TypePtr::OffsetBot) {
vlivanov@5223 1662 alias_type(idx)->set_element(flat->is_aryptr()->elem());
vlivanov@5223 1663 }
vlivanov@5223 1664 }
duke@0 1665 if (flat->isa_klassptr()) {
stefank@2956 1666 if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
duke@0 1667 alias_type(idx)->set_rewritable(false);
stefank@2956 1668 if (flat->offset() == in_bytes(Klass::modifier_flags_offset()))
duke@0 1669 alias_type(idx)->set_rewritable(false);
stefank@2956 1670 if (flat->offset() == in_bytes(Klass::access_flags_offset()))
duke@0 1671 alias_type(idx)->set_rewritable(false);
stefank@2956 1672 if (flat->offset() == in_bytes(Klass::java_mirror_offset()))
duke@0 1673 alias_type(idx)->set_rewritable(false);
duke@0 1674 }
duke@0 1675 // %%% (We would like to finalize JavaThread::threadObj_offset(),
duke@0 1676 // but the base pointer type is not distinctive enough to identify
duke@0 1677 // references into JavaThread.)
duke@0 1678
never@2223 1679 // Check for final fields.
duke@0 1680 const TypeInstPtr* tinst = flat->isa_instptr();
coleenp@113 1681 if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {
never@2223 1682 ciField* field;
never@2223 1683 if (tinst->const_oop() != NULL &&
never@2223 1684 tinst->klass() == ciEnv::current()->Class_klass() &&
never@2223 1685 tinst->offset() >= (tinst->klass()->as_instance_klass()->size_helper() * wordSize)) {
never@2223 1686 // static field
never@2223 1687 ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
never@2223 1688 field = k->get_field_by_offset(tinst->offset(), true);
never@2223 1689 } else {
never@2223 1690 ciInstanceKlass *k = tinst->klass()->as_instance_klass();
never@2223 1691 field = k->get_field_by_offset(tinst->offset(), false);
never@2223 1692 }
never@2223 1693 assert(field == NULL ||
never@2223 1694 original_field == NULL ||
never@2223 1695 (field->holder() == original_field->holder() &&
never@2223 1696 field->offset() == original_field->offset() &&
never@2223 1697 field->is_static() == original_field->is_static()), "wrong field?");
duke@0 1698 // Set field() and is_rewritable() attributes.
duke@0 1699 if (field != NULL) alias_type(idx)->set_field(field);
duke@0 1700 }
duke@0 1701 }
duke@0 1702
duke@0 1703 // Fill the cache for next time.
duke@0 1704 ace->_adr_type = adr_type;
duke@0 1705 ace->_index = idx;
duke@0 1706 assert(alias_type(adr_type) == alias_type(idx), "type must be installed");
duke@0 1707
duke@0 1708 // Might as well try to fill the cache for the flattened version, too.
duke@0 1709 AliasCacheEntry* face = probe_alias_cache(flat);
duke@0 1710 if (face->_adr_type == NULL) {
duke@0 1711 face->_adr_type = flat;
duke@0 1712 face->_index = idx;
duke@0 1713 assert(alias_type(flat) == alias_type(idx), "flat type must work too");
duke@0 1714 }
duke@0 1715
duke@0 1716 return alias_type(idx);
duke@0 1717 }
duke@0 1718
duke@0 1719
duke@0 1720 Compile::AliasType* Compile::alias_type(ciField* field) {
duke@0 1721 const TypeOopPtr* t;
duke@0 1722 if (field->is_static())
never@2223 1723 t = TypeInstPtr::make(field->holder()->java_mirror());
duke@0 1724 else
duke@0 1725 t = TypeOopPtr::make_from_klass_raw(field->holder());
never@2223 1726 AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
vlivanov@5223 1727 assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct");
duke@0 1728 return atp;
duke@0 1729 }
duke@0 1730
duke@0 1731
duke@0 1732 //------------------------------have_alias_type--------------------------------
duke@0 1733 bool Compile::have_alias_type(const TypePtr* adr_type) {
duke@0 1734 AliasCacheEntry* ace = probe_alias_cache(adr_type);
duke@0 1735 if (ace->_adr_type == adr_type) {
duke@0 1736 return true;
duke@0 1737 }
duke@0 1738
duke@0 1739 // Handle special cases.
duke@0 1740 if (adr_type == NULL) return true;
duke@0 1741 if (adr_type == TypePtr::BOTTOM) return true;
duke@0 1742
never@2223 1743 return find_alias_type(adr_type, true, NULL) != NULL;
duke@0 1744 }
duke@0 1745
duke@0 1746 //-----------------------------must_alias--------------------------------------
duke@0 1747 // True if all values of the given address type are in the given alias category.
duke@0 1748 bool Compile::must_alias(const TypePtr* adr_type, int alias_idx) {
duke@0 1749 if (alias_idx == AliasIdxBot) return true; // the universal category
duke@0 1750 if (adr_type == NULL) return true; // NULL serves as TypePtr::TOP
duke@0 1751 if (alias_idx == AliasIdxTop) return false; // the empty category
duke@0 1752 if (adr_type->base() == Type::AnyPtr) return false; // TypePtr::BOTTOM or its twins
duke@0 1753
duke@0 1754 // the only remaining possible overlap is identity
duke@0 1755 int adr_idx = get_alias_index(adr_type);
duke@0 1756 assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, "");
duke@0 1757 assert(adr_idx == alias_idx ||
duke@0 1758 (alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOM
duke@0 1759 && adr_type != TypeOopPtr::BOTTOM),
duke@0 1760 "should not be testing for overlap with an unsafe pointer");
duke@0 1761 return adr_idx == alias_idx;
duke@0 1762 }
duke@0 1763
duke@0 1764 //------------------------------can_alias--------------------------------------
duke@0 1765 // True if any values of the given address type are in the given alias category.
duke@0 1766 bool Compile::can_alias(const TypePtr* adr_type, int alias_idx) {
duke@0 1767 if (alias_idx == AliasIdxTop) return false; // the empty category
duke@0 1768 if (adr_type == NULL) return false; // NULL serves as TypePtr::TOP
duke@0 1769 if (alias_idx == AliasIdxBot) return true; // the universal category
duke@0 1770 if (adr_type->base() == Type::AnyPtr) return true; // TypePtr::BOTTOM or its twins
duke@0 1771
duke@0 1772 // the only remaining possible overlap is identity
duke@0 1773 int adr_idx = get_alias_index(adr_type);
duke@0 1774 assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, "");
duke@0 1775 return adr_idx == alias_idx;
duke@0 1776 }
duke@0 1777
duke@0 1778
duke@0 1779
duke@0 1780 //---------------------------pop_warm_call-------------------------------------
duke@0 1781 WarmCallInfo* Compile::pop_warm_call() {
duke@0 1782 WarmCallInfo* wci = _warm_calls;
duke@0 1783 if (wci != NULL) _warm_calls = wci->remove_from(wci);
duke@0 1784 return wci;
duke@0 1785 }
duke@0 1786
duke@0 1787 //----------------------------Inline_Warm--------------------------------------
duke@0 1788 int Compile::Inline_Warm() {
duke@0 1789 // If there is room, try to inline some more warm call sites.
duke@0 1790 // %%% Do a graph index compaction pass when we think we're out of space?
duke@0 1791 if (!InlineWarmCalls) return 0;
duke@0 1792
duke@0 1793 int calls_made_hot = 0;
duke@0 1794 int room_to_grow = NodeCountInliningCutoff - unique();
duke@0 1795 int amount_to_grow = MIN2(room_to_grow, (int)NodeCountInliningStep);
duke@0 1796 int amount_grown = 0;
duke@0 1797 WarmCallInfo* call;
duke@0 1798 while (amount_to_grow > 0 && (call = pop_warm_call()) != NULL) {
duke@0 1799 int est_size = (int)call->size();
duke@0 1800 if (est_size > (room_to_grow - amount_grown)) {
duke@0 1801 // This one won't fit anyway. Get rid of it.
duke@0 1802 call->make_cold();
duke@0 1803 continue;
duke@0 1804 }
duke@0 1805 call->make_hot();
duke@0 1806 calls_made_hot++;
duke@0 1807 amount_grown += est_size;
duke@0 1808 amount_to_grow -= est_size;
duke@0 1809 }
duke@0 1810
duke@0 1811 if (calls_made_hot > 0) set_major_progress();
duke@0 1812 return calls_made_hot;
duke@0 1813 }
duke@0 1814
duke@0 1815
duke@0 1816 //----------------------------Finish_Warm--------------------------------------
duke@0 1817 void Compile::Finish_Warm() {
duke@0 1818 if (!InlineWarmCalls) return;
duke@0 1819 if (failing()) return;
duke@0 1820 if (warm_calls() == NULL) return;
duke@0 1821
duke@0 1822 // Clean up loose ends, if we are out of space for inlining.
duke@0 1823 WarmCallInfo* call;
duke@0 1824 while ((call = pop_warm_call()) != NULL) {
duke@0 1825 call->make_cold();
duke@0 1826 }
duke@0 1827 }
duke@0 1828
cfang@1172 1829 //---------------------cleanup_loop_predicates-----------------------
cfang@1172 1830 // Remove the opaque nodes that protect the predicates so that all unused
cfang@1172 1831 // checks and uncommon_traps will be eliminated from the ideal graph
cfang@1172 1832 void Compile::cleanup_loop_predicates(PhaseIterGVN &igvn) {
cfang@1172 1833 if (predicate_count()==0) return;
cfang@1172 1834 for (int i = predicate_count(); i > 0; i--) {
cfang@1172 1835 Node * n = predicate_opaque1_node(i-1);
cfang@1172 1836 assert(n->Opcode() == Op_Opaque1, "must be");
cfang@1172 1837 igvn.replace_node(n, n->in(1));
cfang@1172 1838 }
cfang@1172 1839 assert(predicate_count()==0, "should be clean!");
cfang@1172 1840 }
duke@0 1841
roland@3974 1842 // StringOpts and late inlining of string methods
roland@3974 1843 void Compile::inline_string_calls(bool parse_time) {
roland@3974 1844 {
roland@3974 1845 // remove useless nodes to make the usage analysis simpler
roland@3974 1846 ResourceMark rm;
roland@3974 1847 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
roland@3974 1848 }
roland@3974 1849
roland@3974 1850 {
roland@3974 1851 ResourceMark rm;
sla@4802 1852 print_method(PHASE_BEFORE_STRINGOPTS, 3);
roland@3974 1853 PhaseStringOpts pso(initial_gvn(), for_igvn());
sla@4802 1854 print_method(PHASE_AFTER_STRINGOPTS, 3);
roland@3974 1855 }
roland@3974 1856
roland@3974 1857 // now inline anything that we skipped the first time around
roland@3974 1858 if (!parse_time) {
roland@3974 1859 _late_inlines_pos = _late_inlines.length();
roland@3974 1860 }
roland@3974 1861
roland@3974 1862 while (_string_late_inlines.length() > 0) {
roland@3974 1863 CallGenerator* cg = _string_late_inlines.pop();
roland@3974 1864 cg->do_late_inline();
roland@3974 1865 if (failing()) return;
roland@3974 1866 }
roland@3974 1867 _string_late_inlines.trunc_to(0);
roland@3974 1868 }
roland@3974 1869
kvn@4675 1870 // Late inlining of boxing methods
kvn@4675 1871 void Compile::inline_boxing_calls(PhaseIterGVN& igvn) {
kvn@4675 1872 if (_boxing_late_inlines.length() > 0) {
kvn@4675 1873 assert(has_boxed_value(), "inconsistent");
kvn@4675 1874
kvn@4675 1875 PhaseGVN* gvn = initial_gvn();
kvn@4675 1876 set_inlining_incrementally(true);
kvn@4675 1877
kvn@4675 1878 assert( igvn._worklist.size() == 0, "should be done with igvn" );
kvn@4675 1879 for_igvn()->clear();
kvn@4675 1880 gvn->replace_with(&igvn);
kvn@4675 1881
kvn@4675 1882 while (_boxing_late_inlines.length() > 0) {
kvn@4675 1883 CallGenerator* cg = _boxing_late_inlines.pop();
kvn@4675 1884 cg->do_late_inline();
kvn@4675 1885 if (failing()) return;
kvn@4675 1886 }
kvn@4675 1887 _boxing_late_inlines.trunc_to(0);
kvn@4675 1888
kvn@4675 1889 {
kvn@4675 1890 ResourceMark rm;
kvn@4675 1891 PhaseRemoveUseless pru(gvn, for_igvn());
kvn@4675 1892 }
kvn@4675 1893
kvn@4675 1894 igvn = PhaseIterGVN(gvn);
kvn@4675 1895 igvn.optimize();
kvn@4675 1896
kvn@4675 1897 set_inlining_progress(false);
kvn@4675 1898 set_inlining_incrementally(false);
kvn@4675 1899 }
kvn@4675 1900 }
kvn@4675 1901
roland@3974 1902 void Compile::inline_incrementally_one(PhaseIterGVN& igvn) {
roland@3974 1903 assert(IncrementalInline, "incremental inlining should be on");
roland@3974 1904 PhaseGVN* gvn = initial_gvn();
roland@3974 1905
roland@3974 1906 set_inlining_progress(false);
roland@3974 1907 for_igvn()->clear();
roland@3974 1908 gvn->replace_with(&igvn);
roland@3974 1909
roland@3974 1910 int i = 0;
roland@3974 1911
roland@3974 1912 for (; i <_late_inlines.length() && !inlining_progress(); i++) {
roland@3974 1913 CallGenerator* cg = _late_inlines.at(i);
roland@3974 1914 _late_inlines_pos = i+1;
roland@3974 1915 cg->do_late_inline();
roland@3974 1916 if (failing()) return;
roland@3974 1917 }
roland@3974 1918 int j = 0;
roland@3974 1919 for (; i < _late_inlines.length(); i++, j++) {
roland@3974 1920 _late_inlines.at_put(j, _late_inlines.at(i));
roland@3974 1921 }
roland@3974 1922 _late_inlines.trunc_to(j);
roland@3974 1923
roland@3974 1924 {
roland@3974 1925 ResourceMark rm;
kvn@4675 1926 PhaseRemoveUseless pru(gvn, for_igvn());
roland@3974 1927 }
roland@3974 1928
roland@3974 1929 igvn = PhaseIterGVN(gvn);
roland@3974 1930 }
roland@3974 1931
roland@3974 1932 // Perform incremental inlining until bound on number of live nodes is reached
roland@3974 1933 void Compile::inline_incrementally(PhaseIterGVN& igvn) {
roland@3974 1934 PhaseGVN* gvn = initial_gvn();
roland@3974 1935
roland@3974 1936 set_inlining_incrementally(true);
roland@3974 1937 set_inlining_progress(true);
roland@3974 1938 uint low_live_nodes = 0;
roland@3974 1939
roland@3974 1940 while(inlining_progress() && _late_inlines.length() > 0) {
roland@3974 1941
roland@3974 1942 if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {
roland@3974 1943 if (low_live_nodes < (uint)LiveNodeCountInliningCutoff * 8 / 10) {
roland@3974 1944 // PhaseIdealLoop is expensive so we only try it once we are
roland@3974 1945 // out of loop and we only try it again if the previous helped
roland@3974 1946 // got the number of nodes down significantly
roland@3974 1947 PhaseIdealLoop ideal_loop( igvn, false, true );
roland@3974 1948 if (failing()) return;
roland@3974 1949 low_live_nodes = live_nodes();
roland@3974 1950 _major_progress = true;
roland@3974 1951 }
roland@3974 1952
roland@3974 1953 if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {
roland@3974 1954 break;
roland@3974 1955 }
roland@3974 1956 }
roland@3974 1957
roland@3974 1958 inline_incrementally_one(igvn);
roland@3974 1959
roland@3974 1960 if (failing()) return;
roland@3974 1961
roland@3974 1962 igvn.optimize();
roland@3974 1963
roland@3974 1964 if (failing()) return;
roland@3974 1965 }
roland@3974 1966
roland@3974 1967 assert( igvn._worklist.size() == 0, "should be done with igvn" );
roland@3974 1968
roland@3974 1969 if (_string_late_inlines.length() > 0) {
roland@3974 1970 assert(has_stringbuilder(), "inconsistent");
roland@3974 1971 for_igvn()->clear();
roland@3974 1972 initial_gvn()->replace_with(&igvn);
roland@3974 1973
roland@3974 1974 inline_string_calls(false);
roland@3974 1975
roland@3974 1976 if (failing()) return;
roland@3974 1977
roland@3974 1978 {
roland@3974 1979 ResourceMark rm;
roland@3974 1980 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
roland@3974 1981 }
roland@3974 1982
roland@3974 1983 igvn = PhaseIterGVN(gvn);
roland@3974 1984
roland@3974 1985 igvn.optimize();
roland@3974 1986 }
roland@3974 1987
roland@3974 1988 set_inlining_incrementally(false);
roland@3974 1989 }
roland@3974 1990
roland@3974 1991
duke@0 1992 //------------------------------Optimize---------------------------------------
duke@0 1993 // Given a graph, optimize it.
duke@0 1994 void Compile::Optimize() {
duke@0 1995 TracePhase t1("optimizer", &_t_optimizer, true);
duke@0 1996
duke@0 1997 #ifndef PRODUCT
duke@0 1998 if (env()->break_at_compile()) {
duke@0 1999 BREAKPOINT;
duke@0 2000 }
duke@0 2001
duke@0 2002 #endif
duke@0 2003
duke@0 2004 ResourceMark rm;
duke@0 2005 int loop_opts_cnt;
duke@0 2006
duke@0 2007 NOT_PRODUCT( verify_graph_edges(); )
duke@0 2008
sla@4802 2009 print_method(PHASE_AFTER_PARSING);
duke@0 2010
duke@0 2011 {
duke@0 2012 // Iterative Global Value Numbering, including ideal transforms
duke@0 2013 // Initialize IterGVN with types and values from parse-time GVN
duke@0 2014 PhaseIterGVN igvn(initial_gvn());
duke@0 2015 {
duke@0 2016 NOT_PRODUCT( TracePhase t2("iterGVN", &_t_iterGVN, TimeCompiler); )
duke@0 2017 igvn.optimize();
duke@0 2018 }
duke@0 2019
sla@4802 2020 print_method(PHASE_ITER_GVN1, 2);
duke@0 2021
duke@0 2022 if (failing()) return;
duke@0 2023
kvn@4675 2024 {
kvn@4675 2025 NOT_PRODUCT( TracePhase t2("incrementalInline", &_t_incrInline, TimeCompiler); )
kvn@4675 2026 inline_incrementally(igvn);
kvn@4675 2027 }
roland@3974 2028
sla@4802 2029 print_method(PHASE_INCREMENTAL_INLINE, 2);
roland@3974 2030
roland@3974 2031 if (failing()) return;
roland@3974 2032
kvn@4675 2033 if (eliminate_boxing()) {
kvn@4675 2034 NOT_PRODUCT( TracePhase t2("incrementalInline", &_t_incrInline, TimeCompiler); )
kvn@4675 2035 // Inline valueOf() methods now.
kvn@4675 2036 inline_boxing_calls(igvn);
kvn@4675 2037
sla@4802 2038 print_method(PHASE_INCREMENTAL_BOXING_INLINE, 2);
kvn@4675 2039
kvn@4675 2040 if (failing()) return;
kvn@4675 2041 }
kvn@4675 2042
roland@5556 2043 // Remove the speculative part of types and clean up the graph from
roland@5556 2044 // the extra CastPP nodes whose only purpose is to carry them. Do
roland@5556 2045 // that early so that optimizations are not disrupted by the extra
roland@5556 2046 // CastPP nodes.
roland@5556 2047 remove_speculative_types(igvn);
roland@5556 2048
roland@4154 2049 // No more new expensive nodes will be added to the list from here
roland@4154 2050 // so keep only the actual candidates for optimizations.
roland@4154 2051 cleanup_expensive_nodes(igvn);
roland@4154 2052
kvn@1554 2053 // Perform escape analysis
kvn@1554 2054 if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) {
kvn@2825 2055 if (has_loops()) {
kvn@2825 2056 // Cleanup graph (remove dead nodes).
kvn@2825 2057 TracePhase t2("idealLoop", &_t_idealLoop, true);
kvn@2825 2058 PhaseIdealLoop ideal_loop( igvn, false, true );
sla@4802 2059 if (major_progress()) print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
kvn@2825 2060 if (failing()) return;
kvn@2825 2061 }
kvn@1554 2062 ConnectionGraph::do_analysis(this, &igvn);
kvn@1554 2063
kvn@1554 2064 if (failing()) return;
kvn@1554 2065
kvn@2876 2066 // Optimize out fields loads from scalar replaceable allocations.
kvn@1554 2067 igvn.optimize();
sla@4802 2068 print_method(PHASE_ITER_GVN_AFTER_EA, 2);
kvn@1554 2069
kvn@1554 2070 if (failing()) return;
kvn@1554 2071
kvn@2876 2072 if (congraph() != NULL && macro_count() > 0) {
kvn@3216 2073 NOT_PRODUCT( TracePhase t2("macroEliminate", &_t_macroEliminate, TimeCompiler); )
kvn@2876 2074 PhaseMacroExpand mexp(igvn);
kvn@2876 2075 mexp.eliminate_macro_nodes();
kvn@2876 2076 igvn.set_delay_transform(false);
kvn@2876 2077
kvn@2876 2078 igvn.optimize();
sla@4802 2079 print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
kvn@2876 2080
kvn@2876 2081 if (failing()) return;
kvn@2876 2082 }
kvn@1554 2083 }
kvn@1554 2084
duke@0 2085 // Loop transforms on the ideal graph. Range Check Elimination,
duke@0 2086 // peeling, unrolling, etc.
duke@0 2087
duke@0 2088 // Set loop opts counter
duke@0 2089 loop_opts_cnt = num_loop_opts();
duke@0 2090 if((loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
duke@0 2091 {
duke@0 2092 TracePhase t2("idealLoop", &_t_idealLoop, true);
kvn@2292 2093 PhaseIdealLoop ideal_loop( igvn, true );
duke@0 2094 loop_opts_cnt--;
sla@4802 2095 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);
duke@0 2096 if (failing()) return;
duke@0 2097 }
duke@0 2098 // Loop opts pass if partial peeling occurred in previous pass
duke@0 2099 if(PartialPeelLoop && major_progress() && (loop_opts_cnt > 0)) {
duke@0 2100 TracePhase t3("idealLoop", &_t_idealLoop, true);
kvn@2292 2101 PhaseIdealLoop ideal_loop( igvn, false );
duke@0 2102 loop_opts_cnt--;
sla@4802 2103 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);
duke@0 2104 if (failing()) return;
duke@0 2105 }
duke@0 2106 // Loop opts pass for loop-unrolling before CCP
duke@0 2107 if(major_progress() && (loop_opts_cnt > 0)) {
duke@0 2108 TracePhase t4("idealLoop", &_t_idealLoop, true);
kvn@2292 2109 PhaseIdealLoop ideal_loop( igvn, false );
duke@0 2110 loop_opts_cnt--;
sla@4802 2111 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP3, 2);
duke@0 2112 }
never@921 2113 if (!failing()) {
never@921 2114 // Verify that last round of loop opts produced a valid graph
never@921 2115 NOT_PRODUCT( TracePhase t2("idealLoopVerify", &_t_idealLoopVerify, TimeCompiler); )
never@921 2116 PhaseIdealLoop::verify(igvn);
never@921 2117 }
duke@0 2118 }
duke@0 2119 if (failing()) return;
duke@0 2120
duke@0 2121 // Conditional Constant Propagation;
duke@0 2122 PhaseCCP ccp( &igvn );
duke@0 2123 assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
duke@0 2124 {
duke@0 2125 TracePhase t2("ccp", &_t_ccp, true);
duke@0 2126 ccp.do_transform();
duke@0 2127 }
sla@4802 2128 print_method(PHASE_CPP1, 2);
duke@0 2129
duke@0 2130 assert( true, "Break here to ccp.dump_old2new_map()");
duke@0 2131
duke@0 2132 // Iterative Global Value Numbering, including ideal transforms
duke@0 2133 {
duke@0 2134 NOT_PRODUCT( TracePhase t2("iterGVN2", &_t_iterGVN2, TimeCompiler); )
duke@0 2135 igvn = ccp;
duke@0 2136 igvn.optimize();
duke@0 2137 }
duke@0 2138
sla@4802 2139 print_method(PHASE_ITER_GVN2, 2);
duke@0 2140
duke@0 2141 if (failing()) return;
duke@0 2142
duke@0 2143 // Loop transforms on the ideal graph. Range Check Elimination,
duke@0 2144 // peeling, unrolling, etc.
duke@0 2145 if(loop_opts_cnt > 0) {
duke@0 2146 debug_only( int cnt = 0; );
duke@0 2147 while(major_progress() && (loop_opts_cnt > 0)) {
duke@0 2148 TracePhase t2("idealLoop", &_t_idealLoop, true);
duke@0 2149 assert( cnt++ < 40, "infinite cycle in loop optimization" );
kvn@2292 2150 PhaseIdealLoop ideal_loop( igvn, true);
duke@0 2151 loop_opts_cnt--;
sla@4802 2152 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
duke@0 2153 if (failing()) return;
duke@0 2154 }
duke@0 2155 }
never@921 2156
never@921 2157 {
never@921 2158 // Verify that all previous optimizations produced a valid graph
never@921 2159 // at least to this point, even if no loop optimizations were done.
never@921 2160 NOT_PRODUCT( TracePhase t2("idealLoopVerify", &_t_idealLoopVerify, TimeCompiler); )
never@921 2161 PhaseIdealLoop::verify(igvn);
never@921 2162 }
never@921 2163
duke@0 2164 {
duke@0 2165 NOT_PRODUCT( TracePhase t2("macroExpand", &_t_macroExpand, TimeCompiler); )
duke@0 2166 PhaseMacroExpand mex(igvn);
duke@0 2167 if (mex.expand_macro_nodes()) {
duke@0 2168 assert(failing(), "must bail out w/ explicit message");
duke@0 2169 return;
duke@0 2170 }
duke@0 2171 }
duke@0 2172
duke@0 2173 } // (End scope of igvn; run destructor if necessary for asserts.)
duke@0 2174
kvn@4013 2175 dump_inlining();
duke@0 2176 // A method with only infinite loops has no edges entering loops from root
duke@0 2177 {
duke@0 2178 NOT_PRODUCT( TracePhase t2("graphReshape", &_t_graphReshaping, TimeCompiler); )
duke@0 2179 if (final_graph_reshaping()) {
duke@0 2180 assert(failing(), "must bail out w/ explicit message");
duke@0 2181 return;
duke@0 2182 }
duke@0 2183 }
duke@0 2184
sla@4802 2185 print_method(PHASE_OPTIMIZE_FINISHED, 2);
duke@0 2186 }
duke@0 2187
duke@0 2188
duke@0 2189 //------------------------------Code_Gen---------------------------------------
duke@0 2190 // Given a graph, generate code for it
duke@0 2191 void Compile::Code_Gen() {
adlertz@5104 2192 if (failing()) {
adlertz@5104 2193 return;
adlertz@5104 2194 }
duke@0 2195
duke@0 2196 // Perform instruction selection. You might think we could reclaim Matcher
duke@0 2197 // memory PDQ, but actually the Matcher is used in generating spill code.
duke@0 2198 // Internals of the Matcher (including some VectorSets) must remain live
duke@0 2199 // for awhile - thus I cannot reclaim Matcher memory lest a VectorSet usage
duke@0 2200 // set a bit in reclaimed memory.
duke@0 2201
duke@0 2202 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
duke@0 2203 // nodes. Mapping is only valid at the root of each matched subtree.
duke@0 2204 NOT_PRODUCT( verify_graph_edges(); )
duke@0 2205
adlertz@5104 2206 Matcher matcher;
adlertz@5104 2207 _matcher = &matcher;
duke@0 2208 {
duke@0 2209 TracePhase t2("matcher", &_t_matcher, true);
adlertz@5104 2210 matcher.match();
duke@0 2211 }
duke@0 2212 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
duke@0 2213 // nodes. Mapping is only valid at the root of each matched subtree.
duke@0 2214 NOT_PRODUCT( verify_graph_edges(); )
duke@0 2215
duke@0 2216 // If you have too many nodes, or if matching has failed, bail out
duke@0 2217 check_node_count(0, "out of nodes matching instructions");
adlertz@5104 2218 if (failing()) {
adlertz@5104 2219 return;
adlertz@5104 2220 }
duke@0 2221
duke@0 2222 // Build a proper-looking CFG
adlertz@5104 2223 PhaseCFG cfg(node_arena(), root(), matcher);
duke@0 2224 _cfg = &cfg;
duke@0 2225 {
duke@0 2226 NOT_PRODUCT( TracePhase t2("scheduler", &_t_scheduler, TimeCompiler); )
adlertz@5104 2227 bool success = cfg.do_global_code_motion();
adlertz@5104 2228 if (!success) {
adlertz@5104 2229 return;
adlertz@5104 2230 }
adlertz@5104 2231
adlertz@5104 2232 print_method(PHASE_GLOBAL_CODE_MOTION, 2);
duke@0 2233 NOT_PRODUCT( verify_graph_edges(); )
duke@0 2234 debug_only( cfg.verify(); )
duke@0 2235 }
adlertz@5104 2236
adlertz@5104 2237 PhaseChaitin regalloc(unique(), cfg, matcher);
duke@0 2238 _regalloc = &regalloc;
duke@0 2239 {
duke@0 2240 TracePhase t2("regalloc", &_t_registerAllocation, true);
duke@0 2241 // Perform register allocation. After Chaitin, use-def chains are
duke@0 2242 // no longer accurate (at spill code) and so must be ignored.
duke@0 2243 // Node->LRG->reg mappings are still accurate.
duke@0 2244 _regalloc->Register_Allocate();
duke@0 2245
duke@0 2246 // Bail out if the allocator builds too many nodes
neliasso@4514 2247 if (failing()) {
neliasso@4514 2248 return;
neliasso@4514 2249 }
duke@0 2250 }
duke@0 2251
duke@0 2252 // Prior to register allocation we kept empty basic blocks in case the
duke@0 2253 // the allocator needed a place to spill. After register allocation we
duke@0 2254 // are not adding any new instructions. If any basic block is empty, we
duke@0 2255 // can now safely remove it.
duke@0 2256 {
rasbold@418 2257 NOT_PRODUCT( TracePhase t2("blockOrdering", &_t_blockOrdering, TimeCompiler); )
adlertz@5104 2258 cfg.remove_empty_blocks();
rasbold@418 2259 if (do_freq_based_layout()) {
rasbold@418 2260 PhaseBlockLayout layout(cfg);
rasbold@418 2261 } else {
rasbold@418 2262 cfg.set_loop_alignment();
rasbold@418 2263 }
rasbold@418 2264 cfg.fixup_flow();
duke@0 2265 }
duke@0 2266
duke@0 2267 // Apply peephole optimizations
duke@0 2268 if( OptoPeephole ) {
duke@0 2269 NOT_PRODUCT( TracePhase t2("peephole", &_t_peephole, TimeCompiler); )
duke@0 2270 PhasePeephole peep( _regalloc, cfg);
duke@0 2271 peep.do_transform();
duke@0 2272 }
duke@0 2273
goetz@5980 2274 // Do late expand if CPU requires this.
goetz@5980 2275 if (Matcher::require_postalloc_expand) {
goetz@5980 2276 NOT_PRODUCT(TracePhase t2c("postalloc_expand", &_t_postalloc_expand, true));
goetz@5980 2277 cfg.postalloc_expand(_regalloc);
goetz@5980 2278 }
goetz@5980 2279
duke@0 2280 // Convert Nodes to instruction bits in a buffer
duke@0 2281 {
duke@0 2282 // %%%% workspace merge brought two timers together for one job
duke@0 2283 TracePhase t2a("output", &_t_output, true);
duke@0 2284 NOT_PRODUCT( TraceTime t2b(NULL, &_t_codeGeneration, TimeCompiler, false); )
duke@0 2285 Output();
duke@0 2286 }
duke@0 2287
sla@4802 2288 print_method(PHASE_FINAL_CODE);
duke@0 2289
duke@0 2290 // He's dead, Jim.
duke@0 2291 _cfg = (PhaseCFG*)0xdeadbeef;
duke@0 2292 _regalloc = (PhaseChaitin*)0xdeadbeef;
duke@0 2293 }
duke@0 2294
duke@0 2295
duke@0 2296 //------------------------------dump_asm---------------------------------------
duke@0 2297 // Dump formatted assembly
duke@0 2298 #ifndef PRODUCT
duke@0 2299 void Compile::dump_asm(int *pcs, uint pc_limit) {
duke@0 2300 bool cut_short = false;
duke@0 2301 tty->print_cr("#");
duke@0 2302 tty->print("# "); _tf->dump(); tty->cr();
duke@0 2303 tty->print_cr("#");
duke@0 2304
duke@0 2305 // For all blocks
duke@0 2306 int pc = 0x0; // Program counter
duke@0 2307 char starts_bundle = ' ';
duke@0 2308 _regalloc->dump_frame();
duke@0 2309
duke@0 2310 Node *n = NULL;
adlertz@5104 2311 for (uint i = 0; i < _cfg->number_of_blocks(); i++) {
adlertz@5104 2312 if (VMThread::should_terminate()) {
adlertz@5104 2313 cut_short = true;
adlertz@5104 2314 break;
adlertz@5104 2315 }
adlertz@5104 2316 Block* block = _cfg->get_block(i);
adlertz@5104 2317 if (block->is_connector() && !Verbose) {
adlertz@5104 2318 continue;
adlertz@5104 2319 }
adlertz@5200 2320 n = block->head();
adlertz@5104 2321 if (pcs && n->_idx < pc_limit) {
duke@0 2322 tty->print("%3.3x ", pcs[n->_idx]);
adlertz@5104 2323 } else {
duke@0 2324 tty->print(" ");
adlertz@5104 2325 }
adlertz@5104 2326 block->dump_head(_cfg);
adlertz@5104 2327 if (block->is_connector()) {
duke@0 2328 tty->print_cr(" # Empty connector block");
adlertz@5104 2329 } else if (block->num_preds() == 2 && block->pred(1)->is_CatchProj() && block->pred(1)->as_CatchProj()->_con == CatchProjNode::fall_through_index) {
duke@0 2330 tty->print_cr(" # Block is sole successor of call");
duke@0 2331 }
duke@0 2332
duke@0 2333 // For all instructions
duke@0 2334 Node *delay = NULL;
adlertz@5200 2335 for (uint j = 0; j < block->number_of_nodes(); j++) {
adlertz@5104 2336 if (VMThread::should_terminate()) {
adlertz@5104 2337 cut_short = true;
adlertz@5104 2338 break;
adlertz@5104 2339 }
adlertz@5200 2340 n = block->get_node(j);
duke@0 2341 if (valid_bundle_info(n)) {
adlertz@5104 2342 Bundle* bundle = node_bundling(n);
duke@0 2343 if (bundle->used_in_unconditional_delay()) {
duke@0 2344 delay = n;
duke@0 2345 continue;
duke@0 2346 }
adlertz@5104 2347 if (bundle->starts_bundle()) {
duke@0 2348 starts_bundle = '+';
adlertz@5104 2349 }
duke@0 2350 }
duke@0 2351
adlertz@5104 2352 if (WizardMode) {
adlertz@5104 2353 n->dump();
adlertz@5104 2354 }
coleenp@113 2355
duke@0 2356 if( !n->is_Region() && // Dont print in the Assembly
duke@0 2357 !n->is_Phi() && // a few noisely useless nodes
duke@0 2358 !n->is_Proj() &&
duke@0 2359 !n->is_MachTemp() &&
kvn@1100 2360 !n->is_SafePointScalarObject() &&
duke@0 2361 !n->is_Catch() && // Would be nice to print exception table targets
duke@0 2362 !n->is_MergeMem() && // Not very interesting
duke@0 2363 !n->is_top() && // Debug info table constants
duke@0 2364 !(n->is_Con() && !n->is_Mach())// Debug info table constants
duke@0 2365 ) {
duke@0 2366 if (pcs && n->_idx < pc_limit)
duke@0 2367 tty->print("%3.3x", pcs[n->_idx]);
duke@0 2368 else
duke@0 2369 tty->print(" ");
duke@0 2370 tty->print(" %c ", starts_bundle);
duke@0 2371 starts_bundle = ' ';
duke@0 2372 tty->print("\t");
duke@0 2373 n->format(_regalloc, tty);
duke@0 2374 tty->cr();
duke@0 2375 }
duke@0 2376
duke@0 2377 // If we have an instruction with a delay slot, and have seen a delay,
duke@0 2378 // then back up and print it
duke@0 2379 if (valid_bundle_info(n) && node_bundling(n)->use_unconditional_delay()) {
duke@0 2380 assert(delay != NULL, "no unconditional delay instruction");
coleenp@113 2381 if (WizardMode) delay->dump();
coleenp@113 2382
duke@0 2383 if (node_bundling(delay)->starts_bundle())
duke@0 2384 starts_bundle = '+';
duke@0 2385 if (pcs && n->_idx < pc_limit)
duke@0 2386 tty->print("%3.3x", pcs[n->_idx]);
duke@0 2387 else
duke@0 2388 tty->print(" ");
duke@0 2389 tty->print(" %c ", starts_bundle);
duke@0 2390 starts_bundle = ' ';
duke@0 2391 tty->print("\t");
duke@0 2392 delay->format(_regalloc, tty);
duke@0 2393 tty->print_cr("");
duke@0 2394 delay = NULL;
duke@0 2395 }
duke@0 2396
duke@0 2397 // Dump the exception table as well
duke@0 2398 if( n->is_Catch() && (Verbose || WizardMode) ) {
duke@0 2399 // Print the exception table for this offset
duke@0 2400 _handler_table.print_subtable_for(pc);
duke@0 2401 }
duke@0 2402 }
duke@0 2403
duke@0 2404 if (pcs && n->_idx < pc_limit)
duke@0 2405 tty->print_cr("%3.3x", pcs[n->_idx]);
duke@0 2406 else
duke@0 2407 tty->print_cr("");
duke@0 2408
duke@0 2409 assert(cut_short || delay == NULL, "no unconditional delay branch");
duke@0 2410
duke@0 2411 } // End of per-block dump
duke@0 2412 tty->print_cr("");
duke@0 2413
duke@0 2414 if (cut_short) tty->print_cr("*** disassembly is cut short ***");
duke@0 2415 }
duke@0 2416 #endif
duke@0 2417
duke@0 2418 //------------------------------Final_Reshape_Counts---------------------------
duke@0 2419 // This class defines counters to help identify when a method
duke@0 2420 // may/must be executed using hardware with only 24-bit precision.
duke@0 2421 struct Final_Reshape_Counts : public StackObj {
duke@0 2422 int _call_count; // count non-inlined 'common' calls
duke@0 2423 int _float_count; // count float ops requiring 24-bit precision
duke@0 2424 int _double_count; // count double ops requiring more precision
duke@0 2425 int _java_call_count; // count non-inlined 'java' calls
kvn@859 2426 int _inner_loop_count; // count loops which need alignment
duke@0 2427 VectorSet _visited; // Visitation flags
duke@0 2428 Node_List _tests; // Set of IfNodes & PCTableNodes
duke@0 2429
duke@0 2430 Final_Reshape_Counts() :
kvn@859 2431 _call_count(0), _float_count(0), _double_count(0),
kvn@859 2432 _java_call_count(0), _inner_loop_count(0),
duke@0 2433 _visited( Thread::current()->resource_area() ) { }
duke@0 2434
duke@0 2435 void inc_call_count () { _call_count ++; }
duke@0 2436 void inc_float_count () { _float_count ++; }
duke@0 2437 void inc_double_count() { _double_count++; }
duke@0 2438 void inc_java_call_count() { _java_call_count++; }
kvn@859 2439 void inc_inner_loop_count() { _inner_loop_count++; }
duke@0 2440
duke@0 2441 int get_call_count () const { return _call_count ; }
duke@0 2442 int get_float_count () const { return _float_count ; }
duke@0 2443 int get_double_count() const { return _double_count; }
duke@0 2444 int get_java_call_count() const { return _java_call_count; }
kvn@859 2445 int get_inner_loop_count() const { return _inner_loop_count; }
duke@0 2446 };
duke@0 2447
mikael@4454 2448 #ifdef ASSERT
duke@0 2449 static bool oop_offset_is_sane(const TypeInstPtr* tp) {
duke@0 2450 ciInstanceKlass *k = tp->klass()->as_instance_klass();
duke@0 2451 // Make sure the offset goes inside the instance layout.
coleenp@113 2452 return k->contains_field_offset(tp->offset());
duke@0 2453 // Note that OffsetBot and OffsetTop are very negative.
duke@0 2454 }
mikael@4454 2455 #endif
duke@0 2456
never@2345 2457 // Eliminate trivially redundant StoreCMs and accumulate their
never@2345 2458 // precedence edges.
bharadwaj@3880 2459 void Compile::eliminate_redundant_card_marks(Node* n) {
never@2345 2460 assert(n->Opcode() == Op_StoreCM, "expected StoreCM");
never@2345 2461 if (n->in(MemNode::Address)->outcnt() > 1) {
never@2345 2462 // There are multiple users of the same address so it might be
never@2345 2463 // possible to eliminate some of the StoreCMs
never@2345 2464 Node* mem = n->in(MemNode::Memory);
never@2345 2465 Node* adr = n->in(MemNode::Address);
never@2345 2466 Node* val = n->in(MemNode::ValueIn);
never@2345 2467 Node* prev = n;
never@2345 2468 bool done = false;
never@2345 2469 // Walk the chain of StoreCMs eliminating ones that match. As
never@2345 2470 // long as it's a chain of single users then the optimization is
never@2345 2471 // safe. Eliminating partially redundant StoreCMs would require
never@2345 2472 // cloning copies down the other paths.
never@2345 2473 while (mem->Opcode() == Op_StoreCM && mem->outcnt() == 1 && !done) {
never@2345 2474 if (adr == mem->in(MemNode::Address) &&
never@2345 2475 val == mem->in(MemNode::ValueIn)) {
never@2345 2476 // redundant StoreCM
never@2345 2477 if (mem->req() > MemNode::OopStore) {
never@2345 2478 // Hasn't been processed by this code yet.
never@2345 2479 n->add_prec(mem->in(MemNode::OopStore));
never@2345 2480 } else {
never@2345 2481 // Already converted to precedence edge
never@2345 2482 for (uint i = mem->req(); i < mem->len(); i++) {
never@2345 2483 // Accumulate any precedence edges
never@2345 2484 if (mem->in(i) != NULL) {
never@2345 2485 n->add_prec(mem->in(i));
never@2345 2486 }
never@2345 2487 }
never@2345 2488 // Everything above this point has been processed.
never@2345 2489 done = true;
never@2345 2490 }
never@2345 2491 // Eliminate the previous StoreCM
never@2345 2492 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
never@2345 2493 assert(mem->outcnt() == 0, "should be dead");
bharadwaj@3880 2494 mem->disconnect_inputs(NULL, this);
never@2345 2495 } else {
never@2345 2496 prev = mem;
never@2345 2497 }
never@2345 2498 mem = prev->in(MemNode::Memory);
never@2345 2499 }
never@2345 2500 }
never@2345 2501 }
never@2345 2502
duke@0 2503 //------------------------------final_graph_reshaping_impl----------------------
duke@0 2504 // Implement items 1-5 from final_graph_reshaping below.
bharadwaj@3880 2505 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
duke@0 2506
kvn@168 2507 if ( n->outcnt() == 0 ) return; // dead node
duke@0 2508 uint nop = n->Opcode();
duke@0 2509
duke@0 2510 // Check for 2-input instruction with "last use" on right input.
duke@0 2511 // Swap to left input. Implements item (2).
duke@0 2512 if( n->req() == 3 && // two-input instruction
duke@0 2513 n->in(1)->outcnt() > 1 && // left use is NOT a last use
duke@0 2514 (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
duke@0 2515 n->in(2)->outcnt() == 1 &&// right use IS a last use
duke@0 2516 !n->in(2)->is_Con() ) { // right use is not a constant
duke@0 2517 // Check for commutative opcode
duke@0 2518 switch( nop ) {
duke@0 2519 case Op_AddI: case Op_AddF: case Op_AddD: case Op_AddL:
duke@0 2520 case Op_MaxI: case Op_MinI:
duke@0 2521 case Op_MulI: case Op_MulF: case Op_MulD: case Op_MulL:
duke@0 2522 case Op_AndL: case Op_XorL: case Op_OrL:
duke@0 2523 case Op_AndI: case Op_XorI: case Op_OrI: {
duke@0 2524 // Move "last use" input to left by swapping inputs
duke@0 2525 n->swap_edges(1, 2);
duke@0 2526 break;
duke@0 2527 }
duke@0 2528 default:
duke@0 2529 break;
duke@0 2530 }
duke@0 2531 }
duke@0 2532
kvn@1529 2533 #ifdef ASSERT
kvn@1529 2534 if( n->is_Mem() ) {
bharadwaj@3880 2535 int alias_idx = get_alias_index(n->as_Mem()->adr_type());
kvn@1529 2536 assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
kvn@1529 2537 // oop will be recorded in oop map if load crosses safepoint
kvn@1529 2538 n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
kvn@1529 2539 LoadNode::is_immutable_value(n->in(MemNode::Address))),
kvn@1529 2540 "raw memory operations should have control edge");
kvn@1529 2541 }
kvn@1529 2542 #endif
duke@0 2543 // Count FPU ops and common calls, implements item (3)
duke@0 2544 switch( nop ) {
duke@0 2545 // Count all float operations that may use FPU
duke@0 2546 case Op_AddF:
duke@0 2547 case Op_SubF:
duke@0 2548 case Op_MulF:
duke@0 2549 case Op_DivF:
duke@0 2550 case Op_NegF:
duke@0 2551 case Op_ModF:
duke@0 2552 case Op_ConvI2F:
duke@0 2553 case Op_ConF:
duke@0 2554 case Op_CmpF:
duke@0 2555 case Op_CmpF3:
duke@0 2556 // case Op_ConvL2F: // longs are split into 32-bit halves
kvn@859 2557 frc.inc_float_count();
duke@0 2558 break;
duke@0 2559
duke@0 2560 case Op_ConvF2D:
duke@0 2561 case Op_ConvD2F:
kvn@859 2562 frc.inc_float_count();
kvn@859 2563 frc.inc_double_count();
duke@0 2564 break;
duke@0 2565
duke@0 2566 // Count all double operations that may use FPU
duke@0 2567 case Op_AddD:
duke@0 2568 case Op_SubD:
duke@0 2569 case Op_MulD:
duke@0 2570 case Op_DivD:
duke@0 2571 case Op_NegD:
duke@0 2572 case Op_ModD:
duke@0 2573 case Op_ConvI2D:
duke@0 2574 case Op_ConvD2I:
duke@0 2575 // case Op_ConvL2D: // handled by leaf call
duke@0 2576 // case Op_ConvD2L: // handled by leaf call
duke@0 2577 case Op_ConD:
duke@0 2578 case Op_CmpD:
duke@0 2579 case Op_CmpD3:
kvn@859 2580 frc.inc_double_count();
duke@0 2581 break;
duke@0 2582 case Op_Opaque1: // Remove Opaque Nodes before matching
duke@0 2583 case Op_Opaque2: // Remove Opaque Nodes before matching
bharadwaj@3880 2584 n->subsume_by(n->in(1), this);
duke@0 2585 break;
duke@0 2586 case Op_CallStaticJava:
duke@0 2587 case Op_CallJava:
duke@0 2588 case Op_CallDynamicJava:
kvn@859 2589 frc.inc_java_call_count(); // Count java call site;
duke@0 2590 case Op_CallRuntime:
duke@0 2591 case Op_CallLeaf:
duke@0 2592 case Op_CallLeafNoFP: {
duke@0 2593 assert( n->is_Call(), "" );
duke@0 2594 CallNode *call = n->as_Call();
duke@0 2595 // Count call sites where the FP mode bit would have to be flipped.
duke@0 2596 // Do not count uncommon runtime calls:
duke@0 2597 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
duke@0 2598 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...
duke@0 2599 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) {
kvn@859 2600 frc.inc_call_count(); // Count the call site
duke@0 2601 } else { // See if uncommon argument is shared
duke@0 2602 Node *n = call->in(TypeFunc::Parms);
duke@0 2603 int nop = n->Opcode();
duke@0 2604 // Clone shared simple arguments to uncommon calls, item (1).
duke@0 2605 if( n->outcnt() > 1 &&
duke@0 2606 !n->is_Proj() &&
duke@0 2607 nop != Op_CreateEx &&
duke@0 2608 nop != Op_CheckCastPP &&
kvn@331 2609 nop != Op_DecodeN &&
roland@3724 2610 nop != Op_DecodeNKlass &&
duke@0 2611 !n->is_Mem() ) {
duke@0 2612 Node *x = n->clone();
duke@0 2613 call->set_req( TypeFunc::Parms, x );
duke@0 2614 }
duke@0 2615 }
duke@0 2616 break;
duke@0 2617 }
duke@0 2618
duke@0 2619 case Op_StoreD:
duke@0 2620 case Op_LoadD:
duke@0 2621 case Op_LoadD_unaligned:
kvn@859 2622 frc.inc_double_count();
duke@0 2623 goto handle_mem;
duke@0 2624 case Op_StoreF:
duke@0 2625 case Op_LoadF:
kvn@859 2626 frc.inc_float_count();
duke@0 2627 goto handle_mem;
duke@0 2628
never@2345 2629 case Op_StoreCM:
never@2345 2630 {
never@2345 2631 // Convert OopStore dependence into precedence edge
never@2345 2632 Node* prec = n->in(MemNode::OopStore);
never@2345 2633 n->del_req(MemNode::OopStore);
never@2345 2634 n->add_prec(prec);
never@2345 2635 eliminate_redundant_card_marks(n);
never@2345 2636 }
never@2345 2637
never@2345 2638 // fall through
never@2345 2639
duke@0 2640 case Op_StoreB:
duke@0 2641 case Op_StoreC:
duke@0 2642 case Op_StorePConditional:
duke@0 2643 case Op_StoreI:
duke@0 2644 case Op_StoreL:
kvn@420 2645 case Op_StoreIConditional:
duke@0 2646 case Op_StoreLConditional:
duke@0 2647 case Op_CompareAndSwapI:
duke@0 2648 case Op_CompareAndSwapL:
duke@0 2649 case Op_CompareAndSwapP:
coleenp@113 2650 case Op_CompareAndSwapN:
roland@3671 2651 case Op_GetAndAddI:
roland@3671 2652 case Op_GetAndAddL:
roland@3671 2653 case Op_GetAndSetI:
roland@3671 2654 case Op_GetAndSetL:
roland@3671 2655 case Op_GetAndSetP:
roland@3671 2656 case Op_GetAndSetN:
duke@0 2657 case Op_StoreP:
coleenp@113 2658 case Op_StoreN:
roland@3724 2659 case Op_StoreNKlass:
duke@0 2660 case Op_LoadB:
twisti@624 2661 case Op_LoadUB:
twisti@558 2662 case Op_LoadUS:
duke@0 2663 case Op_LoadI:
duke@0 2664 case Op_LoadKlass:
kvn@164 2665 case Op_LoadNKlass:
duke@0 2666 case Op_LoadL:
duke@0 2667 case Op_LoadL_unaligned:
duke@0 2668 case Op_LoadPLocked:
duke@0 2669 case Op_LoadP:
coleenp@113 2670 case Op_LoadN:
duke@0 2671 case Op_LoadRange:
duke@0 2672 case Op_LoadS: {
duke@0 2673 handle_mem:
duke@0 2674 #ifdef ASSERT
duke@0 2675 if( VerifyOptoOopOffsets ) {
duke@0 2676 assert( n->is_Mem(), "" );
duke@0 2677 MemNode *mem = (MemNode*)n;
duke@0 2678 // Check to see if address types have grounded out somehow.
duke@0 2679 const TypeInstPtr *tp = mem->in(MemNode::Address)->bottom_type()->isa_instptr();
duke@0 2680 assert( !tp || oop_offset_is_sane(tp), "" );
duke@0 2681 }
duke@0 2682 #endif
duke@0 2683 break;
duke@0 2684 }
duke@0 2685
duke@0 2686 case Op_AddP: { // Assert sane base pointers
kvn@182 2687 Node *addp = n->in(AddPNode::Address);
duke@0 2688 assert( !addp->is_AddP() ||
duke@0 2689 addp->in(AddPNode::Base)->is_top() || // Top OK for allocation
duke@0 2690 addp->in(AddPNode::Base) == n->in(AddPNode::Base),
duke@0 2691 "Base pointers must match" );
kvn@182 2692 #ifdef _LP64
ehelin@5259 2693 if ((UseCompressedOops || UseCompressedClassPointers) &&
kvn@182 2694 addp->Opcode() == Op_ConP &&
kvn@182 2695 addp == n->in(AddPNode::Base) &&
kvn@182 2696 n->in(AddPNode::Offset)->is_Con()) {
kvn@182 2697 // Use addressing with narrow klass to load with offset on x86.
kvn@182 2698 // On sparc loading 32-bits constant and decoding it have less
kvn@182 2699 // instructions (4) then load 64-bits constant (7).
kvn@182 2700 // Do this transformation here since IGVN will convert ConN back to ConP.
kvn@182 2701 const Type* t = addp->bottom_type();
roland@3724 2702 if (t->isa_oopptr() || t->isa_klassptr()) {
kvn@182 2703 Node* nn = NULL;
kvn@182 2704
roland@3724 2705 int op = t->isa_oopptr() ? Op_ConN : Op_ConNKlass;
roland@3724 2706
kvn@182 2707 // Look for existing ConN node of the same exact type.
bharadwaj@3880 2708 Node* r = root();
kvn@182 2709 uint cnt = r->outcnt();
kvn@182 2710 for (uint i = 0; i < cnt; i++) {
kvn@182 2711 Node* m = r->raw_out(i);
roland@3724 2712 if (m!= NULL && m->Opcode() == op &&
kvn@221 2713 m->bottom_type()->make_ptr() == t) {
kvn@182 2714 nn = m;
kvn@182 2715 break;
kvn@182 2716 }
kvn@182 2717 }
kvn@182 2718 if (nn != NULL) {
kvn@182 2719 // Decode a narrow oop to match address
kvn@182 2720 // [R12 + narrow_oop_reg<<3 + offset]
roland@3724 2721 if (t->isa_oopptr()) {
bharadwaj@3880 2722 nn = new (this) DecodeNNode(nn, t);
roland@3724 2723 } else {
bharadwaj@3880 2724 nn = new (this) DecodeNKlassNode(nn, t);
roland@3724 2725 }
kvn@182 2726 n->set_req(AddPNode::Base, nn);
kvn@182 2727 n->set_req(AddPNode::Address, nn);
kvn@182 2728 if (addp->outcnt() == 0) {
bharadwaj@3880 2729 addp->disconnect_inputs(NULL, this);
kvn@182 2730 }
kvn@182 2731 }
kvn@182 2732 }
kvn@182 2733 }
kvn@182 2734 #endif
duke@0 2735 break;
duke@0 2736 }
duke@0 2737
kvn@164 2738 #ifdef _LP64
kvn@368 2739 case Op_CastPP:
kvn@1495 2740 if (n->in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks()) {
kvn@368 2741 Node* in1 = n->in(1);
kvn@368 2742 const Type* t = n->bottom_type();
kvn@368 2743 Node* new_in1 = in1->clone();
kvn@368 2744 new_in1->as_DecodeN()->set_type(t);
kvn@368 2745
kvn@1495 2746 if (!Matcher::narrow_oop_use_complex_address()) {
kvn@368 2747 //
kvn@368 2748 // x86, ARM and friends can handle 2 adds in addressing mode
kvn@368 2749 // and Matcher can fold a DecodeN node into address by using
kvn@368 2750 // a narrow oop directly and do implicit NULL check in address:
kvn@368 2751 //
kvn@368 2752 // [R12 + narrow_oop_reg<<3 + offset]
kvn@368 2753 // NullCheck narrow_oop_reg
kvn@368 2754 //
kvn@368 2755 // On other platforms (Sparc) we have to keep new DecodeN node and
kvn@368 2756 // use it to do implicit NULL check in address:
kvn@368 2757 //
kvn@368 2758 // decode_not_null narrow_oop_reg, base_reg
kvn@368 2759 // [base_reg + offset]
kvn@368 2760 // NullCheck base_reg
kvn@368 2761 //
twisti@605 2762 // Pin the new DecodeN node to non-null path on these platform (Sparc)
kvn@368 2763 // to keep the information to which NULL check the new DecodeN node
kvn@368 2764 // corresponds to use it as value in implicit_null_check().
kvn@368 2765 //
kvn@368 2766 new_in1->set_req(0, n->in(0));
kvn@368 2767 }
kvn@368 2768
bharadwaj@3880 2769 n->subsume_by(new_in1, this);
kvn@368 2770 if (in1->outcnt() == 0) {
bharadwaj@3880 2771 in1->disconnect_inputs(NULL, this);
kvn@368 2772 }
kvn@368 2773 }
kvn@368 2774 break;
kvn@368 2775
kvn@164 2776 case Op_CmpP:
kvn@168 2777 // Do this transformation here to preserve CmpPNode::sub() and
kvn@168 2778 // other TypePtr related Ideal optimizations (for example, ptr nullness).
roland@3724 2779 if (n->in(1)->is_DecodeNarrowPtr() || n->in(2)->is_DecodeNarrowPtr()) {
kvn@331 2780 Node* in1 = n->in(1);
kvn@331 2781 Node* in2 = n->in(2);
roland@3724 2782 if (!in1->is_DecodeNarrowPtr()) {
kvn@331 2783 in2 = in1;
kvn@331 2784 in1 = n->in(2);
kvn@331 2785 }
roland@3724 2786 assert(in1->is_DecodeNarrowPtr(), "sanity");
kvn@331 2787
kvn@331 2788 Node* new_in2 = NULL;
roland@3724 2789 if (in2->is_DecodeNarrowPtr()) {
roland@3724 2790 assert(in2->Opcode() == in1->Opcode(), "must be same node type");
kvn@331 2791 new_in2 = in2->in(1);
kvn@331 2792 } else if (in2->Opcode() == Op_ConP) {
kvn@331 2793 const Type* t = in2->bottom_type();
kvn@1495 2794 if (t == TypePtr::NULL_PTR) {
roland@3724 2795 assert(in1->is_DecodeN(), "compare klass to null?");
kvn@1495 2796 // Don't convert CmpP null check into CmpN if compressed
kvn@1495 2797 // oops implicit null check is not generated.
kvn@1495 2798 // This will allow to generate normal oop implicit null check.
kvn@1495 2799 if (Matcher::gen_narrow_oop_implicit_null_checks())
bharadwaj@3880 2800 new_in2 = ConNode::make(this, TypeNarrowOop::NULL_PTR);
kvn@368 2801 //
kvn@368 2802 // This transformation together with CastPP transformation above
kvn@368 2803 // will generated code for implicit NULL checks for compressed oops.
kvn@368 2804 //
kvn@368 2805 // The original code after Optimize()
kvn@368 2806 //
kvn@368 2807 // LoadN memory, narrow_oop_reg
kvn@368 2808 // decode narrow_oop_reg, base_reg
kvn@368 2809 // CmpP base_reg, NULL
kvn@368 2810 // CastPP base_reg // NotNull
kvn@368 2811 // Load [base_reg + offset], val_reg
kvn@368 2812 //
kvn@368 2813 // after these transformations will be
kvn@368 2814 //
kvn@368 2815 // LoadN memory, narrow_oop_reg
kvn@368 2816 // CmpN narrow_oop_reg, NULL
kvn@368 2817 // decode_not_null narrow_oop_reg, base_reg
kvn@368 2818 // Load [base_reg + offset], val_reg
kvn@368 2819 //
kvn@368 2820 // and the uncommon path (== NULL) will use narrow_oop_reg directly
kvn@368 2821 // since narrow oops can be used in debug info now (see the code in
kvn@368 2822 // final_graph_reshaping_walk()).
kvn@368 2823 //
kvn@368 2824 // At the end the code will be matched to
kvn@368 2825 // on x86:
kvn@368 2826 //
kvn@368 2827 // Load_narrow_oop memory, narrow_oop_reg
kvn@368 2828 // Load [R12 + narrow_oop_reg<<3 + offset], val_reg
kvn@368 2829 // NullCheck narrow_oop_reg
kvn@368 2830 //
kvn@368 2831 // and on sparc:
kvn@368 2832 //
kvn@368 2833 // Load_narrow_oop memory, narrow_oop_reg
kvn@368 2834 // decode_not_null narrow_oop_reg, base_reg
kvn@368 2835 // Load [base_reg + offset], val_reg
kvn@368 2836 // NullCheck base_reg
kvn@368 2837 //
kvn@164 2838 } else if (t->isa_oopptr()) {
bharadwaj@3880 2839 new_in2 = ConNode::make(this, t->make_narrowoop());
roland@3724 2840 } else if (t->isa_klassptr()) {
bharadwaj@3880 2841 new_in2 = ConNode::make(this, t->make_narrowklass());
kvn@164 2842 }
kvn@164 2843 }
kvn@331 2844 if (new_in2 != NULL) {
bharadwaj@3880 2845 Node* cmpN = new (this) CmpNNode(in1->in(1), new_in2);
bharadwaj@3880 2846 n->subsume_by(cmpN, this);
kvn@331 2847 if (in1->outcnt() == 0) {
bharadwaj@3880 2848 in1->disconnect_inputs(NULL, this);
kvn@331 2849 }
kvn@331 2850 if (in2->outcnt() == 0) {
bharadwaj@3880 2851 in2->disconnect_inputs(NULL, this);
kvn@331 2852 }
kvn@164 2853 }
kvn@164 2854 }
kvn@293 2855 break;
kvn@368 2856
kvn@368 2857 case Op_DecodeN:
roland@3724 2858 case Op_DecodeNKlass:
roland@3724 2859 assert(!n->in(1)->is_EncodeNarrowPtr(), "should be optimized out");
kvn@1495 2860 // DecodeN could be pinned when it can't be fold into
kvn@492 2861 // an address expression, see the code for Op_CastPP above.
roland@3724 2862 assert(n->in(0) == NULL || (UseCompressedOops && !Matcher::narrow_oop_use_complex_address()), "no control");
kvn@368 2863 break;
kvn@368 2864
roland@3724 2865 case Op_EncodeP:
roland@3724 2866 case Op_EncodePKlass: {
kvn@368 2867 Node* in1 = n->in(1);
roland@3724 2868 if (in1->is_DecodeNarrowPtr()) {
bharadwaj@3880 2869 n->subsume_by(in1->in(1), this);
kvn@368 2870 } else if (in1->Opcode() == Op_ConP) {
kvn@368 2871 const Type* t = in1->bottom_type();
kvn@368 2872 if (t == TypePtr::NULL_PTR) {
roland@3724 2873 assert(t->isa_oopptr(), "null klass?");
bharadwaj@3880 2874 n->subsume_by(ConNode::make(this, TypeNarrowOop::NULL_PTR), this);
kvn@368 2875 } else if (t->isa_oopptr()) {
bharadwaj@3880 2876 n->subsume_by(ConNode::make(this, t->make_narrowoop()), this);
roland@3724 2877 } else if (t->isa_klassptr()) {
bharadwaj@3880 2878 n->subsume_by(ConNode::make(this, t->make_narrowklass()), this);
kvn@368 2879 }
kvn@368 2880 }
kvn@368 2881 if (in1->outcnt() == 0) {
bharadwaj@3880 2882 in1->disconnect_inputs(NULL, this);
kvn@368 2883 }
kvn@368 2884 break;
kvn@368 2885 }
kvn@368 2886
never@1080 2887 case Op_Proj: {
never@1080 2888 if (OptimizeStringConcat) {
never@1080 2889 ProjNode* p = n->as_Proj();
never@1080 2890 if (p->_is_io_use) {
never@1080 2891 // Separate projections were used for the exception path which
never@1080 2892 // are normally removed by a late inline. If it wasn't inlined
never@1080 2893 // then they will hang around and should just be replaced with
never@1080 2894 // the original one.
never@1080 2895 Node* proj = NULL;
never@1080 2896 // Replace with just one
never@1080 2897 for (SimpleDUIterator i(p->in(0)); i.has_next(); i.next()) {
never@1080 2898 Node *use = i.get();
never@1080 2899 if (use->is_Proj() && p != use && use->as_Proj()->_con == p->_con) {
never@1080 2900 proj = use;
never@1080 2901 break;
never@1080 2902 }
never@1080 2903 }
kvn@2961 2904 assert(proj != NULL, "must be found");
bharadwaj@3880 2905 p->subsume_by(proj, this);
never@1080 2906 }
never@1080 2907 }
never@1080 2908 break;
never@1080 2909 }
never@1080 2910
kvn@368 2911 case Op_Phi:
roland@3724 2912 if (n->as_Phi()->bottom_type()->isa_narrowoop() || n->as_Phi()->bottom_type()->isa_narrowklass()) {
kvn@368 2913 // The EncodeP optimization may create Phi with the same edges
kvn@368 2914 // for all paths. It is not handled well by Register Allocator.
kvn@368 2915 Node* unique_in = n->in(1);
kvn@368 2916 assert(unique_in != NULL, "");
kvn@368 2917 uint cnt = n->req();
kvn@368 2918 for (uint i = 2; i < cnt; i++) {
kvn@368 2919 Node* m = n->in(i);
kvn@368 2920 assert(m != NULL, "");
kvn@368 2921 if (unique_in != m)
kvn@368 2922 unique_in = NULL;
kvn@368 2923 }
kvn@368 2924 if (unique_in != NULL) {
bharadwaj@3880 2925 n->subsume_by(unique_in, this);
kvn@368 2926 }
kvn@368 2927 }
kvn@368 2928 break;
kvn@368 2929
kvn@164 2930 #endif
kvn@164 2931
duke@0 2932 case Op_ModI:
duke@0 2933 if (UseDivMod) {
duke@0 2934 // Check if a%b and a/b both exist
duke@0 2935 Node* d = n->find_similar(Op_DivI);
duke@0 2936 if (d) {
duke@0 2937 // Replace them with a fused divmod if supported
duke@0 2938 if (Matcher::has_match_rule(Op_DivModI)) {
bharadwaj@3880 2939 DivModINode* divmod = DivModINode::make(this, n);
bharadwaj@3880 2940 d->subsume_by(divmod->div_proj(), this);
bharadwaj@3880 2941 n->subsume_by(divmod->mod_proj(), this);
duke@0 2942 } else {
duke@0 2943 // replace a%b with a-((a/b)*b)
bharadwaj@3880 2944 Node* mult = new (this) MulINode(d, d->in(2));
bharadwaj@3880 2945 Node* sub = new (this) SubINode(d->in(1), mult);
bharadwaj@3880 2946 n->subsume_by(sub, this);
duke@0 2947 }
duke@0 2948 }
duke@0 2949 }
duke@0 2950 break;
duke@0 2951
duke@0 2952 case Op_ModL:
duke@0 2953 if (UseDivMod) {
duke@0 2954 // Check if a%b and a/b both exist
duke@0 2955 Node* d = n->find_similar(Op_DivL);
duke@0 2956 if (d) {
duke@0 2957 // Replace them with a fused divmod if supported
duke@0 2958 if (Matcher::has_match_rule(Op_DivModL)) {
bharadwaj@3880 2959 DivModLNode* divmod = DivModLNode::make(this, n);
bharadwaj@3880 2960 d->subsume_by(divmod->div_proj(), this);
bharadwaj@3880 2961 n->subsume_by(divmod->mod_proj(), this);
duke@0 2962 } else {
duke@0 2963 // replace a%b with a-((a/b)*b)
bharadwaj@3880 2964 Node* mult = new (this) MulLNode(d, d->in(2));
bharadwaj@3880 2965 Node* sub = new (this) SubLNode(d->in(1), mult);
bharadwaj@3880 2966 n->subsume_by(sub, this);
duke@0 2967 }
duke@0 2968 }
duke@0 2969 }
duke@0 2970 break;
duke@0 2971
kvn@3447 2972 case Op_LoadVector:
kvn@3447 2973 case Op_StoreVector:
duke@0 2974 break;
duke@0 2975
duke@0 2976 case Op_PackB:
duke@0 2977 case Op_PackS:
duke@0 2978 case Op_PackI:
duke@0 2979 case Op_PackF:
duke@0 2980 case Op_PackL:
duke@0 2981 case Op_PackD:
duke@0 2982 if (n->req()-1 > 2) {
duke@0 2983 // Replace many operand PackNodes with a binary tree for matching
duke@0 2984 PackNode* p = (PackNode*) n;
bharadwaj@3880 2985 Node* btp = p->binary_tree_pack(this, 1, n->req());
bharadwaj@3880 2986 n->subsume_by(btp, this);
duke@0 2987 }
duke@0 2988 break;
kvn@859 2989 case Op_Loop:
kvn@859 2990 case Op_CountedLoop:
kvn@859 2991 if (n->as_Loop()->is_inner_loop()) {
kvn@859 2992 frc.inc_inner_loop_count();
kvn@859 2993 }
kvn@859 2994 break;
roland@2248 2995 case Op_LShiftI:
roland@2248 2996 case Op_RShiftI:
roland@2248 2997 case Op_URShiftI:
roland@2248 2998 case Op_LShiftL:
roland@2248 2999 case Op_RShiftL:
roland@2248 3000 case Op_URShiftL:
roland@2248 3001 if (Matcher::need_masked_shift_count) {
roland@2248 3002 // The cpu's shift instructions don't restrict the count to the
roland@2248 3003 // lower 5/6 bits. We need to do the masking ourselves.
roland@2248 3004 Node* in2 = n->in(2);
roland@2248 3005 juint mask = (n->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1);
roland@2248 3006 const TypeInt* t = in2->find_int_type();
roland@2248 3007 if (t != NULL && t->is_con()) {
roland@2248 3008 juint shift = t->get_con();
roland@2248 3009 if (shift > mask) { // Unsigned cmp
bharadwaj@3880 3010 n->set_req(2, ConNode::make(this, TypeInt::make(shift & mask)));
roland@2248 3011 }
roland@2248 3012 } else {
roland@2248 3013 if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) {
bharadwaj@3880 3014 Node* shift = new (this) AndINode(in2, ConNode::make(this, TypeInt::make(mask)));
roland@2248 3015 n->set_req(2, shift);
roland@2248 3016 }
roland@2248 3017 }
roland@2248 3018 if (in2->outcnt() == 0) { // Remove dead node
bharadwaj@3880 3019 in2->disconnect_inputs(NULL, this);
roland@2248 3020 }
roland@2248 3021 }
roland@2248 3022 break;
roland@4259 3023 case Op_MemBarStoreStore:
kvn@4675 3024 case Op_MemBarRelease:
roland@4259 3025 // Break the link with AllocateNode: it is no longer useful and
roland@4259 3026 // confuses register allocation.
roland@4259 3027 if (n->req() > MemBarNode::Precedent) {
roland@4259 3028 n->set_req(MemBarNode::Precedent, top());
roland@4259 3029 }
roland@4259 3030 break;
rbackman@5492 3031 // Must set a control edge on all nodes that produce a FlagsProj
rbackman@5492 3032 // so they can't escape the block that consumes the flags.
rbackman@5492 3033 // Must also set the non throwing branch as the control
rbackman@5492 3034 // for all nodes that depends on the result. Unless the node
rbackman@5492 3035 // already have a control that isn't the control of the
rbackman@5492 3036 // flag producer
rbackman@5492 3037 case Op_FlagsProj:
rbackman@5492 3038 {
rbackman@5492 3039 MathExactNode* math = (MathExactNode*) n->in(0);
rbackman@5492 3040 Node* ctrl = math->control_node();
rbackman@5492 3041 Node* non_throwing = math->non_throwing_branch();
rbackman@5492 3042 math->set_req(0, ctrl);
rbackman@5492 3043
rbackman@5492 3044 Node* result = math->result_node();
rbackman@5492 3045 if (result != NULL) {
rbackman@5492 3046 for (DUIterator_Fast jmax, j = result->fast_outs(jmax); j < jmax; j++) {
rbackman@5492 3047 Node* out = result->fast_out(j);
rbackman@5553 3048 // Phi nodes shouldn't be moved. They would only match below if they
rbackman@5553 3049 // had the same control as the MathExactNode. The only time that
rbackman@5553 3050 // would happen is if the Phi is also an input to the MathExact
rbackman@5633 3051 //
rbackman@5633 3052 // Cmp nodes shouldn't have control set at all.
rbackman@5633 3053 if (out->is_Phi() ||
rbackman@5633 3054 out->is_Cmp()) {
rbackman@5633 3055 continue;
rbackman@5633 3056 }
rbackman@5633 3057
rbackman@5633 3058 if (out->in(0) == NULL) {
rbackman@5633 3059 out->set_req(0, non_throwing);
rbackman@5633 3060 } else if (out->in(0) == ctrl) {
rbackman@5633 3061 out->set_req(0, non_throwing);
rbackman@5492 3062 }
rbackman@5492 3063 }
rbackman@5492 3064 }
rbackman@5492 3065 }
rbackman@5492 3066 break;
duke@0 3067 default:
duke@0 3068 assert( !n->is_Call(), "" );
duke@0 3069 assert( !n->is_Mem(), "" );
duke@0 3070 break;
duke@0 3071 }
never@127 3072
never@127 3073 // Collect CFG split points
never@127 3074 if (n->is_MultiBranch())
kvn@859 3075 frc._tests.push(n);
duke@0 3076 }
duke@0 3077
duke@0 3078 //------------------------------final_graph_reshaping_walk---------------------
duke@0 3079 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
duke@0 3080 // requires that the walk visits a node's inputs before visiting the node.
bharadwaj@3880 3081 void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) {
kvn@331 3082 ResourceArea *area = Thread::current()->resource_area();
kvn@331 3083 Unique_Node_List sfpt(area);
kvn@331 3084
kvn@859 3085 frc._visited.set(root->_idx); // first, mark node as visited
duke@0 3086 uint cnt = root->req();
duke@0 3087 Node *n = root;
duke@0 3088 uint i = 0;
duke@0 3089 while (true) {
duke@0 3090 if (i < cnt) {
duke@0 3091 // Place all non-visited non-null inputs onto stack
duke@0 3092 Node* m = n->in(i);
duke@0 3093 ++i;
kvn@859 3094 if (m != NULL && !frc._visited.test_set(m->_idx)) {
kvn@331 3095 if (m->is_SafePoint() && m->as_SafePoint()->jvms() != NULL)
kvn@331 3096 sfpt.push(m);
duke@0 3097 cnt = m->req();
duke@0 3098 nstack.push(n, i); // put on stack parent and next input's index
duke@0 3099 n = m;
duke@0 3100 i = 0;
duke@0 3101 }
duke@0 3102 } else {
duke@0 3103 // Now do post-visit work
kvn@859 3104 final_graph_reshaping_impl( n, frc );
duke@0 3105 if (nstack.is_empty())
duke@0 3106 break; // finished
duke@0 3107 n = nstack.node(); // Get node from stack
duke@0 3108 cnt = n->req();
duke@0 3109 i = nstack.index();
duke@0 3110 nstack.pop(); // Shift to the next node on stack
duke@0 3111 }
duke@0 3112 }
kvn@331 3113
kvn@1495 3114 // Skip next transformation if compressed oops are not used.
roland@3724 3115 if ((UseCompressedOops && !Matcher::gen_narrow_oop_implicit_null_checks()) ||
ehelin@5259 3116 (!UseCompressedOops && !UseCompressedClassPointers))
kvn@1495 3117 return;
kvn@1495 3118
roland@3724 3119 // Go over safepoints nodes to skip DecodeN/DecodeNKlass nodes for debug edges.
kvn@331 3120 // It could be done for an uncommon traps or any safepoints/calls
roland@3724 3121 // if the DecodeN/DecodeNKlass node is referenced only in a debug info.
kvn@331 3122 while (sfpt.size() > 0) {
kvn@331 3123 n = sfpt.pop();
kvn@331 3124 JVMState *jvms = n->as_SafePoint()->jvms();
kvn@331 3125 assert(jvms != NULL, "sanity");
kvn@331 3126 int start = jvms->debug_start();
kvn@331 3127 int end = n->req();
kvn@331 3128 bool is_uncommon = (n->is_CallStaticJava() &&
kvn@331 3129 n->as_CallStaticJava()->uncommon_trap_request() != 0);
kvn@331 3130 for (int j = start; j < end; j++) {
kvn@331 3131 Node* in = n->in(j);
roland@3724 3132 if (in->is_DecodeNarrowPtr()) {
kvn@331 3133 bool safe_to_skip = true;
kvn@331 3134 if (!is_uncommon ) {
kvn@331 3135 // Is it safe to skip?
kvn@331 3136 for (uint i = 0; i < in->outcnt(); i++) {
kvn@331 3137 Node* u = in->raw_out(i);
kvn@331 3138 if (!u->is_SafePoint() ||
kvn@331 3139 u->is_Call() && u->as_Call()->has_non_debug_use(n)) {
kvn@331 3140 safe_to_skip = false;
kvn@331 3141 }
kvn@331 3142 }
kvn@331 3143 }
kvn@331 3144 if (safe_to_skip) {
kvn@331 3145 n->set_req(j, in->in(1));
kvn@331 3146 }
kvn@331 3147 if (in->outcnt() == 0) {
bharadwaj@3880 3148 in->disconnect_inputs(NULL, this);
kvn@331 3149 }
kvn@331 3150 }
kvn@331 3151 }
kvn@331 3152 }
duke@0 3153 }
duke@0 3154
duke@0 3155 //------------------------------final_graph_reshaping--------------------------
duke@0 3156 // Final Graph Reshaping.
duke@0 3157 //
duke@0 3158 // (1) Clone simple inputs to uncommon calls, so they can be scheduled late
duke@0 3159 // and not commoned up and forced early. Must come after regular
duke@0 3160 // optimizations to avoid GVN undoing the cloning. Clone constant
duke@0 3161 // inputs to Loop Phis; these will be split by the allocator anyways.
duke@0 3162 // Remove Opaque nodes.
duke@0 3163 // (2) Move last-uses by commutative operations to the left input to encourage
duke@0 3164 // Intel update-in-place two-address operations and better register usage
duke@0 3165 // on RISCs. Must come after regular optimizations to avoid GVN Ideal
duke@0 3166 // calls canonicalizing them back.
duke@0 3167 // (3) Count the number of double-precision FP ops, single-precision FP ops
duke@0 3168 // and call sites. On Intel, we can get correct rounding either by
duke@0 3169 // forcing singles to memory (requires extra stores and loads after each
duke@0 3170 // FP bytecode) or we can set a rounding mode bit (requires setting and
duke@0 3171 // clearing the mode bit around call sites). The mode bit is only used
duke@0 3172 // if the relative frequency of single FP ops to calls is low enough.
duke@0 3173 // This is a key transform for SPEC mpeg_audio.
duke@0 3174 // (4) Detect infinite loops; blobs of code reachable from above but not
duke@0 3175 // below. Several of the Code_Gen algorithms fail on such code shapes,
duke@0 3176 // so we simply bail out. Happens a lot in ZKM.jar, but also happens
duke@0 3177 // from time to time in other codes (such as -Xcomp finalizer loops, etc).
duke@0 3178 // Detection is by looking for IfNodes where only 1 projection is
duke@0 3179 // reachable from below or CatchNodes missing some targets.
duke@0 3180 // (5) Assert for insane oop offsets in debug mode.
duke@0 3181
duke@0 3182 bool Compile::final_graph_reshaping() {
duke@0 3183 // an infinite loop may have been eliminated by the optimizer,
duke@0 3184 // in which case the graph will be empty.
duke@0 3185 if (root()->req() == 1) {
duke@0 3186 record_method_not_compilable("trivial infinite loop");
duke@0 3187 return true;
duke@0 3188 }
duke@0 3189
roland@4154 3190 // Expensive nodes have their control input set to prevent the GVN
roland@4154 3191 // from freely commoning them. There's no GVN beyond this point so
roland@4154 3192 // no need to keep the control input. We want the expensive nodes to
roland@4154 3193 // be freely moved to the least frequent code path by gcm.
roland@4154 3194 assert(OptimizeExpensiveOps || expensive_count() == 0, "optimization off but list non empty?");
roland@4154 3195 for (int i = 0; i < expensive_count(); i++) {
roland@4154 3196 _expensive_nodes->at(i)->set_req(0, NULL);
roland@4154 3197 }
roland@4154 3198
kvn@859 3199 Final_Reshape_Counts frc;
duke@0 3200
duke@0 3201 // Visit everybody reachable!
duke@0 3202 // Allocate stack of size C->unique()/2 to avoid frequent realloc
duke@0 3203 Node_Stack nstack(unique() >> 1);
kvn@859 3204 final_graph_reshaping_walk(nstack, root(), frc);
duke@0 3205
duke@0 3206 // Check for unreachable (from below) code (i.e., infinite loops).
kvn@859 3207 for( uint i = 0; i < frc._tests.size(); i++ ) {
kvn@859 3208 MultiBranchNode *n = frc._tests[i]->as_MultiBranch();
never@127 3209 // Get number of CFG targets.
duke@0 3210 // Note that PCTables include exception targets after calls.
never@127 3211 uint required_outcnt = n->required_outcnt();
never@127 3212 if (n->outcnt() != required_outcnt) {
duke@0 3213 // Check for a few special cases. Rethrow Nodes never take the
duke@0 3214 // 'fall-thru' path, so expected kids is 1 less.
duke@0 3215 if (n->is_PCTable() && n->in(0) && n->in(0)->in(0)) {
duke@0 3216 if (n->in(0)->in(0)->is_Call()) {
duke@0 3217 CallNode *call = n->in(0)->in(0)->as_Call();
duke@0 3218 if (call->entry_point() == OptoRuntime::rethrow_stub()) {
never@127 3219 required_outcnt--; // Rethrow always has 1 less kid
duke@0 3220 } else if (call->req() > TypeFunc::Parms &&
duke@0 3221 call->is_CallDynamicJava()) {
duke@0 3222 // Check for null receiver. In such case, the optimizer has
duke@0 3223 // detected that the virtual call will always result in a null
duke@0 3224 // pointer exception. The fall-through projection of this CatchNode
duke@0 3225 // will not be populated.
duke@0 3226 Node *arg0 = call->in(TypeFunc::Parms);
duke@0 3227 if (arg0->is_Type() &&
duke@0 3228 arg0->as_Type()->type()->higher_equal(TypePtr::NULL_PTR)) {
never@127 3229 required_outcnt--;
duke@0 3230 }
duke@0 3231 } else if (call->entry_point() == OptoRuntime::new_array_Java() &&
duke@0 3232 call->req() > TypeFunc::Parms+1 &&
duke@0 3233 call->is_CallStaticJava()) {
duke@0 3234 // Check for negative array length. In such case, the optimizer has
duke@0 3235 // detected that the allocation attempt will always result in an
duke@0 3236 // exception. There is no fall-through projection of this CatchNode .
duke@0 3237 Node *arg1 = call->in(TypeFunc::Parms+1);
duke@0 3238 if (arg1->is_Type() &&
duke@0 3239 arg1->as_Type()->type()->join(TypeInt::POS)->empty()) {
never@127 3240 required_outcnt--;
duke@0 3241 }
duke@0 3242 }
duke@0 3243 }
duke@0 3244 }
never@127 3245 // Recheck with a better notion of 'required_outcnt'
never@127 3246 if (n->outcnt() != required_outcnt) {
duke@0 3247 record_method_not_compilable("malformed control flow");
duke@0 3248 return true; // Not all targets reachable!
duke@0 3249 }
duke@0 3250 }
duke@0 3251 // Check that I actually visited all kids. Unreached kids
duke@0 3252 // must be infinite loops.
duke@0 3253 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++)
kvn@859 3254 if (!frc._visited.test(n->fast_out(j)->_idx)) {
duke@0 3255 record_method_not_compilable("infinite loop");
duke@0 3256 return true; // Found unvisited kid; must be unreach
duke@0 3257 }
duke@0 3258 }
duke@0 3259
duke@0 3260 // If original bytecodes contained a mixture of floats and doubles
duke@0 3261 // check if the optimizer has made it homogenous, item (3).
never@929 3262 if( Use24BitFPMode && Use24BitFP && UseSSE == 0 &&
kvn@859 3263 frc.get_float_count() > 32 &&
kvn@859 3264 frc.get_double_count() == 0 &&
kvn@859 3265 (10 * frc.get_call_count() < frc.get_float_count()) ) {
duke@0 3266 set_24_bit_selection_and_mode( false, true );
duke@0 3267 }
duke@0 3268
kvn@859 3269 set_java_calls(frc.get_java_call_count());
kvn@859 3270 set_inner_loops(frc.get_inner_loop_count());
duke@0 3271
duke@0 3272 // No infinite loops, no reason to bail out.
duke@0 3273 return false;
duke@0 3274 }
duke@0 3275
duke@0 3276 //-----------------------------too_many_traps----------------------------------
duke@0 3277 // Report if there are too many traps at the current method and bci.
duke@0 3278 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
duke@0 3279 bool Compile::too_many_traps(ciMethod* method,
duke@0 3280 int bci,
duke@0 3281 Deoptimization::DeoptReason reason) {
duke@0 3282 ciMethodData* md = method->method_data();
duke@0 3283 if (md->is_empty()) {
duke@0 3284 // Assume the trap has not occurred, or that it occurred only
duke@0 3285 // because of a transient condition during start-up in the interpreter.
duke@0 3286 return false;
duke@0 3287 }
duke@0 3288 if (md->has_trap_at(bci, reason) != 0) {
duke@0 3289 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
duke@0 3290 // Also, if there are multiple reasons, or if there is no per-BCI record,
duke@0 3291 // assume the worst.
duke@0 3292 if (log())
duke@0 3293 log()->elem("observe trap='%s' count='%d'",
duke@0 3294 Deoptimization::trap_reason_name(reason),
duke@0 3295 md->trap_count(reason));
duke@0 3296 return true;
duke@0 3297 } else {
duke@0 3298 // Ignore method/bci and see if there have been too many globally.
duke@0 3299 return too_many_traps(reason, md);
duke@0 3300 }
duke@0 3301 }
duke@0 3302
duke@0 3303 // Less-accurate variant which does not require a method and bci.
duke@0 3304 bool Compile::too_many_traps(Deoptimization::DeoptReason reason,
duke@0 3305 ciMethodData* logmd) {
duke@0 3306 if (trap_count(reason) >= (uint)PerMethodTrapLimit) {
duke@0 3307 // Too many traps globally.
duke@0 3308 // Note that we use cumulative trap_count, not just md->trap_count.
duke@0 3309 if (log()) {
duke@0 3310 int mcount = (logmd == NULL)? -1: (int)logmd->trap_count(reason);
duke@0 3311 log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'",
duke@0 3312 Deoptimization::trap_reason_name(reason),
duke@0 3313 mcount, trap_count(reason));
duke@0 3314 }
duke@0 3315 return true;
duke@0 3316 } else {
duke@0 3317 // The coast is clear.
duke@0 3318 return false;
duke@0 3319 }
duke@0 3320 }
duke@0 3321
duke@0 3322 //--------------------------too_many_recompiles--------------------------------
duke@0 3323 // Report if there are too many recompiles at the current method and bci.
duke@0 3324 // Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff.
duke@0 3325 // Is not eager to return true, since this will cause the compiler to use
duke@0 3326 // Action_none for a trap point, to avoid too many recompilations.
duke@0 3327 bool Compile::too_many_recompiles(ciMethod* method,
duke@0 3328 int bci,
duke@0 3329 Deoptimization::DeoptReason reason) {
duke@0 3330 ciMethodData* md = method->method_data();
duke@0 3331 if (md->is_empty()) {
duke@0 3332 // Assume the trap has not occurred, or that it occurred only
duke@0 3333 // because of a transient condition during start-up in the interpreter.
duke@0 3334 return false;
duke@0 3335 }
duke@0 3336 // Pick a cutoff point well within PerBytecodeRecompilationCutoff.
duke@0 3337 uint bc_cutoff = (uint) PerBytecodeRecompilationCutoff / 8;
duke@0 3338 uint m_cutoff = (uint) PerMethodRecompilationCutoff / 2 + 1; // not zero
duke@0 3339 Deoptimization::DeoptReason per_bc_reason
duke@0 3340 = Deoptimization::reason_recorded_per_bytecode_if_any(reason);
duke@0 3341 if ((per_bc_reason == Deoptimization::Reason_none
duke@0 3342 || md->has_trap_at(bci, reason) != 0)
duke@0 3343 // The trap frequency measure we care about is the recompile count:
duke@0 3344 && md->trap_recompiled_at(bci)
duke@0 3345 && md->overflow_recompile_count() >= bc_cutoff) {
duke@0 3346 // Do not emit a trap here if it has already caused recompilations.
duke@0 3347 // Also, if there are multiple reasons, or if there is no per-BCI record,
duke@0 3348 // assume the worst.
duke@0 3349 if (log())
duke@0 3350 log()->elem("observe trap='%s recompiled' count='%d' recompiles2='%d'",
duke@0 3351 Deoptimization::trap_reason_name(reason),
duke@0 3352 md->trap_count(reason),
duke@0 3353 md->overflow_recompile_count());
duke@0 3354 return true;
duke@0 3355 } else if (trap_count(reason) != 0
duke@0 3356 && decompile_count() >= m_cutoff) {
duke@0 3357 // Too many recompiles globally, and we have seen this sort of trap.
duke@0 3358 // Use cumulative decompile_count, not just md->decompile_count.
duke@0 3359 if (log())
duke@0 3360 log()->elem("observe trap='%s' count='%d' mcount='%d' decompiles='%d' mdecompiles='%d'",
duke@0 3361 Deoptimization::trap_reason_name(reason),
duke@0 3362 md->trap_count(reason), trap_count(reason),
duke@0 3363 md->decompile_count(), decompile_count());
duke@0 3364 return true;
duke@0 3365 } else {
duke@0 3366 // The coast is clear.
duke@0 3367 return false;
duke@0 3368 }
duke@0 3369 }
duke@0 3370
goetz@5992 3371 // Compute when not to trap. Used by matching trap based nodes and
goetz@5992 3372 // NullCheck optimization.
goetz@5992 3373 void Compile::set_allowed_deopt_reasons() {
goetz@5992 3374 _allowed_reasons = 0;
goetz@5992 3375 if (is_method_compilation()) {
goetz@5992 3376 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
goetz@5992 3377 assert(rs < BitsPerInt, "recode bit map");
goetz@5992 3378 if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
goetz@5992 3379 _allowed_reasons |= nth_bit(rs);
goetz@5992 3380 }
goetz@5992 3381 }
goetz@5992 3382 }
goetz@5992 3383 }
duke@0 3384
duke@0 3385 #ifndef PRODUCT
duke@0 3386 //------------------------------verify_graph_edges---------------------------
duke@0 3387 // Walk the Graph and verify that there is a one-to-one correspondence
duke@0 3388 // between Use-Def edges and Def-Use edges in the graph.
duke@0 3389 void Compile::verify_graph_edges(bool no_dead_code) {
duke@0 3390 if (VerifyGraphEdges) {
duke@0 3391 ResourceArea *area = Thread::current()->resource_area();
duke@0 3392 Unique_Node_List visited(area);
duke@0 3393 // Call recursive graph walk to check edges
duke@0 3394 _root->verify_edges(visited);
duke@0 3395 if (no_dead_code) {
duke@0 3396 // Now make sure that no visited node is used by an unvisited node.
duke@0 3397 bool dead_nodes = 0;
duke@0 3398 Unique_Node_List checked(area);
duke@0 3399 while (visited.size() > 0) {
duke@0 3400 Node* n = visited.pop();
duke@0 3401 checked.push(n);
duke@0 3402 for (uint i = 0; i < n->outcnt(); i++) {
duke@0 3403 Node* use = n->raw_out(i);
duke@0 3404 if (checked.member(use)) continue; // already checked
duke@0 3405 if (visited.member(use)) continue; // already in the graph
duke@0 3406 if (use->is_Con()) continue; // a dead ConNode is OK
duke@0 3407 // At this point, we have found a dead node which is DU-reachable.
duke@0 3408 if (dead_nodes++ == 0)
duke@0 3409 tty->print_cr("*** Dead nodes reachable via DU edges:");
duke@0 3410 use->dump(2);
duke@0 3411 tty->print_cr("---");
duke@0 3412 checked.push(use); // No repeats; pretend it is now checked.
duke@0 3413 }
duke@0 3414 }
duke@0 3415 assert(dead_nodes == 0, "using nodes must be reachable from root");
duke@0 3416 }
duke@0 3417 }
duke@0 3418 }
iveresov@5635 3419
iveresov@5635 3420 // Verify GC barriers consistency
iveresov@5635 3421 // Currently supported:
iveresov@5635 3422 // - G1 pre-barriers (see GraphKit::g1_write_barrier_pre())
iveresov@5635 3423 void Compile::verify_barriers() {
iveresov@5635 3424 if (UseG1GC) {
iveresov@5635 3425 // Verify G1 pre-barriers
iveresov@5635 3426 const int marking_offset = in_bytes(JavaThread::satb_mark_queue_offset() + PtrQueue::byte_offset_of_active());
iveresov@5635 3427
iveresov@5635 3428 ResourceArea *area = Thread::current()->resource_area();
iveresov@5635 3429 Unique_Node_List visited(area);
iveresov@5635 3430 Node_List worklist(area);
iveresov@5635 3431 // We're going to walk control flow backwards starting from the Root
iveresov@5635 3432 worklist.push(_root);
iveresov@5635 3433 while (worklist.size() > 0) {
iveresov@5635 3434 Node* x = worklist.pop();
iveresov@5635 3435 if (x == NULL || x == top()) continue;
iveresov@5635 3436 if (visited.member(x)) {
iveresov@5635 3437 continue;
iveresov@5635 3438 } else {
iveresov@5635 3439 visited.push(x);
iveresov@5635 3440 }
iveresov@5635 3441
iveresov@5635 3442 if (x->is_Region()) {
iveresov@5635 3443 for (uint i = 1; i < x->req(); i++) {
iveresov@5635 3444 worklist.push(x->in(i));
iveresov@5635 3445 }
iveresov@5635 3446 } else {
iveresov@5635 3447 worklist.push(x->in(0));
iveresov@5635 3448 // We are looking for the pattern:
iveresov@5635 3449 // /->ThreadLocal
iveresov@5635 3450 // If->Bool->CmpI->LoadB->AddP->ConL(marking_offset)
iveresov@5635 3451 // \->ConI(0)
iveresov@5635 3452 // We want to verify that the If and the LoadB have the same control
iveresov@5635 3453 // See GraphKit::g1_write_barrier_pre()
iveresov@5635 3454 if (x->is_If()) {
iveresov@5635 3455 IfNode *iff = x->as_If();
iveresov@5635 3456 if (iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) {
iveresov@5635 3457 CmpNode *cmp = iff->in(1)->in(1)->as_Cmp();
iveresov@5635 3458 if (cmp->Opcode() == Op_CmpI && cmp->in(2)->is_Con() && cmp->in(2)->bottom_type()->is_int()->get_con() == 0
iveresov@5635 3459 && cmp->in(1)->is_Load()) {
iveresov@5635 3460 LoadNode* load = cmp->in(1)->as_Load();
iveresov@5635 3461 if (load->Opcode() == Op_LoadB && load->in(2)->is_AddP() && load->in(2)->in(2)->Opcode() == Op_ThreadLocal
iveresov@5635 3462 && load->in(2)->in(3)->is_Con()
iveresov@5635 3463 && load->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == marking_offset) {
iveresov@5635 3464
iveresov@5635 3465 Node* if_ctrl = iff->in(0);
iveresov@5635 3466 Node* load_ctrl = load->in(0);
iveresov@5635 3467
iveresov@5635 3468 if (if_ctrl != load_ctrl) {
iveresov@5635 3469 // Skip possible CProj->NeverBranch in infinite loops
iveresov@5635 3470 if ((if_ctrl->is_Proj() && if_ctrl->Opcode() == Op_CProj)
iveresov@5635 3471 && (if_ctrl->in(0)->is_MultiBranch() && if_ctrl->in(0)->Opcode() == Op_NeverBranch)) {
iveresov@5635 3472 if_ctrl = if_ctrl->in(0)->in(0);
iveresov@5635 3473 }
iveresov@5635 3474 }
iveresov@5635 3475 assert(load_ctrl != NULL && if_ctrl == load_ctrl, "controls must match");
iveresov@5635 3476 }
iveresov@5635 3477 }
iveresov@5635 3478 }
iveresov@5635 3479 }
iveresov@5635 3480 }
iveresov@5635 3481 }
iveresov@5635 3482 }
iveresov@5635 3483 }
iveresov@5635 3484
duke@0 3485 #endif
duke@0 3486
duke@0 3487 // The Compile object keeps track of failure reasons separately from the ciEnv.
duke@0 3488 // This is required because there is not quite a 1-1 relation between the
duke@0 3489 // ciEnv and its compilation task and the Compile object. Note that one
duke@0 3490 // ciEnv might use two Compile objects, if C2Compiler::compile_method decides
duke@0 3491 // to backtrack and retry without subsuming loads. Other than this backtracking
duke@0 3492 // behavior, the Compile's failure reason is quietly copied up to the ciEnv
duke@0 3493 // by the logic in C2Compiler.
duke@0 3494 void Compile::record_failure(const char* reason) {
duke@0 3495 if (log() != NULL) {
duke@0 3496 log()->elem("failure reason='%s' phase='compile'", reason);
duke@0 3497 }
duke@0 3498 if (_failure_reason == NULL) {
duke@0 3499 // Record the first failure reason.
duke@0 3500 _failure_reason = reason;
duke@0 3501 }
sla@4802 3502
sla@4802 3503 EventCompilerFailure event;
sla@4802 3504 if (event.should_commit()) {
sla@4802 3505 event.set_compileID(Compile::compile_id());
sla@4802 3506 event.set_failure(reason);
sla@4802 3507 event.commit();
sla@4802 3508 }
sla@4802 3509
never@222 3510 if (!C->failure_reason_is(C2Compiler::retry_no_subsuming_loads())) {
sla@4802 3511 C->print_method(PHASE_FAILURE);
never@222 3512 }
duke@0 3513 _root = NULL; // flush the graph, too
duke@0 3514 }
duke@0 3515
duke@0 3516 Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator, bool dolog)
bharadwaj@3880 3517 : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false),
bharadwaj@3880 3518 _phase_name(name), _dolog(dolog)
duke@0 3519 {
duke@0 3520 if (dolog) {
duke@0 3521 C = Compile::current();
duke@0 3522 _log = C->log();
duke@0 3523 } else {
duke@0 3524 C = NULL;
duke@0 3525 _log = NULL;
duke@0 3526 }
duke@0 3527 if (_log != NULL) {
bharadwaj@3880 3528 _log->begin_head("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes());
duke@0 3529 _log->stamp();
duke@0 3530 _log->end_head();
duke@0 3531 }
duke@0 3532 }
duke@0 3533
duke@0 3534 Compile::TracePhase::~TracePhase() {
bharadwaj@3880 3535
bharadwaj@3880 3536 C = Compile::current();
bharadwaj@3880 3537 if (_dolog) {
bharadwaj@3880 3538 _log = C->log();
bharadwaj@3880 3539 } else {
bharadwaj@3880 3540 _log = NULL;
bharadwaj@3880 3541 }
bharadwaj@3880 3542
bharadwaj@3880 3543 #ifdef ASSERT
bharadwaj@3880 3544 if (PrintIdealNodeCount) {
bharadwaj@3880 3545 tty->print_cr("phase name='%s' nodes='%d' live='%d' live_graph_walk='%d'",
bharadwaj@3880 3546 _phase_name, C->unique(), C->live_nodes(), C->count_live_nodes_by_graph_walk());
bharadwaj@3880 3547 }
bharadwaj@3880 3548
bharadwaj@3880 3549 if (VerifyIdealNodeCount) {
bharadwaj@3880 3550 Compile::current()->print_missing_nodes();
bharadwaj@3880 3551 }
bharadwaj@3880 3552 #endif
bharadwaj@3880 3553
duke@0 3554 if (_log != NULL) {
bharadwaj@3880 3555 _log->done("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes());
duke@0 3556 }
duke@0 3557 }
twisti@1915 3558
twisti@1915 3559 //=============================================================================
twisti@1915 3560 // Two Constant's are equal when the type and the value are equal.
twisti@1915 3561 bool Compile::Constant::operator==(const Constant& other) {
twisti@1915 3562 if (type() != other.type() ) return false;
twisti@1915 3563 if (can_be_reused() != other.can_be_reused()) return false;
twisti@1915 3564 // For floating point values we compare the bit pattern.
twisti@1915 3565 switch (type()) {
coleenp@3602 3566 case T_FLOAT: return (_v._value.i == other._v._value.i);
twisti@1915 3567 case T_LONG:
coleenp@3602 3568 case T_DOUBLE: return (_v._value.j == other._v._value.j);
twisti@1915 3569 case T_OBJECT:
coleenp@3602 3570 case T_ADDRESS: return (_v._value.l == other._v._value.l);
coleenp@3602 3571 case T_VOID: re