src/share/vm/opto/compile.cpp

Wed, 10 Aug 2016 14:59:21 +0200

author
simonis
date
Wed, 10 Aug 2016 14:59:21 +0200
changeset 8608
0d78aecb0948
parent 8536
371fd9bb8202
child 8604
04d83ba48607
child 8654
2e734e824d16
permissions
-rw-r--r--

8152172: PPC64: Support AES intrinsics
Summary: Add support for AES intrinsics on PPC64.
Reviewed-by: kvn, mdoerr, simonis, zmajo
Contributed-by: Hiroshi H Horii <horii@jp.ibm.com>

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

mercurial