src/share/vm/opto/compile.cpp

Wed, 10 Apr 2019 11:38:47 +0200

author
sgehwolf
date
Wed, 10 Apr 2019 11:38:47 +0200
changeset 9649
b2000ea410b0
parent 9512
992120803410
child 9572
624a0741915c
child 9858
b985cbb00e68
permissions
-rw-r--r--

8221355: Performance regression after JDK-8155635 backport into 8u
Reviewed-by: shade, roland

duke@435 1 /*
kevinw@9325 2 * Copyright (c) 1997, 2018, 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
shshahma@8654 1598 BasicType Compile::AliasType::basic_type() const {
shshahma@8654 1599 if (element() != NULL) {
shshahma@8654 1600 const Type* element = adr_type()->is_aryptr()->elem();
shshahma@8654 1601 return element->isa_narrowoop() ? T_OBJECT : element->array_element_basic_type();
shshahma@8654 1602 } if (field() != NULL) {
shshahma@8654 1603 return field()->layout_type();
shshahma@8654 1604 } else {
shshahma@8654 1605 return T_ILLEGAL; // unknown
shshahma@8654 1606 }
shshahma@8654 1607 }
shshahma@8654 1608
duke@435 1609 //---------------------------------print_on------------------------------------
duke@435 1610 #ifndef PRODUCT
duke@435 1611 void Compile::AliasType::print_on(outputStream* st) {
duke@435 1612 if (index() < 10)
duke@435 1613 st->print("@ <%d> ", index());
duke@435 1614 else st->print("@ <%d>", index());
duke@435 1615 st->print(is_rewritable() ? " " : " RO");
duke@435 1616 int offset = adr_type()->offset();
duke@435 1617 if (offset == Type::OffsetBot)
duke@435 1618 st->print(" +any");
duke@435 1619 else st->print(" +%-3d", offset);
duke@435 1620 st->print(" in ");
duke@435 1621 adr_type()->dump_on(st);
duke@435 1622 const TypeOopPtr* tjp = adr_type()->isa_oopptr();
duke@435 1623 if (field() != NULL && tjp) {
duke@435 1624 if (tjp->klass() != field()->holder() ||
duke@435 1625 tjp->offset() != field()->offset_in_bytes()) {
duke@435 1626 st->print(" != ");
duke@435 1627 field()->print();
duke@435 1628 st->print(" ***");
duke@435 1629 }
duke@435 1630 }
duke@435 1631 }
duke@435 1632
duke@435 1633 void print_alias_types() {
duke@435 1634 Compile* C = Compile::current();
duke@435 1635 tty->print_cr("--- Alias types, AliasIdxBot .. %d", C->num_alias_types()-1);
duke@435 1636 for (int idx = Compile::AliasIdxBot; idx < C->num_alias_types(); idx++) {
duke@435 1637 C->alias_type(idx)->print_on(tty);
duke@435 1638 tty->cr();
duke@435 1639 }
duke@435 1640 }
duke@435 1641 #endif
duke@435 1642
duke@435 1643
duke@435 1644 //----------------------------probe_alias_cache--------------------------------
duke@435 1645 Compile::AliasCacheEntry* Compile::probe_alias_cache(const TypePtr* adr_type) {
duke@435 1646 intptr_t key = (intptr_t) adr_type;
duke@435 1647 key ^= key >> logAliasCacheSize;
duke@435 1648 return &_alias_cache[key & right_n_bits(logAliasCacheSize)];
duke@435 1649 }
duke@435 1650
duke@435 1651
duke@435 1652 //-----------------------------grow_alias_types--------------------------------
duke@435 1653 void Compile::grow_alias_types() {
duke@435 1654 const int old_ats = _max_alias_types; // how many before?
duke@435 1655 const int new_ats = old_ats; // how many more?
duke@435 1656 const int grow_ats = old_ats+new_ats; // how many now?
duke@435 1657 _max_alias_types = grow_ats;
duke@435 1658 _alias_types = REALLOC_ARENA_ARRAY(comp_arena(), AliasType*, _alias_types, old_ats, grow_ats);
duke@435 1659 AliasType* ats = NEW_ARENA_ARRAY(comp_arena(), AliasType, new_ats);
duke@435 1660 Copy::zero_to_bytes(ats, sizeof(AliasType)*new_ats);
duke@435 1661 for (int i = 0; i < new_ats; i++) _alias_types[old_ats+i] = &ats[i];
duke@435 1662 }
duke@435 1663
duke@435 1664
duke@435 1665 //--------------------------------find_alias_type------------------------------
never@2658 1666 Compile::AliasType* Compile::find_alias_type(const TypePtr* adr_type, bool no_create, ciField* original_field) {
duke@435 1667 if (_AliasLevel == 0)
duke@435 1668 return alias_type(AliasIdxBot);
duke@435 1669
duke@435 1670 AliasCacheEntry* ace = probe_alias_cache(adr_type);
duke@435 1671 if (ace->_adr_type == adr_type) {
duke@435 1672 return alias_type(ace->_index);
duke@435 1673 }
duke@435 1674
duke@435 1675 // Handle special cases.
duke@435 1676 if (adr_type == NULL) return alias_type(AliasIdxTop);
duke@435 1677 if (adr_type == TypePtr::BOTTOM) return alias_type(AliasIdxBot);
duke@435 1678
duke@435 1679 // Do it the slow way.
duke@435 1680 const TypePtr* flat = flatten_alias_type(adr_type);
duke@435 1681
duke@435 1682 #ifdef ASSERT
dbuck@9512 1683 {
dbuck@9512 1684 ResourceMark rm;
dbuck@9512 1685 assert(flat == flatten_alias_type(flat),
dbuck@9512 1686 err_msg("not idempotent: adr_type = %s; flat = %s => %s", Type::str(adr_type),
dbuck@9512 1687 Type::str(flat), Type::str(flatten_alias_type(flat))));
dbuck@9512 1688 assert(flat != TypePtr::BOTTOM,
dbuck@9512 1689 err_msg("cannot alias-analyze an untyped ptr: adr_type = %s", Type::str(adr_type)));
dbuck@9512 1690 if (flat->isa_oopptr() && !flat->isa_klassptr()) {
dbuck@9512 1691 const TypeOopPtr* foop = flat->is_oopptr();
dbuck@9512 1692 // Scalarizable allocations have exact klass always.
dbuck@9512 1693 bool exact = !foop->klass_is_exact() || foop->is_known_instance();
dbuck@9512 1694 const TypePtr* xoop = foop->cast_to_exactness(exact)->is_ptr();
dbuck@9512 1695 assert(foop == flatten_alias_type(xoop),
dbuck@9512 1696 err_msg("exactness must not affect alias type: foop = %s; xoop = %s",
dbuck@9512 1697 Type::str(foop), Type::str(xoop)));
dbuck@9512 1698 }
duke@435 1699 }
duke@435 1700 #endif
duke@435 1701
duke@435 1702 int idx = AliasIdxTop;
duke@435 1703 for (int i = 0; i < num_alias_types(); i++) {
duke@435 1704 if (alias_type(i)->adr_type() == flat) {
duke@435 1705 idx = i;
duke@435 1706 break;
duke@435 1707 }
duke@435 1708 }
duke@435 1709
duke@435 1710 if (idx == AliasIdxTop) {
duke@435 1711 if (no_create) return NULL;
duke@435 1712 // Grow the array if necessary.
duke@435 1713 if (_num_alias_types == _max_alias_types) grow_alias_types();
duke@435 1714 // Add a new alias type.
duke@435 1715 idx = _num_alias_types++;
duke@435 1716 _alias_types[idx]->Init(idx, flat);
duke@435 1717 if (flat == TypeInstPtr::KLASS) alias_type(idx)->set_rewritable(false);
duke@435 1718 if (flat == TypeAryPtr::RANGE) alias_type(idx)->set_rewritable(false);
duke@435 1719 if (flat->isa_instptr()) {
duke@435 1720 if (flat->offset() == java_lang_Class::klass_offset_in_bytes()
duke@435 1721 && flat->is_instptr()->klass() == env()->Class_klass())
duke@435 1722 alias_type(idx)->set_rewritable(false);
duke@435 1723 }
vlivanov@5658 1724 if (flat->isa_aryptr()) {
vlivanov@5658 1725 #ifdef ASSERT
vlivanov@5658 1726 const int header_size_min = arrayOopDesc::base_offset_in_bytes(T_BYTE);
vlivanov@5658 1727 // (T_BYTE has the weakest alignment and size restrictions...)
vlivanov@5658 1728 assert(flat->offset() < header_size_min, "array body reference must be OffsetBot");
vlivanov@5658 1729 #endif
vlivanov@5658 1730 if (flat->offset() == TypePtr::OffsetBot) {
vlivanov@5658 1731 alias_type(idx)->set_element(flat->is_aryptr()->elem());
vlivanov@5658 1732 }
vlivanov@5658 1733 }
duke@435 1734 if (flat->isa_klassptr()) {
stefank@3391 1735 if (flat->offset() == in_bytes(Klass::super_check_offset_offset()))
duke@435 1736 alias_type(idx)->set_rewritable(false);
stefank@3391 1737 if (flat->offset() == in_bytes(Klass::modifier_flags_offset()))
duke@435 1738 alias_type(idx)->set_rewritable(false);
stefank@3391 1739 if (flat->offset() == in_bytes(Klass::access_flags_offset()))
duke@435 1740 alias_type(idx)->set_rewritable(false);
stefank@3391 1741 if (flat->offset() == in_bytes(Klass::java_mirror_offset()))
duke@435 1742 alias_type(idx)->set_rewritable(false);
duke@435 1743 }
duke@435 1744 // %%% (We would like to finalize JavaThread::threadObj_offset(),
duke@435 1745 // but the base pointer type is not distinctive enough to identify
duke@435 1746 // references into JavaThread.)
duke@435 1747
never@2658 1748 // Check for final fields.
duke@435 1749 const TypeInstPtr* tinst = flat->isa_instptr();
coleenp@548 1750 if (tinst && tinst->offset() >= instanceOopDesc::base_offset_in_bytes()) {
never@2658 1751 ciField* field;
never@2658 1752 if (tinst->const_oop() != NULL &&
never@2658 1753 tinst->klass() == ciEnv::current()->Class_klass() &&
never@2658 1754 tinst->offset() >= (tinst->klass()->as_instance_klass()->size_helper() * wordSize)) {
never@2658 1755 // static field
never@2658 1756 ciInstanceKlass* k = tinst->const_oop()->as_instance()->java_lang_Class_klass()->as_instance_klass();
never@2658 1757 field = k->get_field_by_offset(tinst->offset(), true);
never@2658 1758 } else {
never@2658 1759 ciInstanceKlass *k = tinst->klass()->as_instance_klass();
never@2658 1760 field = k->get_field_by_offset(tinst->offset(), false);
never@2658 1761 }
never@2658 1762 assert(field == NULL ||
never@2658 1763 original_field == NULL ||
never@2658 1764 (field->holder() == original_field->holder() &&
never@2658 1765 field->offset() == original_field->offset() &&
never@2658 1766 field->is_static() == original_field->is_static()), "wrong field?");
duke@435 1767 // Set field() and is_rewritable() attributes.
duke@435 1768 if (field != NULL) alias_type(idx)->set_field(field);
duke@435 1769 }
duke@435 1770 }
duke@435 1771
duke@435 1772 // Fill the cache for next time.
duke@435 1773 ace->_adr_type = adr_type;
duke@435 1774 ace->_index = idx;
duke@435 1775 assert(alias_type(adr_type) == alias_type(idx), "type must be installed");
duke@435 1776
duke@435 1777 // Might as well try to fill the cache for the flattened version, too.
duke@435 1778 AliasCacheEntry* face = probe_alias_cache(flat);
duke@435 1779 if (face->_adr_type == NULL) {
duke@435 1780 face->_adr_type = flat;
duke@435 1781 face->_index = idx;
duke@435 1782 assert(alias_type(flat) == alias_type(idx), "flat type must work too");
duke@435 1783 }
duke@435 1784
duke@435 1785 return alias_type(idx);
duke@435 1786 }
duke@435 1787
duke@435 1788
duke@435 1789 Compile::AliasType* Compile::alias_type(ciField* field) {
duke@435 1790 const TypeOopPtr* t;
duke@435 1791 if (field->is_static())
never@2658 1792 t = TypeInstPtr::make(field->holder()->java_mirror());
duke@435 1793 else
duke@435 1794 t = TypeOopPtr::make_from_klass_raw(field->holder());
never@2658 1795 AliasType* atp = alias_type(t->add_offset(field->offset_in_bytes()), field);
vlivanov@5658 1796 assert((field->is_final() || field->is_stable()) == !atp->is_rewritable(), "must get the rewritable bits correct");
duke@435 1797 return atp;
duke@435 1798 }
duke@435 1799
duke@435 1800
duke@435 1801 //------------------------------have_alias_type--------------------------------
duke@435 1802 bool Compile::have_alias_type(const TypePtr* adr_type) {
duke@435 1803 AliasCacheEntry* ace = probe_alias_cache(adr_type);
duke@435 1804 if (ace->_adr_type == adr_type) {
duke@435 1805 return true;
duke@435 1806 }
duke@435 1807
duke@435 1808 // Handle special cases.
duke@435 1809 if (adr_type == NULL) return true;
duke@435 1810 if (adr_type == TypePtr::BOTTOM) return true;
duke@435 1811
never@2658 1812 return find_alias_type(adr_type, true, NULL) != NULL;
duke@435 1813 }
duke@435 1814
duke@435 1815 //-----------------------------must_alias--------------------------------------
duke@435 1816 // True if all values of the given address type are in the given alias category.
duke@435 1817 bool Compile::must_alias(const TypePtr* adr_type, int alias_idx) {
duke@435 1818 if (alias_idx == AliasIdxBot) return true; // the universal category
duke@435 1819 if (adr_type == NULL) return true; // NULL serves as TypePtr::TOP
duke@435 1820 if (alias_idx == AliasIdxTop) return false; // the empty category
duke@435 1821 if (adr_type->base() == Type::AnyPtr) return false; // 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 assert(adr_idx == alias_idx ||
duke@435 1827 (alias_type(alias_idx)->adr_type() != TypeOopPtr::BOTTOM
duke@435 1828 && adr_type != TypeOopPtr::BOTTOM),
duke@435 1829 "should not be testing for overlap with an unsafe pointer");
duke@435 1830 return adr_idx == alias_idx;
duke@435 1831 }
duke@435 1832
duke@435 1833 //------------------------------can_alias--------------------------------------
duke@435 1834 // True if any values of the given address type are in the given alias category.
duke@435 1835 bool Compile::can_alias(const TypePtr* adr_type, int alias_idx) {
duke@435 1836 if (alias_idx == AliasIdxTop) return false; // the empty category
duke@435 1837 if (adr_type == NULL) return false; // NULL serves as TypePtr::TOP
duke@435 1838 if (alias_idx == AliasIdxBot) return true; // the universal category
duke@435 1839 if (adr_type->base() == Type::AnyPtr) return true; // TypePtr::BOTTOM or its twins
duke@435 1840
duke@435 1841 // the only remaining possible overlap is identity
duke@435 1842 int adr_idx = get_alias_index(adr_type);
duke@435 1843 assert(adr_idx != AliasIdxBot && adr_idx != AliasIdxTop, "");
duke@435 1844 return adr_idx == alias_idx;
duke@435 1845 }
duke@435 1846
duke@435 1847
duke@435 1848
duke@435 1849 //---------------------------pop_warm_call-------------------------------------
duke@435 1850 WarmCallInfo* Compile::pop_warm_call() {
duke@435 1851 WarmCallInfo* wci = _warm_calls;
duke@435 1852 if (wci != NULL) _warm_calls = wci->remove_from(wci);
duke@435 1853 return wci;
duke@435 1854 }
duke@435 1855
duke@435 1856 //----------------------------Inline_Warm--------------------------------------
duke@435 1857 int Compile::Inline_Warm() {
duke@435 1858 // If there is room, try to inline some more warm call sites.
duke@435 1859 // %%% Do a graph index compaction pass when we think we're out of space?
duke@435 1860 if (!InlineWarmCalls) return 0;
duke@435 1861
duke@435 1862 int calls_made_hot = 0;
duke@435 1863 int room_to_grow = NodeCountInliningCutoff - unique();
duke@435 1864 int amount_to_grow = MIN2(room_to_grow, (int)NodeCountInliningStep);
duke@435 1865 int amount_grown = 0;
duke@435 1866 WarmCallInfo* call;
duke@435 1867 while (amount_to_grow > 0 && (call = pop_warm_call()) != NULL) {
duke@435 1868 int est_size = (int)call->size();
duke@435 1869 if (est_size > (room_to_grow - amount_grown)) {
duke@435 1870 // This one won't fit anyway. Get rid of it.
duke@435 1871 call->make_cold();
duke@435 1872 continue;
duke@435 1873 }
duke@435 1874 call->make_hot();
duke@435 1875 calls_made_hot++;
duke@435 1876 amount_grown += est_size;
duke@435 1877 amount_to_grow -= est_size;
duke@435 1878 }
duke@435 1879
duke@435 1880 if (calls_made_hot > 0) set_major_progress();
duke@435 1881 return calls_made_hot;
duke@435 1882 }
duke@435 1883
duke@435 1884
duke@435 1885 //----------------------------Finish_Warm--------------------------------------
duke@435 1886 void Compile::Finish_Warm() {
duke@435 1887 if (!InlineWarmCalls) return;
duke@435 1888 if (failing()) return;
duke@435 1889 if (warm_calls() == NULL) return;
duke@435 1890
duke@435 1891 // Clean up loose ends, if we are out of space for inlining.
duke@435 1892 WarmCallInfo* call;
duke@435 1893 while ((call = pop_warm_call()) != NULL) {
duke@435 1894 call->make_cold();
duke@435 1895 }
duke@435 1896 }
duke@435 1897
cfang@1607 1898 //---------------------cleanup_loop_predicates-----------------------
cfang@1607 1899 // Remove the opaque nodes that protect the predicates so that all unused
cfang@1607 1900 // checks and uncommon_traps will be eliminated from the ideal graph
cfang@1607 1901 void Compile::cleanup_loop_predicates(PhaseIterGVN &igvn) {
cfang@1607 1902 if (predicate_count()==0) return;
cfang@1607 1903 for (int i = predicate_count(); i > 0; i--) {
cfang@1607 1904 Node * n = predicate_opaque1_node(i-1);
cfang@1607 1905 assert(n->Opcode() == Op_Opaque1, "must be");
cfang@1607 1906 igvn.replace_node(n, n->in(1));
cfang@1607 1907 }
cfang@1607 1908 assert(predicate_count()==0, "should be clean!");
cfang@1607 1909 }
duke@435 1910
thartmann@8476 1911 void Compile::add_range_check_cast(Node* n) {
thartmann@8476 1912 assert(n->isa_CastII()->has_range_check(), "CastII should have range check dependency");
thartmann@8476 1913 assert(!_range_check_casts->contains(n), "duplicate entry in range check casts");
thartmann@8476 1914 _range_check_casts->append(n);
thartmann@8476 1915 }
thartmann@8476 1916
thartmann@8476 1917 // Remove all range check dependent CastIINodes.
thartmann@8476 1918 void Compile::remove_range_check_casts(PhaseIterGVN &igvn) {
thartmann@8476 1919 for (int i = range_check_cast_count(); i > 0; i--) {
thartmann@8476 1920 Node* cast = range_check_cast_node(i-1);
thartmann@8476 1921 assert(cast->isa_CastII()->has_range_check(), "CastII should have range check dependency");
thartmann@8476 1922 igvn.replace_node(cast, cast->in(1));
thartmann@8476 1923 }
thartmann@8476 1924 assert(range_check_cast_count() == 0, "should be empty");
thartmann@8476 1925 }
thartmann@8476 1926
roland@4409 1927 // StringOpts and late inlining of string methods
roland@4409 1928 void Compile::inline_string_calls(bool parse_time) {
roland@4409 1929 {
roland@4409 1930 // remove useless nodes to make the usage analysis simpler
roland@4409 1931 ResourceMark rm;
roland@4409 1932 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
roland@4409 1933 }
roland@4409 1934
roland@4409 1935 {
roland@4409 1936 ResourceMark rm;
sla@5237 1937 print_method(PHASE_BEFORE_STRINGOPTS, 3);
roland@4409 1938 PhaseStringOpts pso(initial_gvn(), for_igvn());
sla@5237 1939 print_method(PHASE_AFTER_STRINGOPTS, 3);
roland@4409 1940 }
roland@4409 1941
roland@4409 1942 // now inline anything that we skipped the first time around
roland@4409 1943 if (!parse_time) {
roland@4409 1944 _late_inlines_pos = _late_inlines.length();
roland@4409 1945 }
roland@4409 1946
roland@4409 1947 while (_string_late_inlines.length() > 0) {
roland@4409 1948 CallGenerator* cg = _string_late_inlines.pop();
roland@4409 1949 cg->do_late_inline();
roland@4409 1950 if (failing()) return;
roland@4409 1951 }
roland@4409 1952 _string_late_inlines.trunc_to(0);
roland@4409 1953 }
roland@4409 1954
kvn@5110 1955 // Late inlining of boxing methods
kvn@5110 1956 void Compile::inline_boxing_calls(PhaseIterGVN& igvn) {
kvn@5110 1957 if (_boxing_late_inlines.length() > 0) {
kvn@5110 1958 assert(has_boxed_value(), "inconsistent");
kvn@5110 1959
kvn@5110 1960 PhaseGVN* gvn = initial_gvn();
kvn@5110 1961 set_inlining_incrementally(true);
kvn@5110 1962
kvn@5110 1963 assert( igvn._worklist.size() == 0, "should be done with igvn" );
kvn@5110 1964 for_igvn()->clear();
kvn@5110 1965 gvn->replace_with(&igvn);
kvn@5110 1966
roland@7041 1967 _late_inlines_pos = _late_inlines.length();
roland@7041 1968
kvn@5110 1969 while (_boxing_late_inlines.length() > 0) {
kvn@5110 1970 CallGenerator* cg = _boxing_late_inlines.pop();
kvn@5110 1971 cg->do_late_inline();
kvn@5110 1972 if (failing()) return;
kvn@5110 1973 }
kvn@5110 1974 _boxing_late_inlines.trunc_to(0);
kvn@5110 1975
kvn@5110 1976 {
kvn@5110 1977 ResourceMark rm;
kvn@5110 1978 PhaseRemoveUseless pru(gvn, for_igvn());
kvn@5110 1979 }
kvn@5110 1980
kvn@5110 1981 igvn = PhaseIterGVN(gvn);
kvn@5110 1982 igvn.optimize();
kvn@5110 1983
kvn@5110 1984 set_inlining_progress(false);
kvn@5110 1985 set_inlining_incrementally(false);
kvn@5110 1986 }
kvn@5110 1987 }
kvn@5110 1988
roland@4409 1989 void Compile::inline_incrementally_one(PhaseIterGVN& igvn) {
roland@4409 1990 assert(IncrementalInline, "incremental inlining should be on");
roland@4409 1991 PhaseGVN* gvn = initial_gvn();
roland@4409 1992
roland@4409 1993 set_inlining_progress(false);
roland@4409 1994 for_igvn()->clear();
roland@4409 1995 gvn->replace_with(&igvn);
roland@4409 1996
roland@4409 1997 int i = 0;
roland@4409 1998
roland@4409 1999 for (; i <_late_inlines.length() && !inlining_progress(); i++) {
roland@4409 2000 CallGenerator* cg = _late_inlines.at(i);
roland@4409 2001 _late_inlines_pos = i+1;
roland@4409 2002 cg->do_late_inline();
roland@4409 2003 if (failing()) return;
roland@4409 2004 }
roland@4409 2005 int j = 0;
roland@4409 2006 for (; i < _late_inlines.length(); i++, j++) {
roland@4409 2007 _late_inlines.at_put(j, _late_inlines.at(i));
roland@4409 2008 }
roland@4409 2009 _late_inlines.trunc_to(j);
roland@4409 2010
roland@4409 2011 {
roland@4409 2012 ResourceMark rm;
kvn@5110 2013 PhaseRemoveUseless pru(gvn, for_igvn());
roland@4409 2014 }
roland@4409 2015
roland@4409 2016 igvn = PhaseIterGVN(gvn);
roland@4409 2017 }
roland@4409 2018
roland@4409 2019 // Perform incremental inlining until bound on number of live nodes is reached
roland@4409 2020 void Compile::inline_incrementally(PhaseIterGVN& igvn) {
roland@4409 2021 PhaseGVN* gvn = initial_gvn();
roland@4409 2022
roland@4409 2023 set_inlining_incrementally(true);
roland@4409 2024 set_inlining_progress(true);
roland@4409 2025 uint low_live_nodes = 0;
roland@4409 2026
roland@4409 2027 while(inlining_progress() && _late_inlines.length() > 0) {
roland@4409 2028
roland@4409 2029 if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {
roland@4409 2030 if (low_live_nodes < (uint)LiveNodeCountInliningCutoff * 8 / 10) {
roland@4409 2031 // PhaseIdealLoop is expensive so we only try it once we are
roland@7041 2032 // out of live nodes and we only try it again if the previous
roland@7041 2033 // helped got the number of nodes down significantly
roland@4409 2034 PhaseIdealLoop ideal_loop( igvn, false, true );
roland@4409 2035 if (failing()) return;
roland@4409 2036 low_live_nodes = live_nodes();
roland@4409 2037 _major_progress = true;
roland@4409 2038 }
roland@4409 2039
roland@4409 2040 if (live_nodes() > (uint)LiveNodeCountInliningCutoff) {
roland@4409 2041 break;
roland@4409 2042 }
roland@4409 2043 }
roland@4409 2044
roland@4409 2045 inline_incrementally_one(igvn);
roland@4409 2046
roland@4409 2047 if (failing()) return;
roland@4409 2048
roland@4409 2049 igvn.optimize();
roland@4409 2050
roland@4409 2051 if (failing()) return;
roland@4409 2052 }
roland@4409 2053
roland@4409 2054 assert( igvn._worklist.size() == 0, "should be done with igvn" );
roland@4409 2055
roland@4409 2056 if (_string_late_inlines.length() > 0) {
roland@4409 2057 assert(has_stringbuilder(), "inconsistent");
roland@4409 2058 for_igvn()->clear();
roland@4409 2059 initial_gvn()->replace_with(&igvn);
roland@4409 2060
roland@4409 2061 inline_string_calls(false);
roland@4409 2062
roland@4409 2063 if (failing()) return;
roland@4409 2064
roland@4409 2065 {
roland@4409 2066 ResourceMark rm;
roland@4409 2067 PhaseRemoveUseless pru(initial_gvn(), for_igvn());
roland@4409 2068 }
roland@4409 2069
roland@4409 2070 igvn = PhaseIterGVN(gvn);
roland@4409 2071
roland@4409 2072 igvn.optimize();
roland@4409 2073 }
roland@4409 2074
roland@4409 2075 set_inlining_incrementally(false);
roland@4409 2076 }
roland@4409 2077
roland@4409 2078
duke@435 2079 //------------------------------Optimize---------------------------------------
duke@435 2080 // Given a graph, optimize it.
duke@435 2081 void Compile::Optimize() {
duke@435 2082 TracePhase t1("optimizer", &_t_optimizer, true);
duke@435 2083
duke@435 2084 #ifndef PRODUCT
duke@435 2085 if (env()->break_at_compile()) {
duke@435 2086 BREAKPOINT;
duke@435 2087 }
duke@435 2088
duke@435 2089 #endif
duke@435 2090
duke@435 2091 ResourceMark rm;
duke@435 2092 int loop_opts_cnt;
duke@435 2093
duke@435 2094 NOT_PRODUCT( verify_graph_edges(); )
duke@435 2095
sla@5237 2096 print_method(PHASE_AFTER_PARSING);
duke@435 2097
duke@435 2098 {
duke@435 2099 // Iterative Global Value Numbering, including ideal transforms
duke@435 2100 // Initialize IterGVN with types and values from parse-time GVN
duke@435 2101 PhaseIterGVN igvn(initial_gvn());
duke@435 2102 {
duke@435 2103 NOT_PRODUCT( TracePhase t2("iterGVN", &_t_iterGVN, TimeCompiler); )
duke@435 2104 igvn.optimize();
duke@435 2105 }
duke@435 2106
sla@5237 2107 print_method(PHASE_ITER_GVN1, 2);
duke@435 2108
duke@435 2109 if (failing()) return;
duke@435 2110
kvn@5110 2111 {
kvn@5110 2112 NOT_PRODUCT( TracePhase t2("incrementalInline", &_t_incrInline, TimeCompiler); )
kvn@5110 2113 inline_incrementally(igvn);
kvn@5110 2114 }
roland@4409 2115
sla@5237 2116 print_method(PHASE_INCREMENTAL_INLINE, 2);
roland@4409 2117
roland@4409 2118 if (failing()) return;
roland@4409 2119
kvn@5110 2120 if (eliminate_boxing()) {
kvn@5110 2121 NOT_PRODUCT( TracePhase t2("incrementalInline", &_t_incrInline, TimeCompiler); )
kvn@5110 2122 // Inline valueOf() methods now.
kvn@5110 2123 inline_boxing_calls(igvn);
kvn@5110 2124
roland@7041 2125 if (AlwaysIncrementalInline) {
roland@7041 2126 inline_incrementally(igvn);
roland@7041 2127 }
roland@7041 2128
sla@5237 2129 print_method(PHASE_INCREMENTAL_BOXING_INLINE, 2);
kvn@5110 2130
kvn@5110 2131 if (failing()) return;
kvn@5110 2132 }
kvn@5110 2133
roland@5991 2134 // Remove the speculative part of types and clean up the graph from
roland@5991 2135 // the extra CastPP nodes whose only purpose is to carry them. Do
roland@5991 2136 // that early so that optimizations are not disrupted by the extra
roland@5991 2137 // CastPP nodes.
roland@5991 2138 remove_speculative_types(igvn);
roland@5991 2139
roland@4589 2140 // No more new expensive nodes will be added to the list from here
roland@4589 2141 // so keep only the actual candidates for optimizations.
roland@4589 2142 cleanup_expensive_nodes(igvn);
roland@4589 2143
zmajo@8193 2144 if (!failing() && RenumberLiveNodes && live_nodes() + NodeLimitFudgeFactor < unique()) {
zmajo@8193 2145 NOT_PRODUCT(Compile::TracePhase t2("", &_t_renumberLive, TimeCompiler);)
zmajo@8193 2146 initial_gvn()->replace_with(&igvn);
zmajo@8193 2147 for_igvn()->clear();
zmajo@8193 2148 Unique_Node_List new_worklist(C->comp_arena());
zmajo@8193 2149 {
zmajo@8193 2150 ResourceMark rm;
zmajo@8193 2151 PhaseRenumberLive prl = PhaseRenumberLive(initial_gvn(), for_igvn(), &new_worklist);
zmajo@8193 2152 }
zmajo@8193 2153 set_for_igvn(&new_worklist);
zmajo@8193 2154 igvn = PhaseIterGVN(initial_gvn());
zmajo@8193 2155 igvn.optimize();
zmajo@8193 2156 }
zmajo@8193 2157
kvn@1989 2158 // Perform escape analysis
kvn@1989 2159 if (_do_escape_analysis && ConnectionGraph::has_candidates(this)) {
kvn@3260 2160 if (has_loops()) {
kvn@3260 2161 // Cleanup graph (remove dead nodes).
kvn@3260 2162 TracePhase t2("idealLoop", &_t_idealLoop, true);
kvn@3260 2163 PhaseIdealLoop ideal_loop( igvn, false, true );
sla@5237 2164 if (major_progress()) print_method(PHASE_PHASEIDEAL_BEFORE_EA, 2);
kvn@3260 2165 if (failing()) return;
kvn@3260 2166 }
kvn@1989 2167 ConnectionGraph::do_analysis(this, &igvn);
kvn@1989 2168
kvn@1989 2169 if (failing()) return;
kvn@1989 2170
kvn@3311 2171 // Optimize out fields loads from scalar replaceable allocations.
kvn@1989 2172 igvn.optimize();
sla@5237 2173 print_method(PHASE_ITER_GVN_AFTER_EA, 2);
kvn@1989 2174
kvn@1989 2175 if (failing()) return;
kvn@1989 2176
kvn@3311 2177 if (congraph() != NULL && macro_count() > 0) {
kvn@3651 2178 NOT_PRODUCT( TracePhase t2("macroEliminate", &_t_macroEliminate, TimeCompiler); )
kvn@3311 2179 PhaseMacroExpand mexp(igvn);
kvn@3311 2180 mexp.eliminate_macro_nodes();
kvn@3311 2181 igvn.set_delay_transform(false);
kvn@3311 2182
kvn@3311 2183 igvn.optimize();
sla@5237 2184 print_method(PHASE_ITER_GVN_AFTER_ELIMINATION, 2);
kvn@3311 2185
kvn@3311 2186 if (failing()) return;
kvn@3311 2187 }
kvn@1989 2188 }
kvn@1989 2189
duke@435 2190 // Loop transforms on the ideal graph. Range Check Elimination,
duke@435 2191 // peeling, unrolling, etc.
duke@435 2192
duke@435 2193 // Set loop opts counter
duke@435 2194 loop_opts_cnt = num_loop_opts();
duke@435 2195 if((loop_opts_cnt > 0) && (has_loops() || has_split_ifs())) {
duke@435 2196 {
duke@435 2197 TracePhase t2("idealLoop", &_t_idealLoop, true);
kvn@2727 2198 PhaseIdealLoop ideal_loop( igvn, true );
duke@435 2199 loop_opts_cnt--;
sla@5237 2200 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP1, 2);
duke@435 2201 if (failing()) return;
duke@435 2202 }
duke@435 2203 // Loop opts pass if partial peeling occurred in previous pass
duke@435 2204 if(PartialPeelLoop && major_progress() && (loop_opts_cnt > 0)) {
duke@435 2205 TracePhase t3("idealLoop", &_t_idealLoop, true);
kvn@2727 2206 PhaseIdealLoop ideal_loop( igvn, false );
duke@435 2207 loop_opts_cnt--;
sla@5237 2208 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP2, 2);
duke@435 2209 if (failing()) return;
duke@435 2210 }
duke@435 2211 // Loop opts pass for loop-unrolling before CCP
duke@435 2212 if(major_progress() && (loop_opts_cnt > 0)) {
duke@435 2213 TracePhase t4("idealLoop", &_t_idealLoop, true);
kvn@2727 2214 PhaseIdealLoop ideal_loop( igvn, false );
duke@435 2215 loop_opts_cnt--;
sla@5237 2216 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP3, 2);
duke@435 2217 }
never@1356 2218 if (!failing()) {
never@1356 2219 // Verify that last round of loop opts produced a valid graph
never@1356 2220 NOT_PRODUCT( TracePhase t2("idealLoopVerify", &_t_idealLoopVerify, TimeCompiler); )
never@1356 2221 PhaseIdealLoop::verify(igvn);
never@1356 2222 }
duke@435 2223 }
duke@435 2224 if (failing()) return;
duke@435 2225
duke@435 2226 // Conditional Constant Propagation;
duke@435 2227 PhaseCCP ccp( &igvn );
duke@435 2228 assert( true, "Break here to ccp.dump_nodes_and_types(_root,999,1)");
duke@435 2229 {
duke@435 2230 TracePhase t2("ccp", &_t_ccp, true);
duke@435 2231 ccp.do_transform();
duke@435 2232 }
sla@5237 2233 print_method(PHASE_CPP1, 2);
duke@435 2234
duke@435 2235 assert( true, "Break here to ccp.dump_old2new_map()");
duke@435 2236
duke@435 2237 // Iterative Global Value Numbering, including ideal transforms
duke@435 2238 {
duke@435 2239 NOT_PRODUCT( TracePhase t2("iterGVN2", &_t_iterGVN2, TimeCompiler); )
duke@435 2240 igvn = ccp;
duke@435 2241 igvn.optimize();
duke@435 2242 }
duke@435 2243
sla@5237 2244 print_method(PHASE_ITER_GVN2, 2);
duke@435 2245
duke@435 2246 if (failing()) return;
duke@435 2247
duke@435 2248 // Loop transforms on the ideal graph. Range Check Elimination,
duke@435 2249 // peeling, unrolling, etc.
duke@435 2250 if(loop_opts_cnt > 0) {
duke@435 2251 debug_only( int cnt = 0; );
duke@435 2252 while(major_progress() && (loop_opts_cnt > 0)) {
duke@435 2253 TracePhase t2("idealLoop", &_t_idealLoop, true);
duke@435 2254 assert( cnt++ < 40, "infinite cycle in loop optimization" );
kvn@2727 2255 PhaseIdealLoop ideal_loop( igvn, true);
duke@435 2256 loop_opts_cnt--;
sla@5237 2257 if (major_progress()) print_method(PHASE_PHASEIDEALLOOP_ITERATIONS, 2);
duke@435 2258 if (failing()) return;
duke@435 2259 }
duke@435 2260 }
never@1356 2261
never@1356 2262 {
never@1356 2263 // Verify that all previous optimizations produced a valid graph
never@1356 2264 // at least to this point, even if no loop optimizations were done.
never@1356 2265 NOT_PRODUCT( TracePhase t2("idealLoopVerify", &_t_idealLoopVerify, TimeCompiler); )
never@1356 2266 PhaseIdealLoop::verify(igvn);
never@1356 2267 }
never@1356 2268
thartmann@8476 2269 if (range_check_cast_count() > 0) {
thartmann@8476 2270 // No more loop optimizations. Remove all range check dependent CastIINodes.
thartmann@8476 2271 C->remove_range_check_casts(igvn);
thartmann@8476 2272 igvn.optimize();
thartmann@8476 2273 }
thartmann@8476 2274
duke@435 2275 {
duke@435 2276 NOT_PRODUCT( TracePhase t2("macroExpand", &_t_macroExpand, TimeCompiler); )
duke@435 2277 PhaseMacroExpand mex(igvn);
duke@435 2278 if (mex.expand_macro_nodes()) {
duke@435 2279 assert(failing(), "must bail out w/ explicit message");
duke@435 2280 return;
duke@435 2281 }
duke@435 2282 }
duke@435 2283
duke@435 2284 } // (End scope of igvn; run destructor if necessary for asserts.)
duke@435 2285
kvn@4448 2286 dump_inlining();
duke@435 2287 // A method with only infinite loops has no edges entering loops from root
duke@435 2288 {
duke@435 2289 NOT_PRODUCT( TracePhase t2("graphReshape", &_t_graphReshaping, TimeCompiler); )
duke@435 2290 if (final_graph_reshaping()) {
duke@435 2291 assert(failing(), "must bail out w/ explicit message");
duke@435 2292 return;
duke@435 2293 }
duke@435 2294 }
duke@435 2295
sla@5237 2296 print_method(PHASE_OPTIMIZE_FINISHED, 2);
duke@435 2297 }
duke@435 2298
duke@435 2299
duke@435 2300 //------------------------------Code_Gen---------------------------------------
duke@435 2301 // Given a graph, generate code for it
duke@435 2302 void Compile::Code_Gen() {
adlertz@5539 2303 if (failing()) {
adlertz@5539 2304 return;
adlertz@5539 2305 }
duke@435 2306
duke@435 2307 // Perform instruction selection. You might think we could reclaim Matcher
duke@435 2308 // memory PDQ, but actually the Matcher is used in generating spill code.
duke@435 2309 // Internals of the Matcher (including some VectorSets) must remain live
duke@435 2310 // for awhile - thus I cannot reclaim Matcher memory lest a VectorSet usage
duke@435 2311 // set a bit in reclaimed memory.
duke@435 2312
duke@435 2313 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
duke@435 2314 // nodes. Mapping is only valid at the root of each matched subtree.
duke@435 2315 NOT_PRODUCT( verify_graph_edges(); )
duke@435 2316
adlertz@5539 2317 Matcher matcher;
adlertz@5539 2318 _matcher = &matcher;
duke@435 2319 {
duke@435 2320 TracePhase t2("matcher", &_t_matcher, true);
adlertz@5539 2321 matcher.match();
duke@435 2322 }
duke@435 2323 // In debug mode can dump m._nodes.dump() for mapping of ideal to machine
duke@435 2324 // nodes. Mapping is only valid at the root of each matched subtree.
duke@435 2325 NOT_PRODUCT( verify_graph_edges(); )
duke@435 2326
duke@435 2327 // If you have too many nodes, or if matching has failed, bail out
duke@435 2328 check_node_count(0, "out of nodes matching instructions");
adlertz@5539 2329 if (failing()) {
adlertz@5539 2330 return;
adlertz@5539 2331 }
duke@435 2332
duke@435 2333 // Build a proper-looking CFG
adlertz@5539 2334 PhaseCFG cfg(node_arena(), root(), matcher);
duke@435 2335 _cfg = &cfg;
duke@435 2336 {
duke@435 2337 NOT_PRODUCT( TracePhase t2("scheduler", &_t_scheduler, TimeCompiler); )
adlertz@5539 2338 bool success = cfg.do_global_code_motion();
adlertz@5539 2339 if (!success) {
adlertz@5539 2340 return;
adlertz@5539 2341 }
adlertz@5539 2342
adlertz@5539 2343 print_method(PHASE_GLOBAL_CODE_MOTION, 2);
duke@435 2344 NOT_PRODUCT( verify_graph_edges(); )
duke@435 2345 debug_only( cfg.verify(); )
duke@435 2346 }
adlertz@5539 2347
adlertz@5539 2348 PhaseChaitin regalloc(unique(), cfg, matcher);
duke@435 2349 _regalloc = &regalloc;
duke@435 2350 {
duke@435 2351 TracePhase t2("regalloc", &_t_registerAllocation, true);
duke@435 2352 // Perform register allocation. After Chaitin, use-def chains are
duke@435 2353 // no longer accurate (at spill code) and so must be ignored.
duke@435 2354 // Node->LRG->reg mappings are still accurate.
duke@435 2355 _regalloc->Register_Allocate();
duke@435 2356
duke@435 2357 // Bail out if the allocator builds too many nodes
neliasso@4949 2358 if (failing()) {
neliasso@4949 2359 return;
neliasso@4949 2360 }
duke@435 2361 }
duke@435 2362
duke@435 2363 // Prior to register allocation we kept empty basic blocks in case the
duke@435 2364 // the allocator needed a place to spill. After register allocation we
duke@435 2365 // are not adding any new instructions. If any basic block is empty, we
duke@435 2366 // can now safely remove it.
duke@435 2367 {
rasbold@853 2368 NOT_PRODUCT( TracePhase t2("blockOrdering", &_t_blockOrdering, TimeCompiler); )
adlertz@5539 2369 cfg.remove_empty_blocks();
rasbold@853 2370 if (do_freq_based_layout()) {
rasbold@853 2371 PhaseBlockLayout layout(cfg);
rasbold@853 2372 } else {
rasbold@853 2373 cfg.set_loop_alignment();
rasbold@853 2374 }
rasbold@853 2375 cfg.fixup_flow();
duke@435 2376 }
duke@435 2377
duke@435 2378 // Apply peephole optimizations
duke@435 2379 if( OptoPeephole ) {
duke@435 2380 NOT_PRODUCT( TracePhase t2("peephole", &_t_peephole, TimeCompiler); )
duke@435 2381 PhasePeephole peep( _regalloc, cfg);
duke@435 2382 peep.do_transform();
duke@435 2383 }
duke@435 2384
goetz@6478 2385 // Do late expand if CPU requires this.
goetz@6478 2386 if (Matcher::require_postalloc_expand) {
goetz@6478 2387 NOT_PRODUCT(TracePhase t2c("postalloc_expand", &_t_postalloc_expand, true));
goetz@6478 2388 cfg.postalloc_expand(_regalloc);
goetz@6478 2389 }
goetz@6478 2390
duke@435 2391 // Convert Nodes to instruction bits in a buffer
duke@435 2392 {
duke@435 2393 // %%%% workspace merge brought two timers together for one job
duke@435 2394 TracePhase t2a("output", &_t_output, true);
duke@435 2395 NOT_PRODUCT( TraceTime t2b(NULL, &_t_codeGeneration, TimeCompiler, false); )
duke@435 2396 Output();
duke@435 2397 }
duke@435 2398
sla@5237 2399 print_method(PHASE_FINAL_CODE);
duke@435 2400
duke@435 2401 // He's dead, Jim.
kevinw@9325 2402 _cfg = (PhaseCFG*)((intptr_t)0xdeadbeef);
kevinw@9325 2403 _regalloc = (PhaseChaitin*)((intptr_t)0xdeadbeef);
duke@435 2404 }
duke@435 2405
duke@435 2406
duke@435 2407 //------------------------------dump_asm---------------------------------------
duke@435 2408 // Dump formatted assembly
duke@435 2409 #ifndef PRODUCT
duke@435 2410 void Compile::dump_asm(int *pcs, uint pc_limit) {
duke@435 2411 bool cut_short = false;
duke@435 2412 tty->print_cr("#");
duke@435 2413 tty->print("# "); _tf->dump(); tty->cr();
duke@435 2414 tty->print_cr("#");
duke@435 2415
duke@435 2416 // For all blocks
duke@435 2417 int pc = 0x0; // Program counter
duke@435 2418 char starts_bundle = ' ';
duke@435 2419 _regalloc->dump_frame();
duke@435 2420
duke@435 2421 Node *n = NULL;
adlertz@5539 2422 for (uint i = 0; i < _cfg->number_of_blocks(); i++) {
adlertz@5539 2423 if (VMThread::should_terminate()) {
adlertz@5539 2424 cut_short = true;
adlertz@5539 2425 break;
adlertz@5539 2426 }
adlertz@5539 2427 Block* block = _cfg->get_block(i);
adlertz@5539 2428 if (block->is_connector() && !Verbose) {
adlertz@5539 2429 continue;
adlertz@5539 2430 }
adlertz@5635 2431 n = block->head();
adlertz@5539 2432 if (pcs && n->_idx < pc_limit) {
duke@435 2433 tty->print("%3.3x ", pcs[n->_idx]);
adlertz@5539 2434 } else {
duke@435 2435 tty->print(" ");
adlertz@5539 2436 }
adlertz@5539 2437 block->dump_head(_cfg);
adlertz@5539 2438 if (block->is_connector()) {
duke@435 2439 tty->print_cr(" # Empty connector block");
adlertz@5539 2440 } else if (block->num_preds() == 2 && block->pred(1)->is_CatchProj() && block->pred(1)->as_CatchProj()->_con == CatchProjNode::fall_through_index) {
duke@435 2441 tty->print_cr(" # Block is sole successor of call");
duke@435 2442 }
duke@435 2443
duke@435 2444 // For all instructions
duke@435 2445 Node *delay = NULL;
adlertz@5635 2446 for (uint j = 0; j < block->number_of_nodes(); j++) {
adlertz@5539 2447 if (VMThread::should_terminate()) {
adlertz@5539 2448 cut_short = true;
adlertz@5539 2449 break;
adlertz@5539 2450 }
adlertz@5635 2451 n = block->get_node(j);
duke@435 2452 if (valid_bundle_info(n)) {
adlertz@5539 2453 Bundle* bundle = node_bundling(n);
duke@435 2454 if (bundle->used_in_unconditional_delay()) {
duke@435 2455 delay = n;
duke@435 2456 continue;
duke@435 2457 }
adlertz@5539 2458 if (bundle->starts_bundle()) {
duke@435 2459 starts_bundle = '+';
adlertz@5539 2460 }
duke@435 2461 }
duke@435 2462
adlertz@5539 2463 if (WizardMode) {
adlertz@5539 2464 n->dump();
adlertz@5539 2465 }
coleenp@548 2466
duke@435 2467 if( !n->is_Region() && // Dont print in the Assembly
duke@435 2468 !n->is_Phi() && // a few noisely useless nodes
duke@435 2469 !n->is_Proj() &&
duke@435 2470 !n->is_MachTemp() &&
kvn@1535 2471 !n->is_SafePointScalarObject() &&
duke@435 2472 !n->is_Catch() && // Would be nice to print exception table targets
duke@435 2473 !n->is_MergeMem() && // Not very interesting
duke@435 2474 !n->is_top() && // Debug info table constants
duke@435 2475 !(n->is_Con() && !n->is_Mach())// Debug info table constants
duke@435 2476 ) {
duke@435 2477 if (pcs && n->_idx < pc_limit)
duke@435 2478 tty->print("%3.3x", pcs[n->_idx]);
duke@435 2479 else
duke@435 2480 tty->print(" ");
duke@435 2481 tty->print(" %c ", starts_bundle);
duke@435 2482 starts_bundle = ' ';
duke@435 2483 tty->print("\t");
duke@435 2484 n->format(_regalloc, tty);
duke@435 2485 tty->cr();
duke@435 2486 }
duke@435 2487
duke@435 2488 // If we have an instruction with a delay slot, and have seen a delay,
duke@435 2489 // then back up and print it
duke@435 2490 if (valid_bundle_info(n) && node_bundling(n)->use_unconditional_delay()) {
duke@435 2491 assert(delay != NULL, "no unconditional delay instruction");
coleenp@548 2492 if (WizardMode) delay->dump();
coleenp@548 2493
duke@435 2494 if (node_bundling(delay)->starts_bundle())
duke@435 2495 starts_bundle = '+';
duke@435 2496 if (pcs && n->_idx < pc_limit)
duke@435 2497 tty->print("%3.3x", pcs[n->_idx]);
duke@435 2498 else
duke@435 2499 tty->print(" ");
duke@435 2500 tty->print(" %c ", starts_bundle);
duke@435 2501 starts_bundle = ' ';
duke@435 2502 tty->print("\t");
duke@435 2503 delay->format(_regalloc, tty);
drchase@6680 2504 tty->cr();
duke@435 2505 delay = NULL;
duke@435 2506 }
duke@435 2507
duke@435 2508 // Dump the exception table as well
duke@435 2509 if( n->is_Catch() && (Verbose || WizardMode) ) {
duke@435 2510 // Print the exception table for this offset
duke@435 2511 _handler_table.print_subtable_for(pc);
duke@435 2512 }
duke@435 2513 }
duke@435 2514
duke@435 2515 if (pcs && n->_idx < pc_limit)
duke@435 2516 tty->print_cr("%3.3x", pcs[n->_idx]);
duke@435 2517 else
drchase@6680 2518 tty->cr();
duke@435 2519
duke@435 2520 assert(cut_short || delay == NULL, "no unconditional delay branch");
duke@435 2521
duke@435 2522 } // End of per-block dump
drchase@6680 2523 tty->cr();
duke@435 2524
duke@435 2525 if (cut_short) tty->print_cr("*** disassembly is cut short ***");
duke@435 2526 }
duke@435 2527 #endif
duke@435 2528
duke@435 2529 //------------------------------Final_Reshape_Counts---------------------------
duke@435 2530 // This class defines counters to help identify when a method
duke@435 2531 // may/must be executed using hardware with only 24-bit precision.
duke@435 2532 struct Final_Reshape_Counts : public StackObj {
duke@435 2533 int _call_count; // count non-inlined 'common' calls
duke@435 2534 int _float_count; // count float ops requiring 24-bit precision
duke@435 2535 int _double_count; // count double ops requiring more precision
duke@435 2536 int _java_call_count; // count non-inlined 'java' calls
kvn@1294 2537 int _inner_loop_count; // count loops which need alignment
duke@435 2538 VectorSet _visited; // Visitation flags
duke@435 2539 Node_List _tests; // Set of IfNodes & PCTableNodes
duke@435 2540
duke@435 2541 Final_Reshape_Counts() :
kvn@1294 2542 _call_count(0), _float_count(0), _double_count(0),
kvn@1294 2543 _java_call_count(0), _inner_loop_count(0),
duke@435 2544 _visited( Thread::current()->resource_area() ) { }
duke@435 2545
duke@435 2546 void inc_call_count () { _call_count ++; }
duke@435 2547 void inc_float_count () { _float_count ++; }
duke@435 2548 void inc_double_count() { _double_count++; }
duke@435 2549 void inc_java_call_count() { _java_call_count++; }
kvn@1294 2550 void inc_inner_loop_count() { _inner_loop_count++; }
duke@435 2551
duke@435 2552 int get_call_count () const { return _call_count ; }
duke@435 2553 int get_float_count () const { return _float_count ; }
duke@435 2554 int get_double_count() const { return _double_count; }
duke@435 2555 int get_java_call_count() const { return _java_call_count; }
kvn@1294 2556 int get_inner_loop_count() const { return _inner_loop_count; }
duke@435 2557 };
duke@435 2558
mikael@4889 2559 #ifdef ASSERT
duke@435 2560 static bool oop_offset_is_sane(const TypeInstPtr* tp) {
duke@435 2561 ciInstanceKlass *k = tp->klass()->as_instance_klass();
duke@435 2562 // Make sure the offset goes inside the instance layout.
coleenp@548 2563 return k->contains_field_offset(tp->offset());
duke@435 2564 // Note that OffsetBot and OffsetTop are very negative.
duke@435 2565 }
mikael@4889 2566 #endif
duke@435 2567
never@2780 2568 // Eliminate trivially redundant StoreCMs and accumulate their
never@2780 2569 // precedence edges.
bharadwaj@4315 2570 void Compile::eliminate_redundant_card_marks(Node* n) {
never@2780 2571 assert(n->Opcode() == Op_StoreCM, "expected StoreCM");
never@2780 2572 if (n->in(MemNode::Address)->outcnt() > 1) {
never@2780 2573 // There are multiple users of the same address so it might be
never@2780 2574 // possible to eliminate some of the StoreCMs
never@2780 2575 Node* mem = n->in(MemNode::Memory);
never@2780 2576 Node* adr = n->in(MemNode::Address);
never@2780 2577 Node* val = n->in(MemNode::ValueIn);
never@2780 2578 Node* prev = n;
never@2780 2579 bool done = false;
never@2780 2580 // Walk the chain of StoreCMs eliminating ones that match. As
never@2780 2581 // long as it's a chain of single users then the optimization is
never@2780 2582 // safe. Eliminating partially redundant StoreCMs would require
never@2780 2583 // cloning copies down the other paths.
never@2780 2584 while (mem->Opcode() == Op_StoreCM && mem->outcnt() == 1 && !done) {
never@2780 2585 if (adr == mem->in(MemNode::Address) &&
never@2780 2586 val == mem->in(MemNode::ValueIn)) {
never@2780 2587 // redundant StoreCM
never@2780 2588 if (mem->req() > MemNode::OopStore) {
never@2780 2589 // Hasn't been processed by this code yet.
never@2780 2590 n->add_prec(mem->in(MemNode::OopStore));
never@2780 2591 } else {
never@2780 2592 // Already converted to precedence edge
never@2780 2593 for (uint i = mem->req(); i < mem->len(); i++) {
never@2780 2594 // Accumulate any precedence edges
never@2780 2595 if (mem->in(i) != NULL) {
never@2780 2596 n->add_prec(mem->in(i));
never@2780 2597 }
never@2780 2598 }
never@2780 2599 // Everything above this point has been processed.
never@2780 2600 done = true;
never@2780 2601 }
never@2780 2602 // Eliminate the previous StoreCM
never@2780 2603 prev->set_req(MemNode::Memory, mem->in(MemNode::Memory));
never@2780 2604 assert(mem->outcnt() == 0, "should be dead");
bharadwaj@4315 2605 mem->disconnect_inputs(NULL, this);
never@2780 2606 } else {
never@2780 2607 prev = mem;
never@2780 2608 }
never@2780 2609 mem = prev->in(MemNode::Memory);
never@2780 2610 }
never@2780 2611 }
never@2780 2612 }
never@2780 2613
duke@435 2614 //------------------------------final_graph_reshaping_impl----------------------
duke@435 2615 // Implement items 1-5 from final_graph_reshaping below.
bharadwaj@4315 2616 void Compile::final_graph_reshaping_impl( Node *n, Final_Reshape_Counts &frc) {
duke@435 2617
kvn@603 2618 if ( n->outcnt() == 0 ) return; // dead node
duke@435 2619 uint nop = n->Opcode();
duke@435 2620
duke@435 2621 // Check for 2-input instruction with "last use" on right input.
duke@435 2622 // Swap to left input. Implements item (2).
duke@435 2623 if( n->req() == 3 && // two-input instruction
duke@435 2624 n->in(1)->outcnt() > 1 && // left use is NOT a last use
duke@435 2625 (!n->in(1)->is_Phi() || n->in(1)->in(2) != n) && // it is not data loop
duke@435 2626 n->in(2)->outcnt() == 1 &&// right use IS a last use
duke@435 2627 !n->in(2)->is_Con() ) { // right use is not a constant
duke@435 2628 // Check for commutative opcode
duke@435 2629 switch( nop ) {
duke@435 2630 case Op_AddI: case Op_AddF: case Op_AddD: case Op_AddL:
duke@435 2631 case Op_MaxI: case Op_MinI:
duke@435 2632 case Op_MulI: case Op_MulF: case Op_MulD: case Op_MulL:
duke@435 2633 case Op_AndL: case Op_XorL: case Op_OrL:
duke@435 2634 case Op_AndI: case Op_XorI: case Op_OrI: {
duke@435 2635 // Move "last use" input to left by swapping inputs
duke@435 2636 n->swap_edges(1, 2);
duke@435 2637 break;
duke@435 2638 }
duke@435 2639 default:
duke@435 2640 break;
duke@435 2641 }
duke@435 2642 }
duke@435 2643
kvn@1964 2644 #ifdef ASSERT
kvn@1964 2645 if( n->is_Mem() ) {
bharadwaj@4315 2646 int alias_idx = get_alias_index(n->as_Mem()->adr_type());
kvn@1964 2647 assert( n->in(0) != NULL || alias_idx != Compile::AliasIdxRaw ||
kvn@1964 2648 // oop will be recorded in oop map if load crosses safepoint
kvn@1964 2649 n->is_Load() && (n->as_Load()->bottom_type()->isa_oopptr() ||
kvn@1964 2650 LoadNode::is_immutable_value(n->in(MemNode::Address))),
kvn@1964 2651 "raw memory operations should have control edge");
kvn@1964 2652 }
kvn@1964 2653 #endif
duke@435 2654 // Count FPU ops and common calls, implements item (3)
duke@435 2655 switch( nop ) {
duke@435 2656 // Count all float operations that may use FPU
duke@435 2657 case Op_AddF:
duke@435 2658 case Op_SubF:
duke@435 2659 case Op_MulF:
duke@435 2660 case Op_DivF:
duke@435 2661 case Op_NegF:
duke@435 2662 case Op_ModF:
duke@435 2663 case Op_ConvI2F:
duke@435 2664 case Op_ConF:
duke@435 2665 case Op_CmpF:
duke@435 2666 case Op_CmpF3:
duke@435 2667 // case Op_ConvL2F: // longs are split into 32-bit halves
kvn@1294 2668 frc.inc_float_count();
duke@435 2669 break;
duke@435 2670
duke@435 2671 case Op_ConvF2D:
duke@435 2672 case Op_ConvD2F:
kvn@1294 2673 frc.inc_float_count();
kvn@1294 2674 frc.inc_double_count();
duke@435 2675 break;
duke@435 2676
duke@435 2677 // Count all double operations that may use FPU
duke@435 2678 case Op_AddD:
duke@435 2679 case Op_SubD:
duke@435 2680 case Op_MulD:
duke@435 2681 case Op_DivD:
duke@435 2682 case Op_NegD:
duke@435 2683 case Op_ModD:
duke@435 2684 case Op_ConvI2D:
duke@435 2685 case Op_ConvD2I:
duke@435 2686 // case Op_ConvL2D: // handled by leaf call
duke@435 2687 // case Op_ConvD2L: // handled by leaf call
duke@435 2688 case Op_ConD:
duke@435 2689 case Op_CmpD:
duke@435 2690 case Op_CmpD3:
kvn@1294 2691 frc.inc_double_count();
duke@435 2692 break;
duke@435 2693 case Op_Opaque1: // Remove Opaque Nodes before matching
duke@435 2694 case Op_Opaque2: // Remove Opaque Nodes before matching
kvn@6429 2695 case Op_Opaque3:
bharadwaj@4315 2696 n->subsume_by(n->in(1), this);
duke@435 2697 break;
duke@435 2698 case Op_CallStaticJava:
duke@435 2699 case Op_CallJava:
duke@435 2700 case Op_CallDynamicJava:
kvn@1294 2701 frc.inc_java_call_count(); // Count java call site;
duke@435 2702 case Op_CallRuntime:
duke@435 2703 case Op_CallLeaf:
duke@435 2704 case Op_CallLeafNoFP: {
duke@435 2705 assert( n->is_Call(), "" );
duke@435 2706 CallNode *call = n->as_Call();
duke@435 2707 // Count call sites where the FP mode bit would have to be flipped.
duke@435 2708 // Do not count uncommon runtime calls:
duke@435 2709 // uncommon_trap, _complete_monitor_locking, _complete_monitor_unlocking,
duke@435 2710 // _new_Java, _new_typeArray, _new_objArray, _rethrow_Java, ...
duke@435 2711 if( !call->is_CallStaticJava() || !call->as_CallStaticJava()->_name ) {
kvn@1294 2712 frc.inc_call_count(); // Count the call site
duke@435 2713 } else { // See if uncommon argument is shared
duke@435 2714 Node *n = call->in(TypeFunc::Parms);
duke@435 2715 int nop = n->Opcode();
duke@435 2716 // Clone shared simple arguments to uncommon calls, item (1).
duke@435 2717 if( n->outcnt() > 1 &&
duke@435 2718 !n->is_Proj() &&
duke@435 2719 nop != Op_CreateEx &&
duke@435 2720 nop != Op_CheckCastPP &&
kvn@766 2721 nop != Op_DecodeN &&
roland@4159 2722 nop != Op_DecodeNKlass &&
duke@435 2723 !n->is_Mem() ) {
duke@435 2724 Node *x = n->clone();
duke@435 2725 call->set_req( TypeFunc::Parms, x );
duke@435 2726 }
duke@435 2727 }
duke@435 2728 break;
duke@435 2729 }
duke@435 2730
duke@435 2731 case Op_StoreD:
duke@435 2732 case Op_LoadD:
duke@435 2733 case Op_LoadD_unaligned:
kvn@1294 2734 frc.inc_double_count();
duke@435 2735 goto handle_mem;
duke@435 2736 case Op_StoreF:
duke@435 2737 case Op_LoadF:
kvn@1294 2738 frc.inc_float_count();
duke@435 2739 goto handle_mem;
duke@435 2740
never@2780 2741 case Op_StoreCM:
never@2780 2742 {
never@2780 2743 // Convert OopStore dependence into precedence edge
never@2780 2744 Node* prec = n->in(MemNode::OopStore);
never@2780 2745 n->del_req(MemNode::OopStore);
never@2780 2746 n->add_prec(prec);
never@2780 2747 eliminate_redundant_card_marks(n);
never@2780 2748 }
never@2780 2749
never@2780 2750 // fall through
never@2780 2751
duke@435 2752 case Op_StoreB:
duke@435 2753 case Op_StoreC:
duke@435 2754 case Op_StorePConditional:
duke@435 2755 case Op_StoreI:
duke@435 2756 case Op_StoreL:
kvn@855 2757 case Op_StoreIConditional:
duke@435 2758 case Op_StoreLConditional:
duke@435 2759 case Op_CompareAndSwapI:
duke@435 2760 case Op_CompareAndSwapL:
duke@435 2761 case Op_CompareAndSwapP:
coleenp@548 2762 case Op_CompareAndSwapN:
roland@4106 2763 case Op_GetAndAddI:
roland@4106 2764 case Op_GetAndAddL:
roland@4106 2765 case Op_GetAndSetI:
roland@4106 2766 case Op_GetAndSetL:
roland@4106 2767 case Op_GetAndSetP:
roland@4106 2768 case Op_GetAndSetN:
duke@435 2769 case Op_StoreP:
coleenp@548 2770 case Op_StoreN:
roland@4159 2771 case Op_StoreNKlass:
duke@435 2772 case Op_LoadB:
twisti@1059 2773 case Op_LoadUB:
twisti@993 2774 case Op_LoadUS:
duke@435 2775 case Op_LoadI:
duke@435 2776 case Op_LoadKlass:
kvn@599 2777 case Op_LoadNKlass:
duke@435 2778 case Op_LoadL:
duke@435 2779 case Op_LoadL_unaligned:
duke@435 2780 case Op_LoadPLocked:
duke@435 2781 case Op_LoadP:
coleenp@548 2782 case Op_LoadN:
duke@435 2783 case Op_LoadRange:
duke@435 2784 case Op_LoadS: {
duke@435 2785 handle_mem:
duke@435 2786 #ifdef ASSERT
duke@435 2787 if( VerifyOptoOopOffsets ) {
duke@435 2788 assert( n->is_Mem(), "" );
duke@435 2789 MemNode *mem = (MemNode*)n;
duke@435 2790 // Check to see if address types have grounded out somehow.
duke@435 2791 const TypeInstPtr *tp = mem->in(MemNode::Address)->bottom_type()->isa_instptr();
duke@435 2792 assert( !tp || oop_offset_is_sane(tp), "" );
duke@435 2793 }
duke@435 2794 #endif
duke@435 2795 break;
duke@435 2796 }
duke@435 2797
duke@435 2798 case Op_AddP: { // Assert sane base pointers
kvn@617 2799 Node *addp = n->in(AddPNode::Address);
duke@435 2800 assert( !addp->is_AddP() ||
duke@435 2801 addp->in(AddPNode::Base)->is_top() || // Top OK for allocation
duke@435 2802 addp->in(AddPNode::Base) == n->in(AddPNode::Base),
duke@435 2803 "Base pointers must match" );
kvn@617 2804 #ifdef _LP64
ehelin@5694 2805 if ((UseCompressedOops || UseCompressedClassPointers) &&
kvn@617 2806 addp->Opcode() == Op_ConP &&
kvn@617 2807 addp == n->in(AddPNode::Base) &&
kvn@617 2808 n->in(AddPNode::Offset)->is_Con()) {
kvn@617 2809 // Use addressing with narrow klass to load with offset on x86.
kvn@617 2810 // On sparc loading 32-bits constant and decoding it have less
kvn@617 2811 // instructions (4) then load 64-bits constant (7).
kvn@617 2812 // Do this transformation here since IGVN will convert ConN back to ConP.
kvn@617 2813 const Type* t = addp->bottom_type();
roland@4159 2814 if (t->isa_oopptr() || t->isa_klassptr()) {
kvn@617 2815 Node* nn = NULL;
kvn@617 2816
roland@4159 2817 int op = t->isa_oopptr() ? Op_ConN : Op_ConNKlass;
roland@4159 2818
kvn@617 2819 // Look for existing ConN node of the same exact type.
bharadwaj@4315 2820 Node* r = root();
kvn@617 2821 uint cnt = r->outcnt();
kvn@617 2822 for (uint i = 0; i < cnt; i++) {
kvn@617 2823 Node* m = r->raw_out(i);
roland@4159 2824 if (m!= NULL && m->Opcode() == op &&
kvn@656 2825 m->bottom_type()->make_ptr() == t) {
kvn@617 2826 nn = m;
kvn@617 2827 break;
kvn@617 2828 }
kvn@617 2829 }
kvn@617 2830 if (nn != NULL) {
kvn@617 2831 // Decode a narrow oop to match address
kvn@617 2832 // [R12 + narrow_oop_reg<<3 + offset]
roland@4159 2833 if (t->isa_oopptr()) {
bharadwaj@4315 2834 nn = new (this) DecodeNNode(nn, t);
roland@4159 2835 } else {
bharadwaj@4315 2836 nn = new (this) DecodeNKlassNode(nn, t);
roland@4159 2837 }
kvn@617 2838 n->set_req(AddPNode::Base, nn);
kvn@617 2839 n->set_req(AddPNode::Address, nn);
kvn@617 2840 if (addp->outcnt() == 0) {
bharadwaj@4315 2841 addp->disconnect_inputs(NULL, this);
kvn@617 2842 }
kvn@617 2843 }
kvn@617 2844 }
kvn@617 2845 }
kvn@617 2846 #endif
duke@435 2847 break;
duke@435 2848 }
duke@435 2849
kvn@599 2850 #ifdef _LP64
kvn@803 2851 case Op_CastPP:
kvn@1930 2852 if (n->in(1)->is_DecodeN() && Matcher::gen_narrow_oop_implicit_null_checks()) {
kvn@803 2853 Node* in1 = n->in(1);
kvn@803 2854 const Type* t = n->bottom_type();
kvn@803 2855 Node* new_in1 = in1->clone();
kvn@803 2856 new_in1->as_DecodeN()->set_type(t);
kvn@803 2857
kvn@1930 2858 if (!Matcher::narrow_oop_use_complex_address()) {
kvn@803 2859 //
kvn@803 2860 // x86, ARM and friends can handle 2 adds in addressing mode
kvn@803 2861 // and Matcher can fold a DecodeN node into address by using
kvn@803 2862 // a narrow oop directly and do implicit NULL check in address:
kvn@803 2863 //
kvn@803 2864 // [R12 + narrow_oop_reg<<3 + offset]
kvn@803 2865 // NullCheck narrow_oop_reg
kvn@803 2866 //
kvn@803 2867 // On other platforms (Sparc) we have to keep new DecodeN node and
kvn@803 2868 // use it to do implicit NULL check in address:
kvn@803 2869 //
kvn@803 2870 // decode_not_null narrow_oop_reg, base_reg
kvn@803 2871 // [base_reg + offset]
kvn@803 2872 // NullCheck base_reg
kvn@803 2873 //
twisti@1040 2874 // Pin the new DecodeN node to non-null path on these platform (Sparc)
kvn@803 2875 // to keep the information to which NULL check the new DecodeN node
kvn@803 2876 // corresponds to use it as value in implicit_null_check().
kvn@803 2877 //
kvn@803 2878 new_in1->set_req(0, n->in(0));
kvn@803 2879 }
kvn@803 2880
bharadwaj@4315 2881 n->subsume_by(new_in1, this);
kvn@803 2882 if (in1->outcnt() == 0) {
bharadwaj@4315 2883 in1->disconnect_inputs(NULL, this);
kvn@803 2884 }
kvn@803 2885 }
kvn@803 2886 break;
kvn@803 2887
kvn@599 2888 case Op_CmpP:
kvn@603 2889 // Do this transformation here to preserve CmpPNode::sub() and
kvn@603 2890 // other TypePtr related Ideal optimizations (for example, ptr nullness).
roland@4159 2891 if (n->in(1)->is_DecodeNarrowPtr() || n->in(2)->is_DecodeNarrowPtr()) {
kvn@766 2892 Node* in1 = n->in(1);
kvn@766 2893 Node* in2 = n->in(2);
roland@4159 2894 if (!in1->is_DecodeNarrowPtr()) {
kvn@766 2895 in2 = in1;
kvn@766 2896 in1 = n->in(2);
kvn@766 2897 }
roland@4159 2898 assert(in1->is_DecodeNarrowPtr(), "sanity");
kvn@766 2899
kvn@766 2900 Node* new_in2 = NULL;
roland@4159 2901 if (in2->is_DecodeNarrowPtr()) {
roland@4159 2902 assert(in2->Opcode() == in1->Opcode(), "must be same node type");
kvn@766 2903 new_in2 = in2->in(1);
kvn@766 2904 } else if (in2->Opcode() == Op_ConP) {
kvn@766 2905 const Type* t = in2->bottom_type();
kvn@1930 2906 if (t == TypePtr::NULL_PTR) {
roland@4159 2907 assert(in1->is_DecodeN(), "compare klass to null?");
kvn@1930 2908 // Don't convert CmpP null check into CmpN if compressed
kvn@1930 2909 // oops implicit null check is not generated.
kvn@1930 2910 // This will allow to generate normal oop implicit null check.
kvn@1930 2911 if (Matcher::gen_narrow_oop_implicit_null_checks())
bharadwaj@4315 2912 new_in2 = ConNode::make(this, TypeNarrowOop::NULL_PTR);
kvn@803 2913 //
kvn@803 2914 // This transformation together with CastPP transformation above
kvn@803 2915 // will generated code for implicit NULL checks for compressed oops.
kvn@803 2916 //
kvn@803 2917 // The original code after Optimize()
kvn@803 2918 //
kvn@803 2919 // LoadN memory, narrow_oop_reg
kvn@803 2920 // decode narrow_oop_reg, base_reg
kvn@803 2921 // CmpP base_reg, NULL
kvn@803 2922 // CastPP base_reg // NotNull
kvn@803 2923 // Load [base_reg + offset], val_reg
kvn@803 2924 //
kvn@803 2925 // after these transformations will be
kvn@803 2926 //
kvn@803 2927 // LoadN memory, narrow_oop_reg
kvn@803 2928 // CmpN narrow_oop_reg, NULL
kvn@803 2929 // decode_not_null narrow_oop_reg, base_reg
kvn@803 2930 // Load [base_reg + offset], val_reg
kvn@803 2931 //
kvn@803 2932 // and the uncommon path (== NULL) will use narrow_oop_reg directly
kvn@803 2933 // since narrow oops can be used in debug info now (see the code in
kvn@803 2934 // final_graph_reshaping_walk()).
kvn@803 2935 //
kvn@803 2936 // At the end the code will be matched to
kvn@803 2937 // on x86:
kvn@803 2938 //
kvn@803 2939 // Load_narrow_oop memory, narrow_oop_reg
kvn@803 2940 // Load [R12 + narrow_oop_reg<<3 + offset], val_reg
kvn@803 2941 // NullCheck narrow_oop_reg
kvn@803 2942 //
kvn@803 2943 // and on sparc:
kvn@803 2944 //
kvn@803 2945 // Load_narrow_oop memory, narrow_oop_reg
kvn@803 2946 // decode_not_null narrow_oop_reg, base_reg
kvn@803 2947 // Load [base_reg + offset], val_reg
kvn@803 2948 // NullCheck base_reg
kvn@803 2949 //
kvn@599 2950 } else if (t->isa_oopptr()) {
bharadwaj@4315 2951 new_in2 = ConNode::make(this, t->make_narrowoop());
roland@4159 2952 } else if (t->isa_klassptr()) {
bharadwaj@4315 2953 new_in2 = ConNode::make(this, t->make_narrowklass());
kvn@599 2954 }
kvn@599 2955 }
kvn@766 2956 if (new_in2 != NULL) {
bharadwaj@4315 2957 Node* cmpN = new (this) CmpNNode(in1->in(1), new_in2);
bharadwaj@4315 2958 n->subsume_by(cmpN, this);
kvn@766 2959 if (in1->outcnt() == 0) {
bharadwaj@4315 2960 in1->disconnect_inputs(NULL, this);
kvn@766 2961 }
kvn@766 2962 if (in2->outcnt() == 0) {
bharadwaj@4315 2963 in2->disconnect_inputs(NULL, this);
kvn@766 2964 }
kvn@599 2965 }
kvn@599 2966 }
kvn@728 2967 break;
kvn@803 2968
kvn@803 2969 case Op_DecodeN:
roland@4159 2970 case Op_DecodeNKlass:
roland@4159 2971 assert(!n->in(1)->is_EncodeNarrowPtr(), "should be optimized out");
kvn@1930 2972 // DecodeN could be pinned when it can't be fold into
kvn@927 2973 // an address expression, see the code for Op_CastPP above.
roland@4159 2974 assert(n->in(0) == NULL || (UseCompressedOops && !Matcher::narrow_oop_use_complex_address()), "no control");
kvn@803 2975 break;
kvn@803 2976
roland@4159 2977 case Op_EncodeP:
roland@4159 2978 case Op_EncodePKlass: {
kvn@803 2979 Node* in1 = n->in(1);
roland@4159 2980 if (in1->is_DecodeNarrowPtr()) {
bharadwaj@4315 2981 n->subsume_by(in1->in(1), this);
kvn@803 2982 } else if (in1->Opcode() == Op_ConP) {
kvn@803 2983 const Type* t = in1->bottom_type();
kvn@803 2984 if (t == TypePtr::NULL_PTR) {
roland@4159 2985 assert(t->isa_oopptr(), "null klass?");
bharadwaj@4315 2986 n->subsume_by(ConNode::make(this, TypeNarrowOop::NULL_PTR), this);
kvn@803 2987 } else if (t->isa_oopptr()) {
bharadwaj@4315 2988 n->subsume_by(ConNode::make(this, t->make_narrowoop()), this);
roland@4159 2989 } else if (t->isa_klassptr()) {
bharadwaj@4315 2990 n->subsume_by(ConNode::make(this, t->make_narrowklass()), this);
kvn@803 2991 }
kvn@803 2992 }
kvn@803 2993 if (in1->outcnt() == 0) {
bharadwaj@4315 2994 in1->disconnect_inputs(NULL, this);
kvn@803 2995 }
kvn@803 2996 break;
kvn@803 2997 }
kvn@803 2998
never@1515 2999 case Op_Proj: {
never@1515 3000 if (OptimizeStringConcat) {
never@1515 3001 ProjNode* p = n->as_Proj();
never@1515 3002 if (p->_is_io_use) {
never@1515 3003 // Separate projections were used for the exception path which
never@1515 3004 // are normally removed by a late inline. If it wasn't inlined
never@1515 3005 // then they will hang around and should just be replaced with
never@1515 3006 // the original one.
never@1515 3007 Node* proj = NULL;
never@1515 3008 // Replace with just one
never@1515 3009 for (SimpleDUIterator i(p->in(0)); i.has_next(); i.next()) {
never@1515 3010 Node *use = i.get();
never@1515 3011 if (use->is_Proj() && p != use && use->as_Proj()->_con == p->_con) {
never@1515 3012 proj = use;
never@1515 3013 break;
never@1515 3014 }
never@1515 3015 }
kvn@3396 3016 assert(proj != NULL, "must be found");
bharadwaj@4315 3017 p->subsume_by(proj, this);
never@1515 3018 }
never@1515 3019 }
never@1515 3020 break;
never@1515 3021 }
never@1515 3022
kvn@803 3023 case Op_Phi:
roland@4159 3024 if (n->as_Phi()->bottom_type()->isa_narrowoop() || n->as_Phi()->bottom_type()->isa_narrowklass()) {
kvn@803 3025 // The EncodeP optimization may create Phi with the same edges
kvn@803 3026 // for all paths. It is not handled well by Register Allocator.
kvn@803 3027 Node* unique_in = n->in(1);
kvn@803 3028 assert(unique_in != NULL, "");
kvn@803 3029 uint cnt = n->req();
kvn@803 3030 for (uint i = 2; i < cnt; i++) {
kvn@803 3031 Node* m = n->in(i);
kvn@803 3032 assert(m != NULL, "");
kvn@803 3033 if (unique_in != m)
kvn@803 3034 unique_in = NULL;
kvn@803 3035 }
kvn@803 3036 if (unique_in != NULL) {
bharadwaj@4315 3037 n->subsume_by(unique_in, this);
kvn@803 3038 }
kvn@803 3039 }
kvn@803 3040 break;
kvn@803 3041
kvn@599 3042 #endif
kvn@599 3043
thartmann@8476 3044 #ifdef ASSERT
thartmann@8476 3045 case Op_CastII:
thartmann@8476 3046 // Verify that all range check dependent CastII nodes were removed.
thartmann@8476 3047 if (n->isa_CastII()->has_range_check()) {
thartmann@8476 3048 n->dump(3);
thartmann@8476 3049 assert(false, "Range check dependent CastII node was not removed");
thartmann@8476 3050 }
thartmann@8476 3051 break;
thartmann@8476 3052 #endif
thartmann@8476 3053
duke@435 3054 case Op_ModI:
duke@435 3055 if (UseDivMod) {
duke@435 3056 // Check if a%b and a/b both exist
duke@435 3057 Node* d = n->find_similar(Op_DivI);
duke@435 3058 if (d) {
duke@435 3059 // Replace them with a fused divmod if supported
duke@435 3060 if (Matcher::has_match_rule(Op_DivModI)) {
bharadwaj@4315 3061 DivModINode* divmod = DivModINode::make(this, n);
bharadwaj@4315 3062 d->subsume_by(divmod->div_proj(), this);
bharadwaj@4315 3063 n->subsume_by(divmod->mod_proj(), this);
duke@435 3064 } else {
duke@435 3065 // replace a%b with a-((a/b)*b)
bharadwaj@4315 3066 Node* mult = new (this) MulINode(d, d->in(2));
bharadwaj@4315 3067 Node* sub = new (this) SubINode(d->in(1), mult);
bharadwaj@4315 3068 n->subsume_by(sub, this);
duke@435 3069 }
duke@435 3070 }
duke@435 3071 }
duke@435 3072 break;
duke@435 3073
duke@435 3074 case Op_ModL:
duke@435 3075 if (UseDivMod) {
duke@435 3076 // Check if a%b and a/b both exist
duke@435 3077 Node* d = n->find_similar(Op_DivL);
duke@435 3078 if (d) {
duke@435 3079 // Replace them with a fused divmod if supported
duke@435 3080 if (Matcher::has_match_rule(Op_DivModL)) {
bharadwaj@4315 3081 DivModLNode* divmod = DivModLNode::make(this, n);
bharadwaj@4315 3082 d->subsume_by(divmod->div_proj(), this);
bharadwaj@4315 3083 n->subsume_by(divmod->mod_proj(), this);
duke@435 3084 } else {
duke@435 3085 // replace a%b with a-((a/b)*b)
bharadwaj@4315 3086 Node* mult = new (this) MulLNode(d, d->in(2));
bharadwaj@4315 3087 Node* sub = new (this) SubLNode(d->in(1), mult);
bharadwaj@4315 3088 n->subsume_by(sub, this);
duke@435 3089 }
duke@435 3090 }
duke@435 3091 }
duke@435 3092 break;
duke@435 3093
kvn@3882 3094 case Op_LoadVector:
kvn@3882 3095 case Op_StoreVector:
duke@435 3096 break;
duke@435 3097
duke@435 3098 case Op_PackB:
duke@435 3099 case Op_PackS:
duke@435 3100 case Op_PackI:
duke@435 3101 case Op_PackF:
duke@435 3102 case Op_PackL:
duke@435 3103 case Op_PackD:
duke@435 3104 if (n->req()-1 > 2) {
duke@435 3105 // Replace many operand PackNodes with a binary tree for matching
duke@435 3106 PackNode* p = (PackNode*) n;
bharadwaj@4315 3107 Node* btp = p->binary_tree_pack(this, 1, n->req());
bharadwaj@4315 3108 n->subsume_by(btp, this);
duke@435 3109 }
duke@435 3110 break;
kvn@1294 3111 case Op_Loop:
kvn@1294 3112 case Op_CountedLoop:
kvn@1294 3113 if (n->as_Loop()->is_inner_loop()) {
kvn@1294 3114 frc.inc_inner_loop_count();
kvn@1294 3115 }
kvn@1294 3116 break;
roland@2683 3117 case Op_LShiftI:
roland@2683 3118 case Op_RShiftI:
roland@2683 3119 case Op_URShiftI:
roland@2683 3120 case Op_LShiftL:
roland@2683 3121 case Op_RShiftL:
roland@2683 3122 case Op_URShiftL:
roland@2683 3123 if (Matcher::need_masked_shift_count) {
roland@2683 3124 // The cpu's shift instructions don't restrict the count to the
roland@2683 3125 // lower 5/6 bits. We need to do the masking ourselves.
roland@2683 3126 Node* in2 = n->in(2);
roland@2683 3127 juint mask = (n->bottom_type() == TypeInt::INT) ? (BitsPerInt - 1) : (BitsPerLong - 1);
roland@2683 3128 const TypeInt* t = in2->find_int_type();
roland@2683 3129 if (t != NULL && t->is_con()) {
roland@2683 3130 juint shift = t->get_con();
roland@2683 3131 if (shift > mask) { // Unsigned cmp
bharadwaj@4315 3132 n->set_req(2, ConNode::make(this, TypeInt::make(shift & mask)));
roland@2683 3133 }
roland@2683 3134 } else {
roland@2683 3135 if (t == NULL || t->_lo < 0 || t->_hi > (int)mask) {
bharadwaj@4315 3136 Node* shift = new (this) AndINode(in2, ConNode::make(this, TypeInt::make(mask)));
roland@2683 3137 n->set_req(2, shift);
roland@2683 3138 }
roland@2683 3139 }
roland@2683 3140 if (in2->outcnt() == 0) { // Remove dead node
bharadwaj@4315 3141 in2->disconnect_inputs(NULL, this);
roland@2683 3142 }
roland@2683 3143 }
roland@2683 3144 break;
roland@4694 3145 case Op_MemBarStoreStore:
kvn@5110 3146 case Op_MemBarRelease:
roland@4694 3147 // Break the link with AllocateNode: it is no longer useful and
roland@4694 3148 // confuses register allocation.
roland@4694 3149 if (n->req() > MemBarNode::Precedent) {
roland@4694 3150 n->set_req(MemBarNode::Precedent, top());
roland@4694 3151 }
roland@4694 3152 break;
duke@435 3153 default:
duke@435 3154 assert( !n->is_Call(), "" );
duke@435 3155 assert( !n->is_Mem(), "" );
vlivanov@7789 3156 assert( nop != Op_ProfileBoolean, "should be eliminated during IGVN");
duke@435 3157 break;
duke@435 3158 }
never@562 3159
never@562 3160 // Collect CFG split points
never@562 3161 if (n->is_MultiBranch())
kvn@1294 3162 frc._tests.push(n);
duke@435 3163 }
duke@435 3164
duke@435 3165 //------------------------------final_graph_reshaping_walk---------------------
duke@435 3166 // Replacing Opaque nodes with their input in final_graph_reshaping_impl(),
duke@435 3167 // requires that the walk visits a node's inputs before visiting the node.
bharadwaj@4315 3168 void Compile::final_graph_reshaping_walk( Node_Stack &nstack, Node *root, Final_Reshape_Counts &frc ) {
kvn@766 3169 ResourceArea *area = Thread::current()->resource_area();
kvn@766 3170 Unique_Node_List sfpt(area);
kvn@766 3171
kvn@1294 3172 frc._visited.set(root->_idx); // first, mark node as visited
duke@435 3173 uint cnt = root->req();
duke@435 3174 Node *n = root;
duke@435 3175 uint i = 0;
duke@435 3176 while (true) {
duke@435 3177 if (i < cnt) {
duke@435 3178 // Place all non-visited non-null inputs onto stack
duke@435 3179 Node* m = n->in(i);
duke@435 3180 ++i;
kvn@1294 3181 if (m != NULL && !frc._visited.test_set(m->_idx)) {
roland@6723 3182 if (m->is_SafePoint() && m->as_SafePoint()->jvms() != NULL) {
roland@6723 3183 // compute worst case interpreter size in case of a deoptimization
roland@6723 3184 update_interpreter_frame_size(m->as_SafePoint()->jvms()->interpreter_frame_size());
roland@6723 3185
kvn@766 3186 sfpt.push(m);
roland@6723 3187 }
duke@435 3188 cnt = m->req();
duke@435 3189 nstack.push(n, i); // put on stack parent and next input's index
duke@435 3190 n = m;
duke@435 3191 i = 0;
duke@435 3192 }
duke@435 3193 } else {
duke@435 3194 // Now do post-visit work
kvn@1294 3195 final_graph_reshaping_impl( n, frc );
duke@435 3196 if (nstack.is_empty())
duke@435 3197 break; // finished
duke@435 3198 n = nstack.node(); // Get node from stack
duke@435 3199 cnt = n->req();
duke@435 3200 i = nstack.index();
duke@435 3201 nstack.pop(); // Shift to the next node on stack
duke@435 3202 }
duke@435 3203 }
kvn@766 3204
kvn@1930 3205 // Skip next transformation if compressed oops are not used.
roland@4159 3206 if ((UseCompressedOops && !Matcher::gen_narrow_oop_implicit_null_checks()) ||
ehelin@5694 3207 (!UseCompressedOops && !UseCompressedClassPointers))
kvn@1930 3208 return;
kvn@1930 3209
roland@4159 3210 // Go over safepoints nodes to skip DecodeN/DecodeNKlass nodes for debug edges.
kvn@766 3211 // It could be done for an uncommon traps or any safepoints/calls
roland@4159 3212 // if the DecodeN/DecodeNKlass node is referenced only in a debug info.
kvn@766 3213 while (sfpt.size() > 0) {
kvn@766 3214 n = sfpt.pop();
kvn@766 3215 JVMState *jvms = n->as_SafePoint()->jvms();
kvn@766 3216 assert(jvms != NULL, "sanity");
kvn@766 3217 int start = jvms->debug_start();
kvn@766 3218 int end = n->req();
kvn@766 3219 bool is_uncommon = (n->is_CallStaticJava() &&
kvn@766 3220 n->as_CallStaticJava()->uncommon_trap_request() != 0);
kvn@766 3221 for (int j = start; j < end; j++) {
kvn@766 3222 Node* in = n->in(j);
roland@4159 3223 if (in->is_DecodeNarrowPtr()) {
kvn@766 3224 bool safe_to_skip = true;
kvn@766 3225 if (!is_uncommon ) {
kvn@766 3226 // Is it safe to skip?
kvn@766 3227 for (uint i = 0; i < in->outcnt(); i++) {
kvn@766 3228 Node* u = in->raw_out(i);
kvn@766 3229 if (!u->is_SafePoint() ||
kvn@766 3230 u->is_Call() && u->as_Call()->has_non_debug_use(n)) {
kvn@766 3231 safe_to_skip = false;
kvn@766 3232 }
kvn@766 3233 }
kvn@766 3234 }
kvn@766 3235 if (safe_to_skip) {
kvn@766 3236 n->set_req(j, in->in(1));
kvn@766 3237 }
kvn@766 3238 if (in->outcnt() == 0) {
bharadwaj@4315 3239 in->disconnect_inputs(NULL, this);
kvn@766 3240 }
kvn@766 3241 }
kvn@766 3242 }
kvn@766 3243 }
duke@435 3244 }
duke@435 3245
duke@435 3246 //------------------------------final_graph_reshaping--------------------------
duke@435 3247 // Final Graph Reshaping.
duke@435 3248 //
duke@435 3249 // (1) Clone simple inputs to uncommon calls, so they can be scheduled late
duke@435 3250 // and not commoned up and forced early. Must come after regular
duke@435 3251 // optimizations to avoid GVN undoing the cloning. Clone constant
duke@435 3252 // inputs to Loop Phis; these will be split by the allocator anyways.
duke@435 3253 // Remove Opaque nodes.
duke@435 3254 // (2) Move last-uses by commutative operations to the left input to encourage
duke@435 3255 // Intel update-in-place two-address operations and better register usage
duke@435 3256 // on RISCs. Must come after regular optimizations to avoid GVN Ideal
duke@435 3257 // calls canonicalizing them back.
duke@435 3258 // (3) Count the number of double-precision FP ops, single-precision FP ops
duke@435 3259 // and call sites. On Intel, we can get correct rounding either by
duke@435 3260 // forcing singles to memory (requires extra stores and loads after each
duke@435 3261 // FP bytecode) or we can set a rounding mode bit (requires setting and
duke@435 3262 // clearing the mode bit around call sites). The mode bit is only used
duke@435 3263 // if the relative frequency of single FP ops to calls is low enough.
duke@435 3264 // This is a key transform for SPEC mpeg_audio.
duke@435 3265 // (4) Detect infinite loops; blobs of code reachable from above but not
duke@435 3266 // below. Several of the Code_Gen algorithms fail on such code shapes,
duke@435 3267 // so we simply bail out. Happens a lot in ZKM.jar, but also happens
duke@435 3268 // from time to time in other codes (such as -Xcomp finalizer loops, etc).
duke@435 3269 // Detection is by looking for IfNodes where only 1 projection is
duke@435 3270 // reachable from below or CatchNodes missing some targets.
duke@435 3271 // (5) Assert for insane oop offsets in debug mode.
duke@435 3272
duke@435 3273 bool Compile::final_graph_reshaping() {
duke@435 3274 // an infinite loop may have been eliminated by the optimizer,
duke@435 3275 // in which case the graph will be empty.
duke@435 3276 if (root()->req() == 1) {
duke@435 3277 record_method_not_compilable("trivial infinite loop");
duke@435 3278 return true;
duke@435 3279 }
duke@435 3280
roland@4589 3281 // Expensive nodes have their control input set to prevent the GVN
roland@4589 3282 // from freely commoning them. There's no GVN beyond this point so
roland@4589 3283 // no need to keep the control input. We want the expensive nodes to
roland@4589 3284 // be freely moved to the least frequent code path by gcm.
roland@4589 3285 assert(OptimizeExpensiveOps || expensive_count() == 0, "optimization off but list non empty?");
roland@4589 3286 for (int i = 0; i < expensive_count(); i++) {
roland@4589 3287 _expensive_nodes->at(i)->set_req(0, NULL);
roland@4589 3288 }
roland@4589 3289
kvn@1294 3290 Final_Reshape_Counts frc;
duke@435 3291
duke@435 3292 // Visit everybody reachable!
zmajo@8068 3293 // Allocate stack of size C->live_nodes()/2 to avoid frequent realloc
zmajo@8068 3294 Node_Stack nstack(live_nodes() >> 1);
kvn@1294 3295 final_graph_reshaping_walk(nstack, root(), frc);
duke@435 3296
duke@435 3297 // Check for unreachable (from below) code (i.e., infinite loops).
kvn@1294 3298 for( uint i = 0; i < frc._tests.size(); i++ ) {
kvn@1294 3299 MultiBranchNode *n = frc._tests[i]->as_MultiBranch();
never@562 3300 // Get number of CFG targets.
duke@435 3301 // Note that PCTables include exception targets after calls.
never@562 3302 uint required_outcnt = n->required_outcnt();
never@562 3303 if (n->outcnt() != required_outcnt) {
duke@435 3304 // Check for a few special cases. Rethrow Nodes never take the
duke@435 3305 // 'fall-thru' path, so expected kids is 1 less.
duke@435 3306 if (n->is_PCTable() && n->in(0) && n->in(0)->in(0)) {
duke@435 3307 if (n->in(0)->in(0)->is_Call()) {
duke@435 3308 CallNode *call = n->in(0)->in(0)->as_Call();
duke@435 3309 if (call->entry_point() == OptoRuntime::rethrow_stub()) {
never@562 3310 required_outcnt--; // Rethrow always has 1 less kid
duke@435 3311 } else if (call->req() > TypeFunc::Parms &&
duke@435 3312 call->is_CallDynamicJava()) {
duke@435 3313 // Check for null receiver. In such case, the optimizer has
duke@435 3314 // detected that the virtual call will always result in a null
duke@435 3315 // pointer exception. The fall-through projection of this CatchNode
duke@435 3316 // will not be populated.
duke@435 3317 Node *arg0 = call->in(TypeFunc::Parms);
duke@435 3318 if (arg0->is_Type() &&
duke@435 3319 arg0->as_Type()->type()->higher_equal(TypePtr::NULL_PTR)) {
never@562 3320 required_outcnt--;
duke@435 3321 }
duke@435 3322 } else if (call->entry_point() == OptoRuntime::new_array_Java() &&
duke@435 3323 call->req() > TypeFunc::Parms+1 &&
duke@435 3324 call->is_CallStaticJava()) {
duke@435 3325 // Check for negative array length. In such case, the optimizer has
duke@435 3326 // detected that the allocation attempt will always result in an
duke@435 3327 // exception. There is no fall-through projection of this CatchNode .
duke@435 3328 Node *arg1 = call->in(TypeFunc::Parms+1);
duke@435 3329 if (arg1->is_Type() &&
duke@435 3330 arg1->as_Type()->type()->join(TypeInt::POS)->empty()) {
never@562 3331 required_outcnt--;
duke@435 3332 }
duke@435 3333 }
duke@435 3334 }
duke@435 3335 }
never@562 3336 // Recheck with a better notion of 'required_outcnt'
never@562 3337 if (n->outcnt() != required_outcnt) {
duke@435 3338 record_method_not_compilable("malformed control flow");
duke@435 3339 return true; // Not all targets reachable!
duke@435 3340 }
duke@435 3341 }
duke@435 3342 // Check that I actually visited all kids. Unreached kids
duke@435 3343 // must be infinite loops.
duke@435 3344 for (DUIterator_Fast jmax, j = n->fast_outs(jmax); j < jmax; j++)
kvn@1294 3345 if (!frc._visited.test(n->fast_out(j)->_idx)) {
duke@435 3346 record_method_not_compilable("infinite loop");
duke@435 3347 return true; // Found unvisited kid; must be unreach
duke@435 3348 }
duke@435 3349 }
duke@435 3350
duke@435 3351 // If original bytecodes contained a mixture of floats and doubles
duke@435 3352 // check if the optimizer has made it homogenous, item (3).
never@1364 3353 if( Use24BitFPMode && Use24BitFP && UseSSE == 0 &&
kvn@1294 3354 frc.get_float_count() > 32 &&
kvn@1294 3355 frc.get_double_count() == 0 &&
kvn@1294 3356 (10 * frc.get_call_count() < frc.get_float_count()) ) {
duke@435 3357 set_24_bit_selection_and_mode( false, true );
duke@435 3358 }
duke@435 3359
kvn@1294 3360 set_java_calls(frc.get_java_call_count());
kvn@1294 3361 set_inner_loops(frc.get_inner_loop_count());
duke@435 3362
duke@435 3363 // No infinite loops, no reason to bail out.
duke@435 3364 return false;
duke@435 3365 }
duke@435 3366
duke@435 3367 //-----------------------------too_many_traps----------------------------------
duke@435 3368 // Report if there are too many traps at the current method and bci.
duke@435 3369 // Return true if there was a trap, and/or PerMethodTrapLimit is exceeded.
duke@435 3370 bool Compile::too_many_traps(ciMethod* method,
duke@435 3371 int bci,
duke@435 3372 Deoptimization::DeoptReason reason) {
duke@435 3373 ciMethodData* md = method->method_data();
duke@435 3374 if (md->is_empty()) {
duke@435 3375 // Assume the trap has not occurred, or that it occurred only
duke@435 3376 // because of a transient condition during start-up in the interpreter.
duke@435 3377 return false;
duke@435 3378 }
roland@6377 3379 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : NULL;
roland@6377 3380 if (md->has_trap_at(bci, m, reason) != 0) {
duke@435 3381 // Assume PerBytecodeTrapLimit==0, for a more conservative heuristic.
duke@435 3382 // Also, if there are multiple reasons, or if there is no per-BCI record,
duke@435 3383 // assume the worst.
duke@435 3384 if (log())
duke@435 3385 log()->elem("observe trap='%s' count='%d'",
duke@435 3386 Deoptimization::trap_reason_name(reason),
duke@435 3387 md->trap_count(reason));
duke@435 3388 return true;
duke@435 3389 } else {
duke@435 3390 // Ignore method/bci and see if there have been too many globally.
duke@435 3391 return too_many_traps(reason, md);
duke@435 3392 }
duke@435 3393 }
duke@435 3394
duke@435 3395 // Less-accurate variant which does not require a method and bci.
duke@435 3396 bool Compile::too_many_traps(Deoptimization::DeoptReason reason,
duke@435 3397 ciMethodData* logmd) {
roland@6377 3398 if (trap_count(reason) >= Deoptimization::per_method_trap_limit(reason)) {
duke@435 3399 // Too many traps globally.
duke@435 3400 // Note that we use cumulative trap_count, not just md->trap_count.
duke@435 3401 if (log()) {
duke@435 3402 int mcount = (logmd == NULL)? -1: (int)logmd->trap_count(reason);
duke@435 3403 log()->elem("observe trap='%s' count='0' mcount='%d' ccount='%d'",
duke@435 3404 Deoptimization::trap_reason_name(reason),
duke@435 3405 mcount, trap_count(reason));
duke@435 3406 }
duke@435 3407 return true;
duke@435 3408 } else {
duke@435 3409 // The coast is clear.
duke@435 3410 return false;
duke@435 3411 }
duke@435 3412 }
duke@435 3413
duke@435 3414 //--------------------------too_many_recompiles--------------------------------
duke@435 3415 // Report if there are too many recompiles at the current method and bci.
duke@435 3416 // Consults PerBytecodeRecompilationCutoff and PerMethodRecompilationCutoff.
duke@435 3417 // Is not eager to return true, since this will cause the compiler to use
duke@435 3418 // Action_none for a trap point, to avoid too many recompilations.
duke@435 3419 bool Compile::too_many_recompiles(ciMethod* method,
duke@435 3420 int bci,
duke@435 3421 Deoptimization::DeoptReason reason) {
duke@435 3422 ciMethodData* md = method->method_data();
duke@435 3423 if (md->is_empty()) {
duke@435 3424 // Assume the trap has not occurred, or that it occurred only
duke@435 3425 // because of a transient condition during start-up in the interpreter.
duke@435 3426 return false;
duke@435 3427 }
duke@435 3428 // Pick a cutoff point well within PerBytecodeRecompilationCutoff.
duke@435 3429 uint bc_cutoff = (uint) PerBytecodeRecompilationCutoff / 8;
duke@435 3430 uint m_cutoff = (uint) PerMethodRecompilationCutoff / 2 + 1; // not zero
duke@435 3431 Deoptimization::DeoptReason per_bc_reason
duke@435 3432 = Deoptimization::reason_recorded_per_bytecode_if_any(reason);
roland@6377 3433 ciMethod* m = Deoptimization::reason_is_speculate(reason) ? this->method() : NULL;
duke@435 3434 if ((per_bc_reason == Deoptimization::Reason_none
roland@6377 3435 || md->has_trap_at(bci, m, reason) != 0)
duke@435 3436 // The trap frequency measure we care about is the recompile count:
roland@6377 3437 && md->trap_recompiled_at(bci, m)
duke@435 3438 && md->overflow_recompile_count() >= bc_cutoff) {
duke@435 3439 // Do not emit a trap here if it has already caused recompilations.
duke@435 3440 // Also, if there are multiple reasons, or if there is no per-BCI record,
duke@435 3441 // assume the worst.
duke@435 3442 if (log())
duke@435 3443 log()->elem("observe trap='%s recompiled' count='%d' recompiles2='%d'",
duke@435 3444 Deoptimization::trap_reason_name(reason),
duke@435 3445 md->trap_count(reason),
duke@435 3446 md->overflow_recompile_count());
duke@435 3447 return true;
duke@435 3448 } else if (trap_count(reason) != 0
duke@435 3449 && decompile_count() >= m_cutoff) {
duke@435 3450 // Too many recompiles globally, and we have seen this sort of trap.
duke@435 3451 // Use cumulative decompile_count, not just md->decompile_count.
duke@435 3452 if (log())
duke@435 3453 log()->elem("observe trap='%s' count='%d' mcount='%d' decompiles='%d' mdecompiles='%d'",
duke@435 3454 Deoptimization::trap_reason_name(reason),
duke@435 3455 md->trap_count(reason), trap_count(reason),
duke@435 3456 md->decompile_count(), decompile_count());
duke@435 3457 return true;
duke@435 3458 } else {
duke@435 3459 // The coast is clear.
duke@435 3460 return false;
duke@435 3461 }
duke@435 3462 }
duke@435 3463
goetz@6490 3464 // Compute when not to trap. Used by matching trap based nodes and
goetz@6490 3465 // NullCheck optimization.
goetz@6490 3466 void Compile::set_allowed_deopt_reasons() {
goetz@6490 3467 _allowed_reasons = 0;
goetz@6490 3468 if (is_method_compilation()) {
goetz@6490 3469 for (int rs = (int)Deoptimization::Reason_none+1; rs < Compile::trapHistLength; rs++) {
goetz@6490 3470 assert(rs < BitsPerInt, "recode bit map");
goetz@6490 3471 if (!too_many_traps((Deoptimization::DeoptReason) rs)) {
goetz@6490 3472 _allowed_reasons |= nth_bit(rs);
goetz@6490 3473 }
goetz@6490 3474 }
goetz@6490 3475 }
goetz@6490 3476 }
duke@435 3477
duke@435 3478 #ifndef PRODUCT
duke@435 3479 //------------------------------verify_graph_edges---------------------------
duke@435 3480 // Walk the Graph and verify that there is a one-to-one correspondence
duke@435 3481 // between Use-Def edges and Def-Use edges in the graph.
duke@435 3482 void Compile::verify_graph_edges(bool no_dead_code) {
duke@435 3483 if (VerifyGraphEdges) {
duke@435 3484 ResourceArea *area = Thread::current()->resource_area();
duke@435 3485 Unique_Node_List visited(area);
duke@435 3486 // Call recursive graph walk to check edges
duke@435 3487 _root->verify_edges(visited);
duke@435 3488 if (no_dead_code) {
duke@435 3489 // Now make sure that no visited node is used by an unvisited node.
thartmann@9335 3490 bool dead_nodes = false;
duke@435 3491 Unique_Node_List checked(area);
duke@435 3492 while (visited.size() > 0) {
duke@435 3493 Node* n = visited.pop();
duke@435 3494 checked.push(n);
duke@435 3495 for (uint i = 0; i < n->outcnt(); i++) {
duke@435 3496 Node* use = n->raw_out(i);
duke@435 3497 if (checked.member(use)) continue; // already checked
duke@435 3498 if (visited.member(use)) continue; // already in the graph
duke@435 3499 if (use->is_Con()) continue; // a dead ConNode is OK
duke@435 3500 // At this point, we have found a dead node which is DU-reachable.
thartmann@9335 3501 if (!dead_nodes) {
duke@435 3502 tty->print_cr("*** Dead nodes reachable via DU edges:");
thartmann@9335 3503 dead_nodes = true;
thartmann@9335 3504 }
duke@435 3505 use->dump(2);
duke@435 3506 tty->print_cr("---");
duke@435 3507 checked.push(use); // No repeats; pretend it is now checked.
duke@435 3508 }
duke@435 3509 }
thartmann@9335 3510 assert(!dead_nodes, "using nodes must be reachable from root");
duke@435 3511 }
duke@435 3512 }
duke@435 3513 }
iveresov@6070 3514
iveresov@6070 3515 // Verify GC barriers consistency
iveresov@6070 3516 // Currently supported:
iveresov@6070 3517 // - G1 pre-barriers (see GraphKit::g1_write_barrier_pre())
iveresov@6070 3518 void Compile::verify_barriers() {
iveresov@6070 3519 if (UseG1GC) {
iveresov@6070 3520 // Verify G1 pre-barriers
iveresov@6070 3521 const int marking_offset = in_bytes(JavaThread::satb_mark_queue_offset() + PtrQueue::byte_offset_of_active());
iveresov@6070 3522
iveresov@6070 3523 ResourceArea *area = Thread::current()->resource_area();
iveresov@6070 3524 Unique_Node_List visited(area);
iveresov@6070 3525 Node_List worklist(area);
iveresov@6070 3526 // We're going to walk control flow backwards starting from the Root
iveresov@6070 3527 worklist.push(_root);
iveresov@6070 3528 while (worklist.size() > 0) {
iveresov@6070 3529 Node* x = worklist.pop();
iveresov@6070 3530 if (x == NULL || x == top()) continue;
iveresov@6070 3531 if (visited.member(x)) {
iveresov@6070 3532 continue;
iveresov@6070 3533 } else {
iveresov@6070 3534 visited.push(x);
iveresov@6070 3535 }
iveresov@6070 3536
iveresov@6070 3537 if (x->is_Region()) {
iveresov@6070 3538 for (uint i = 1; i < x->req(); i++) {
iveresov@6070 3539 worklist.push(x->in(i));
iveresov@6070 3540 }
iveresov@6070 3541 } else {
iveresov@6070 3542 worklist.push(x->in(0));
iveresov@6070 3543 // We are looking for the pattern:
iveresov@6070 3544 // /->ThreadLocal
iveresov@6070 3545 // If->Bool->CmpI->LoadB->AddP->ConL(marking_offset)
iveresov@6070 3546 // \->ConI(0)
iveresov@6070 3547 // We want to verify that the If and the LoadB have the same control
iveresov@6070 3548 // See GraphKit::g1_write_barrier_pre()
iveresov@6070 3549 if (x->is_If()) {
iveresov@6070 3550 IfNode *iff = x->as_If();
iveresov@6070 3551 if (iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) {
iveresov@6070 3552 CmpNode *cmp = iff->in(1)->in(1)->as_Cmp();
iveresov@6070 3553 if (cmp->Opcode() == Op_CmpI && cmp->in(2)->is_Con() && cmp->in(2)->bottom_type()->is_int()->get_con() == 0
iveresov@6070 3554 && cmp->in(1)->is_Load()) {
iveresov@6070 3555 LoadNode* load = cmp->in(1)->as_Load();
iveresov@6070 3556 if (load->Opcode() == Op_LoadB && load->in(2)->is_AddP() && load->in(2)->in(2)->Opcode() == Op_ThreadLocal
iveresov@6070 3557 && load->in(2)->in(3)->is_Con()
iveresov@6070 3558 && load->in(2)->in(3)->bottom_type()->is_intptr_t()->get_con() == marking_offset) {
iveresov@6070 3559
iveresov@6070 3560 Node* if_ctrl = iff->in(0);
iveresov@6070 3561 Node* load_ctrl = load->in(0);
iveresov@6070 3562
iveresov@6070 3563 if (if_ctrl != load_ctrl) {
iveresov@6070 3564 // Skip possible CProj->NeverBranch in infinite loops
iveresov@6070 3565 if ((if_ctrl->is_Proj() && if_ctrl->Opcode() == Op_CProj)
iveresov@6070 3566 && (if_ctrl->in(0)->is_MultiBranch() && if_ctrl->in(0)->Opcode() == Op_NeverBranch)) {
iveresov@6070 3567 if_ctrl = if_ctrl->in(0)->in(0);
iveresov@6070 3568 }
iveresov@6070 3569 }
iveresov@6070 3570 assert(load_ctrl != NULL && if_ctrl == load_ctrl, "controls must match");
iveresov@6070 3571 }
iveresov@6070 3572 }
iveresov@6070 3573 }
iveresov@6070 3574 }
iveresov@6070 3575 }
iveresov@6070 3576 }
iveresov@6070 3577 }
iveresov@6070 3578 }
iveresov@6070 3579
duke@435 3580 #endif
duke@435 3581
duke@435 3582 // The Compile object keeps track of failure reasons separately from the ciEnv.
duke@435 3583 // This is required because there is not quite a 1-1 relation between the
duke@435 3584 // ciEnv and its compilation task and the Compile object. Note that one
duke@435 3585 // ciEnv might use two Compile objects, if C2Compiler::compile_method decides
duke@435 3586 // to backtrack and retry without subsuming loads. Other than this backtracking
duke@435 3587 // behavior, the Compile's failure reason is quietly copied up to the ciEnv
duke@435 3588 // by the logic in C2Compiler.
duke@435 3589 void Compile::record_failure(const char* reason) {
duke@435 3590 if (log() != NULL) {
duke@435 3591 log()->elem("failure reason='%s' phase='compile'", reason);
duke@435 3592 }
duke@435 3593 if (_failure_reason == NULL) {
duke@435 3594 // Record the first failure reason.
duke@435 3595 _failure_reason = reason;
duke@435 3596 }
sla@5237 3597
sla@5237 3598 EventCompilerFailure event;
sla@5237 3599 if (event.should_commit()) {
sla@5237 3600 event.set_compileID(Compile::compile_id());
sla@5237 3601 event.set_failure(reason);
sla@5237 3602 event.commit();
sla@5237 3603 }
sla@5237 3604
never@657 3605 if (!C->failure_reason_is(C2Compiler::retry_no_subsuming_loads())) {
sla@5237 3606 C->print_method(PHASE_FAILURE);
never@657 3607 }
duke@435 3608 _root = NULL; // flush the graph, too
duke@435 3609 }
duke@435 3610
duke@435 3611 Compile::TracePhase::TracePhase(const char* name, elapsedTimer* accumulator, bool dolog)
bharadwaj@4315 3612 : TraceTime(NULL, accumulator, false NOT_PRODUCT( || TimeCompiler ), false),
bharadwaj@4315 3613 _phase_name(name), _dolog(dolog)
duke@435 3614 {
duke@435 3615 if (dolog) {
duke@435 3616 C = Compile::current();
duke@435 3617 _log = C->log();
duke@435 3618 } else {
duke@435 3619 C = NULL;
duke@435 3620 _log = NULL;
duke@435 3621 }
duke@435 3622 if (_log != NULL) {
bharadwaj@4315 3623 _log->begin_head("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes());
duke@435 3624 _log->stamp();
duke@435 3625 _log->end_head();
duke@435 3626 }
duke@435 3627 }
duke@435 3628
duke@435 3629 Compile::TracePhase::~TracePhase() {
bharadwaj@4315 3630
bharadwaj@4315 3631 C = Compile::current();
bharadwaj@4315 3632 if (_dolog) {
bharadwaj@4315 3633 _log = C->log();
bharadwaj@4315 3634 } else {
bharadwaj@4315 3635 _log = NULL;
bharadwaj@4315 3636 }
bharadwaj@4315 3637
bharadwaj@4315 3638 #ifdef ASSERT
bharadwaj@4315 3639 if (PrintIdealNodeCount) {
bharadwaj@4315 3640 tty->print_cr("phase name='%s' nodes='%d' live='%d' live_graph_walk='%d'",
bharadwaj@4315 3641 _phase_name, C->unique(), C->live_nodes(), C->count_live_nodes_by_graph_walk());
bharadwaj@4315 3642 }
bharadwaj@4315 3643
bharadwaj@4315 3644 if (VerifyIdealNodeCount) {
bharadwaj@4315 3645 Compile::current()->print_missing_nodes();
bharadwaj@4315 3646 }
bharadwaj@4315 3647 #endif
bharadwaj@4315 3648
duke@435 3649 if (_log != NULL) {
bharadwaj@4315 3650 _log->done("phase name='%s' nodes='%d' live='%d'", _phase_name, C->unique(), C->live_nodes());
duke@435 3651 }
duke@435 3652 }
twisti@2350 3653
twisti@2350 3654 //=============================================================================
twisti@2350 3655 // Two Constant's are equal when the type and the value are equal.
twisti@2350 3656 bool Compile::Constant::operator==(const Constant& other) {
twisti@2350 3657 if (type() != other.type() ) return false;
twisti@2350 3658 if (can_be_reused() != other.can_be_reused()) return false;
twisti@2350 3659 // For floating point values we compare the bit pattern.
twisti@2350 3660 switch (type()) {
coleenp@4037 3661 case T_FLOAT: return (_v._value.i == other._v._value.i);
twisti@2350 3662 case T_LONG:
coleenp@4037 3663 case T_DOUBLE: return (_v._value.j == other._v._value.j);
twisti@2350 3664 case T_OBJECT:
coleenp@4037 3665 case T_ADDRESS: return (_v._value.l == other._v._value.l);
coleenp@4037 3666 case T_VOID: return (_v._value.l == other._v._value.l); // jump-table entries
kvn@4199 3667 case T_METADATA: return (_v._metadata == other._v._metadata);
twisti@2350 3668 default: ShouldNotReachHere();
twisti@2350 3669 }
twisti@2350 3670 return false;
twisti@2350 3671 }
twisti@2350 3672
twisti@2350 3673 static int type_to_size_in_bytes(BasicType t) {
twisti@2350 3674 switch (t) {
twisti@2350 3675 case T_LONG: return sizeof(jlong );
twisti@2350 3676 case T_FLOAT: return sizeof(jfloat );
twisti@2350 3677 case T_DOUBLE: return sizeof(jdouble);
coleenp@4037 3678 case T_METADATA: return sizeof(Metadata*);
twisti@2350 3679 // We use T_VOID as marker for jump-table entries (labels) which
twisti@3310 3680 // need an internal word relocation.
twisti@2350 3681 case T_VOID:
twisti@2350 3682 case T_ADDRESS:
twisti@2350 3683 case T_OBJECT: return sizeof(jobject);
twisti@2350 3684 }
twisti@2350 3685
twisti@2350 3686 ShouldNotReachHere();
twisti@2350 3687 return -1;
twisti@2350 3688 }
twisti@2350 3689
twisti@3310 3690 int Compile::ConstantTable::qsort_comparator(Constant* a, Constant* b) {
twisti@3310 3691 // sort descending
twisti@3310 3692 if (a->freq() > b->freq()) return -1;
twisti@3310 3693 if (a->freq() < b->freq()) return 1;
twisti@3310 3694 return 0;
twisti@3310 3695 }
twisti@3310 3696
twisti@2350 3697 void Compile::ConstantTable::calculate_offsets_and_size() {
twisti@3310 3698 // First, sort the array by frequencies.
twisti@3310 3699 _constants.sort(qsort_comparator);
twisti@3310 3700
twisti@3310 3701 #ifdef ASSERT
twisti@3310 3702 // Make sure all jump-table entries were sorted to the end of the
twisti@3310 3703 // array (they have a negative frequency).
twisti@3310 3704 bool found_void = false;
twisti@3310 3705 for (int i = 0; i < _constants.length(); i++) {
twisti@3310 3706 Constant con = _constants.at(i);
twisti@3310 3707 if (con.type() == T_VOID)
twisti@3310 3708 found_void = true; // jump-tables
twisti@3310 3709 else
twisti@3310 3710 assert(!found_void, "wrong sorting");
twisti@3310 3711 }
twisti@3310 3712 #endif
twisti@3310 3713
twisti@3310 3714 int offset = 0;
twisti@3310 3715 for (int i = 0; i < _constants.length(); i++) {
twisti@3310 3716 Constant* con = _constants.adr_at(i);
twisti@3310 3717
twisti@3310 3718 // Align offset for type.
twisti@3310 3719 int typesize = type_to_size_in_bytes(con->type());
twisti@3310 3720 offset = align_size_up(offset, typesize);
twisti@3310 3721 con->set_offset(offset); // set constant's offset
twisti@3310 3722
twisti@3310 3723 if (con->type() == T_VOID) {
twisti@3310 3724 MachConstantNode* n = (MachConstantNode*) con->get_jobject();
twisti@3310 3725 offset = offset + typesize * n->outcnt(); // expand jump-table
twisti@3310 3726 } else {
twisti@3310 3727 offset = offset + typesize;
twisti@2350 3728 }
twisti@2350 3729 }
twisti@2350 3730
twisti@2350 3731 // Align size up to the next section start (which is insts; see
twisti@2350 3732 // CodeBuffer::align_at_start).
twisti@2350 3733 assert(_size == -1, "already set?");
twisti@3310 3734 _size = align_size_up(offset, CodeEntryAlignment);
twisti@2350 3735 }
twisti@2350 3736
twisti@2350 3737 void Compile::ConstantTable::emit(CodeBuffer& cb) {
twisti@2350 3738 MacroAssembler _masm(&cb);
twisti@3310 3739 for (int i = 0; i < _constants.length(); i++) {
twisti@3310 3740 Constant con = _constants.at(i);
csahu@8316 3741 address constant_addr = NULL;
twisti@3310 3742 switch (con.type()) {
twisti@3310 3743 case T_LONG: constant_addr = _masm.long_constant( con.get_jlong() ); break;
twisti@3310 3744 case T_FLOAT: constant_addr = _masm.float_constant( con.get_jfloat() ); break;
twisti@3310 3745 case T_DOUBLE: constant_addr = _masm.double_constant(con.get_jdouble()); break;
twisti@3310 3746 case T_OBJECT: {
twisti@3310 3747 jobject obj = con.get_jobject();
twisti@3310 3748 int oop_index = _masm.oop_recorder()->find_index(obj);
twisti@3310 3749 constant_addr = _masm.address_constant((address) obj, oop_Relocation::spec(oop_index));
twisti@3310 3750 break;
twisti@3310 3751 }
twisti@3310 3752 case T_ADDRESS: {
twisti@3310 3753 address addr = (address) con.get_jobject();
twisti@3310 3754 constant_addr = _masm.address_constant(addr);
twisti@3310 3755 break;
twisti@3310 3756 }
twisti@3310 3757 // We use T_VOID as marker for jump-table entries (labels) which
twisti@3310 3758 // need an internal word relocation.
twisti@3310 3759 case T_VOID: {
twisti@3310 3760 MachConstantNode* n = (MachConstantNode*) con.get_jobject();
twisti@3310 3761 // Fill the jump-table with a dummy word. The real value is
twisti@3310 3762 // filled in later in fill_jump_table.
twisti@3310 3763 address dummy = (address) n;
twisti@3310 3764 constant_addr = _masm.address_constant(dummy);
twisti@3310 3765 // Expand jump-table
twisti@3310 3766 for (uint i = 1; i < n->outcnt(); i++) {
twisti@3310 3767 address temp_addr = _masm.address_constant(dummy + i);
twisti@3310 3768 assert(temp_addr, "consts section too small");
twisti@2350 3769 }
twisti@3310 3770 break;
twisti@2350 3771 }
coleenp@4037 3772 case T_METADATA: {
coleenp@4037 3773 Metadata* obj = con.get_metadata();
coleenp@4037 3774 int metadata_index = _masm.oop_recorder()->find_index(obj);
coleenp@4037 3775 constant_addr = _masm.address_constant((address) obj, metadata_Relocation::spec(metadata_index));
coleenp@4037 3776 break;
coleenp@4037 3777 }
twisti@3310 3778 default: ShouldNotReachHere();
twisti@3310 3779 }
twisti@3310 3780 assert(constant_addr, "consts section too small");
drchase@6680 3781 assert((constant_addr - _masm.code()->consts()->start()) == con.offset(),
drchase@6680 3782 err_msg_res("must be: %d == %d", (int) (constant_addr - _masm.code()->consts()->start()), (int)(con.offset())));
twisti@2350 3783 }
twisti@2350 3784 }
twisti@2350 3785
twisti@2350 3786 int Compile::ConstantTable::find_offset(Constant& con) const {
twisti@2350 3787 int idx = _constants.find(con);
twisti@2350 3788 assert(idx != -1, "constant must be in constant table");
twisti@2350 3789 int offset = _constants.at(idx).offset();
twisti@2350 3790 assert(offset != -1, "constant table not emitted yet?");
twisti@2350 3791 return offset;
twisti@2350 3792 }
twisti@2350 3793
twisti@2350 3794 void Compile::ConstantTable::add(Constant& con) {
twisti@2350 3795 if (con.can_be_reused()) {
twisti@2350 3796 int idx = _constants.find(con);
twisti@2350 3797 if (idx != -1 && _constants.at(idx).can_be_reused()) {
twisti@3310 3798 _constants.adr_at(idx)->inc_freq(con.freq()); // increase the frequency by the current value
twisti@2350 3799 return;
twisti@2350 3800 }
twisti@2350 3801 }
twisti@2350 3802 (void) _constants.append(con);
twisti@2350 3803 }
twisti@2350 3804
twisti@3310 3805 Compile::Constant Compile::ConstantTable::add(MachConstantNode* n, BasicType type, jvalue value) {
adlertz@5509 3806 Block* b = Compile::current()->cfg()->get_block_for_node(n);
twisti@3310 3807 Constant con(type, value, b->_freq);
twisti@2350 3808 add(con);
twisti@2350 3809 return con;
twisti@2350 3810 }
twisti@2350 3811
coleenp@4037 3812 Compile::Constant Compile::ConstantTable::add(Metadata* metadata) {
coleenp@4037 3813 Constant con(metadata);
coleenp@4037 3814 add(con);
coleenp@4037 3815 return con;
coleenp@4037 3816 }
coleenp@4037 3817
twisti@3310 3818 Compile::Constant Compile::ConstantTable::add(MachConstantNode* n, MachOper* oper) {
twisti@2350 3819 jvalue value;
twisti@2350 3820 BasicType type = oper->type()->basic_type();
twisti@2350 3821 switch (type) {
twisti@2350 3822 case T_LONG: value.j = oper->constantL(); break;
twisti@2350 3823 case T_FLOAT: value.f = oper->constantF(); break;
twisti@2350 3824 case T_DOUBLE: value.d = oper->constantD(); break;
twisti@2350 3825 case T_OBJECT:
twisti@2350 3826 case T_ADDRESS: value.l = (jobject) oper->constant(); break;
coleenp@4037 3827 case T_METADATA: return add((Metadata*)oper->constant()); break;
coleenp@4037 3828 default: guarantee(false, err_msg_res("unhandled type: %s", type2name(type)));
twisti@2350 3829 }
twisti@3310 3830 return add(n, type, value);
twisti@2350 3831 }
twisti@2350 3832
twisti@3310 3833 Compile::Constant Compile::ConstantTable::add_jump_table(MachConstantNode* n) {
twisti@2350 3834 jvalue value;
twisti@2350 3835 // We can use the node pointer here to identify the right jump-table
twisti@2350 3836 // as this method is called from Compile::Fill_buffer right before
twisti@2350 3837 // the MachNodes are emitted and the jump-table is filled (means the
twisti@2350 3838 // MachNode pointers do not change anymore).
twisti@2350 3839 value.l = (jobject) n;
twisti@3310 3840 Constant con(T_VOID, value, next_jump_table_freq(), false); // Labels of a jump-table cannot be reused.
twisti@3310 3841 add(con);
twisti@2350 3842 return con;
twisti@2350 3843 }
twisti@2350 3844
twisti@2350 3845 void Compile::ConstantTable::fill_jump_table(CodeBuffer& cb, MachConstantNode* n, GrowableArray<Label*> labels) const {
twisti@2350 3846 // If called from Compile::scratch_emit_size do nothing.
twisti@2350 3847 if (Compile::current()->in_scratch_emit_size()) return;
twisti@2350 3848
twisti@2350 3849 assert(labels.is_nonempty(), "must be");
kvn@3971 3850 assert((uint) labels.length() == n->outcnt(), err_msg_res("must be equal: %d == %d", labels.length(), n->outcnt()));
twisti@2350 3851
twisti@2350 3852 // Since MachConstantNode::constant_offset() also contains
twisti@2350 3853 // table_base_offset() we need to subtract the table_base_offset()
twisti@2350 3854 // to get the plain offset into the constant table.
twisti@2350 3855 int offset = n->constant_offset() - table_base_offset();
twisti@2350 3856
twisti@2350 3857 MacroAssembler _masm(&cb);
twisti@2350 3858 address* jump_table_base = (address*) (_masm.code()->consts()->start() + offset);
twisti@2350 3859
twisti@3310 3860 for (uint i = 0; i < n->outcnt(); i++) {
twisti@2350 3861 address* constant_addr = &jump_table_base[i];
drchase@6680 3862 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 3863 *constant_addr = cb.consts()->target(*labels.at(i), (address) constant_addr);
twisti@2350 3864 cb.consts()->relocate((address) constant_addr, relocInfo::internal_word_type);
twisti@2350 3865 }
twisti@2350 3866 }
roland@4357 3867
roland@4357 3868 void Compile::dump_inlining() {
kvn@5763 3869 if (print_inlining() || print_intrinsics()) {
roland@4409 3870 // Print inlining message for candidates that we couldn't inline
roland@4409 3871 // for lack of space or non constant receiver
roland@4409 3872 for (int i = 0; i < _late_inlines.length(); i++) {
roland@4409 3873 CallGenerator* cg = _late_inlines.at(i);
roland@4409 3874 cg->print_inlining_late("live nodes > LiveNodeCountInliningCutoff");
roland@4409 3875 }
roland@4409 3876 Unique_Node_List useful;
roland@4409 3877 useful.push(root());
roland@4409 3878 for (uint next = 0; next < useful.size(); ++next) {
roland@4409 3879 Node* n = useful.at(next);
roland@4409 3880 if (n->is_Call() && n->as_Call()->generator() != NULL && n->as_Call()->generator()->call_node() == n) {
roland@4409 3881 CallNode* call = n->as_Call();
roland@4409 3882 CallGenerator* cg = call->generator();
roland@4409 3883 cg->print_inlining_late("receiver not constant");
roland@4409 3884 }
roland@4409 3885 uint max = n->len();
roland@4409 3886 for ( uint i = 0; i < max; ++i ) {
roland@4409 3887 Node *m = n->in(i);
roland@4409 3888 if ( m == NULL ) continue;
roland@4409 3889 useful.push(m);
roland@4409 3890 }
roland@4409 3891 }
roland@4357 3892 for (int i = 0; i < _print_inlining_list->length(); i++) {
drchase@6680 3893 tty->print("%s", _print_inlining_list->adr_at(i)->ss()->as_string());
roland@4357 3894 }
roland@4357 3895 }
roland@4357 3896 }
roland@4589 3897
kvn@6217 3898 // Dump inlining replay data to the stream.
kvn@6217 3899 // Don't change thread state and acquire any locks.
kvn@6217 3900 void Compile::dump_inline_data(outputStream* out) {
kvn@6217 3901 InlineTree* inl_tree = ilt();
kvn@6217 3902 if (inl_tree != NULL) {
kvn@6217 3903 out->print(" inline %d", inl_tree->count());
kvn@6217 3904 inl_tree->dump_replay_data(out);
kvn@6217 3905 }
kvn@6217 3906 }
kvn@6217 3907
roland@4589 3908 int Compile::cmp_expensive_nodes(Node* n1, Node* n2) {
roland@4589 3909 if (n1->Opcode() < n2->Opcode()) return -1;
roland@4589 3910 else if (n1->Opcode() > n2->Opcode()) return 1;
roland@4589 3911
roland@4589 3912 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 3913 for (uint i = 1; i < n1->req(); i++) {
roland@4589 3914 if (n1->in(i) < n2->in(i)) return -1;
roland@4589 3915 else if (n1->in(i) > n2->in(i)) return 1;
roland@4589 3916 }
roland@4589 3917
roland@4589 3918 return 0;
roland@4589 3919 }
roland@4589 3920
roland@4589 3921 int Compile::cmp_expensive_nodes(Node** n1p, Node** n2p) {
roland@4589 3922 Node* n1 = *n1p;
roland@4589 3923 Node* n2 = *n2p;
roland@4589 3924
roland@4589 3925 return cmp_expensive_nodes(n1, n2);
roland@4589 3926 }
roland@4589 3927
roland@4589 3928 void Compile::sort_expensive_nodes() {
roland@4589 3929 if (!expensive_nodes_sorted()) {
roland@4589 3930 _expensive_nodes->sort(cmp_expensive_nodes);
roland@4589 3931 }
roland@4589 3932 }
roland@4589 3933
roland@4589 3934 bool Compile::expensive_nodes_sorted() const {
roland@4589 3935 for (int i = 1; i < _expensive_nodes->length(); i++) {
roland@4589 3936 if (cmp_expensive_nodes(_expensive_nodes->adr_at(i), _expensive_nodes->adr_at(i-1)) < 0) {
roland@4589 3937 return false;
roland@4589 3938 }
roland@4589 3939 }
roland@4589 3940 return true;
roland@4589 3941 }
roland@4589 3942
roland@4589 3943 bool Compile::should_optimize_expensive_nodes(PhaseIterGVN &igvn) {
roland@4589 3944 if (_expensive_nodes->length() == 0) {
roland@4589 3945 return false;
roland@4589 3946 }
roland@4589 3947
roland@4589 3948 assert(OptimizeExpensiveOps, "optimization off?");
roland@4589 3949
roland@4589 3950 // Take this opportunity to remove dead nodes from the list
roland@4589 3951 int j = 0;
roland@4589 3952 for (int i = 0; i < _expensive_nodes->length(); i++) {
roland@4589 3953 Node* n = _expensive_nodes->at(i);
roland@4589 3954 if (!n->is_unreachable(igvn)) {
roland@4589 3955 assert(n->is_expensive(), "should be expensive");
roland@4589 3956 _expensive_nodes->at_put(j, n);
roland@4589 3957 j++;
roland@4589 3958 }
roland@4589 3959 }
roland@4589 3960 _expensive_nodes->trunc_to(j);
roland@4589 3961
roland@4589 3962 // Then sort the list so that similar nodes are next to each other
roland@4589 3963 // and check for at least two nodes of identical kind with same data
roland@4589 3964 // inputs.
roland@4589 3965 sort_expensive_nodes();
roland@4589 3966
roland@4589 3967 for (int i = 0; i < _expensive_nodes->length()-1; i++) {
roland@4589 3968 if (cmp_expensive_nodes(_expensive_nodes->adr_at(i), _expensive_nodes->adr_at(i+1)) == 0) {
roland@4589 3969 return true;
roland@4589 3970 }
roland@4589 3971 }
roland@4589 3972
roland@4589 3973 return false;
roland@4589 3974 }
roland@4589 3975
roland@4589 3976 void Compile::cleanup_expensive_nodes(PhaseIterGVN &igvn) {
roland@4589 3977 if (_expensive_nodes->length() == 0) {
roland@4589 3978 return;
roland@4589 3979 }
roland@4589 3980
roland@4589 3981 assert(OptimizeExpensiveOps, "optimization off?");
roland@4589 3982
roland@4589 3983 // Sort to bring similar nodes next to each other and clear the
roland@4589 3984 // control input of nodes for which there's only a single copy.
roland@4589 3985 sort_expensive_nodes();
roland@4589 3986
roland@4589 3987 int j = 0;
roland@4589 3988 int identical = 0;
roland@4589 3989 int i = 0;
roland@4589 3990 for (; i < _expensive_nodes->length()-1; i++) {
roland@4589 3991 assert(j <= i, "can't write beyond current index");
roland@4589 3992 if (_expensive_nodes->at(i)->Opcode() == _expensive_nodes->at(i+1)->Opcode()) {
roland@4589 3993 identical++;
roland@4589 3994 _expensive_nodes->at_put(j++, _expensive_nodes->at(i));
roland@4589 3995 continue;
roland@4589 3996 }
roland@4589 3997 if (identical > 0) {
roland@4589 3998 _expensive_nodes->at_put(j++, _expensive_nodes->at(i));
roland@4589 3999 identical = 0;
roland@4589 4000 } else {
roland@4589 4001 Node* n = _expensive_nodes->at(i);
roland@4589 4002 igvn.hash_delete(n);
roland@4589 4003 n->set_req(0, NULL);
roland@4589 4004 igvn.hash_insert(n);
roland@4589 4005 }
roland@4589 4006 }
roland@4589 4007 if (identical > 0) {
roland@4589 4008 _expensive_nodes->at_put(j++, _expensive_nodes->at(i));
roland@4589 4009 } else if (_expensive_nodes->length() >= 1) {
roland@4589 4010 Node* n = _expensive_nodes->at(i);
roland@4589 4011 igvn.hash_delete(n);
roland@4589 4012 n->set_req(0, NULL);
roland@4589 4013 igvn.hash_insert(n);
roland@4589 4014 }
roland@4589 4015 _expensive_nodes->trunc_to(j);
roland@4589 4016 }
roland@4589 4017
roland@4589 4018 void Compile::add_expensive_node(Node * n) {
roland@4589 4019 assert(!_expensive_nodes->contains(n), "duplicate entry in expensive list");
roland@4589 4020 assert(n->is_expensive(), "expensive nodes with non-null control here only");
roland@4589 4021 assert(!n->is_CFG() && !n->is_Mem(), "no cfg or memory nodes here");
roland@4589 4022 if (OptimizeExpensiveOps) {
roland@4589 4023 _expensive_nodes->append(n);
roland@4589 4024 } else {
roland@4589 4025 // Clear control input and let IGVN optimize expensive nodes if
roland@4589 4026 // OptimizeExpensiveOps is off.
roland@4589 4027 n->set_req(0, NULL);
roland@4589 4028 }
roland@4589 4029 }
shade@4691 4030
roland@5991 4031 /**
roland@5991 4032 * Remove the speculative part of types and clean up the graph
roland@5991 4033 */
roland@5991 4034 void Compile::remove_speculative_types(PhaseIterGVN &igvn) {
roland@5991 4035 if (UseTypeSpeculation) {
roland@5991 4036 Unique_Node_List worklist;
roland@5991 4037 worklist.push(root());
roland@5991 4038 int modified = 0;
roland@5991 4039 // Go over all type nodes that carry a speculative type, drop the
roland@5991 4040 // speculative part of the type and enqueue the node for an igvn
roland@5991 4041 // which may optimize it out.
roland@5991 4042 for (uint next = 0; next < worklist.size(); ++next) {
roland@5991 4043 Node *n = worklist.at(next);
roland@6313 4044 if (n->is_Type()) {
roland@5991 4045 TypeNode* tn = n->as_Type();
roland@6313 4046 const Type* t = tn->type();
roland@6313 4047 const Type* t_no_spec = t->remove_speculative();
roland@6313 4048 if (t_no_spec != t) {
roland@6313 4049 bool in_hash = igvn.hash_delete(n);
roland@6313 4050 assert(in_hash, "node should be in igvn hash table");
roland@6313 4051 tn->set_type(t_no_spec);
roland@6313 4052 igvn.hash_insert(n);
roland@6313 4053 igvn._worklist.push(n); // give it a chance to go away
roland@6313 4054 modified++;
roland@6313 4055 }
roland@5991 4056 }
roland@5991 4057 uint max = n->len();
roland@5991 4058 for( uint i = 0; i < max; ++i ) {
roland@5991 4059 Node *m = n->in(i);
roland@5991 4060 if (not_a_node(m)) continue;
roland@5991 4061 worklist.push(m);
roland@5991 4062 }
roland@5991 4063 }
roland@5991 4064 // Drop the speculative part of all types in the igvn's type table
roland@5991 4065 igvn.remove_speculative_types();
roland@5991 4066 if (modified > 0) {
roland@5991 4067 igvn.optimize();
roland@5991 4068 }
roland@6313 4069 #ifdef ASSERT
roland@6313 4070 // Verify that after the IGVN is over no speculative type has resurfaced
roland@6313 4071 worklist.clear();
roland@6313 4072 worklist.push(root());
roland@6313 4073 for (uint next = 0; next < worklist.size(); ++next) {
roland@6313 4074 Node *n = worklist.at(next);
anoll@6638 4075 const Type* t = igvn.type_or_null(n);
anoll@6638 4076 assert((t == NULL) || (t == t->remove_speculative()), "no more speculative types");
roland@6313 4077 if (n->is_Type()) {
roland@6313 4078 t = n->as_Type()->type();
roland@6313 4079 assert(t == t->remove_speculative(), "no more speculative types");
roland@6313 4080 }
roland@6313 4081 uint max = n->len();
roland@6313 4082 for( uint i = 0; i < max; ++i ) {
roland@6313 4083 Node *m = n->in(i);
roland@6313 4084 if (not_a_node(m)) continue;
roland@6313 4085 worklist.push(m);
roland@6313 4086 }
roland@6313 4087 }
roland@6313 4088 igvn.check_no_speculative_types();
roland@6313 4089 #endif
roland@5991 4090 }
roland@5991 4091 }
roland@5991 4092
thartmann@8476 4093 // Convert integer value to a narrowed long type dependent on ctrl (for example, a range check)
thartmann@8476 4094 Node* Compile::constrained_convI2L(PhaseGVN* phase, Node* value, const TypeInt* itype, Node* ctrl) {
thartmann@8476 4095 if (ctrl != NULL) {
thartmann@8476 4096 // Express control dependency by a CastII node with a narrow type.
thartmann@8476 4097 value = new (phase->C) CastIINode(value, itype, false, true /* range check dependency */);
thartmann@8476 4098 // Make the CastII node dependent on the control input to prevent the narrowed ConvI2L
thartmann@8476 4099 // node from floating above the range check during loop optimizations. Otherwise, the
thartmann@8476 4100 // ConvI2L node may be eliminated independently of the range check, causing the data path
thartmann@8476 4101 // to become TOP while the control path is still there (although it's unreachable).
thartmann@8476 4102 value->set_req(0, ctrl);
thartmann@8476 4103 // Save CastII node to remove it after loop optimizations.
thartmann@8476 4104 phase->C->add_range_check_cast(value);
thartmann@8476 4105 value = phase->transform(value);
thartmann@8476 4106 }
thartmann@8476 4107 const TypeLong* ltype = TypeLong::make(itype->_lo, itype->_hi, itype->_widen);
thartmann@8476 4108 return phase->transform(new (phase->C) ConvI2LNode(value, ltype));
thartmann@8476 4109 }
thartmann@8476 4110
shade@4691 4111 // Auxiliary method to support randomized stressing/fuzzing.
shade@4691 4112 //
shade@4691 4113 // This method can be called the arbitrary number of times, with current count
shade@4691 4114 // as the argument. The logic allows selecting a single candidate from the
shade@4691 4115 // running list of candidates as follows:
shade@4691 4116 // int count = 0;
shade@4691 4117 // Cand* selected = null;
shade@4691 4118 // while(cand = cand->next()) {
shade@4691 4119 // if (randomized_select(++count)) {
shade@4691 4120 // selected = cand;
shade@4691 4121 // }
shade@4691 4122 // }
shade@4691 4123 //
shade@4691 4124 // Including count equalizes the chances any candidate is "selected".
shade@4691 4125 // This is useful when we don't have the complete list of candidates to choose
shade@4691 4126 // from uniformly. In this case, we need to adjust the randomicity of the
shade@4691 4127 // selection, or else we will end up biasing the selection towards the latter
shade@4691 4128 // candidates.
shade@4691 4129 //
shade@4691 4130 // Quick back-envelope calculation shows that for the list of n candidates
shade@4691 4131 // the equal probability for the candidate to persist as "best" can be
shade@4691 4132 // achieved by replacing it with "next" k-th candidate with the probability
shade@4691 4133 // of 1/k. It can be easily shown that by the end of the run, the
shade@4691 4134 // probability for any candidate is converged to 1/n, thus giving the
shade@4691 4135 // uniform distribution among all the candidates.
shade@4691 4136 //
shade@4691 4137 // We don't care about the domain size as long as (RANDOMIZED_DOMAIN / count) is large.
shade@4691 4138 #define RANDOMIZED_DOMAIN_POW 29
shade@4691 4139 #define RANDOMIZED_DOMAIN (1 << RANDOMIZED_DOMAIN_POW)
shade@4691 4140 #define RANDOMIZED_DOMAIN_MASK ((1 << (RANDOMIZED_DOMAIN_POW + 1)) - 1)
shade@4691 4141 bool Compile::randomized_select(int count) {
shade@4691 4142 assert(count > 0, "only positive");
shade@4691 4143 return (os::random() & RANDOMIZED_DOMAIN_MASK) < (RANDOMIZED_DOMAIN / count);
shade@4691 4144 }

mercurial