src/share/vm/opto/compile.cpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 8856
ac27a9c85bea
child 9448
73d689add964
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

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

mercurial