src/share/vm/opto/compile.cpp

Thu, 20 Feb 2014 11:05:12 +0100

author
goetz
date
Thu, 20 Feb 2014 11:05:12 +0100
changeset 6510
7c462558a08a
parent 6507
752ba2e5f6d0
child 6518
62c54fcc0a35
permissions
-rw-r--r--

8035394: PPC64: Make usage of intrinsic dsqrt depend on processor recognition.
Reviewed-by: kvn

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

mercurial