src/share/vm/opto/escape.cpp

Tue, 02 Jul 2013 20:42:12 -0400

author
drchase
date
Tue, 02 Jul 2013 20:42:12 -0400
changeset 5353
b800986664f4
parent 5237
f2110083203d
child 5910
6171eb9da4fd
permissions
-rw-r--r--

7088419: Use x86 Hardware CRC32 Instruction with java.util.zip.CRC32
Summary: add intrinsics using new instruction to interpreter, C1, C2, for suitable x86; add test
Reviewed-by: kvn, twisti

duke@435 1 /*
sla@5237 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "ci/bcEscapeAnalyzer.hpp"
kvn@3651 27 #include "compiler/compileLog.hpp"
stefank@2314 28 #include "libadt/vectset.hpp"
stefank@2314 29 #include "memory/allocation.hpp"
stefank@2314 30 #include "opto/c2compiler.hpp"
stefank@2314 31 #include "opto/callnode.hpp"
stefank@2314 32 #include "opto/cfgnode.hpp"
stefank@2314 33 #include "opto/compile.hpp"
stefank@2314 34 #include "opto/escape.hpp"
stefank@2314 35 #include "opto/phaseX.hpp"
stefank@2314 36 #include "opto/rootnode.hpp"
duke@435 37
kvn@1989 38 ConnectionGraph::ConnectionGraph(Compile * C, PhaseIterGVN *igvn) :
kvn@3651 39 _nodes(C->comp_arena(), C->unique(), C->unique(), NULL),
kvn@679 40 _collecting(true),
kvn@3651 41 _verify(false),
kvn@679 42 _compile(C),
kvn@1989 43 _igvn(igvn),
kvn@679 44 _node_map(C->comp_arena()) {
kvn@3651 45 // Add unknown java object.
kvn@3651 46 add_java_object(C->top(), PointsToNode::GlobalEscape);
kvn@3651 47 phantom_obj = ptnode_adr(C->top()->_idx)->as_JavaObject();
kvn@688 48 // Add ConP(#NULL) and ConN(#NULL) nodes.
kvn@688 49 Node* oop_null = igvn->zerocon(T_OBJECT);
kvn@3651 50 assert(oop_null->_idx < nodes_size(), "should be created already");
kvn@3651 51 add_java_object(oop_null, PointsToNode::NoEscape);
kvn@3651 52 null_obj = ptnode_adr(oop_null->_idx)->as_JavaObject();
kvn@688 53 if (UseCompressedOops) {
kvn@688 54 Node* noop_null = igvn->zerocon(T_NARROWOOP);
kvn@3651 55 assert(noop_null->_idx < nodes_size(), "should be created already");
kvn@3651 56 map_ideal_node(noop_null, null_obj);
kvn@688 57 }
kvn@3309 58 _pcmp_neq = NULL; // Should be initialized
kvn@3309 59 _pcmp_eq = NULL;
duke@435 60 }
duke@435 61
kvn@3651 62 bool ConnectionGraph::has_candidates(Compile *C) {
kvn@3651 63 // EA brings benefits only when the code has allocations and/or locks which
kvn@3651 64 // are represented by ideal Macro nodes.
kvn@3651 65 int cnt = C->macro_count();
kvn@5110 66 for (int i = 0; i < cnt; i++) {
kvn@3651 67 Node *n = C->macro_node(i);
kvn@5110 68 if (n->is_Allocate())
kvn@3651 69 return true;
kvn@5110 70 if (n->is_Lock()) {
kvn@3651 71 Node* obj = n->as_Lock()->obj_node()->uncast();
kvn@5110 72 if (!(obj->is_Parm() || obj->is_Con()))
kvn@3651 73 return true;
kvn@3318 74 }
kvn@5110 75 if (n->is_CallStaticJava() &&
kvn@5110 76 n->as_CallStaticJava()->is_boxing_method()) {
kvn@5110 77 return true;
kvn@5110 78 }
kvn@3318 79 }
kvn@3651 80 return false;
duke@435 81 }
duke@435 82
kvn@3651 83 void ConnectionGraph::do_analysis(Compile *C, PhaseIterGVN *igvn) {
kvn@3651 84 Compile::TracePhase t2("escapeAnalysis", &Phase::_t_escapeAnalysis, true);
kvn@3651 85 ResourceMark rm;
duke@435 86
kvn@3651 87 // Add ConP#NULL and ConN#NULL nodes before ConnectionGraph construction
kvn@3651 88 // to create space for them in ConnectionGraph::_nodes[].
kvn@3651 89 Node* oop_null = igvn->zerocon(T_OBJECT);
kvn@3651 90 Node* noop_null = igvn->zerocon(T_NARROWOOP);
kvn@3651 91 ConnectionGraph* congraph = new(C->comp_arena()) ConnectionGraph(C, igvn);
kvn@3651 92 // Perform escape analysis
kvn@3651 93 if (congraph->compute_escape()) {
kvn@3651 94 // There are non escaping objects.
kvn@3651 95 C->set_congraph(congraph);
kvn@3651 96 }
kvn@3651 97 // Cleanup.
kvn@3651 98 if (oop_null->outcnt() == 0)
kvn@3651 99 igvn->hash_delete(oop_null);
kvn@3651 100 if (noop_null->outcnt() == 0)
kvn@3651 101 igvn->hash_delete(noop_null);
duke@435 102 }
duke@435 103
kvn@3651 104 bool ConnectionGraph::compute_escape() {
kvn@3651 105 Compile* C = _compile;
kvn@3651 106 PhaseGVN* igvn = _igvn;
kvn@3651 107
kvn@3651 108 // Worklists used by EA.
kvn@3651 109 Unique_Node_List delayed_worklist;
kvn@3651 110 GrowableArray<Node*> alloc_worklist;
kvn@3651 111 GrowableArray<Node*> ptr_cmp_worklist;
kvn@3651 112 GrowableArray<Node*> storestore_worklist;
kvn@3651 113 GrowableArray<PointsToNode*> ptnodes_worklist;
kvn@3651 114 GrowableArray<JavaObjectNode*> java_objects_worklist;
kvn@3651 115 GrowableArray<JavaObjectNode*> non_escaped_worklist;
kvn@3651 116 GrowableArray<FieldNode*> oop_fields_worklist;
kvn@3651 117 DEBUG_ONLY( GrowableArray<Node*> addp_worklist; )
kvn@3651 118
kvn@3651 119 { Compile::TracePhase t3("connectionGraph", &Phase::_t_connectionGraph, true);
kvn@3651 120
kvn@3651 121 // 1. Populate Connection Graph (CG) with PointsTo nodes.
kvn@5110 122 ideal_nodes.map(C->live_nodes(), NULL); // preallocate space
kvn@3651 123 // Initialize worklist
kvn@3651 124 if (C->root() != NULL) {
kvn@3651 125 ideal_nodes.push(C->root());
kvn@3651 126 }
kvn@3651 127 for( uint next = 0; next < ideal_nodes.size(); ++next ) {
kvn@3651 128 Node* n = ideal_nodes.at(next);
kvn@3651 129 // Create PointsTo nodes and add them to Connection Graph. Called
kvn@3651 130 // only once per ideal node since ideal_nodes is Unique_Node list.
kvn@3651 131 add_node_to_connection_graph(n, &delayed_worklist);
kvn@3651 132 PointsToNode* ptn = ptnode_adr(n->_idx);
kvn@3651 133 if (ptn != NULL) {
kvn@3651 134 ptnodes_worklist.append(ptn);
kvn@3651 135 if (ptn->is_JavaObject()) {
kvn@3651 136 java_objects_worklist.append(ptn->as_JavaObject());
kvn@3651 137 if ((n->is_Allocate() || n->is_CallStaticJava()) &&
kvn@3651 138 (ptn->escape_state() < PointsToNode::GlobalEscape)) {
kvn@3651 139 // Only allocations and java static calls results are interesting.
kvn@3651 140 non_escaped_worklist.append(ptn->as_JavaObject());
kvn@3651 141 }
kvn@3651 142 } else if (ptn->is_Field() && ptn->as_Field()->is_oop()) {
kvn@3651 143 oop_fields_worklist.append(ptn->as_Field());
kvn@3651 144 }
kvn@3651 145 }
kvn@3651 146 if (n->is_MergeMem()) {
kvn@3651 147 // Collect all MergeMem nodes to add memory slices for
kvn@3651 148 // scalar replaceable objects in split_unique_types().
kvn@3651 149 _mergemem_worklist.append(n->as_MergeMem());
kvn@3651 150 } else if (OptimizePtrCompare && n->is_Cmp() &&
kvn@3651 151 (n->Opcode() == Op_CmpP || n->Opcode() == Op_CmpN)) {
kvn@3651 152 // Collect compare pointers nodes.
kvn@3651 153 ptr_cmp_worklist.append(n);
kvn@3651 154 } else if (n->is_MemBarStoreStore()) {
kvn@3651 155 // Collect all MemBarStoreStore nodes so that depending on the
kvn@3651 156 // escape status of the associated Allocate node some of them
kvn@3651 157 // may be eliminated.
kvn@3651 158 storestore_worklist.append(n);
kvn@5110 159 } else if (n->is_MemBar() && (n->Opcode() == Op_MemBarRelease) &&
kvn@5110 160 (n->req() > MemBarNode::Precedent)) {
kvn@5110 161 record_for_optimizer(n);
kvn@3651 162 #ifdef ASSERT
kvn@5110 163 } else if (n->is_AddP()) {
kvn@3651 164 // Collect address nodes for graph verification.
kvn@3651 165 addp_worklist.append(n);
kvn@3651 166 #endif
kvn@3651 167 }
kvn@3651 168 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
kvn@3651 169 Node* m = n->fast_out(i); // Get user
kvn@3651 170 ideal_nodes.push(m);
kvn@3651 171 }
kvn@3651 172 }
kvn@3651 173 if (non_escaped_worklist.length() == 0) {
kvn@3651 174 _collecting = false;
kvn@3651 175 return false; // Nothing to do.
kvn@3651 176 }
kvn@3651 177 // Add final simple edges to graph.
kvn@3651 178 while(delayed_worklist.size() > 0) {
kvn@3651 179 Node* n = delayed_worklist.pop();
kvn@3651 180 add_final_edges(n);
kvn@3651 181 }
kvn@3651 182 int ptnodes_length = ptnodes_worklist.length();
kvn@3651 183
kvn@3651 184 #ifdef ASSERT
kvn@3651 185 if (VerifyConnectionGraph) {
kvn@3651 186 // Verify that no new simple edges could be created and all
kvn@3651 187 // local vars has edges.
kvn@3651 188 _verify = true;
kvn@3651 189 for (int next = 0; next < ptnodes_length; ++next) {
kvn@3651 190 PointsToNode* ptn = ptnodes_worklist.at(next);
kvn@3651 191 add_final_edges(ptn->ideal_node());
kvn@3651 192 if (ptn->is_LocalVar() && ptn->edge_count() == 0) {
kvn@3651 193 ptn->dump();
kvn@3651 194 assert(ptn->as_LocalVar()->edge_count() > 0, "sanity");
kvn@3651 195 }
kvn@3651 196 }
kvn@3651 197 _verify = false;
kvn@3651 198 }
kvn@3651 199 #endif
kvn@3651 200
kvn@3651 201 // 2. Finish Graph construction by propagating references to all
kvn@3651 202 // java objects through graph.
kvn@3651 203 if (!complete_connection_graph(ptnodes_worklist, non_escaped_worklist,
kvn@3651 204 java_objects_worklist, oop_fields_worklist)) {
kvn@3651 205 // All objects escaped or hit time or iterations limits.
kvn@3651 206 _collecting = false;
kvn@3651 207 return false;
kvn@3651 208 }
kvn@3651 209
kvn@3651 210 // 3. Adjust scalar_replaceable state of nonescaping objects and push
kvn@3651 211 // scalar replaceable allocations on alloc_worklist for processing
kvn@3651 212 // in split_unique_types().
kvn@3651 213 int non_escaped_length = non_escaped_worklist.length();
kvn@3651 214 for (int next = 0; next < non_escaped_length; next++) {
kvn@3651 215 JavaObjectNode* ptn = non_escaped_worklist.at(next);
kvn@5110 216 bool noescape = (ptn->escape_state() == PointsToNode::NoEscape);
kvn@5110 217 Node* n = ptn->ideal_node();
kvn@5110 218 if (n->is_Allocate()) {
kvn@5110 219 n->as_Allocate()->_is_non_escaping = noescape;
kvn@5110 220 }
kvn@5110 221 if (n->is_CallStaticJava()) {
kvn@5110 222 n->as_CallStaticJava()->_is_non_escaping = noescape;
kvn@5110 223 }
kvn@5110 224 if (noescape && ptn->scalar_replaceable()) {
kvn@3651 225 adjust_scalar_replaceable_state(ptn);
kvn@3651 226 if (ptn->scalar_replaceable()) {
kvn@3651 227 alloc_worklist.append(ptn->ideal_node());
kvn@3651 228 }
kvn@3651 229 }
kvn@3651 230 }
kvn@3651 231
kvn@3651 232 #ifdef ASSERT
kvn@3651 233 if (VerifyConnectionGraph) {
kvn@3651 234 // Verify that graph is complete - no new edges could be added or needed.
kvn@3651 235 verify_connection_graph(ptnodes_worklist, non_escaped_worklist,
kvn@3651 236 java_objects_worklist, addp_worklist);
kvn@3651 237 }
kvn@3651 238 assert(C->unique() == nodes_size(), "no new ideal nodes should be added during ConnectionGraph build");
kvn@3651 239 assert(null_obj->escape_state() == PointsToNode::NoEscape &&
kvn@3651 240 null_obj->edge_count() == 0 &&
kvn@3651 241 !null_obj->arraycopy_src() &&
kvn@3651 242 !null_obj->arraycopy_dst(), "sanity");
kvn@3651 243 #endif
kvn@3651 244
kvn@3651 245 _collecting = false;
kvn@3651 246
kvn@3651 247 } // TracePhase t3("connectionGraph")
kvn@3651 248
kvn@3651 249 // 4. Optimize ideal graph based on EA information.
kvn@3651 250 bool has_non_escaping_obj = (non_escaped_worklist.length() > 0);
kvn@3651 251 if (has_non_escaping_obj) {
kvn@3651 252 optimize_ideal_graph(ptr_cmp_worklist, storestore_worklist);
kvn@3651 253 }
kvn@3651 254
kvn@3651 255 #ifndef PRODUCT
kvn@3651 256 if (PrintEscapeAnalysis) {
kvn@3651 257 dump(ptnodes_worklist); // Dump ConnectionGraph
kvn@3651 258 }
kvn@3651 259 #endif
kvn@3651 260
kvn@3651 261 bool has_scalar_replaceable_candidates = (alloc_worklist.length() > 0);
kvn@3651 262 #ifdef ASSERT
kvn@3651 263 if (VerifyConnectionGraph) {
kvn@3651 264 int alloc_length = alloc_worklist.length();
kvn@3651 265 for (int next = 0; next < alloc_length; ++next) {
kvn@3651 266 Node* n = alloc_worklist.at(next);
kvn@3651 267 PointsToNode* ptn = ptnode_adr(n->_idx);
kvn@3651 268 assert(ptn->escape_state() == PointsToNode::NoEscape && ptn->scalar_replaceable(), "sanity");
kvn@3651 269 }
kvn@3651 270 }
kvn@3651 271 #endif
kvn@3651 272
kvn@3651 273 // 5. Separate memory graph for scalar replaceable allcations.
kvn@3651 274 if (has_scalar_replaceable_candidates &&
kvn@3651 275 C->AliasLevel() >= 3 && EliminateAllocations) {
kvn@3651 276 // Now use the escape information to create unique types for
kvn@3651 277 // scalar replaceable objects.
kvn@3651 278 split_unique_types(alloc_worklist);
kvn@3651 279 if (C->failing()) return false;
sla@5237 280 C->print_method(PHASE_AFTER_EA, 2);
kvn@3651 281
kvn@3651 282 #ifdef ASSERT
kvn@3651 283 } else if (Verbose && (PrintEscapeAnalysis || PrintEliminateAllocations)) {
kvn@3651 284 tty->print("=== No allocations eliminated for ");
kvn@3651 285 C->method()->print_short_name();
kvn@3651 286 if(!EliminateAllocations) {
kvn@3651 287 tty->print(" since EliminateAllocations is off ===");
kvn@3651 288 } else if(!has_scalar_replaceable_candidates) {
kvn@3651 289 tty->print(" since there are no scalar replaceable candidates ===");
kvn@3651 290 } else if(C->AliasLevel() < 3) {
kvn@3651 291 tty->print(" since AliasLevel < 3 ===");
kvn@3651 292 }
kvn@3651 293 tty->cr();
kvn@3651 294 #endif
kvn@3651 295 }
kvn@3651 296 return has_non_escaping_obj;
kvn@3651 297 }
kvn@3651 298
roland@4106 299 // Utility function for nodes that load an object
roland@4106 300 void ConnectionGraph::add_objload_to_connection_graph(Node *n, Unique_Node_List *delayed_worklist) {
roland@4106 301 // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because
roland@4106 302 // ThreadLocal has RawPtr type.
roland@4106 303 const Type* t = _igvn->type(n);
roland@4106 304 if (t->make_ptr() != NULL) {
roland@4106 305 Node* adr = n->in(MemNode::Address);
roland@4106 306 #ifdef ASSERT
roland@4106 307 if (!adr->is_AddP()) {
roland@4106 308 assert(_igvn->type(adr)->isa_rawptr(), "sanity");
roland@4106 309 } else {
roland@4106 310 assert((ptnode_adr(adr->_idx) == NULL ||
roland@4106 311 ptnode_adr(adr->_idx)->as_Field()->is_oop()), "sanity");
roland@4106 312 }
roland@4106 313 #endif
roland@4106 314 add_local_var_and_edge(n, PointsToNode::NoEscape,
roland@4106 315 adr, delayed_worklist);
roland@4106 316 }
roland@4106 317 }
roland@4106 318
kvn@3651 319 // Populate Connection Graph with PointsTo nodes and create simple
kvn@3651 320 // connection graph edges.
kvn@3651 321 void ConnectionGraph::add_node_to_connection_graph(Node *n, Unique_Node_List *delayed_worklist) {
kvn@3651 322 assert(!_verify, "this method sould not be called for verification");
kvn@3651 323 PhaseGVN* igvn = _igvn;
kvn@3651 324 uint n_idx = n->_idx;
kvn@3651 325 PointsToNode* n_ptn = ptnode_adr(n_idx);
kvn@3651 326 if (n_ptn != NULL)
kvn@3651 327 return; // No need to redefine PointsTo node during first iteration.
kvn@3651 328
kvn@3651 329 if (n->is_Call()) {
kvn@3651 330 // Arguments to allocation and locking don't escape.
kvn@3651 331 if (n->is_AbstractLock()) {
kvn@3651 332 // Put Lock and Unlock nodes on IGVN worklist to process them during
kvn@3651 333 // first IGVN optimization when escape information is still available.
kvn@3651 334 record_for_optimizer(n);
kvn@3651 335 } else if (n->is_Allocate()) {
kvn@3651 336 add_call_node(n->as_Call());
kvn@3651 337 record_for_optimizer(n);
kvn@3651 338 } else {
kvn@3651 339 if (n->is_CallStaticJava()) {
kvn@3651 340 const char* name = n->as_CallStaticJava()->_name;
kvn@3651 341 if (name != NULL && strcmp(name, "uncommon_trap") == 0)
kvn@3651 342 return; // Skip uncommon traps
kvn@3651 343 }
kvn@3651 344 // Don't mark as processed since call's arguments have to be processed.
kvn@3651 345 delayed_worklist->push(n);
kvn@3651 346 // Check if a call returns an object.
kvn@5110 347 if ((n->as_Call()->returns_pointer() &&
kvn@5110 348 n->as_Call()->proj_out(TypeFunc::Parms) != NULL) ||
kvn@5110 349 (n->is_CallStaticJava() &&
kvn@5110 350 n->as_CallStaticJava()->is_boxing_method())) {
kvn@3651 351 add_call_node(n->as_Call());
kvn@3651 352 }
kvn@3651 353 }
kvn@3651 354 return;
kvn@3651 355 }
kvn@3651 356 // Put this check here to process call arguments since some call nodes
kvn@3651 357 // point to phantom_obj.
kvn@3651 358 if (n_ptn == phantom_obj || n_ptn == null_obj)
kvn@3651 359 return; // Skip predefined nodes.
kvn@3651 360
kvn@3651 361 int opcode = n->Opcode();
kvn@3651 362 switch (opcode) {
kvn@3651 363 case Op_AddP: {
kvn@3651 364 Node* base = get_addp_base(n);
kvn@3651 365 PointsToNode* ptn_base = ptnode_adr(base->_idx);
kvn@3651 366 // Field nodes are created for all field types. They are used in
kvn@3651 367 // adjust_scalar_replaceable_state() and split_unique_types().
kvn@3651 368 // Note, non-oop fields will have only base edges in Connection
kvn@3651 369 // Graph because such fields are not used for oop loads and stores.
kvn@3651 370 int offset = address_offset(n, igvn);
kvn@3651 371 add_field(n, PointsToNode::NoEscape, offset);
kvn@3651 372 if (ptn_base == NULL) {
kvn@3651 373 delayed_worklist->push(n); // Process it later.
kvn@3651 374 } else {
kvn@3651 375 n_ptn = ptnode_adr(n_idx);
kvn@3651 376 add_base(n_ptn->as_Field(), ptn_base);
kvn@3651 377 }
kvn@3651 378 break;
kvn@3651 379 }
kvn@3651 380 case Op_CastX2P: {
kvn@3651 381 map_ideal_node(n, phantom_obj);
kvn@3651 382 break;
kvn@3651 383 }
kvn@3651 384 case Op_CastPP:
kvn@3651 385 case Op_CheckCastPP:
kvn@3651 386 case Op_EncodeP:
roland@4159 387 case Op_DecodeN:
roland@4159 388 case Op_EncodePKlass:
roland@4159 389 case Op_DecodeNKlass: {
kvn@3651 390 add_local_var_and_edge(n, PointsToNode::NoEscape,
kvn@3651 391 n->in(1), delayed_worklist);
kvn@3651 392 break;
kvn@3651 393 }
kvn@3651 394 case Op_CMoveP: {
kvn@3651 395 add_local_var(n, PointsToNode::NoEscape);
kvn@3651 396 // Do not add edges during first iteration because some could be
kvn@3651 397 // not defined yet.
kvn@3651 398 delayed_worklist->push(n);
kvn@3651 399 break;
kvn@3651 400 }
kvn@3651 401 case Op_ConP:
roland@4159 402 case Op_ConN:
roland@4159 403 case Op_ConNKlass: {
kvn@3651 404 // assume all oop constants globally escape except for null
kvn@3651 405 PointsToNode::EscapeState es;
kvn@5110 406 const Type* t = igvn->type(n);
kvn@5110 407 if (t == TypePtr::NULL_PTR || t == TypeNarrowOop::NULL_PTR) {
kvn@3651 408 es = PointsToNode::NoEscape;
kvn@3651 409 } else {
kvn@3651 410 es = PointsToNode::GlobalEscape;
kvn@3651 411 }
kvn@3651 412 add_java_object(n, es);
kvn@3651 413 break;
kvn@3651 414 }
kvn@3651 415 case Op_CreateEx: {
kvn@3651 416 // assume that all exception objects globally escape
kvn@3651 417 add_java_object(n, PointsToNode::GlobalEscape);
kvn@3651 418 break;
kvn@3651 419 }
kvn@3651 420 case Op_LoadKlass:
kvn@3651 421 case Op_LoadNKlass: {
kvn@3651 422 // Unknown class is loaded
kvn@3651 423 map_ideal_node(n, phantom_obj);
kvn@3651 424 break;
kvn@3651 425 }
kvn@3651 426 case Op_LoadP:
kvn@3651 427 case Op_LoadN:
kvn@3651 428 case Op_LoadPLocked: {
roland@4106 429 add_objload_to_connection_graph(n, delayed_worklist);
kvn@3651 430 break;
kvn@3651 431 }
kvn@3651 432 case Op_Parm: {
kvn@3651 433 map_ideal_node(n, phantom_obj);
kvn@3651 434 break;
kvn@3651 435 }
kvn@3651 436 case Op_PartialSubtypeCheck: {
kvn@3651 437 // Produces Null or notNull and is used in only in CmpP so
kvn@3651 438 // phantom_obj could be used.
kvn@3651 439 map_ideal_node(n, phantom_obj); // Result is unknown
kvn@3651 440 break;
kvn@3651 441 }
kvn@3651 442 case Op_Phi: {
kvn@3651 443 // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because
roland@4106 444 // ThreadLocal has RawPtr type.
kvn@3651 445 const Type* t = n->as_Phi()->type();
kvn@3651 446 if (t->make_ptr() != NULL) {
kvn@3651 447 add_local_var(n, PointsToNode::NoEscape);
kvn@3651 448 // Do not add edges during first iteration because some could be
kvn@3651 449 // not defined yet.
kvn@3651 450 delayed_worklist->push(n);
kvn@3651 451 }
kvn@3651 452 break;
kvn@3651 453 }
kvn@3651 454 case Op_Proj: {
kvn@3651 455 // we are only interested in the oop result projection from a call
kvn@3651 456 if (n->as_Proj()->_con == TypeFunc::Parms && n->in(0)->is_Call() &&
kvn@3651 457 n->in(0)->as_Call()->returns_pointer()) {
kvn@3651 458 add_local_var_and_edge(n, PointsToNode::NoEscape,
kvn@3651 459 n->in(0), delayed_worklist);
kvn@3651 460 }
kvn@3651 461 break;
kvn@3651 462 }
kvn@3651 463 case Op_Rethrow: // Exception object escapes
kvn@3651 464 case Op_Return: {
kvn@3651 465 if (n->req() > TypeFunc::Parms &&
kvn@3651 466 igvn->type(n->in(TypeFunc::Parms))->isa_oopptr()) {
kvn@3651 467 // Treat Return value as LocalVar with GlobalEscape escape state.
kvn@3651 468 add_local_var_and_edge(n, PointsToNode::GlobalEscape,
kvn@3651 469 n->in(TypeFunc::Parms), delayed_worklist);
kvn@3651 470 }
kvn@3651 471 break;
kvn@3651 472 }
roland@4106 473 case Op_GetAndSetP:
roland@4106 474 case Op_GetAndSetN: {
roland@4106 475 add_objload_to_connection_graph(n, delayed_worklist);
roland@4106 476 // fallthrough
roland@4106 477 }
kvn@3651 478 case Op_StoreP:
kvn@3651 479 case Op_StoreN:
roland@4159 480 case Op_StoreNKlass:
kvn@3651 481 case Op_StorePConditional:
kvn@3651 482 case Op_CompareAndSwapP:
kvn@3651 483 case Op_CompareAndSwapN: {
kvn@3651 484 Node* adr = n->in(MemNode::Address);
kvn@3651 485 const Type *adr_type = igvn->type(adr);
kvn@3651 486 adr_type = adr_type->make_ptr();
kvn@5111 487 if (adr_type == NULL) {
kvn@5111 488 break; // skip dead nodes
kvn@5111 489 }
kvn@3651 490 if (adr_type->isa_oopptr() ||
roland@4159 491 (opcode == Op_StoreP || opcode == Op_StoreN || opcode == Op_StoreNKlass) &&
kvn@3651 492 (adr_type == TypeRawPtr::NOTNULL &&
kvn@3651 493 adr->in(AddPNode::Address)->is_Proj() &&
kvn@3651 494 adr->in(AddPNode::Address)->in(0)->is_Allocate())) {
kvn@3651 495 delayed_worklist->push(n); // Process it later.
kvn@3651 496 #ifdef ASSERT
kvn@3651 497 assert(adr->is_AddP(), "expecting an AddP");
kvn@3651 498 if (adr_type == TypeRawPtr::NOTNULL) {
kvn@3651 499 // Verify a raw address for a store captured by Initialize node.
kvn@3651 500 int offs = (int)igvn->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
kvn@3651 501 assert(offs != Type::OffsetBot, "offset must be a constant");
kvn@3651 502 }
kvn@3657 503 #endif
kvn@3651 504 } else {
kvn@3651 505 // Ignore copy the displaced header to the BoxNode (OSR compilation).
kvn@3651 506 if (adr->is_BoxLock())
kvn@3651 507 break;
kvn@3657 508 // Stored value escapes in unsafe access.
kvn@3657 509 if ((opcode == Op_StoreP) && (adr_type == TypeRawPtr::BOTTOM)) {
kvn@3657 510 // Pointer stores in G1 barriers looks like unsafe access.
kvn@3657 511 // Ignore such stores to be able scalar replace non-escaping
kvn@3657 512 // allocations.
kvn@3657 513 if (UseG1GC && adr->is_AddP()) {
kvn@3657 514 Node* base = get_addp_base(adr);
kvn@3657 515 if (base->Opcode() == Op_LoadP &&
kvn@3657 516 base->in(MemNode::Address)->is_AddP()) {
kvn@3657 517 adr = base->in(MemNode::Address);
kvn@3657 518 Node* tls = get_addp_base(adr);
kvn@3657 519 if (tls->Opcode() == Op_ThreadLocal) {
kvn@3657 520 int offs = (int)igvn->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
kvn@3657 521 if (offs == in_bytes(JavaThread::satb_mark_queue_offset() +
kvn@3657 522 PtrQueue::byte_offset_of_buf())) {
kvn@3657 523 break; // G1 pre barier previous oop value store.
kvn@3657 524 }
kvn@3657 525 if (offs == in_bytes(JavaThread::dirty_card_queue_offset() +
kvn@3657 526 PtrQueue::byte_offset_of_buf())) {
kvn@3657 527 break; // G1 post barier card address store.
kvn@3657 528 }
kvn@3657 529 }
kvn@3657 530 }
kvn@3657 531 }
kvn@3657 532 delayed_worklist->push(n); // Process unsafe access later.
kvn@3657 533 break;
kvn@3651 534 }
kvn@3657 535 #ifdef ASSERT
kvn@3657 536 n->dump(1);
kvn@3657 537 assert(false, "not unsafe or G1 barrier raw StoreP");
kvn@3651 538 #endif
kvn@3651 539 }
kvn@3651 540 break;
kvn@3651 541 }
kvn@3651 542 case Op_AryEq:
kvn@3651 543 case Op_StrComp:
kvn@3651 544 case Op_StrEquals:
kvn@4479 545 case Op_StrIndexOf:
kvn@4479 546 case Op_EncodeISOArray: {
kvn@3651 547 add_local_var(n, PointsToNode::ArgEscape);
kvn@3651 548 delayed_worklist->push(n); // Process it later.
kvn@3651 549 break;
kvn@3651 550 }
kvn@3651 551 case Op_ThreadLocal: {
kvn@3651 552 add_java_object(n, PointsToNode::ArgEscape);
kvn@3651 553 break;
kvn@3651 554 }
kvn@3651 555 default:
kvn@3651 556 ; // Do nothing for nodes not related to EA.
kvn@3651 557 }
kvn@3651 558 return;
kvn@3651 559 }
kvn@3651 560
kvn@3651 561 #ifdef ASSERT
kvn@3651 562 #define ELSE_FAIL(name) \
kvn@3651 563 /* Should not be called for not pointer type. */ \
kvn@3651 564 n->dump(1); \
kvn@3651 565 assert(false, name); \
kvn@3651 566 break;
kvn@3651 567 #else
kvn@3651 568 #define ELSE_FAIL(name) \
kvn@3651 569 break;
kvn@3651 570 #endif
kvn@3651 571
kvn@3651 572 // Add final simple edges to graph.
kvn@3651 573 void ConnectionGraph::add_final_edges(Node *n) {
kvn@3651 574 PointsToNode* n_ptn = ptnode_adr(n->_idx);
kvn@3651 575 #ifdef ASSERT
kvn@3651 576 if (_verify && n_ptn->is_JavaObject())
kvn@3651 577 return; // This method does not change graph for JavaObject.
kvn@3651 578 #endif
kvn@3651 579
kvn@3651 580 if (n->is_Call()) {
kvn@3651 581 process_call_arguments(n->as_Call());
kvn@3651 582 return;
kvn@3651 583 }
kvn@3651 584 assert(n->is_Store() || n->is_LoadStore() ||
kvn@3651 585 (n_ptn != NULL) && (n_ptn->ideal_node() != NULL),
kvn@3651 586 "node should be registered already");
kvn@3651 587 int opcode = n->Opcode();
kvn@3651 588 switch (opcode) {
kvn@3651 589 case Op_AddP: {
kvn@3651 590 Node* base = get_addp_base(n);
kvn@3651 591 PointsToNode* ptn_base = ptnode_adr(base->_idx);
kvn@3651 592 assert(ptn_base != NULL, "field's base should be registered");
kvn@3651 593 add_base(n_ptn->as_Field(), ptn_base);
kvn@3651 594 break;
kvn@3651 595 }
kvn@3651 596 case Op_CastPP:
kvn@3651 597 case Op_CheckCastPP:
kvn@3651 598 case Op_EncodeP:
roland@4159 599 case Op_DecodeN:
roland@4159 600 case Op_EncodePKlass:
roland@4159 601 case Op_DecodeNKlass: {
kvn@3651 602 add_local_var_and_edge(n, PointsToNode::NoEscape,
kvn@3651 603 n->in(1), NULL);
kvn@3651 604 break;
kvn@3651 605 }
kvn@3651 606 case Op_CMoveP: {
kvn@3651 607 for (uint i = CMoveNode::IfFalse; i < n->req(); i++) {
kvn@3651 608 Node* in = n->in(i);
kvn@3651 609 if (in == NULL)
kvn@3651 610 continue; // ignore NULL
kvn@3651 611 Node* uncast_in = in->uncast();
kvn@3651 612 if (uncast_in->is_top() || uncast_in == n)
kvn@3651 613 continue; // ignore top or inputs which go back this node
kvn@3651 614 PointsToNode* ptn = ptnode_adr(in->_idx);
kvn@3651 615 assert(ptn != NULL, "node should be registered");
kvn@3651 616 add_edge(n_ptn, ptn);
kvn@3651 617 }
kvn@3651 618 break;
kvn@3651 619 }
kvn@3651 620 case Op_LoadP:
kvn@3651 621 case Op_LoadN:
kvn@3651 622 case Op_LoadPLocked: {
kvn@3651 623 // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because
roland@4106 624 // ThreadLocal has RawPtr type.
kvn@3651 625 const Type* t = _igvn->type(n);
kvn@3651 626 if (t->make_ptr() != NULL) {
kvn@3651 627 Node* adr = n->in(MemNode::Address);
kvn@3651 628 add_local_var_and_edge(n, PointsToNode::NoEscape, adr, NULL);
kvn@3651 629 break;
kvn@3651 630 }
kvn@3651 631 ELSE_FAIL("Op_LoadP");
kvn@3651 632 }
kvn@3651 633 case Op_Phi: {
kvn@3651 634 // Using isa_ptr() instead of isa_oopptr() for LoadP and Phi because
roland@4106 635 // ThreadLocal has RawPtr type.
kvn@3651 636 const Type* t = n->as_Phi()->type();
kvn@3651 637 if (t->make_ptr() != NULL) {
kvn@3651 638 for (uint i = 1; i < n->req(); i++) {
kvn@3651 639 Node* in = n->in(i);
kvn@3651 640 if (in == NULL)
kvn@3651 641 continue; // ignore NULL
kvn@3651 642 Node* uncast_in = in->uncast();
kvn@3651 643 if (uncast_in->is_top() || uncast_in == n)
kvn@3651 644 continue; // ignore top or inputs which go back this node
kvn@3651 645 PointsToNode* ptn = ptnode_adr(in->_idx);
kvn@3651 646 assert(ptn != NULL, "node should be registered");
kvn@3651 647 add_edge(n_ptn, ptn);
kvn@3651 648 }
kvn@3651 649 break;
kvn@3651 650 }
kvn@3651 651 ELSE_FAIL("Op_Phi");
kvn@3651 652 }
kvn@3651 653 case Op_Proj: {
kvn@3651 654 // we are only interested in the oop result projection from a call
kvn@3651 655 if (n->as_Proj()->_con == TypeFunc::Parms && n->in(0)->is_Call() &&
kvn@3651 656 n->in(0)->as_Call()->returns_pointer()) {
kvn@3651 657 add_local_var_and_edge(n, PointsToNode::NoEscape, n->in(0), NULL);
kvn@3651 658 break;
kvn@3651 659 }
kvn@3651 660 ELSE_FAIL("Op_Proj");
kvn@3651 661 }
kvn@3651 662 case Op_Rethrow: // Exception object escapes
kvn@3651 663 case Op_Return: {
kvn@3651 664 if (n->req() > TypeFunc::Parms &&
kvn@3651 665 _igvn->type(n->in(TypeFunc::Parms))->isa_oopptr()) {
kvn@3651 666 // Treat Return value as LocalVar with GlobalEscape escape state.
kvn@3651 667 add_local_var_and_edge(n, PointsToNode::GlobalEscape,
kvn@3651 668 n->in(TypeFunc::Parms), NULL);
kvn@3651 669 break;
kvn@3651 670 }
kvn@3651 671 ELSE_FAIL("Op_Return");
kvn@3651 672 }
kvn@3651 673 case Op_StoreP:
kvn@3651 674 case Op_StoreN:
roland@4159 675 case Op_StoreNKlass:
kvn@3651 676 case Op_StorePConditional:
kvn@3651 677 case Op_CompareAndSwapP:
roland@4106 678 case Op_CompareAndSwapN:
roland@4106 679 case Op_GetAndSetP:
roland@4106 680 case Op_GetAndSetN: {
kvn@3651 681 Node* adr = n->in(MemNode::Address);
kvn@3651 682 const Type *adr_type = _igvn->type(adr);
kvn@3651 683 adr_type = adr_type->make_ptr();
kvn@5111 684 #ifdef ASSERT
kvn@5111 685 if (adr_type == NULL) {
kvn@5111 686 n->dump(1);
kvn@5111 687 assert(adr_type != NULL, "dead node should not be on list");
kvn@5111 688 break;
kvn@5111 689 }
kvn@5111 690 #endif
kvn@5111 691 if (opcode == Op_GetAndSetP || opcode == Op_GetAndSetN) {
kvn@5111 692 add_local_var_and_edge(n, PointsToNode::NoEscape, adr, NULL);
kvn@5111 693 }
kvn@3651 694 if (adr_type->isa_oopptr() ||
roland@4159 695 (opcode == Op_StoreP || opcode == Op_StoreN || opcode == Op_StoreNKlass) &&
kvn@3651 696 (adr_type == TypeRawPtr::NOTNULL &&
kvn@3651 697 adr->in(AddPNode::Address)->is_Proj() &&
kvn@3651 698 adr->in(AddPNode::Address)->in(0)->is_Allocate())) {
kvn@3651 699 // Point Address to Value
kvn@3651 700 PointsToNode* adr_ptn = ptnode_adr(adr->_idx);
kvn@3651 701 assert(adr_ptn != NULL &&
kvn@3651 702 adr_ptn->as_Field()->is_oop(), "node should be registered");
kvn@3651 703 Node *val = n->in(MemNode::ValueIn);
kvn@3651 704 PointsToNode* ptn = ptnode_adr(val->_idx);
kvn@3651 705 assert(ptn != NULL, "node should be registered");
kvn@3651 706 add_edge(adr_ptn, ptn);
kvn@3651 707 break;
kvn@3657 708 } else if ((opcode == Op_StoreP) && (adr_type == TypeRawPtr::BOTTOM)) {
kvn@3657 709 // Stored value escapes in unsafe access.
kvn@3657 710 Node *val = n->in(MemNode::ValueIn);
kvn@3657 711 PointsToNode* ptn = ptnode_adr(val->_idx);
kvn@3657 712 assert(ptn != NULL, "node should be registered");
kvn@3657 713 ptn->set_escape_state(PointsToNode::GlobalEscape);
kvn@3657 714 // Add edge to object for unsafe access with offset.
kvn@3657 715 PointsToNode* adr_ptn = ptnode_adr(adr->_idx);
kvn@3657 716 assert(adr_ptn != NULL, "node should be registered");
kvn@3657 717 if (adr_ptn->is_Field()) {
kvn@3657 718 assert(adr_ptn->as_Field()->is_oop(), "should be oop field");
kvn@3657 719 add_edge(adr_ptn, ptn);
kvn@3657 720 }
kvn@3657 721 break;
kvn@3651 722 }
kvn@3651 723 ELSE_FAIL("Op_StoreP");
kvn@3651 724 }
kvn@3651 725 case Op_AryEq:
kvn@3651 726 case Op_StrComp:
kvn@3651 727 case Op_StrEquals:
kvn@4479 728 case Op_StrIndexOf:
kvn@4479 729 case Op_EncodeISOArray: {
kvn@3651 730 // char[] arrays passed to string intrinsic do not escape but
kvn@3651 731 // they are not scalar replaceable. Adjust escape state for them.
kvn@3651 732 // Start from in(2) edge since in(1) is memory edge.
kvn@3651 733 for (uint i = 2; i < n->req(); i++) {
kvn@3651 734 Node* adr = n->in(i);
kvn@3651 735 const Type* at = _igvn->type(adr);
kvn@3651 736 if (!adr->is_top() && at->isa_ptr()) {
kvn@3651 737 assert(at == Type::TOP || at == TypePtr::NULL_PTR ||
kvn@3651 738 at->isa_ptr() != NULL, "expecting a pointer");
kvn@3651 739 if (adr->is_AddP()) {
kvn@3651 740 adr = get_addp_base(adr);
kvn@3651 741 }
kvn@3651 742 PointsToNode* ptn = ptnode_adr(adr->_idx);
kvn@3651 743 assert(ptn != NULL, "node should be registered");
kvn@3651 744 add_edge(n_ptn, ptn);
kvn@3651 745 }
kvn@3651 746 }
kvn@3651 747 break;
kvn@3651 748 }
kvn@3651 749 default: {
kvn@3651 750 // This method should be called only for EA specific nodes which may
kvn@3651 751 // miss some edges when they were created.
kvn@3651 752 #ifdef ASSERT
kvn@3651 753 n->dump(1);
kvn@3651 754 #endif
kvn@3651 755 guarantee(false, "unknown node");
kvn@3651 756 }
kvn@3651 757 }
kvn@3651 758 return;
kvn@3651 759 }
kvn@3651 760
kvn@3651 761 void ConnectionGraph::add_call_node(CallNode* call) {
kvn@3651 762 assert(call->returns_pointer(), "only for call which returns pointer");
kvn@3651 763 uint call_idx = call->_idx;
kvn@3651 764 if (call->is_Allocate()) {
kvn@3651 765 Node* k = call->in(AllocateNode::KlassNode);
kvn@3651 766 const TypeKlassPtr* kt = k->bottom_type()->isa_klassptr();
kvn@3651 767 assert(kt != NULL, "TypeKlassPtr required.");
kvn@3651 768 ciKlass* cik = kt->klass();
kvn@3651 769 PointsToNode::EscapeState es = PointsToNode::NoEscape;
kvn@3651 770 bool scalar_replaceable = true;
kvn@3651 771 if (call->is_AllocateArray()) {
kvn@3651 772 if (!cik->is_array_klass()) { // StressReflectiveCode
kvn@3651 773 es = PointsToNode::GlobalEscape;
kvn@3651 774 } else {
kvn@3651 775 int length = call->in(AllocateNode::ALength)->find_int_con(-1);
kvn@3651 776 if (length < 0 || length > EliminateAllocationArraySizeLimit) {
kvn@3651 777 // Not scalar replaceable if the length is not constant or too big.
kvn@3651 778 scalar_replaceable = false;
kvn@3651 779 }
kvn@3651 780 }
kvn@3651 781 } else { // Allocate instance
kvn@3651 782 if (cik->is_subclass_of(_compile->env()->Thread_klass()) ||
kvn@3651 783 !cik->is_instance_klass() || // StressReflectiveCode
kvn@3651 784 cik->as_instance_klass()->has_finalizer()) {
kvn@3651 785 es = PointsToNode::GlobalEscape;
kvn@3651 786 }
kvn@3651 787 }
kvn@3651 788 add_java_object(call, es);
kvn@3651 789 PointsToNode* ptn = ptnode_adr(call_idx);
kvn@3651 790 if (!scalar_replaceable && ptn->scalar_replaceable()) {
kvn@3651 791 ptn->set_scalar_replaceable(false);
kvn@3651 792 }
kvn@3651 793 } else if (call->is_CallStaticJava()) {
kvn@3651 794 // Call nodes could be different types:
kvn@3651 795 //
kvn@3651 796 // 1. CallDynamicJavaNode (what happened during call is unknown):
kvn@3651 797 //
kvn@3651 798 // - mapped to GlobalEscape JavaObject node if oop is returned;
kvn@3651 799 //
kvn@3651 800 // - all oop arguments are escaping globally;
kvn@3651 801 //
kvn@3651 802 // 2. CallStaticJavaNode (execute bytecode analysis if possible):
kvn@3651 803 //
kvn@3651 804 // - the same as CallDynamicJavaNode if can't do bytecode analysis;
kvn@3651 805 //
kvn@3651 806 // - mapped to GlobalEscape JavaObject node if unknown oop is returned;
kvn@3651 807 // - mapped to NoEscape JavaObject node if non-escaping object allocated
kvn@3651 808 // during call is returned;
kvn@3651 809 // - mapped to ArgEscape LocalVar node pointed to object arguments
kvn@3651 810 // which are returned and does not escape during call;
kvn@3651 811 //
kvn@3651 812 // - oop arguments escaping status is defined by bytecode analysis;
kvn@3651 813 //
kvn@3651 814 // For a static call, we know exactly what method is being called.
kvn@3651 815 // Use bytecode estimator to record whether the call's return value escapes.
kvn@3651 816 ciMethod* meth = call->as_CallJava()->method();
kvn@3651 817 if (meth == NULL) {
kvn@3651 818 const char* name = call->as_CallStaticJava()->_name;
kvn@3651 819 assert(strncmp(name, "_multianewarray", 15) == 0, "TODO: add failed case check");
kvn@3651 820 // Returns a newly allocated unescaped object.
kvn@3651 821 add_java_object(call, PointsToNode::NoEscape);
kvn@3651 822 ptnode_adr(call_idx)->set_scalar_replaceable(false);
kvn@5110 823 } else if (meth->is_boxing_method()) {
kvn@5110 824 // Returns boxing object
kvn@5113 825 PointsToNode::EscapeState es;
kvn@5113 826 vmIntrinsics::ID intr = meth->intrinsic_id();
kvn@5113 827 if (intr == vmIntrinsics::_floatValue || intr == vmIntrinsics::_doubleValue) {
kvn@5113 828 // It does not escape if object is always allocated.
kvn@5113 829 es = PointsToNode::NoEscape;
kvn@5113 830 } else {
kvn@5113 831 // It escapes globally if object could be loaded from cache.
kvn@5113 832 es = PointsToNode::GlobalEscape;
kvn@5113 833 }
kvn@5113 834 add_java_object(call, es);
kvn@3651 835 } else {
kvn@3651 836 BCEscapeAnalyzer* call_analyzer = meth->get_bcea();
kvn@3651 837 call_analyzer->copy_dependencies(_compile->dependencies());
kvn@3651 838 if (call_analyzer->is_return_allocated()) {
kvn@3651 839 // Returns a newly allocated unescaped object, simply
kvn@3651 840 // update dependency information.
kvn@3651 841 // Mark it as NoEscape so that objects referenced by
kvn@3651 842 // it's fields will be marked as NoEscape at least.
kvn@3651 843 add_java_object(call, PointsToNode::NoEscape);
kvn@3651 844 ptnode_adr(call_idx)->set_scalar_replaceable(false);
kvn@3651 845 } else {
kvn@3651 846 // Determine whether any arguments are returned.
kvn@3651 847 const TypeTuple* d = call->tf()->domain();
kvn@3651 848 bool ret_arg = false;
kvn@3651 849 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
kvn@3651 850 if (d->field_at(i)->isa_ptr() != NULL &&
kvn@3651 851 call_analyzer->is_arg_returned(i - TypeFunc::Parms)) {
kvn@3651 852 ret_arg = true;
kvn@3651 853 break;
kvn@3651 854 }
kvn@3651 855 }
kvn@3651 856 if (ret_arg) {
kvn@3651 857 add_local_var(call, PointsToNode::ArgEscape);
kvn@3651 858 } else {
kvn@3651 859 // Returns unknown object.
kvn@3651 860 map_ideal_node(call, phantom_obj);
kvn@3651 861 }
kvn@3651 862 }
kvn@3651 863 }
kvn@3651 864 } else {
kvn@3651 865 // An other type of call, assume the worst case:
kvn@3651 866 // returned value is unknown and globally escapes.
kvn@3651 867 assert(call->Opcode() == Op_CallDynamicJava, "add failed case check");
kvn@3651 868 map_ideal_node(call, phantom_obj);
kvn@3651 869 }
kvn@3651 870 }
kvn@3651 871
kvn@3651 872 void ConnectionGraph::process_call_arguments(CallNode *call) {
kvn@3651 873 bool is_arraycopy = false;
kvn@3651 874 switch (call->Opcode()) {
kvn@3651 875 #ifdef ASSERT
kvn@3651 876 case Op_Allocate:
kvn@3651 877 case Op_AllocateArray:
kvn@3651 878 case Op_Lock:
kvn@3651 879 case Op_Unlock:
kvn@3651 880 assert(false, "should be done already");
kvn@3651 881 break;
kvn@3651 882 #endif
kvn@3651 883 case Op_CallLeafNoFP:
kvn@3651 884 is_arraycopy = (call->as_CallLeaf()->_name != NULL &&
kvn@3651 885 strstr(call->as_CallLeaf()->_name, "arraycopy") != 0);
kvn@3651 886 // fall through
kvn@3651 887 case Op_CallLeaf: {
kvn@3651 888 // Stub calls, objects do not escape but they are not scale replaceable.
kvn@3651 889 // Adjust escape state for outgoing arguments.
kvn@3651 890 const TypeTuple * d = call->tf()->domain();
kvn@3651 891 bool src_has_oops = false;
kvn@3651 892 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
kvn@3651 893 const Type* at = d->field_at(i);
kvn@3651 894 Node *arg = call->in(i);
kvn@3651 895 const Type *aat = _igvn->type(arg);
kvn@3651 896 if (arg->is_top() || !at->isa_ptr() || !aat->isa_ptr())
kvn@3651 897 continue;
kvn@3651 898 if (arg->is_AddP()) {
kvn@3651 899 //
kvn@3651 900 // The inline_native_clone() case when the arraycopy stub is called
kvn@3651 901 // after the allocation before Initialize and CheckCastPP nodes.
kvn@3651 902 // Or normal arraycopy for object arrays case.
kvn@3651 903 //
kvn@3651 904 // Set AddP's base (Allocate) as not scalar replaceable since
kvn@3651 905 // pointer to the base (with offset) is passed as argument.
kvn@3651 906 //
kvn@3651 907 arg = get_addp_base(arg);
kvn@3651 908 }
kvn@3651 909 PointsToNode* arg_ptn = ptnode_adr(arg->_idx);
kvn@3651 910 assert(arg_ptn != NULL, "should be registered");
kvn@3651 911 PointsToNode::EscapeState arg_esc = arg_ptn->escape_state();
kvn@3651 912 if (is_arraycopy || arg_esc < PointsToNode::ArgEscape) {
kvn@3651 913 assert(aat == Type::TOP || aat == TypePtr::NULL_PTR ||
kvn@3651 914 aat->isa_ptr() != NULL, "expecting an Ptr");
kvn@3651 915 bool arg_has_oops = aat->isa_oopptr() &&
kvn@3651 916 (aat->isa_oopptr()->klass() == NULL || aat->isa_instptr() ||
kvn@3651 917 (aat->isa_aryptr() && aat->isa_aryptr()->klass()->is_obj_array_klass()));
kvn@3651 918 if (i == TypeFunc::Parms) {
kvn@3651 919 src_has_oops = arg_has_oops;
kvn@3651 920 }
kvn@3651 921 //
kvn@3651 922 // src or dst could be j.l.Object when other is basic type array:
kvn@3651 923 //
kvn@3651 924 // arraycopy(char[],0,Object*,0,size);
kvn@3651 925 // arraycopy(Object*,0,char[],0,size);
kvn@3651 926 //
kvn@3651 927 // Don't add edges in such cases.
kvn@3651 928 //
kvn@3651 929 bool arg_is_arraycopy_dest = src_has_oops && is_arraycopy &&
kvn@3651 930 arg_has_oops && (i > TypeFunc::Parms);
kvn@3651 931 #ifdef ASSERT
kvn@3651 932 if (!(is_arraycopy ||
kvn@4205 933 (call->as_CallLeaf()->_name != NULL &&
kvn@4205 934 (strcmp(call->as_CallLeaf()->_name, "g1_wb_pre") == 0 ||
kvn@4205 935 strcmp(call->as_CallLeaf()->_name, "g1_wb_post") == 0 ||
drchase@5353 936 strcmp(call->as_CallLeaf()->_name, "updateBytesCRC32") == 0 ||
kvn@4205 937 strcmp(call->as_CallLeaf()->_name, "aescrypt_encryptBlock") == 0 ||
kvn@4205 938 strcmp(call->as_CallLeaf()->_name, "aescrypt_decryptBlock") == 0 ||
kvn@4205 939 strcmp(call->as_CallLeaf()->_name, "cipherBlockChaining_encryptAESCrypt") == 0 ||
kvn@4205 940 strcmp(call->as_CallLeaf()->_name, "cipherBlockChaining_decryptAESCrypt") == 0)
kvn@4205 941 ))) {
kvn@3651 942 call->dump();
kvn@4205 943 fatal(err_msg_res("EA unexpected CallLeaf %s", call->as_CallLeaf()->_name));
kvn@3651 944 }
kvn@3651 945 #endif
kvn@3651 946 // Always process arraycopy's destination object since
kvn@3651 947 // we need to add all possible edges to references in
kvn@3651 948 // source object.
kvn@3651 949 if (arg_esc >= PointsToNode::ArgEscape &&
kvn@3651 950 !arg_is_arraycopy_dest) {
kvn@3651 951 continue;
kvn@3651 952 }
kvn@3651 953 set_escape_state(arg_ptn, PointsToNode::ArgEscape);
kvn@3651 954 if (arg_is_arraycopy_dest) {
kvn@3651 955 Node* src = call->in(TypeFunc::Parms);
kvn@3651 956 if (src->is_AddP()) {
kvn@3651 957 src = get_addp_base(src);
kvn@3651 958 }
kvn@3651 959 PointsToNode* src_ptn = ptnode_adr(src->_idx);
kvn@3651 960 assert(src_ptn != NULL, "should be registered");
kvn@3651 961 if (arg_ptn != src_ptn) {
kvn@3651 962 // Special arraycopy edge:
kvn@3651 963 // A destination object's field can't have the source object
kvn@3651 964 // as base since objects escape states are not related.
kvn@3651 965 // Only escape state of destination object's fields affects
kvn@3651 966 // escape state of fields in source object.
kvn@3651 967 add_arraycopy(call, PointsToNode::ArgEscape, src_ptn, arg_ptn);
kvn@3651 968 }
kvn@3651 969 }
kvn@3651 970 }
kvn@3651 971 }
kvn@3651 972 break;
kvn@3651 973 }
kvn@3651 974 case Op_CallStaticJava: {
kvn@3651 975 // For a static call, we know exactly what method is being called.
kvn@3651 976 // Use bytecode estimator to record the call's escape affects
kvn@3651 977 #ifdef ASSERT
kvn@3651 978 const char* name = call->as_CallStaticJava()->_name;
kvn@3651 979 assert((name == NULL || strcmp(name, "uncommon_trap") != 0), "normal calls only");
kvn@3651 980 #endif
kvn@3651 981 ciMethod* meth = call->as_CallJava()->method();
kvn@5110 982 if ((meth != NULL) && meth->is_boxing_method()) {
kvn@5110 983 break; // Boxing methods do not modify any oops.
kvn@5110 984 }
kvn@3651 985 BCEscapeAnalyzer* call_analyzer = (meth !=NULL) ? meth->get_bcea() : NULL;
kvn@3651 986 // fall-through if not a Java method or no analyzer information
kvn@3651 987 if (call_analyzer != NULL) {
kvn@3651 988 PointsToNode* call_ptn = ptnode_adr(call->_idx);
kvn@3651 989 const TypeTuple* d = call->tf()->domain();
kvn@3651 990 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
kvn@3651 991 const Type* at = d->field_at(i);
kvn@3651 992 int k = i - TypeFunc::Parms;
kvn@3651 993 Node* arg = call->in(i);
kvn@3651 994 PointsToNode* arg_ptn = ptnode_adr(arg->_idx);
kvn@3651 995 if (at->isa_ptr() != NULL &&
kvn@3651 996 call_analyzer->is_arg_returned(k)) {
kvn@3651 997 // The call returns arguments.
kvn@3651 998 if (call_ptn != NULL) { // Is call's result used?
kvn@3651 999 assert(call_ptn->is_LocalVar(), "node should be registered");
kvn@3651 1000 assert(arg_ptn != NULL, "node should be registered");
kvn@3651 1001 add_edge(call_ptn, arg_ptn);
kvn@3651 1002 }
kvn@3651 1003 }
kvn@3651 1004 if (at->isa_oopptr() != NULL &&
kvn@3651 1005 arg_ptn->escape_state() < PointsToNode::GlobalEscape) {
kvn@3651 1006 if (!call_analyzer->is_arg_stack(k)) {
kvn@3651 1007 // The argument global escapes
kvn@3651 1008 set_escape_state(arg_ptn, PointsToNode::GlobalEscape);
kvn@3651 1009 } else {
kvn@3651 1010 set_escape_state(arg_ptn, PointsToNode::ArgEscape);
kvn@3651 1011 if (!call_analyzer->is_arg_local(k)) {
kvn@3651 1012 // The argument itself doesn't escape, but any fields might
kvn@3651 1013 set_fields_escape_state(arg_ptn, PointsToNode::GlobalEscape);
kvn@3651 1014 }
kvn@3651 1015 }
kvn@3651 1016 }
kvn@3651 1017 }
kvn@3651 1018 if (call_ptn != NULL && call_ptn->is_LocalVar()) {
kvn@3651 1019 // The call returns arguments.
kvn@3651 1020 assert(call_ptn->edge_count() > 0, "sanity");
kvn@3651 1021 if (!call_analyzer->is_return_local()) {
kvn@3651 1022 // Returns also unknown object.
kvn@3651 1023 add_edge(call_ptn, phantom_obj);
kvn@3651 1024 }
kvn@3651 1025 }
kvn@3651 1026 break;
kvn@3651 1027 }
kvn@3651 1028 }
kvn@3651 1029 default: {
kvn@3651 1030 // Fall-through here if not a Java method or no analyzer information
kvn@3651 1031 // or some other type of call, assume the worst case: all arguments
kvn@3651 1032 // globally escape.
kvn@3651 1033 const TypeTuple* d = call->tf()->domain();
kvn@3651 1034 for (uint i = TypeFunc::Parms; i < d->cnt(); i++) {
kvn@3651 1035 const Type* at = d->field_at(i);
kvn@3651 1036 if (at->isa_oopptr() != NULL) {
kvn@3651 1037 Node* arg = call->in(i);
kvn@3651 1038 if (arg->is_AddP()) {
kvn@3651 1039 arg = get_addp_base(arg);
kvn@3651 1040 }
kvn@3651 1041 assert(ptnode_adr(arg->_idx) != NULL, "should be defined already");
kvn@3651 1042 set_escape_state(ptnode_adr(arg->_idx), PointsToNode::GlobalEscape);
kvn@3651 1043 }
kvn@3651 1044 }
kvn@3651 1045 }
kvn@3651 1046 }
kvn@3651 1047 }
kvn@3651 1048
kvn@3651 1049
kvn@3651 1050 // Finish Graph construction.
kvn@3651 1051 bool ConnectionGraph::complete_connection_graph(
kvn@3651 1052 GrowableArray<PointsToNode*>& ptnodes_worklist,
kvn@3651 1053 GrowableArray<JavaObjectNode*>& non_escaped_worklist,
kvn@3651 1054 GrowableArray<JavaObjectNode*>& java_objects_worklist,
kvn@3651 1055 GrowableArray<FieldNode*>& oop_fields_worklist) {
kvn@3651 1056 // Normally only 1-3 passes needed to build Connection Graph depending
kvn@3651 1057 // on graph complexity. Observed 8 passes in jvm2008 compiler.compiler.
kvn@3651 1058 // Set limit to 20 to catch situation when something did go wrong and
kvn@3651 1059 // bailout Escape Analysis.
kvn@3651 1060 // Also limit build time to 30 sec (60 in debug VM).
kvn@3651 1061 #define CG_BUILD_ITER_LIMIT 20
kvn@3651 1062 #ifdef ASSERT
kvn@3651 1063 #define CG_BUILD_TIME_LIMIT 60.0
kvn@3651 1064 #else
kvn@3651 1065 #define CG_BUILD_TIME_LIMIT 30.0
kvn@3651 1066 #endif
kvn@3651 1067
kvn@3651 1068 // Propagate GlobalEscape and ArgEscape escape states and check that
kvn@3651 1069 // we still have non-escaping objects. The method pushs on _worklist
kvn@3651 1070 // Field nodes which reference phantom_object.
kvn@3651 1071 if (!find_non_escaped_objects(ptnodes_worklist, non_escaped_worklist)) {
kvn@3651 1072 return false; // Nothing to do.
kvn@3651 1073 }
kvn@3651 1074 // Now propagate references to all JavaObject nodes.
kvn@3651 1075 int java_objects_length = java_objects_worklist.length();
kvn@3651 1076 elapsedTimer time;
kvn@3651 1077 int new_edges = 1;
kvn@3651 1078 int iterations = 0;
kvn@3651 1079 do {
kvn@3651 1080 while ((new_edges > 0) &&
kvn@3651 1081 (iterations++ < CG_BUILD_ITER_LIMIT) &&
kvn@3651 1082 (time.seconds() < CG_BUILD_TIME_LIMIT)) {
kvn@3651 1083 time.start();
kvn@3651 1084 new_edges = 0;
kvn@3651 1085 // Propagate references to phantom_object for nodes pushed on _worklist
kvn@3651 1086 // by find_non_escaped_objects() and find_field_value().
kvn@3651 1087 new_edges += add_java_object_edges(phantom_obj, false);
kvn@3651 1088 for (int next = 0; next < java_objects_length; ++next) {
kvn@3651 1089 JavaObjectNode* ptn = java_objects_worklist.at(next);
kvn@3651 1090 new_edges += add_java_object_edges(ptn, true);
kvn@3651 1091 }
kvn@3651 1092 if (new_edges > 0) {
kvn@3651 1093 // Update escape states on each iteration if graph was updated.
kvn@3651 1094 if (!find_non_escaped_objects(ptnodes_worklist, non_escaped_worklist)) {
kvn@3651 1095 return false; // Nothing to do.
kvn@3651 1096 }
kvn@3651 1097 }
kvn@3651 1098 time.stop();
kvn@3651 1099 }
kvn@3651 1100 if ((iterations < CG_BUILD_ITER_LIMIT) &&
kvn@3651 1101 (time.seconds() < CG_BUILD_TIME_LIMIT)) {
kvn@3651 1102 time.start();
kvn@3651 1103 // Find fields which have unknown value.
kvn@3651 1104 int fields_length = oop_fields_worklist.length();
kvn@3651 1105 for (int next = 0; next < fields_length; next++) {
kvn@3651 1106 FieldNode* field = oop_fields_worklist.at(next);
kvn@3651 1107 if (field->edge_count() == 0) {
kvn@3651 1108 new_edges += find_field_value(field);
kvn@3651 1109 // This code may added new edges to phantom_object.
kvn@3651 1110 // Need an other cycle to propagate references to phantom_object.
kvn@3651 1111 }
kvn@3651 1112 }
kvn@3651 1113 time.stop();
kvn@3651 1114 } else {
kvn@3651 1115 new_edges = 0; // Bailout
kvn@3651 1116 }
kvn@3651 1117 } while (new_edges > 0);
kvn@3651 1118
kvn@3651 1119 // Bailout if passed limits.
kvn@3651 1120 if ((iterations >= CG_BUILD_ITER_LIMIT) ||
kvn@3651 1121 (time.seconds() >= CG_BUILD_TIME_LIMIT)) {
kvn@3651 1122 Compile* C = _compile;
kvn@3651 1123 if (C->log() != NULL) {
kvn@3651 1124 C->log()->begin_elem("connectionGraph_bailout reason='reached ");
kvn@3651 1125 C->log()->text("%s", (iterations >= CG_BUILD_ITER_LIMIT) ? "iterations" : "time");
kvn@3651 1126 C->log()->end_elem(" limit'");
kvn@3651 1127 }
kvn@4206 1128 assert(ExitEscapeAnalysisOnTimeout, err_msg_res("infinite EA connection graph build (%f sec, %d iterations) with %d nodes and worklist size %d",
kvn@3651 1129 time.seconds(), iterations, nodes_size(), ptnodes_worklist.length()));
kvn@3651 1130 // Possible infinite build_connection_graph loop,
kvn@3651 1131 // bailout (no changes to ideal graph were made).
kvn@3651 1132 return false;
kvn@3651 1133 }
kvn@3651 1134 #ifdef ASSERT
kvn@3651 1135 if (Verbose && PrintEscapeAnalysis) {
kvn@3651 1136 tty->print_cr("EA: %d iterations to build connection graph with %d nodes and worklist size %d",
kvn@3651 1137 iterations, nodes_size(), ptnodes_worklist.length());
kvn@3651 1138 }
kvn@3651 1139 #endif
kvn@3651 1140
kvn@3651 1141 #undef CG_BUILD_ITER_LIMIT
kvn@3651 1142 #undef CG_BUILD_TIME_LIMIT
kvn@3651 1143
kvn@3651 1144 // Find fields initialized by NULL for non-escaping Allocations.
kvn@3651 1145 int non_escaped_length = non_escaped_worklist.length();
kvn@3651 1146 for (int next = 0; next < non_escaped_length; next++) {
kvn@3651 1147 JavaObjectNode* ptn = non_escaped_worklist.at(next);
kvn@3651 1148 PointsToNode::EscapeState es = ptn->escape_state();
kvn@3651 1149 assert(es <= PointsToNode::ArgEscape, "sanity");
kvn@3651 1150 if (es == PointsToNode::NoEscape) {
kvn@3651 1151 if (find_init_values(ptn, null_obj, _igvn) > 0) {
kvn@3651 1152 // Adding references to NULL object does not change escape states
kvn@3651 1153 // since it does not escape. Also no fields are added to NULL object.
kvn@3651 1154 add_java_object_edges(null_obj, false);
kvn@3651 1155 }
kvn@3651 1156 }
kvn@3651 1157 Node* n = ptn->ideal_node();
kvn@3651 1158 if (n->is_Allocate()) {
kvn@3651 1159 // The object allocated by this Allocate node will never be
kvn@3651 1160 // seen by an other thread. Mark it so that when it is
kvn@3651 1161 // expanded no MemBarStoreStore is added.
kvn@3651 1162 InitializeNode* ini = n->as_Allocate()->initialization();
kvn@3651 1163 if (ini != NULL)
kvn@3651 1164 ini->set_does_not_escape();
kvn@3651 1165 }
kvn@3651 1166 }
kvn@3651 1167 return true; // Finished graph construction.
kvn@3651 1168 }
kvn@3651 1169
kvn@3651 1170 // Propagate GlobalEscape and ArgEscape escape states to all nodes
kvn@3651 1171 // and check that we still have non-escaping java objects.
kvn@3651 1172 bool ConnectionGraph::find_non_escaped_objects(GrowableArray<PointsToNode*>& ptnodes_worklist,
kvn@3651 1173 GrowableArray<JavaObjectNode*>& non_escaped_worklist) {
kvn@3651 1174 GrowableArray<PointsToNode*> escape_worklist;
kvn@3651 1175 // First, put all nodes with GlobalEscape and ArgEscape states on worklist.
kvn@3651 1176 int ptnodes_length = ptnodes_worklist.length();
kvn@3651 1177 for (int next = 0; next < ptnodes_length; ++next) {
kvn@3651 1178 PointsToNode* ptn = ptnodes_worklist.at(next);
kvn@3651 1179 if (ptn->escape_state() >= PointsToNode::ArgEscape ||
kvn@3651 1180 ptn->fields_escape_state() >= PointsToNode::ArgEscape) {
kvn@3651 1181 escape_worklist.push(ptn);
kvn@3651 1182 }
kvn@3651 1183 }
kvn@3651 1184 // Set escape states to referenced nodes (edges list).
kvn@3651 1185 while (escape_worklist.length() > 0) {
kvn@3651 1186 PointsToNode* ptn = escape_worklist.pop();
kvn@3651 1187 PointsToNode::EscapeState es = ptn->escape_state();
kvn@3651 1188 PointsToNode::EscapeState field_es = ptn->fields_escape_state();
kvn@3651 1189 if (ptn->is_Field() && ptn->as_Field()->is_oop() &&
kvn@3651 1190 es >= PointsToNode::ArgEscape) {
kvn@3651 1191 // GlobalEscape or ArgEscape state of field means it has unknown value.
kvn@3651 1192 if (add_edge(ptn, phantom_obj)) {
kvn@3651 1193 // New edge was added
kvn@3651 1194 add_field_uses_to_worklist(ptn->as_Field());
kvn@3651 1195 }
kvn@3651 1196 }
kvn@3651 1197 for (EdgeIterator i(ptn); i.has_next(); i.next()) {
kvn@3651 1198 PointsToNode* e = i.get();
kvn@3651 1199 if (e->is_Arraycopy()) {
kvn@3651 1200 assert(ptn->arraycopy_dst(), "sanity");
kvn@3651 1201 // Propagate only fields escape state through arraycopy edge.
kvn@3651 1202 if (e->fields_escape_state() < field_es) {
kvn@3651 1203 set_fields_escape_state(e, field_es);
kvn@3651 1204 escape_worklist.push(e);
kvn@3651 1205 }
kvn@3651 1206 } else if (es >= field_es) {
kvn@3651 1207 // fields_escape_state is also set to 'es' if it is less than 'es'.
kvn@3651 1208 if (e->escape_state() < es) {
kvn@3651 1209 set_escape_state(e, es);
kvn@3651 1210 escape_worklist.push(e);
kvn@3651 1211 }
kvn@3651 1212 } else {
kvn@3651 1213 // Propagate field escape state.
kvn@3651 1214 bool es_changed = false;
kvn@3651 1215 if (e->fields_escape_state() < field_es) {
kvn@3651 1216 set_fields_escape_state(e, field_es);
kvn@3651 1217 es_changed = true;
kvn@3651 1218 }
kvn@3651 1219 if ((e->escape_state() < field_es) &&
kvn@3651 1220 e->is_Field() && ptn->is_JavaObject() &&
kvn@3651 1221 e->as_Field()->is_oop()) {
kvn@3651 1222 // Change escape state of referenced fileds.
kvn@3651 1223 set_escape_state(e, field_es);
kvn@3651 1224 es_changed = true;;
kvn@3651 1225 } else if (e->escape_state() < es) {
kvn@3651 1226 set_escape_state(e, es);
kvn@3651 1227 es_changed = true;;
kvn@3651 1228 }
kvn@3651 1229 if (es_changed) {
kvn@3651 1230 escape_worklist.push(e);
kvn@3651 1231 }
kvn@3651 1232 }
kvn@3651 1233 }
kvn@3651 1234 }
kvn@3651 1235 // Remove escaped objects from non_escaped list.
kvn@3651 1236 for (int next = non_escaped_worklist.length()-1; next >= 0 ; --next) {
kvn@3651 1237 JavaObjectNode* ptn = non_escaped_worklist.at(next);
kvn@3651 1238 if (ptn->escape_state() >= PointsToNode::GlobalEscape) {
kvn@3651 1239 non_escaped_worklist.delete_at(next);
kvn@3651 1240 }
kvn@3651 1241 if (ptn->escape_state() == PointsToNode::NoEscape) {
kvn@3651 1242 // Find fields in non-escaped allocations which have unknown value.
kvn@3651 1243 find_init_values(ptn, phantom_obj, NULL);
kvn@3651 1244 }
kvn@3651 1245 }
kvn@3651 1246 return (non_escaped_worklist.length() > 0);
kvn@3651 1247 }
kvn@3651 1248
kvn@3651 1249 // Add all references to JavaObject node by walking over all uses.
kvn@3651 1250 int ConnectionGraph::add_java_object_edges(JavaObjectNode* jobj, bool populate_worklist) {
kvn@3651 1251 int new_edges = 0;
kvn@3651 1252 if (populate_worklist) {
kvn@3651 1253 // Populate _worklist by uses of jobj's uses.
kvn@3651 1254 for (UseIterator i(jobj); i.has_next(); i.next()) {
kvn@3651 1255 PointsToNode* use = i.get();
kvn@3651 1256 if (use->is_Arraycopy())
kvn@3651 1257 continue;
kvn@3651 1258 add_uses_to_worklist(use);
kvn@3651 1259 if (use->is_Field() && use->as_Field()->is_oop()) {
kvn@3651 1260 // Put on worklist all field's uses (loads) and
kvn@3651 1261 // related field nodes (same base and offset).
kvn@3651 1262 add_field_uses_to_worklist(use->as_Field());
kvn@3651 1263 }
kvn@3651 1264 }
kvn@3651 1265 }
kvn@3651 1266 while(_worklist.length() > 0) {
kvn@3651 1267 PointsToNode* use = _worklist.pop();
kvn@3651 1268 if (PointsToNode::is_base_use(use)) {
kvn@3651 1269 // Add reference from jobj to field and from field to jobj (field's base).
kvn@3651 1270 use = PointsToNode::get_use_node(use)->as_Field();
kvn@3651 1271 if (add_base(use->as_Field(), jobj)) {
kvn@3651 1272 new_edges++;
kvn@3651 1273 }
kvn@3651 1274 continue;
kvn@3651 1275 }
kvn@3651 1276 assert(!use->is_JavaObject(), "sanity");
kvn@3651 1277 if (use->is_Arraycopy()) {
kvn@3651 1278 if (jobj == null_obj) // NULL object does not have field edges
kvn@3651 1279 continue;
kvn@3651 1280 // Added edge from Arraycopy node to arraycopy's source java object
kvn@3651 1281 if (add_edge(use, jobj)) {
kvn@3651 1282 jobj->set_arraycopy_src();
kvn@3651 1283 new_edges++;
kvn@3651 1284 }
kvn@3651 1285 // and stop here.
kvn@3651 1286 continue;
kvn@3651 1287 }
kvn@3651 1288 if (!add_edge(use, jobj))
kvn@3651 1289 continue; // No new edge added, there was such edge already.
kvn@3651 1290 new_edges++;
kvn@3651 1291 if (use->is_LocalVar()) {
kvn@3651 1292 add_uses_to_worklist(use);
kvn@3651 1293 if (use->arraycopy_dst()) {
kvn@3651 1294 for (EdgeIterator i(use); i.has_next(); i.next()) {
kvn@3651 1295 PointsToNode* e = i.get();
kvn@3651 1296 if (e->is_Arraycopy()) {
kvn@3651 1297 if (jobj == null_obj) // NULL object does not have field edges
kvn@3651 1298 continue;
kvn@3651 1299 // Add edge from arraycopy's destination java object to Arraycopy node.
kvn@3651 1300 if (add_edge(jobj, e)) {
kvn@3651 1301 new_edges++;
kvn@3651 1302 jobj->set_arraycopy_dst();
kvn@3651 1303 }
kvn@3651 1304 }
kvn@3651 1305 }
kvn@3651 1306 }
kvn@3651 1307 } else {
kvn@3651 1308 // Added new edge to stored in field values.
kvn@3651 1309 // Put on worklist all field's uses (loads) and
kvn@3651 1310 // related field nodes (same base and offset).
kvn@3651 1311 add_field_uses_to_worklist(use->as_Field());
kvn@3651 1312 }
kvn@3651 1313 }
kvn@3651 1314 return new_edges;
kvn@3651 1315 }
kvn@3651 1316
kvn@3651 1317 // Put on worklist all related field nodes.
kvn@3651 1318 void ConnectionGraph::add_field_uses_to_worklist(FieldNode* field) {
kvn@3651 1319 assert(field->is_oop(), "sanity");
kvn@3651 1320 int offset = field->offset();
kvn@3651 1321 add_uses_to_worklist(field);
kvn@3651 1322 // Loop over all bases of this field and push on worklist Field nodes
kvn@3651 1323 // with the same offset and base (since they may reference the same field).
kvn@3651 1324 for (BaseIterator i(field); i.has_next(); i.next()) {
kvn@3651 1325 PointsToNode* base = i.get();
kvn@3651 1326 add_fields_to_worklist(field, base);
kvn@3651 1327 // Check if the base was source object of arraycopy and go over arraycopy's
kvn@3651 1328 // destination objects since values stored to a field of source object are
kvn@3651 1329 // accessable by uses (loads) of fields of destination objects.
kvn@3651 1330 if (base->arraycopy_src()) {
kvn@3651 1331 for (UseIterator j(base); j.has_next(); j.next()) {
kvn@3651 1332 PointsToNode* arycp = j.get();
kvn@3651 1333 if (arycp->is_Arraycopy()) {
kvn@3651 1334 for (UseIterator k(arycp); k.has_next(); k.next()) {
kvn@3651 1335 PointsToNode* abase = k.get();
kvn@3651 1336 if (abase->arraycopy_dst() && abase != base) {
kvn@3651 1337 // Look for the same arracopy reference.
kvn@3651 1338 add_fields_to_worklist(field, abase);
kvn@3651 1339 }
kvn@3651 1340 }
kvn@3651 1341 }
kvn@3651 1342 }
kvn@3651 1343 }
kvn@3651 1344 }
kvn@3651 1345 }
kvn@3651 1346
kvn@3651 1347 // Put on worklist all related field nodes.
kvn@3651 1348 void ConnectionGraph::add_fields_to_worklist(FieldNode* field, PointsToNode* base) {
kvn@3651 1349 int offset = field->offset();
kvn@3651 1350 if (base->is_LocalVar()) {
kvn@3651 1351 for (UseIterator j(base); j.has_next(); j.next()) {
kvn@3651 1352 PointsToNode* f = j.get();
kvn@3651 1353 if (PointsToNode::is_base_use(f)) { // Field
kvn@3651 1354 f = PointsToNode::get_use_node(f);
kvn@3651 1355 if (f == field || !f->as_Field()->is_oop())
kvn@3651 1356 continue;
kvn@3651 1357 int offs = f->as_Field()->offset();
kvn@3651 1358 if (offs == offset || offset == Type::OffsetBot || offs == Type::OffsetBot) {
kvn@3651 1359 add_to_worklist(f);
kvn@3651 1360 }
kvn@3651 1361 }
kvn@3651 1362 }
kvn@3651 1363 } else {
kvn@3651 1364 assert(base->is_JavaObject(), "sanity");
kvn@3651 1365 if (// Skip phantom_object since it is only used to indicate that
kvn@3651 1366 // this field's content globally escapes.
kvn@3651 1367 (base != phantom_obj) &&
kvn@3651 1368 // NULL object node does not have fields.
kvn@3651 1369 (base != null_obj)) {
kvn@3651 1370 for (EdgeIterator i(base); i.has_next(); i.next()) {
kvn@3651 1371 PointsToNode* f = i.get();
kvn@3651 1372 // Skip arraycopy edge since store to destination object field
kvn@3651 1373 // does not update value in source object field.
kvn@3651 1374 if (f->is_Arraycopy()) {
kvn@3651 1375 assert(base->arraycopy_dst(), "sanity");
kvn@3651 1376 continue;
kvn@3651 1377 }
kvn@3651 1378 if (f == field || !f->as_Field()->is_oop())
kvn@3651 1379 continue;
kvn@3651 1380 int offs = f->as_Field()->offset();
kvn@3651 1381 if (offs == offset || offset == Type::OffsetBot || offs == Type::OffsetBot) {
kvn@3651 1382 add_to_worklist(f);
kvn@3651 1383 }
kvn@3651 1384 }
kvn@3651 1385 }
kvn@3651 1386 }
kvn@3651 1387 }
kvn@3651 1388
kvn@3651 1389 // Find fields which have unknown value.
kvn@3651 1390 int ConnectionGraph::find_field_value(FieldNode* field) {
kvn@3651 1391 // Escaped fields should have init value already.
kvn@3651 1392 assert(field->escape_state() == PointsToNode::NoEscape, "sanity");
kvn@3651 1393 int new_edges = 0;
kvn@3651 1394 for (BaseIterator i(field); i.has_next(); i.next()) {
kvn@3651 1395 PointsToNode* base = i.get();
kvn@3651 1396 if (base->is_JavaObject()) {
kvn@3651 1397 // Skip Allocate's fields which will be processed later.
kvn@3651 1398 if (base->ideal_node()->is_Allocate())
kvn@3651 1399 return 0;
kvn@3651 1400 assert(base == null_obj, "only NULL ptr base expected here");
kvn@3651 1401 }
kvn@3651 1402 }
kvn@3651 1403 if (add_edge(field, phantom_obj)) {
kvn@3651 1404 // New edge was added
kvn@3651 1405 new_edges++;
kvn@3651 1406 add_field_uses_to_worklist(field);
kvn@3651 1407 }
kvn@3651 1408 return new_edges;
kvn@3651 1409 }
kvn@3651 1410
kvn@3651 1411 // Find fields initializing values for allocations.
kvn@3651 1412 int ConnectionGraph::find_init_values(JavaObjectNode* pta, PointsToNode* init_val, PhaseTransform* phase) {
kvn@3651 1413 assert(pta->escape_state() == PointsToNode::NoEscape, "Not escaped Allocate nodes only");
kvn@3651 1414 int new_edges = 0;
kvn@3651 1415 Node* alloc = pta->ideal_node();
kvn@3651 1416 if (init_val == phantom_obj) {
kvn@3651 1417 // Do nothing for Allocate nodes since its fields values are "known".
kvn@3651 1418 if (alloc->is_Allocate())
kvn@3651 1419 return 0;
kvn@3651 1420 assert(alloc->as_CallStaticJava(), "sanity");
kvn@3651 1421 #ifdef ASSERT
kvn@3651 1422 if (alloc->as_CallStaticJava()->method() == NULL) {
kvn@3651 1423 const char* name = alloc->as_CallStaticJava()->_name;
kvn@3651 1424 assert(strncmp(name, "_multianewarray", 15) == 0, "sanity");
kvn@3651 1425 }
kvn@3651 1426 #endif
kvn@3651 1427 // Non-escaped allocation returned from Java or runtime call have
kvn@3651 1428 // unknown values in fields.
kvn@3651 1429 for (EdgeIterator i(pta); i.has_next(); i.next()) {
kvn@4255 1430 PointsToNode* field = i.get();
kvn@4255 1431 if (field->is_Field() && field->as_Field()->is_oop()) {
kvn@4255 1432 if (add_edge(field, phantom_obj)) {
kvn@3651 1433 // New edge was added
kvn@3651 1434 new_edges++;
kvn@4255 1435 add_field_uses_to_worklist(field->as_Field());
kvn@3651 1436 }
kvn@3651 1437 }
kvn@3651 1438 }
kvn@3651 1439 return new_edges;
kvn@3651 1440 }
kvn@3651 1441 assert(init_val == null_obj, "sanity");
kvn@3651 1442 // Do nothing for Call nodes since its fields values are unknown.
kvn@3651 1443 if (!alloc->is_Allocate())
kvn@3651 1444 return 0;
kvn@3651 1445
kvn@3651 1446 InitializeNode* ini = alloc->as_Allocate()->initialization();
kvn@3651 1447 Compile* C = _compile;
kvn@3651 1448 bool visited_bottom_offset = false;
kvn@3651 1449 GrowableArray<int> offsets_worklist;
kvn@3651 1450
kvn@3651 1451 // Check if an oop field's initializing value is recorded and add
kvn@3651 1452 // a corresponding NULL if field's value if it is not recorded.
kvn@3651 1453 // Connection Graph does not record a default initialization by NULL
kvn@3651 1454 // captured by Initialize node.
kvn@3651 1455 //
kvn@3651 1456 for (EdgeIterator i(pta); i.has_next(); i.next()) {
kvn@4255 1457 PointsToNode* field = i.get(); // Field (AddP)
kvn@4255 1458 if (!field->is_Field() || !field->as_Field()->is_oop())
kvn@3651 1459 continue; // Not oop field
kvn@4255 1460 int offset = field->as_Field()->offset();
kvn@3651 1461 if (offset == Type::OffsetBot) {
kvn@3651 1462 if (!visited_bottom_offset) {
kvn@3651 1463 // OffsetBot is used to reference array's element,
kvn@3651 1464 // always add reference to NULL to all Field nodes since we don't
kvn@3651 1465 // known which element is referenced.
kvn@4255 1466 if (add_edge(field, null_obj)) {
kvn@3651 1467 // New edge was added
kvn@3651 1468 new_edges++;
kvn@4255 1469 add_field_uses_to_worklist(field->as_Field());
kvn@3651 1470 visited_bottom_offset = true;
kvn@3651 1471 }
kvn@3651 1472 }
kvn@3651 1473 } else {
kvn@3651 1474 // Check only oop fields.
kvn@4255 1475 const Type* adr_type = field->ideal_node()->as_AddP()->bottom_type();
kvn@3651 1476 if (adr_type->isa_rawptr()) {
kvn@3651 1477 #ifdef ASSERT
kvn@3651 1478 // Raw pointers are used for initializing stores so skip it
kvn@3651 1479 // since it should be recorded already
kvn@4255 1480 Node* base = get_addp_base(field->ideal_node());
kvn@3651 1481 assert(adr_type->isa_rawptr() && base->is_Proj() &&
kvn@3651 1482 (base->in(0) == alloc),"unexpected pointer type");
kvn@3651 1483 #endif
kvn@3651 1484 continue;
kvn@3651 1485 }
kvn@3651 1486 if (!offsets_worklist.contains(offset)) {
kvn@3651 1487 offsets_worklist.append(offset);
kvn@3651 1488 Node* value = NULL;
kvn@3651 1489 if (ini != NULL) {
kvn@4255 1490 // StoreP::memory_type() == T_ADDRESS
kvn@4255 1491 BasicType ft = UseCompressedOops ? T_NARROWOOP : T_ADDRESS;
kvn@4255 1492 Node* store = ini->find_captured_store(offset, type2aelembytes(ft, true), phase);
kvn@4255 1493 // Make sure initializing store has the same type as this AddP.
kvn@4255 1494 // This AddP may reference non existing field because it is on a
kvn@4255 1495 // dead branch of bimorphic call which is not eliminated yet.
kvn@4255 1496 if (store != NULL && store->is_Store() &&
kvn@4255 1497 store->as_Store()->memory_type() == ft) {
kvn@3651 1498 value = store->in(MemNode::ValueIn);
kvn@4255 1499 #ifdef ASSERT
kvn@4255 1500 if (VerifyConnectionGraph) {
kvn@4255 1501 // Verify that AddP already points to all objects the value points to.
kvn@4255 1502 PointsToNode* val = ptnode_adr(value->_idx);
kvn@4255 1503 assert((val != NULL), "should be processed already");
kvn@4255 1504 PointsToNode* missed_obj = NULL;
kvn@4255 1505 if (val->is_JavaObject()) {
kvn@4255 1506 if (!field->points_to(val->as_JavaObject())) {
kvn@4255 1507 missed_obj = val;
kvn@4255 1508 }
kvn@4255 1509 } else {
kvn@4255 1510 if (!val->is_LocalVar() || (val->edge_count() == 0)) {
kvn@4255 1511 tty->print_cr("----------init store has invalid value -----");
kvn@4255 1512 store->dump();
kvn@4255 1513 val->dump();
kvn@4255 1514 assert(val->is_LocalVar() && (val->edge_count() > 0), "should be processed already");
kvn@4255 1515 }
kvn@4255 1516 for (EdgeIterator j(val); j.has_next(); j.next()) {
kvn@4255 1517 PointsToNode* obj = j.get();
kvn@4255 1518 if (obj->is_JavaObject()) {
kvn@4255 1519 if (!field->points_to(obj->as_JavaObject())) {
kvn@4255 1520 missed_obj = obj;
kvn@4255 1521 break;
kvn@4255 1522 }
kvn@4255 1523 }
kvn@4255 1524 }
kvn@4255 1525 }
kvn@4255 1526 if (missed_obj != NULL) {
kvn@4255 1527 tty->print_cr("----------field---------------------------------");
kvn@4255 1528 field->dump();
kvn@4255 1529 tty->print_cr("----------missed referernce to object-----------");
kvn@4255 1530 missed_obj->dump();
kvn@4255 1531 tty->print_cr("----------object referernced by init store -----");
kvn@4255 1532 store->dump();
kvn@4255 1533 val->dump();
kvn@4255 1534 assert(!field->points_to(missed_obj->as_JavaObject()), "missed JavaObject reference");
kvn@4255 1535 }
kvn@4255 1536 }
kvn@4255 1537 #endif
kvn@3651 1538 } else {
kvn@3651 1539 // There could be initializing stores which follow allocation.
kvn@3651 1540 // For example, a volatile field store is not collected
kvn@3651 1541 // by Initialize node.
kvn@3651 1542 //
kvn@3651 1543 // Need to check for dependent loads to separate such stores from
kvn@3651 1544 // stores which follow loads. For now, add initial value NULL so
kvn@3651 1545 // that compare pointers optimization works correctly.
kvn@3651 1546 }
kvn@3651 1547 }
kvn@3651 1548 if (value == NULL) {
kvn@3651 1549 // A field's initializing value was not recorded. Add NULL.
kvn@4255 1550 if (add_edge(field, null_obj)) {
kvn@3651 1551 // New edge was added
kvn@3651 1552 new_edges++;
kvn@4255 1553 add_field_uses_to_worklist(field->as_Field());
kvn@3651 1554 }
kvn@3651 1555 }
kvn@3651 1556 }
kvn@3651 1557 }
kvn@3651 1558 }
kvn@3651 1559 return new_edges;
kvn@3651 1560 }
kvn@3651 1561
kvn@3651 1562 // Adjust scalar_replaceable state after Connection Graph is built.
kvn@3651 1563 void ConnectionGraph::adjust_scalar_replaceable_state(JavaObjectNode* jobj) {
kvn@3651 1564 // Search for non-escaping objects which are not scalar replaceable
kvn@3651 1565 // and mark them to propagate the state to referenced objects.
kvn@3651 1566
kvn@3651 1567 // 1. An object is not scalar replaceable if the field into which it is
kvn@3651 1568 // stored has unknown offset (stored into unknown element of an array).
kvn@3651 1569 //
kvn@3651 1570 for (UseIterator i(jobj); i.has_next(); i.next()) {
kvn@3651 1571 PointsToNode* use = i.get();
kvn@3651 1572 assert(!use->is_Arraycopy(), "sanity");
kvn@3651 1573 if (use->is_Field()) {
kvn@3651 1574 FieldNode* field = use->as_Field();
kvn@3651 1575 assert(field->is_oop() && field->scalar_replaceable() &&
kvn@3651 1576 field->fields_escape_state() == PointsToNode::NoEscape, "sanity");
kvn@3651 1577 if (field->offset() == Type::OffsetBot) {
kvn@3651 1578 jobj->set_scalar_replaceable(false);
kvn@3651 1579 return;
kvn@3651 1580 }
kvn@3651 1581 }
kvn@3651 1582 assert(use->is_Field() || use->is_LocalVar(), "sanity");
kvn@3651 1583 // 2. An object is not scalar replaceable if it is merged with other objects.
kvn@3651 1584 for (EdgeIterator j(use); j.has_next(); j.next()) {
kvn@3651 1585 PointsToNode* ptn = j.get();
kvn@3651 1586 if (ptn->is_JavaObject() && ptn != jobj) {
kvn@3651 1587 // Mark all objects.
kvn@3651 1588 jobj->set_scalar_replaceable(false);
kvn@3651 1589 ptn->set_scalar_replaceable(false);
kvn@3651 1590 }
kvn@3651 1591 }
kvn@3651 1592 if (!jobj->scalar_replaceable()) {
kvn@3651 1593 return;
kvn@3651 1594 }
kvn@3651 1595 }
kvn@3651 1596
kvn@3651 1597 for (EdgeIterator j(jobj); j.has_next(); j.next()) {
kvn@3651 1598 // Non-escaping object node should point only to field nodes.
kvn@3651 1599 FieldNode* field = j.get()->as_Field();
kvn@3651 1600 int offset = field->as_Field()->offset();
kvn@3651 1601
kvn@3651 1602 // 3. An object is not scalar replaceable if it has a field with unknown
kvn@3651 1603 // offset (array's element is accessed in loop).
kvn@3651 1604 if (offset == Type::OffsetBot) {
kvn@3651 1605 jobj->set_scalar_replaceable(false);
kvn@3651 1606 return;
kvn@3651 1607 }
kvn@3651 1608 // 4. Currently an object is not scalar replaceable if a LoadStore node
kvn@3651 1609 // access its field since the field value is unknown after it.
kvn@3651 1610 //
kvn@3651 1611 Node* n = field->ideal_node();
kvn@3651 1612 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
kvn@3651 1613 if (n->fast_out(i)->is_LoadStore()) {
kvn@3651 1614 jobj->set_scalar_replaceable(false);
kvn@3651 1615 return;
kvn@3651 1616 }
kvn@3651 1617 }
kvn@3651 1618
kvn@3651 1619 // 5. Or the address may point to more then one object. This may produce
kvn@3651 1620 // the false positive result (set not scalar replaceable)
kvn@3651 1621 // since the flow-insensitive escape analysis can't separate
kvn@3651 1622 // the case when stores overwrite the field's value from the case
kvn@3651 1623 // when stores happened on different control branches.
kvn@3651 1624 //
kvn@3651 1625 // Note: it will disable scalar replacement in some cases:
kvn@3651 1626 //
kvn@3651 1627 // Point p[] = new Point[1];
kvn@3651 1628 // p[0] = new Point(); // Will be not scalar replaced
kvn@3651 1629 //
kvn@3651 1630 // but it will save us from incorrect optimizations in next cases:
kvn@3651 1631 //
kvn@3651 1632 // Point p[] = new Point[1];
kvn@3651 1633 // if ( x ) p[0] = new Point(); // Will be not scalar replaced
kvn@3651 1634 //
kvn@3651 1635 if (field->base_count() > 1) {
kvn@3651 1636 for (BaseIterator i(field); i.has_next(); i.next()) {
kvn@3651 1637 PointsToNode* base = i.get();
kvn@3651 1638 // Don't take into account LocalVar nodes which
kvn@3651 1639 // may point to only one object which should be also
kvn@3651 1640 // this field's base by now.
kvn@3651 1641 if (base->is_JavaObject() && base != jobj) {
kvn@3651 1642 // Mark all bases.
kvn@3651 1643 jobj->set_scalar_replaceable(false);
kvn@3651 1644 base->set_scalar_replaceable(false);
kvn@3651 1645 }
kvn@3651 1646 }
kvn@3651 1647 }
kvn@3651 1648 }
kvn@3651 1649 }
kvn@3651 1650
kvn@3651 1651 #ifdef ASSERT
kvn@3651 1652 void ConnectionGraph::verify_connection_graph(
kvn@3651 1653 GrowableArray<PointsToNode*>& ptnodes_worklist,
kvn@3651 1654 GrowableArray<JavaObjectNode*>& non_escaped_worklist,
kvn@3651 1655 GrowableArray<JavaObjectNode*>& java_objects_worklist,
kvn@3651 1656 GrowableArray<Node*>& addp_worklist) {
kvn@3651 1657 // Verify that graph is complete - no new edges could be added.
kvn@3651 1658 int java_objects_length = java_objects_worklist.length();
kvn@3651 1659 int non_escaped_length = non_escaped_worklist.length();
kvn@3651 1660 int new_edges = 0;
kvn@3651 1661 for (int next = 0; next < java_objects_length; ++next) {
kvn@3651 1662 JavaObjectNode* ptn = java_objects_worklist.at(next);
kvn@3651 1663 new_edges += add_java_object_edges(ptn, true);
kvn@3651 1664 }
kvn@3651 1665 assert(new_edges == 0, "graph was not complete");
kvn@3651 1666 // Verify that escape state is final.
kvn@3651 1667 int length = non_escaped_worklist.length();
kvn@3651 1668 find_non_escaped_objects(ptnodes_worklist, non_escaped_worklist);
kvn@3651 1669 assert((non_escaped_length == non_escaped_worklist.length()) &&
kvn@3651 1670 (non_escaped_length == length) &&
kvn@3651 1671 (_worklist.length() == 0), "escape state was not final");
kvn@3651 1672
kvn@3651 1673 // Verify fields information.
kvn@3651 1674 int addp_length = addp_worklist.length();
kvn@3651 1675 for (int next = 0; next < addp_length; ++next ) {
kvn@3651 1676 Node* n = addp_worklist.at(next);
kvn@3651 1677 FieldNode* field = ptnode_adr(n->_idx)->as_Field();
kvn@3651 1678 if (field->is_oop()) {
kvn@3651 1679 // Verify that field has all bases
kvn@3651 1680 Node* base = get_addp_base(n);
kvn@3651 1681 PointsToNode* ptn = ptnode_adr(base->_idx);
kvn@3651 1682 if (ptn->is_JavaObject()) {
kvn@3651 1683 assert(field->has_base(ptn->as_JavaObject()), "sanity");
kvn@3651 1684 } else {
kvn@3651 1685 assert(ptn->is_LocalVar(), "sanity");
kvn@3651 1686 for (EdgeIterator i(ptn); i.has_next(); i.next()) {
kvn@3651 1687 PointsToNode* e = i.get();
kvn@3651 1688 if (e->is_JavaObject()) {
kvn@3651 1689 assert(field->has_base(e->as_JavaObject()), "sanity");
kvn@3651 1690 }
kvn@3651 1691 }
kvn@3651 1692 }
kvn@3651 1693 // Verify that all fields have initializing values.
kvn@3651 1694 if (field->edge_count() == 0) {
kvn@4255 1695 tty->print_cr("----------field does not have references----------");
kvn@3651 1696 field->dump();
kvn@4255 1697 for (BaseIterator i(field); i.has_next(); i.next()) {
kvn@4255 1698 PointsToNode* base = i.get();
kvn@4255 1699 tty->print_cr("----------field has next base---------------------");
kvn@4255 1700 base->dump();
kvn@4255 1701 if (base->is_JavaObject() && (base != phantom_obj) && (base != null_obj)) {
kvn@4255 1702 tty->print_cr("----------base has fields-------------------------");
kvn@4255 1703 for (EdgeIterator j(base); j.has_next(); j.next()) {
kvn@4255 1704 j.get()->dump();
kvn@4255 1705 }
kvn@4255 1706 tty->print_cr("----------base has references---------------------");
kvn@4255 1707 for (UseIterator j(base); j.has_next(); j.next()) {
kvn@4255 1708 j.get()->dump();
kvn@4255 1709 }
kvn@4255 1710 }
kvn@4255 1711 }
kvn@4255 1712 for (UseIterator i(field); i.has_next(); i.next()) {
kvn@4255 1713 i.get()->dump();
kvn@4255 1714 }
kvn@3651 1715 assert(field->edge_count() > 0, "sanity");
kvn@3651 1716 }
kvn@3651 1717 }
kvn@3651 1718 }
kvn@3651 1719 }
kvn@3651 1720 #endif
kvn@3651 1721
kvn@3651 1722 // Optimize ideal graph.
kvn@3651 1723 void ConnectionGraph::optimize_ideal_graph(GrowableArray<Node*>& ptr_cmp_worklist,
kvn@3651 1724 GrowableArray<Node*>& storestore_worklist) {
kvn@3651 1725 Compile* C = _compile;
kvn@3651 1726 PhaseIterGVN* igvn = _igvn;
kvn@3651 1727 if (EliminateLocks) {
kvn@3651 1728 // Mark locks before changing ideal graph.
kvn@3651 1729 int cnt = C->macro_count();
kvn@3651 1730 for( int i=0; i < cnt; i++ ) {
kvn@3651 1731 Node *n = C->macro_node(i);
kvn@3651 1732 if (n->is_AbstractLock()) { // Lock and Unlock nodes
kvn@3651 1733 AbstractLockNode* alock = n->as_AbstractLock();
kvn@3651 1734 if (!alock->is_non_esc_obj()) {
kvn@3651 1735 if (not_global_escape(alock->obj_node())) {
kvn@3651 1736 assert(!alock->is_eliminated() || alock->is_coarsened(), "sanity");
kvn@3651 1737 // The lock could be marked eliminated by lock coarsening
kvn@3651 1738 // code during first IGVN before EA. Replace coarsened flag
kvn@3651 1739 // to eliminate all associated locks/unlocks.
kvn@3651 1740 alock->set_non_esc_obj();
kvn@3651 1741 }
kvn@3651 1742 }
kvn@3651 1743 }
kvn@3651 1744 }
kvn@3651 1745 }
kvn@3651 1746
kvn@3651 1747 if (OptimizePtrCompare) {
kvn@3651 1748 // Add ConI(#CC_GT) and ConI(#CC_EQ).
kvn@3651 1749 _pcmp_neq = igvn->makecon(TypeInt::CC_GT);
kvn@3651 1750 _pcmp_eq = igvn->makecon(TypeInt::CC_EQ);
kvn@3651 1751 // Optimize objects compare.
kvn@3651 1752 while (ptr_cmp_worklist.length() != 0) {
kvn@3651 1753 Node *n = ptr_cmp_worklist.pop();
kvn@3651 1754 Node *res = optimize_ptr_compare(n);
kvn@3651 1755 if (res != NULL) {
kvn@3651 1756 #ifndef PRODUCT
kvn@3651 1757 if (PrintOptimizePtrCompare) {
kvn@3651 1758 tty->print_cr("++++ Replaced: %d %s(%d,%d) --> %s", n->_idx, (n->Opcode() == Op_CmpP ? "CmpP" : "CmpN"), n->in(1)->_idx, n->in(2)->_idx, (res == _pcmp_eq ? "EQ" : "NotEQ"));
kvn@3651 1759 if (Verbose) {
kvn@3651 1760 n->dump(1);
kvn@3651 1761 }
kvn@3651 1762 }
kvn@3651 1763 #endif
kvn@3651 1764 igvn->replace_node(n, res);
kvn@3651 1765 }
kvn@3651 1766 }
kvn@3651 1767 // cleanup
kvn@3651 1768 if (_pcmp_neq->outcnt() == 0)
kvn@3651 1769 igvn->hash_delete(_pcmp_neq);
kvn@3651 1770 if (_pcmp_eq->outcnt() == 0)
kvn@3651 1771 igvn->hash_delete(_pcmp_eq);
kvn@3651 1772 }
kvn@3651 1773
kvn@3651 1774 // For MemBarStoreStore nodes added in library_call.cpp, check
kvn@3651 1775 // escape status of associated AllocateNode and optimize out
kvn@3651 1776 // MemBarStoreStore node if the allocated object never escapes.
kvn@3651 1777 while (storestore_worklist.length() != 0) {
kvn@3651 1778 Node *n = storestore_worklist.pop();
kvn@3651 1779 MemBarStoreStoreNode *storestore = n ->as_MemBarStoreStore();
kvn@3651 1780 Node *alloc = storestore->in(MemBarNode::Precedent)->in(0);
kvn@3651 1781 assert (alloc->is_Allocate(), "storestore should point to AllocateNode");
kvn@3651 1782 if (not_global_escape(alloc)) {
kvn@3651 1783 MemBarNode* mb = MemBarNode::make(C, Op_MemBarCPUOrder, Compile::AliasIdxBot);
kvn@3651 1784 mb->init_req(TypeFunc::Memory, storestore->in(TypeFunc::Memory));
kvn@3651 1785 mb->init_req(TypeFunc::Control, storestore->in(TypeFunc::Control));
kvn@3651 1786 igvn->register_new_node_with_optimizer(mb);
kvn@3651 1787 igvn->replace_node(storestore, mb);
kvn@3651 1788 }
kvn@3651 1789 }
kvn@3651 1790 }
kvn@3651 1791
kvn@3651 1792 // Optimize objects compare.
kvn@3651 1793 Node* ConnectionGraph::optimize_ptr_compare(Node* n) {
kvn@3651 1794 assert(OptimizePtrCompare, "sanity");
kvn@3651 1795 PointsToNode* ptn1 = ptnode_adr(n->in(1)->_idx);
kvn@3651 1796 PointsToNode* ptn2 = ptnode_adr(n->in(2)->_idx);
kvn@3651 1797 JavaObjectNode* jobj1 = unique_java_object(n->in(1));
kvn@3651 1798 JavaObjectNode* jobj2 = unique_java_object(n->in(2));
kvn@3651 1799 assert(ptn1->is_JavaObject() || ptn1->is_LocalVar(), "sanity");
kvn@3651 1800 assert(ptn2->is_JavaObject() || ptn2->is_LocalVar(), "sanity");
kvn@3651 1801
kvn@3651 1802 // Check simple cases first.
kvn@3651 1803 if (jobj1 != NULL) {
kvn@3651 1804 if (jobj1->escape_state() == PointsToNode::NoEscape) {
kvn@3651 1805 if (jobj1 == jobj2) {
kvn@3651 1806 // Comparing the same not escaping object.
kvn@3651 1807 return _pcmp_eq;
kvn@3651 1808 }
kvn@3651 1809 Node* obj = jobj1->ideal_node();
kvn@3651 1810 // Comparing not escaping allocation.
kvn@3651 1811 if ((obj->is_Allocate() || obj->is_CallStaticJava()) &&
kvn@3651 1812 !ptn2->points_to(jobj1)) {
kvn@3651 1813 return _pcmp_neq; // This includes nullness check.
kvn@3651 1814 }
kvn@3651 1815 }
kvn@3651 1816 }
kvn@3651 1817 if (jobj2 != NULL) {
kvn@3651 1818 if (jobj2->escape_state() == PointsToNode::NoEscape) {
kvn@3651 1819 Node* obj = jobj2->ideal_node();
kvn@3651 1820 // Comparing not escaping allocation.
kvn@3651 1821 if ((obj->is_Allocate() || obj->is_CallStaticJava()) &&
kvn@3651 1822 !ptn1->points_to(jobj2)) {
kvn@3651 1823 return _pcmp_neq; // This includes nullness check.
kvn@3651 1824 }
kvn@3651 1825 }
kvn@3651 1826 }
kvn@3651 1827 if (jobj1 != NULL && jobj1 != phantom_obj &&
kvn@3651 1828 jobj2 != NULL && jobj2 != phantom_obj &&
kvn@3651 1829 jobj1->ideal_node()->is_Con() &&
kvn@3651 1830 jobj2->ideal_node()->is_Con()) {
kvn@3651 1831 // Klass or String constants compare. Need to be careful with
kvn@3651 1832 // compressed pointers - compare types of ConN and ConP instead of nodes.
kvn@5111 1833 const Type* t1 = jobj1->ideal_node()->get_ptr_type();
kvn@5111 1834 const Type* t2 = jobj2->ideal_node()->get_ptr_type();
kvn@3651 1835 if (t1->make_ptr() == t2->make_ptr()) {
kvn@3651 1836 return _pcmp_eq;
kvn@3651 1837 } else {
kvn@3651 1838 return _pcmp_neq;
kvn@3651 1839 }
kvn@3651 1840 }
kvn@3651 1841 if (ptn1->meet(ptn2)) {
kvn@3651 1842 return NULL; // Sets are not disjoint
kvn@3651 1843 }
kvn@3651 1844
kvn@3651 1845 // Sets are disjoint.
kvn@3651 1846 bool set1_has_unknown_ptr = ptn1->points_to(phantom_obj);
kvn@3651 1847 bool set2_has_unknown_ptr = ptn2->points_to(phantom_obj);
kvn@3651 1848 bool set1_has_null_ptr = ptn1->points_to(null_obj);
kvn@3651 1849 bool set2_has_null_ptr = ptn2->points_to(null_obj);
kvn@3651 1850 if (set1_has_unknown_ptr && set2_has_null_ptr ||
kvn@3651 1851 set2_has_unknown_ptr && set1_has_null_ptr) {
kvn@3651 1852 // Check nullness of unknown object.
kvn@3651 1853 return NULL;
kvn@3651 1854 }
kvn@3651 1855
kvn@3651 1856 // Disjointness by itself is not sufficient since
kvn@3651 1857 // alias analysis is not complete for escaped objects.
kvn@3651 1858 // Disjoint sets are definitely unrelated only when
kvn@3651 1859 // at least one set has only not escaping allocations.
kvn@3651 1860 if (!set1_has_unknown_ptr && !set1_has_null_ptr) {
kvn@3651 1861 if (ptn1->non_escaping_allocation()) {
kvn@3651 1862 return _pcmp_neq;
kvn@3651 1863 }
kvn@3651 1864 }
kvn@3651 1865 if (!set2_has_unknown_ptr && !set2_has_null_ptr) {
kvn@3651 1866 if (ptn2->non_escaping_allocation()) {
kvn@3651 1867 return _pcmp_neq;
kvn@3651 1868 }
kvn@3651 1869 }
kvn@3651 1870 return NULL;
kvn@3651 1871 }
kvn@3651 1872
kvn@3651 1873 // Connection Graph constuction functions.
kvn@3651 1874
kvn@3651 1875 void ConnectionGraph::add_local_var(Node *n, PointsToNode::EscapeState es) {
kvn@3651 1876 PointsToNode* ptadr = _nodes.at(n->_idx);
kvn@3651 1877 if (ptadr != NULL) {
kvn@3651 1878 assert(ptadr->is_LocalVar() && ptadr->ideal_node() == n, "sanity");
kvn@3651 1879 return;
kvn@3651 1880 }
kvn@3651 1881 Compile* C = _compile;
kvn@3651 1882 ptadr = new (C->comp_arena()) LocalVarNode(C, n, es);
kvn@3651 1883 _nodes.at_put(n->_idx, ptadr);
kvn@3651 1884 }
kvn@3651 1885
kvn@3651 1886 void ConnectionGraph::add_java_object(Node *n, PointsToNode::EscapeState es) {
kvn@3651 1887 PointsToNode* ptadr = _nodes.at(n->_idx);
kvn@3651 1888 if (ptadr != NULL) {
kvn@3651 1889 assert(ptadr->is_JavaObject() && ptadr->ideal_node() == n, "sanity");
kvn@3651 1890 return;
kvn@3651 1891 }
kvn@3651 1892 Compile* C = _compile;
kvn@3651 1893 ptadr = new (C->comp_arena()) JavaObjectNode(C, n, es);
kvn@3651 1894 _nodes.at_put(n->_idx, ptadr);
kvn@3651 1895 }
kvn@3651 1896
kvn@3651 1897 void ConnectionGraph::add_field(Node *n, PointsToNode::EscapeState es, int offset) {
kvn@3651 1898 PointsToNode* ptadr = _nodes.at(n->_idx);
kvn@3651 1899 if (ptadr != NULL) {
kvn@3651 1900 assert(ptadr->is_Field() && ptadr->ideal_node() == n, "sanity");
kvn@3651 1901 return;
kvn@3651 1902 }
twisti@3969 1903 bool unsafe = false;
twisti@3969 1904 bool is_oop = is_oop_field(n, offset, &unsafe);
twisti@3969 1905 if (unsafe) {
twisti@3969 1906 es = PointsToNode::GlobalEscape;
twisti@3969 1907 }
kvn@3651 1908 Compile* C = _compile;
kvn@3651 1909 FieldNode* field = new (C->comp_arena()) FieldNode(C, n, es, offset, is_oop);
kvn@3651 1910 _nodes.at_put(n->_idx, field);
kvn@3651 1911 }
kvn@3651 1912
kvn@3651 1913 void ConnectionGraph::add_arraycopy(Node *n, PointsToNode::EscapeState es,
kvn@3651 1914 PointsToNode* src, PointsToNode* dst) {
kvn@3651 1915 assert(!src->is_Field() && !dst->is_Field(), "only for JavaObject and LocalVar");
kvn@3651 1916 assert((src != null_obj) && (dst != null_obj), "not for ConP NULL");
kvn@3651 1917 PointsToNode* ptadr = _nodes.at(n->_idx);
kvn@3651 1918 if (ptadr != NULL) {
kvn@3651 1919 assert(ptadr->is_Arraycopy() && ptadr->ideal_node() == n, "sanity");
kvn@3651 1920 return;
kvn@3651 1921 }
kvn@3651 1922 Compile* C = _compile;
kvn@3651 1923 ptadr = new (C->comp_arena()) ArraycopyNode(C, n, es);
kvn@3651 1924 _nodes.at_put(n->_idx, ptadr);
kvn@3651 1925 // Add edge from arraycopy node to source object.
kvn@3651 1926 (void)add_edge(ptadr, src);
kvn@3651 1927 src->set_arraycopy_src();
kvn@3651 1928 // Add edge from destination object to arraycopy node.
kvn@3651 1929 (void)add_edge(dst, ptadr);
kvn@3651 1930 dst->set_arraycopy_dst();
kvn@3651 1931 }
kvn@3651 1932
twisti@3969 1933 bool ConnectionGraph::is_oop_field(Node* n, int offset, bool* unsafe) {
kvn@3651 1934 const Type* adr_type = n->as_AddP()->bottom_type();
kvn@3651 1935 BasicType bt = T_INT;
kvn@3651 1936 if (offset == Type::OffsetBot) {
kvn@3651 1937 // Check only oop fields.
kvn@3651 1938 if (!adr_type->isa_aryptr() ||
kvn@3651 1939 (adr_type->isa_aryptr()->klass() == NULL) ||
kvn@3651 1940 adr_type->isa_aryptr()->klass()->is_obj_array_klass()) {
kvn@3651 1941 // OffsetBot is used to reference array's element. Ignore first AddP.
kvn@3651 1942 if (find_second_addp(n, n->in(AddPNode::Base)) == NULL) {
kvn@3651 1943 bt = T_OBJECT;
kvn@3651 1944 }
kvn@3651 1945 }
kvn@3651 1946 } else if (offset != oopDesc::klass_offset_in_bytes()) {
kvn@3651 1947 if (adr_type->isa_instptr()) {
kvn@3651 1948 ciField* field = _compile->alias_type(adr_type->isa_instptr())->field();
kvn@3651 1949 if (field != NULL) {
kvn@3651 1950 bt = field->layout_type();
kvn@3651 1951 } else {
twisti@3969 1952 // Check for unsafe oop field access
twisti@3969 1953 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
twisti@3969 1954 int opcode = n->fast_out(i)->Opcode();
twisti@3969 1955 if (opcode == Op_StoreP || opcode == Op_LoadP ||
twisti@3969 1956 opcode == Op_StoreN || opcode == Op_LoadN) {
twisti@3969 1957 bt = T_OBJECT;
twisti@3969 1958 (*unsafe) = true;
twisti@3969 1959 break;
twisti@3969 1960 }
twisti@3969 1961 }
kvn@3651 1962 }
kvn@3651 1963 } else if (adr_type->isa_aryptr()) {
kvn@3651 1964 if (offset == arrayOopDesc::length_offset_in_bytes()) {
kvn@3651 1965 // Ignore array length load.
kvn@3651 1966 } else if (find_second_addp(n, n->in(AddPNode::Base)) != NULL) {
kvn@3651 1967 // Ignore first AddP.
kvn@3651 1968 } else {
kvn@3651 1969 const Type* elemtype = adr_type->isa_aryptr()->elem();
kvn@3651 1970 bt = elemtype->array_element_basic_type();
kvn@3651 1971 }
kvn@3651 1972 } else if (adr_type->isa_rawptr() || adr_type->isa_klassptr()) {
kvn@3651 1973 // Allocation initialization, ThreadLocal field access, unsafe access
kvn@3651 1974 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
kvn@3651 1975 int opcode = n->fast_out(i)->Opcode();
kvn@3651 1976 if (opcode == Op_StoreP || opcode == Op_LoadP ||
kvn@3651 1977 opcode == Op_StoreN || opcode == Op_LoadN) {
kvn@3651 1978 bt = T_OBJECT;
twisti@3969 1979 break;
kvn@3651 1980 }
kvn@3651 1981 }
kvn@3651 1982 }
kvn@3651 1983 }
kvn@3651 1984 return (bt == T_OBJECT || bt == T_NARROWOOP || bt == T_ARRAY);
kvn@3651 1985 }
kvn@3651 1986
kvn@3651 1987 // Returns unique pointed java object or NULL.
kvn@3651 1988 JavaObjectNode* ConnectionGraph::unique_java_object(Node *n) {
kvn@3651 1989 assert(!_collecting, "should not call when contructed graph");
kvn@3651 1990 // If the node was created after the escape computation we can't answer.
kvn@3651 1991 uint idx = n->_idx;
kvn@3651 1992 if (idx >= nodes_size()) {
kvn@3651 1993 return NULL;
kvn@3651 1994 }
kvn@3651 1995 PointsToNode* ptn = ptnode_adr(idx);
kvn@3651 1996 if (ptn->is_JavaObject()) {
kvn@3651 1997 return ptn->as_JavaObject();
kvn@3651 1998 }
kvn@3651 1999 assert(ptn->is_LocalVar(), "sanity");
kvn@3651 2000 // Check all java objects it points to.
kvn@3651 2001 JavaObjectNode* jobj = NULL;
kvn@3651 2002 for (EdgeIterator i(ptn); i.has_next(); i.next()) {
kvn@3651 2003 PointsToNode* e = i.get();
kvn@3651 2004 if (e->is_JavaObject()) {
kvn@3651 2005 if (jobj == NULL) {
kvn@3651 2006 jobj = e->as_JavaObject();
kvn@3651 2007 } else if (jobj != e) {
kvn@3651 2008 return NULL;
kvn@3651 2009 }
kvn@3651 2010 }
kvn@3651 2011 }
kvn@3651 2012 return jobj;
kvn@3651 2013 }
kvn@3651 2014
kvn@3651 2015 // Return true if this node points only to non-escaping allocations.
kvn@3651 2016 bool PointsToNode::non_escaping_allocation() {
kvn@3651 2017 if (is_JavaObject()) {
kvn@3651 2018 Node* n = ideal_node();
kvn@3651 2019 if (n->is_Allocate() || n->is_CallStaticJava()) {
kvn@3651 2020 return (escape_state() == PointsToNode::NoEscape);
kvn@3651 2021 } else {
kvn@3651 2022 return false;
kvn@3651 2023 }
kvn@3651 2024 }
kvn@3651 2025 assert(is_LocalVar(), "sanity");
kvn@3651 2026 // Check all java objects it points to.
kvn@3651 2027 for (EdgeIterator i(this); i.has_next(); i.next()) {
kvn@3651 2028 PointsToNode* e = i.get();
kvn@3651 2029 if (e->is_JavaObject()) {
kvn@3651 2030 Node* n = e->ideal_node();
kvn@3651 2031 if ((e->escape_state() != PointsToNode::NoEscape) ||
kvn@3651 2032 !(n->is_Allocate() || n->is_CallStaticJava())) {
kvn@3651 2033 return false;
kvn@3651 2034 }
kvn@3651 2035 }
kvn@3651 2036 }
kvn@3651 2037 return true;
kvn@3651 2038 }
kvn@3651 2039
kvn@3651 2040 // Return true if we know the node does not escape globally.
kvn@3651 2041 bool ConnectionGraph::not_global_escape(Node *n) {
kvn@3651 2042 assert(!_collecting, "should not call during graph construction");
kvn@3651 2043 // If the node was created after the escape computation we can't answer.
kvn@3651 2044 uint idx = n->_idx;
kvn@3651 2045 if (idx >= nodes_size()) {
kvn@3651 2046 return false;
kvn@3651 2047 }
kvn@3651 2048 PointsToNode* ptn = ptnode_adr(idx);
kvn@3651 2049 PointsToNode::EscapeState es = ptn->escape_state();
kvn@3651 2050 // If we have already computed a value, return it.
kvn@3651 2051 if (es >= PointsToNode::GlobalEscape)
kvn@3651 2052 return false;
kvn@3651 2053 if (ptn->is_JavaObject()) {
kvn@3651 2054 return true; // (es < PointsToNode::GlobalEscape);
kvn@3651 2055 }
kvn@3651 2056 assert(ptn->is_LocalVar(), "sanity");
kvn@3651 2057 // Check all java objects it points to.
kvn@3651 2058 for (EdgeIterator i(ptn); i.has_next(); i.next()) {
kvn@3651 2059 if (i.get()->escape_state() >= PointsToNode::GlobalEscape)
kvn@3651 2060 return false;
kvn@3651 2061 }
kvn@3651 2062 return true;
kvn@3651 2063 }
kvn@3651 2064
kvn@3651 2065
kvn@3651 2066 // Helper functions
kvn@3651 2067
kvn@3651 2068 // Return true if this node points to specified node or nodes it points to.
kvn@3651 2069 bool PointsToNode::points_to(JavaObjectNode* ptn) const {
kvn@3651 2070 if (is_JavaObject()) {
kvn@3651 2071 return (this == ptn);
kvn@3651 2072 }
kvn@4255 2073 assert(is_LocalVar() || is_Field(), "sanity");
kvn@3651 2074 for (EdgeIterator i(this); i.has_next(); i.next()) {
kvn@3651 2075 if (i.get() == ptn)
kvn@3651 2076 return true;
kvn@3651 2077 }
kvn@3651 2078 return false;
kvn@3651 2079 }
kvn@3651 2080
kvn@3651 2081 // Return true if one node points to an other.
kvn@3651 2082 bool PointsToNode::meet(PointsToNode* ptn) {
kvn@3651 2083 if (this == ptn) {
kvn@3651 2084 return true;
kvn@3651 2085 } else if (ptn->is_JavaObject()) {
kvn@3651 2086 return this->points_to(ptn->as_JavaObject());
kvn@3651 2087 } else if (this->is_JavaObject()) {
kvn@3651 2088 return ptn->points_to(this->as_JavaObject());
kvn@3651 2089 }
kvn@3651 2090 assert(this->is_LocalVar() && ptn->is_LocalVar(), "sanity");
kvn@3651 2091 int ptn_count = ptn->edge_count();
kvn@3651 2092 for (EdgeIterator i(this); i.has_next(); i.next()) {
kvn@3651 2093 PointsToNode* this_e = i.get();
kvn@3651 2094 for (int j = 0; j < ptn_count; j++) {
kvn@3651 2095 if (this_e == ptn->edge(j))
kvn@3651 2096 return true;
kvn@3651 2097 }
kvn@3651 2098 }
kvn@3651 2099 return false;
kvn@3651 2100 }
kvn@3651 2101
kvn@3651 2102 #ifdef ASSERT
kvn@3651 2103 // Return true if bases point to this java object.
kvn@3651 2104 bool FieldNode::has_base(JavaObjectNode* jobj) const {
kvn@3651 2105 for (BaseIterator i(this); i.has_next(); i.next()) {
kvn@3651 2106 if (i.get() == jobj)
kvn@3651 2107 return true;
kvn@3651 2108 }
kvn@3651 2109 return false;
kvn@3651 2110 }
kvn@3651 2111 #endif
kvn@3651 2112
kvn@500 2113 int ConnectionGraph::address_offset(Node* adr, PhaseTransform *phase) {
kvn@500 2114 const Type *adr_type = phase->type(adr);
kvn@500 2115 if (adr->is_AddP() && adr_type->isa_oopptr() == NULL &&
kvn@500 2116 adr->in(AddPNode::Address)->is_Proj() &&
kvn@500 2117 adr->in(AddPNode::Address)->in(0)->is_Allocate()) {
kvn@500 2118 // We are computing a raw address for a store captured by an Initialize
kvn@500 2119 // compute an appropriate address type. AddP cases #3 and #5 (see below).
kvn@500 2120 int offs = (int)phase->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
kvn@500 2121 assert(offs != Type::OffsetBot ||
kvn@500 2122 adr->in(AddPNode::Address)->in(0)->is_AllocateArray(),
kvn@500 2123 "offset must be a constant or it is initialization of array");
kvn@500 2124 return offs;
kvn@500 2125 }
kvn@500 2126 const TypePtr *t_ptr = adr_type->isa_ptr();
duke@435 2127 assert(t_ptr != NULL, "must be a pointer type");
duke@435 2128 return t_ptr->offset();
duke@435 2129 }
duke@435 2130
kvn@3651 2131 Node* ConnectionGraph::get_addp_base(Node *addp) {
kvn@500 2132 assert(addp->is_AddP(), "must be AddP");
kvn@500 2133 //
kvn@500 2134 // AddP cases for Base and Address inputs:
kvn@500 2135 // case #1. Direct object's field reference:
kvn@500 2136 // Allocate
kvn@500 2137 // |
kvn@500 2138 // Proj #5 ( oop result )
kvn@500 2139 // |
kvn@500 2140 // CheckCastPP (cast to instance type)
kvn@500 2141 // | |
kvn@500 2142 // AddP ( base == address )
kvn@500 2143 //
kvn@500 2144 // case #2. Indirect object's field reference:
kvn@500 2145 // Phi
kvn@500 2146 // |
kvn@500 2147 // CastPP (cast to instance type)
kvn@500 2148 // | |
kvn@500 2149 // AddP ( base == address )
kvn@500 2150 //
kvn@500 2151 // case #3. Raw object's field reference for Initialize node:
kvn@500 2152 // Allocate
kvn@500 2153 // |
kvn@500 2154 // Proj #5 ( oop result )
kvn@500 2155 // top |
kvn@500 2156 // \ |
kvn@500 2157 // AddP ( base == top )
kvn@500 2158 //
kvn@500 2159 // case #4. Array's element reference:
kvn@500 2160 // {CheckCastPP | CastPP}
kvn@500 2161 // | | |
kvn@500 2162 // | AddP ( array's element offset )
kvn@500 2163 // | |
kvn@500 2164 // AddP ( array's offset )
kvn@500 2165 //
kvn@500 2166 // case #5. Raw object's field reference for arraycopy stub call:
kvn@500 2167 // The inline_native_clone() case when the arraycopy stub is called
kvn@500 2168 // after the allocation before Initialize and CheckCastPP nodes.
kvn@500 2169 // Allocate
kvn@500 2170 // |
kvn@500 2171 // Proj #5 ( oop result )
kvn@500 2172 // | |
kvn@500 2173 // AddP ( base == address )
kvn@500 2174 //
kvn@512 2175 // case #6. Constant Pool, ThreadLocal, CastX2P or
kvn@512 2176 // Raw object's field reference:
kvn@512 2177 // {ConP, ThreadLocal, CastX2P, raw Load}
kvn@500 2178 // top |
kvn@500 2179 // \ |
kvn@500 2180 // AddP ( base == top )
kvn@500 2181 //
kvn@512 2182 // case #7. Klass's field reference.
kvn@512 2183 // LoadKlass
kvn@512 2184 // | |
kvn@512 2185 // AddP ( base == address )
kvn@512 2186 //
kvn@599 2187 // case #8. narrow Klass's field reference.
kvn@599 2188 // LoadNKlass
kvn@599 2189 // |
kvn@599 2190 // DecodeN
kvn@599 2191 // | |
kvn@599 2192 // AddP ( base == address )
kvn@599 2193 //
kvn@3651 2194 Node *base = addp->in(AddPNode::Base);
kvn@3651 2195 if (base->uncast()->is_top()) { // The AddP case #3 and #6.
kvn@3651 2196 base = addp->in(AddPNode::Address);
kvn@1392 2197 while (base->is_AddP()) {
kvn@1392 2198 // Case #6 (unsafe access) may have several chained AddP nodes.
kvn@3651 2199 assert(base->in(AddPNode::Base)->uncast()->is_top(), "expected unsafe access address only");
kvn@3651 2200 base = base->in(AddPNode::Address);
kvn@1392 2201 }
kvn@3651 2202 Node* uncast_base = base->uncast();
kvn@3651 2203 int opcode = uncast_base->Opcode();
kvn@3651 2204 assert(opcode == Op_ConP || opcode == Op_ThreadLocal ||
roland@4159 2205 opcode == Op_CastX2P || uncast_base->is_DecodeNarrowPtr() ||
kvn@5223 2206 (uncast_base->is_Mem() && (uncast_base->bottom_type()->isa_rawptr() != NULL)) ||
kvn@3651 2207 (uncast_base->is_Proj() && uncast_base->in(0)->is_Allocate()), "sanity");
duke@435 2208 }
kvn@500 2209 return base;
kvn@500 2210 }
kvn@500 2211
kvn@3651 2212 Node* ConnectionGraph::find_second_addp(Node* addp, Node* n) {
kvn@500 2213 assert(addp->is_AddP() && addp->outcnt() > 0, "Don't process dead nodes");
kvn@500 2214 Node* addp2 = addp->raw_out(0);
kvn@500 2215 if (addp->outcnt() == 1 && addp2->is_AddP() &&
kvn@500 2216 addp2->in(AddPNode::Base) == n &&
kvn@500 2217 addp2->in(AddPNode::Address) == addp) {
kvn@500 2218 assert(addp->in(AddPNode::Base) == n, "expecting the same base");
kvn@500 2219 //
kvn@500 2220 // Find array's offset to push it on worklist first and
kvn@500 2221 // as result process an array's element offset first (pushed second)
kvn@500 2222 // to avoid CastPP for the array's offset.
kvn@500 2223 // Otherwise the inserted CastPP (LocalVar) will point to what
kvn@500 2224 // the AddP (Field) points to. Which would be wrong since
kvn@500 2225 // the algorithm expects the CastPP has the same point as
kvn@500 2226 // as AddP's base CheckCastPP (LocalVar).
kvn@500 2227 //
kvn@500 2228 // ArrayAllocation
kvn@500 2229 // |
kvn@500 2230 // CheckCastPP
kvn@500 2231 // |
kvn@500 2232 // memProj (from ArrayAllocation CheckCastPP)
kvn@500 2233 // | ||
kvn@500 2234 // | || Int (element index)
kvn@500 2235 // | || | ConI (log(element size))
kvn@500 2236 // | || | /
kvn@500 2237 // | || LShift
kvn@500 2238 // | || /
kvn@500 2239 // | AddP (array's element offset)
kvn@500 2240 // | |
kvn@500 2241 // | | ConI (array's offset: #12(32-bits) or #24(64-bits))
kvn@500 2242 // | / /
kvn@500 2243 // AddP (array's offset)
kvn@500 2244 // |
kvn@500 2245 // Load/Store (memory operation on array's element)
kvn@500 2246 //
kvn@500 2247 return addp2;
kvn@500 2248 }
kvn@500 2249 return NULL;
duke@435 2250 }
duke@435 2251
duke@435 2252 //
duke@435 2253 // Adjust the type and inputs of an AddP which computes the
duke@435 2254 // address of a field of an instance
duke@435 2255 //
kvn@3651 2256 bool ConnectionGraph::split_AddP(Node *addp, Node *base) {
kvn@3651 2257 PhaseGVN* igvn = _igvn;
kvn@500 2258 const TypeOopPtr *base_t = igvn->type(base)->isa_oopptr();
kvn@658 2259 assert(base_t != NULL && base_t->is_known_instance(), "expecting instance oopptr");
duke@435 2260 const TypeOopPtr *t = igvn->type(addp)->isa_oopptr();
kvn@500 2261 if (t == NULL) {
kvn@500 2262 // We are computing a raw address for a store captured by an Initialize
kvn@728 2263 // compute an appropriate address type (cases #3 and #5).
kvn@500 2264 assert(igvn->type(addp) == TypeRawPtr::NOTNULL, "must be raw pointer");
kvn@500 2265 assert(addp->in(AddPNode::Address)->is_Proj(), "base of raw address must be result projection from allocation");
kvn@741 2266 intptr_t offs = (int)igvn->find_intptr_t_con(addp->in(AddPNode::Offset), Type::OffsetBot);
kvn@500 2267 assert(offs != Type::OffsetBot, "offset must be a constant");
kvn@500 2268 t = base_t->add_offset(offs)->is_oopptr();
kvn@500 2269 }
kvn@658 2270 int inst_id = base_t->instance_id();
kvn@658 2271 assert(!t->is_known_instance() || t->instance_id() == inst_id,
duke@435 2272 "old type must be non-instance or match new type");
kvn@728 2273
kvn@728 2274 // The type 't' could be subclass of 'base_t'.
kvn@728 2275 // As result t->offset() could be large then base_t's size and it will
kvn@728 2276 // cause the failure in add_offset() with narrow oops since TypeOopPtr()
kvn@728 2277 // constructor verifies correctness of the offset.
kvn@728 2278 //
twisti@1040 2279 // It could happened on subclass's branch (from the type profiling
kvn@728 2280 // inlining) which was not eliminated during parsing since the exactness
kvn@728 2281 // of the allocation type was not propagated to the subclass type check.
kvn@728 2282 //
kvn@1423 2283 // Or the type 't' could be not related to 'base_t' at all.
kvn@1423 2284 // It could happened when CHA type is different from MDO type on a dead path
kvn@1423 2285 // (for example, from instanceof check) which is not collapsed during parsing.
kvn@1423 2286 //
kvn@728 2287 // Do nothing for such AddP node and don't process its users since
kvn@728 2288 // this code branch will go away.
kvn@728 2289 //
kvn@728 2290 if (!t->is_known_instance() &&
kvn@1423 2291 !base_t->klass()->is_subtype_of(t->klass())) {
kvn@728 2292 return false; // bail out
kvn@728 2293 }
duke@435 2294 const TypeOopPtr *tinst = base_t->add_offset(t->offset())->is_oopptr();
kvn@1497 2295 // Do NOT remove the next line: ensure a new alias index is allocated
kvn@1497 2296 // for the instance type. Note: C++ will not remove it since the call
kvn@1497 2297 // has side effect.
duke@435 2298 int alias_idx = _compile->get_alias_index(tinst);
duke@435 2299 igvn->set_type(addp, tinst);
duke@435 2300 // record the allocation in the node map
kvn@3651 2301 set_map(addp, get_map(base->_idx));
kvn@688 2302 // Set addp's Base and Address to 'base'.
kvn@688 2303 Node *abase = addp->in(AddPNode::Base);
kvn@688 2304 Node *adr = addp->in(AddPNode::Address);
kvn@688 2305 if (adr->is_Proj() && adr->in(0)->is_Allocate() &&
kvn@688 2306 adr->in(0)->_idx == (uint)inst_id) {
kvn@688 2307 // Skip AddP cases #3 and #5.
kvn@688 2308 } else {
kvn@688 2309 assert(!abase->is_top(), "sanity"); // AddP case #3
kvn@688 2310 if (abase != base) {
kvn@688 2311 igvn->hash_delete(addp);
kvn@688 2312 addp->set_req(AddPNode::Base, base);
kvn@688 2313 if (abase == adr) {
kvn@688 2314 addp->set_req(AddPNode::Address, base);
kvn@688 2315 } else {
kvn@688 2316 // AddP case #4 (adr is array's element offset AddP node)
kvn@688 2317 #ifdef ASSERT
kvn@688 2318 const TypeOopPtr *atype = igvn->type(adr)->isa_oopptr();
kvn@688 2319 assert(adr->is_AddP() && atype != NULL &&
kvn@688 2320 atype->instance_id() == inst_id, "array's element offset should be processed first");
kvn@688 2321 #endif
kvn@688 2322 }
kvn@688 2323 igvn->hash_insert(addp);
duke@435 2324 }
duke@435 2325 }
kvn@500 2326 // Put on IGVN worklist since at least addp's type was changed above.
kvn@500 2327 record_for_optimizer(addp);
kvn@728 2328 return true;
duke@435 2329 }
duke@435 2330
duke@435 2331 //
duke@435 2332 // Create a new version of orig_phi if necessary. Returns either the newly
kvn@2741 2333 // created phi or an existing phi. Sets create_new to indicate whether a new
duke@435 2334 // phi was created. Cache the last newly created phi in the node map.
duke@435 2335 //
kvn@3651 2336 PhiNode *ConnectionGraph::create_split_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist, bool &new_created) {
duke@435 2337 Compile *C = _compile;
kvn@3651 2338 PhaseGVN* igvn = _igvn;
duke@435 2339 new_created = false;
duke@435 2340 int phi_alias_idx = C->get_alias_index(orig_phi->adr_type());
duke@435 2341 // nothing to do if orig_phi is bottom memory or matches alias_idx
kvn@500 2342 if (phi_alias_idx == alias_idx) {
duke@435 2343 return orig_phi;
duke@435 2344 }
kvn@1286 2345 // Have we recently created a Phi for this alias index?
duke@435 2346 PhiNode *result = get_map_phi(orig_phi->_idx);
duke@435 2347 if (result != NULL && C->get_alias_index(result->adr_type()) == alias_idx) {
duke@435 2348 return result;
duke@435 2349 }
kvn@1286 2350 // Previous check may fail when the same wide memory Phi was split into Phis
kvn@1286 2351 // for different memory slices. Search all Phis for this region.
kvn@1286 2352 if (result != NULL) {
kvn@1286 2353 Node* region = orig_phi->in(0);
kvn@1286 2354 for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) {
kvn@1286 2355 Node* phi = region->fast_out(i);
kvn@1286 2356 if (phi->is_Phi() &&
kvn@1286 2357 C->get_alias_index(phi->as_Phi()->adr_type()) == alias_idx) {
kvn@1286 2358 assert(phi->_idx >= nodes_size(), "only new Phi per instance memory slice");
kvn@1286 2359 return phi->as_Phi();
kvn@1286 2360 }
kvn@1286 2361 }
kvn@1286 2362 }
bharadwaj@4315 2363 if ((int) (C->live_nodes() + 2*NodeLimitFudgeFactor) > MaxNodeLimit) {
kvn@473 2364 if (C->do_escape_analysis() == true && !C->failing()) {
kvn@473 2365 // Retry compilation without escape analysis.
kvn@473 2366 // If this is the first failure, the sentinel string will "stick"
kvn@473 2367 // to the Compile object, and the C2Compiler will see it and retry.
kvn@473 2368 C->record_failure(C2Compiler::retry_no_escape_analysis());
kvn@473 2369 }
kvn@473 2370 return NULL;
kvn@473 2371 }
duke@435 2372 orig_phi_worklist.append_if_missing(orig_phi);
kvn@500 2373 const TypePtr *atype = C->get_adr_type(alias_idx);
duke@435 2374 result = PhiNode::make(orig_phi->in(0), NULL, Type::MEMORY, atype);
kvn@1286 2375 C->copy_node_notes_to(result, orig_phi);
duke@435 2376 igvn->set_type(result, result->bottom_type());
duke@435 2377 record_for_optimizer(result);
kvn@3651 2378 set_map(orig_phi, result);
duke@435 2379 new_created = true;
duke@435 2380 return result;
duke@435 2381 }
duke@435 2382
duke@435 2383 //
kvn@2741 2384 // Return a new version of Memory Phi "orig_phi" with the inputs having the
duke@435 2385 // specified alias index.
duke@435 2386 //
kvn@3651 2387 PhiNode *ConnectionGraph::split_memory_phi(PhiNode *orig_phi, int alias_idx, GrowableArray<PhiNode *> &orig_phi_worklist) {
duke@435 2388 assert(alias_idx != Compile::AliasIdxBot, "can't split out bottom memory");
duke@435 2389 Compile *C = _compile;
kvn@3651 2390 PhaseGVN* igvn = _igvn;
duke@435 2391 bool new_phi_created;
kvn@3651 2392 PhiNode *result = create_split_phi(orig_phi, alias_idx, orig_phi_worklist, new_phi_created);
duke@435 2393 if (!new_phi_created) {
duke@435 2394 return result;
duke@435 2395 }
duke@435 2396 GrowableArray<PhiNode *> phi_list;
duke@435 2397 GrowableArray<uint> cur_input;
duke@435 2398 PhiNode *phi = orig_phi;
duke@435 2399 uint idx = 1;
duke@435 2400 bool finished = false;
duke@435 2401 while(!finished) {
duke@435 2402 while (idx < phi->req()) {
kvn@3651 2403 Node *mem = find_inst_mem(phi->in(idx), alias_idx, orig_phi_worklist);
duke@435 2404 if (mem != NULL && mem->is_Phi()) {
kvn@3651 2405 PhiNode *newphi = create_split_phi(mem->as_Phi(), alias_idx, orig_phi_worklist, new_phi_created);
duke@435 2406 if (new_phi_created) {
duke@435 2407 // found an phi for which we created a new split, push current one on worklist and begin
duke@435 2408 // processing new one
duke@435 2409 phi_list.push(phi);
duke@435 2410 cur_input.push(idx);
duke@435 2411 phi = mem->as_Phi();
kvn@500 2412 result = newphi;
duke@435 2413 idx = 1;
duke@435 2414 continue;
duke@435 2415 } else {
kvn@500 2416 mem = newphi;
duke@435 2417 }
duke@435 2418 }
kvn@473 2419 if (C->failing()) {
kvn@473 2420 return NULL;
kvn@473 2421 }
duke@435 2422 result->set_req(idx++, mem);
duke@435 2423 }
duke@435 2424 #ifdef ASSERT
duke@435 2425 // verify that the new Phi has an input for each input of the original
duke@435 2426 assert( phi->req() == result->req(), "must have same number of inputs.");
duke@435 2427 assert( result->in(0) != NULL && result->in(0) == phi->in(0), "regions must match");
kvn@500 2428 #endif
kvn@500 2429 // Check if all new phi's inputs have specified alias index.
kvn@500 2430 // Otherwise use old phi.
duke@435 2431 for (uint i = 1; i < phi->req(); i++) {
kvn@500 2432 Node* in = result->in(i);
kvn@500 2433 assert((phi->in(i) == NULL) == (in == NULL), "inputs must correspond.");
duke@435 2434 }
duke@435 2435 // we have finished processing a Phi, see if there are any more to do
duke@435 2436 finished = (phi_list.length() == 0 );
duke@435 2437 if (!finished) {
duke@435 2438 phi = phi_list.pop();
duke@435 2439 idx = cur_input.pop();
kvn@500 2440 PhiNode *prev_result = get_map_phi(phi->_idx);
kvn@500 2441 prev_result->set_req(idx++, result);
kvn@500 2442 result = prev_result;
duke@435 2443 }
duke@435 2444 }
duke@435 2445 return result;
duke@435 2446 }
duke@435 2447
kvn@500 2448 //
kvn@500 2449 // The next methods are derived from methods in MemNode.
kvn@500 2450 //
kvn@3651 2451 Node* ConnectionGraph::step_through_mergemem(MergeMemNode *mmem, int alias_idx, const TypeOopPtr *toop) {
kvn@500 2452 Node *mem = mmem;
never@2170 2453 // TypeOopPtr::NOTNULL+any is an OOP with unknown offset - generally
kvn@500 2454 // means an array I have not precisely typed yet. Do not do any
kvn@500 2455 // alias stuff with it any time soon.
kvn@3651 2456 if (toop->base() != Type::AnyPtr &&
never@2170 2457 !(toop->klass() != NULL &&
never@2170 2458 toop->klass()->is_java_lang_Object() &&
kvn@3651 2459 toop->offset() == Type::OffsetBot)) {
kvn@500 2460 mem = mmem->memory_at(alias_idx);
kvn@500 2461 // Update input if it is progress over what we have now
kvn@500 2462 }
kvn@500 2463 return mem;
kvn@500 2464 }
kvn@500 2465
kvn@500 2466 //
kvn@1536 2467 // Move memory users to their memory slices.
kvn@1536 2468 //
kvn@3651 2469 void ConnectionGraph::move_inst_mem(Node* n, GrowableArray<PhiNode *> &orig_phis) {
kvn@1536 2470 Compile* C = _compile;
kvn@3651 2471 PhaseGVN* igvn = _igvn;
kvn@1536 2472 const TypePtr* tp = igvn->type(n->in(MemNode::Address))->isa_ptr();
kvn@1536 2473 assert(tp != NULL, "ptr type");
kvn@1536 2474 int alias_idx = C->get_alias_index(tp);
kvn@1536 2475 int general_idx = C->get_general_index(alias_idx);
kvn@1536 2476
kvn@1536 2477 // Move users first
kvn@1536 2478 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
kvn@1536 2479 Node* use = n->fast_out(i);
kvn@1536 2480 if (use->is_MergeMem()) {
kvn@1536 2481 MergeMemNode* mmem = use->as_MergeMem();
kvn@1536 2482 assert(n == mmem->memory_at(alias_idx), "should be on instance memory slice");
kvn@1536 2483 if (n != mmem->memory_at(general_idx) || alias_idx == general_idx) {
kvn@1536 2484 continue; // Nothing to do
kvn@1536 2485 }
kvn@1536 2486 // Replace previous general reference to mem node.
kvn@1536 2487 uint orig_uniq = C->unique();
kvn@3651 2488 Node* m = find_inst_mem(n, general_idx, orig_phis);
kvn@1536 2489 assert(orig_uniq == C->unique(), "no new nodes");
kvn@1536 2490 mmem->set_memory_at(general_idx, m);
kvn@1536 2491 --imax;
kvn@1536 2492 --i;
kvn@1536 2493 } else if (use->is_MemBar()) {
kvn@1536 2494 assert(!use->is_Initialize(), "initializing stores should not be moved");
kvn@1536 2495 if (use->req() > MemBarNode::Precedent &&
kvn@1536 2496 use->in(MemBarNode::Precedent) == n) {
kvn@1536 2497 // Don't move related membars.
kvn@1536 2498 record_for_optimizer(use);
kvn@1536 2499 continue;
kvn@1536 2500 }
kvn@1536 2501 tp = use->as_MemBar()->adr_type()->isa_ptr();
kvn@1536 2502 if (tp != NULL && C->get_alias_index(tp) == alias_idx ||
kvn@1536 2503 alias_idx == general_idx) {
kvn@1536 2504 continue; // Nothing to do
kvn@1536 2505 }
kvn@1536 2506 // Move to general memory slice.
kvn@1536 2507 uint orig_uniq = C->unique();
kvn@3651 2508 Node* m = find_inst_mem(n, general_idx, orig_phis);
kvn@1536 2509 assert(orig_uniq == C->unique(), "no new nodes");
kvn@1536 2510 igvn->hash_delete(use);
kvn@1536 2511 imax -= use->replace_edge(n, m);
kvn@1536 2512 igvn->hash_insert(use);
kvn@1536 2513 record_for_optimizer(use);
kvn@1536 2514 --i;
kvn@1536 2515 #ifdef ASSERT
kvn@1536 2516 } else if (use->is_Mem()) {
kvn@1536 2517 if (use->Opcode() == Op_StoreCM && use->in(MemNode::OopStore) == n) {
kvn@1536 2518 // Don't move related cardmark.
kvn@1536 2519 continue;
kvn@1536 2520 }
kvn@1536 2521 // Memory nodes should have new memory input.
kvn@1536 2522 tp = igvn->type(use->in(MemNode::Address))->isa_ptr();
kvn@1536 2523 assert(tp != NULL, "ptr type");
kvn@1536 2524 int idx = C->get_alias_index(tp);
kvn@1536 2525 assert(get_map(use->_idx) != NULL || idx == alias_idx,
kvn@1536 2526 "Following memory nodes should have new memory input or be on the same memory slice");
kvn@1536 2527 } else if (use->is_Phi()) {
kvn@1536 2528 // Phi nodes should be split and moved already.
kvn@1536 2529 tp = use->as_Phi()->adr_type()->isa_ptr();
kvn@1536 2530 assert(tp != NULL, "ptr type");
kvn@1536 2531 int idx = C->get_alias_index(tp);
kvn@1536 2532 assert(idx == alias_idx, "Following Phi nodes should be on the same memory slice");
kvn@1536 2533 } else {
kvn@1536 2534 use->dump();
kvn@1536 2535 assert(false, "should not be here");
kvn@1536 2536 #endif
kvn@1536 2537 }
kvn@1536 2538 }
kvn@1536 2539 }
kvn@1536 2540
kvn@1536 2541 //
kvn@500 2542 // Search memory chain of "mem" to find a MemNode whose address
kvn@500 2543 // is the specified alias index.
kvn@500 2544 //
kvn@3651 2545 Node* ConnectionGraph::find_inst_mem(Node *orig_mem, int alias_idx, GrowableArray<PhiNode *> &orig_phis) {
kvn@500 2546 if (orig_mem == NULL)
kvn@500 2547 return orig_mem;
kvn@3651 2548 Compile* C = _compile;
kvn@3651 2549 PhaseGVN* igvn = _igvn;
never@2170 2550 const TypeOopPtr *toop = C->get_adr_type(alias_idx)->isa_oopptr();
never@2170 2551 bool is_instance = (toop != NULL) && toop->is_known_instance();
kvn@688 2552 Node *start_mem = C->start()->proj_out(TypeFunc::Memory);
kvn@500 2553 Node *prev = NULL;
kvn@500 2554 Node *result = orig_mem;
kvn@500 2555 while (prev != result) {
kvn@500 2556 prev = result;
kvn@688 2557 if (result == start_mem)
twisti@1040 2558 break; // hit one of our sentinels
kvn@500 2559 if (result->is_Mem()) {
kvn@3651 2560 const Type *at = igvn->type(result->in(MemNode::Address));
kvn@2741 2561 if (at == Type::TOP)
kvn@2741 2562 break; // Dead
kvn@2741 2563 assert (at->isa_ptr() != NULL, "pointer type required.");
kvn@2741 2564 int idx = C->get_alias_index(at->is_ptr());
kvn@2741 2565 if (idx == alias_idx)
kvn@2741 2566 break; // Found
kvn@2741 2567 if (!is_instance && (at->isa_oopptr() == NULL ||
kvn@2741 2568 !at->is_oopptr()->is_known_instance())) {
kvn@2741 2569 break; // Do not skip store to general memory slice.
kvn@500 2570 }
kvn@688 2571 result = result->in(MemNode::Memory);
kvn@500 2572 }
kvn@500 2573 if (!is_instance)
kvn@500 2574 continue; // don't search further for non-instance types
kvn@500 2575 // skip over a call which does not affect this memory slice
kvn@500 2576 if (result->is_Proj() && result->as_Proj()->_con == TypeFunc::Memory) {
kvn@500 2577 Node *proj_in = result->in(0);
never@2170 2578 if (proj_in->is_Allocate() && proj_in->_idx == (uint)toop->instance_id()) {
twisti@1040 2579 break; // hit one of our sentinels
kvn@688 2580 } else if (proj_in->is_Call()) {
kvn@500 2581 CallNode *call = proj_in->as_Call();
kvn@3651 2582 if (!call->may_modify(toop, igvn)) {
kvn@500 2583 result = call->in(TypeFunc::Memory);
kvn@500 2584 }
kvn@500 2585 } else if (proj_in->is_Initialize()) {
kvn@500 2586 AllocateNode* alloc = proj_in->as_Initialize()->allocation();
kvn@500 2587 // Stop if this is the initialization for the object instance which
kvn@500 2588 // which contains this memory slice, otherwise skip over it.
never@2170 2589 if (alloc == NULL || alloc->_idx != (uint)toop->instance_id()) {
kvn@500 2590 result = proj_in->in(TypeFunc::Memory);
kvn@500 2591 }
kvn@500 2592 } else if (proj_in->is_MemBar()) {
kvn@500 2593 result = proj_in->in(TypeFunc::Memory);
kvn@500 2594 }
kvn@500 2595 } else if (result->is_MergeMem()) {
kvn@500 2596 MergeMemNode *mmem = result->as_MergeMem();
never@2170 2597 result = step_through_mergemem(mmem, alias_idx, toop);
kvn@500 2598 if (result == mmem->base_memory()) {
kvn@500 2599 // Didn't find instance memory, search through general slice recursively.
kvn@500 2600 result = mmem->memory_at(C->get_general_index(alias_idx));
kvn@3651 2601 result = find_inst_mem(result, alias_idx, orig_phis);
kvn@500 2602 if (C->failing()) {
kvn@500 2603 return NULL;
kvn@500 2604 }
kvn@500 2605 mmem->set_memory_at(alias_idx, result);
kvn@500 2606 }
kvn@500 2607 } else if (result->is_Phi() &&
kvn@500 2608 C->get_alias_index(result->as_Phi()->adr_type()) != alias_idx) {
kvn@3651 2609 Node *un = result->as_Phi()->unique_input(igvn);
kvn@500 2610 if (un != NULL) {
kvn@1536 2611 orig_phis.append_if_missing(result->as_Phi());
kvn@500 2612 result = un;
kvn@500 2613 } else {
kvn@500 2614 break;
kvn@500 2615 }
kvn@1535 2616 } else if (result->is_ClearArray()) {
kvn@3651 2617 if (!ClearArrayNode::step_through(&result, (uint)toop->instance_id(), igvn)) {
kvn@1535 2618 // Can not bypass initialization of the instance
kvn@1535 2619 // we are looking for.
kvn@1535 2620 break;
kvn@1535 2621 }
kvn@1535 2622 // Otherwise skip it (the call updated 'result' value).
kvn@1019 2623 } else if (result->Opcode() == Op_SCMemProj) {
kvn@4479 2624 Node* mem = result->in(0);
kvn@4479 2625 Node* adr = NULL;
kvn@4479 2626 if (mem->is_LoadStore()) {
kvn@4479 2627 adr = mem->in(MemNode::Address);
kvn@4479 2628 } else {
kvn@4479 2629 assert(mem->Opcode() == Op_EncodeISOArray, "sanity");
kvn@4479 2630 adr = mem->in(3); // Memory edge corresponds to destination array
kvn@4479 2631 }
kvn@4479 2632 const Type *at = igvn->type(adr);
kvn@1019 2633 if (at != Type::TOP) {
kvn@1019 2634 assert (at->isa_ptr() != NULL, "pointer type required.");
kvn@1019 2635 int idx = C->get_alias_index(at->is_ptr());
kvn@1019 2636 assert(idx != alias_idx, "Object is not scalar replaceable if a LoadStore node access its field");
kvn@1019 2637 break;
kvn@1019 2638 }
kvn@4479 2639 result = mem->in(MemNode::Memory);
kvn@500 2640 }
kvn@500 2641 }
kvn@682 2642 if (result->is_Phi()) {
kvn@500 2643 PhiNode *mphi = result->as_Phi();
kvn@500 2644 assert(mphi->bottom_type() == Type::MEMORY, "memory phi required");
kvn@500 2645 const TypePtr *t = mphi->adr_type();
kvn@2741 2646 if (!is_instance) {
kvn@682 2647 // Push all non-instance Phis on the orig_phis worklist to update inputs
kvn@682 2648 // during Phase 4 if needed.
kvn@682 2649 orig_phis.append_if_missing(mphi);
kvn@2741 2650 } else if (C->get_alias_index(t) != alias_idx) {
kvn@2741 2651 // Create a new Phi with the specified alias index type.
kvn@3651 2652 result = split_memory_phi(mphi, alias_idx, orig_phis);
kvn@500 2653 }
kvn@500 2654 }
kvn@500 2655 // the result is either MemNode, PhiNode, InitializeNode.
kvn@500 2656 return result;
kvn@500 2657 }
kvn@500 2658
duke@435 2659 //
duke@435 2660 // Convert the types of unescaped object to instance types where possible,
duke@435 2661 // propagate the new type information through the graph, and update memory
duke@435 2662 // edges and MergeMem inputs to reflect the new type.
duke@435 2663 //
duke@435 2664 // We start with allocations (and calls which may be allocations) on alloc_worklist.
duke@435 2665 // The processing is done in 4 phases:
duke@435 2666 //
duke@435 2667 // Phase 1: Process possible allocations from alloc_worklist. Create instance
duke@435 2668 // types for the CheckCastPP for allocations where possible.
duke@435 2669 // Propagate the the new types through users as follows:
duke@435 2670 // casts and Phi: push users on alloc_worklist
duke@435 2671 // AddP: cast Base and Address inputs to the instance type
duke@435 2672 // push any AddP users on alloc_worklist and push any memnode
duke@435 2673 // users onto memnode_worklist.
duke@435 2674 // Phase 2: Process MemNode's from memnode_worklist. compute new address type and
duke@435 2675 // search the Memory chain for a store with the appropriate type
duke@435 2676 // address type. If a Phi is found, create a new version with
twisti@1040 2677 // the appropriate memory slices from each of the Phi inputs.
duke@435 2678 // For stores, process the users as follows:
duke@435 2679 // MemNode: push on memnode_worklist
duke@435 2680 // MergeMem: push on mergemem_worklist
duke@435 2681 // Phase 3: Process MergeMem nodes from mergemem_worklist. Walk each memory slice
duke@435 2682 // moving the first node encountered of each instance type to the
duke@435 2683 // the input corresponding to its alias index.
duke@435 2684 // appropriate memory slice.
duke@435 2685 // Phase 4: Update the inputs of non-instance memory Phis and the Memory input of memnodes.
duke@435 2686 //
duke@435 2687 // In the following example, the CheckCastPP nodes are the cast of allocation
duke@435 2688 // results and the allocation of node 29 is unescaped and eligible to be an
duke@435 2689 // instance type.
duke@435 2690 //
duke@435 2691 // We start with:
duke@435 2692 //
duke@435 2693 // 7 Parm #memory
duke@435 2694 // 10 ConI "12"
duke@435 2695 // 19 CheckCastPP "Foo"
duke@435 2696 // 20 AddP _ 19 19 10 Foo+12 alias_index=4
duke@435 2697 // 29 CheckCastPP "Foo"
duke@435 2698 // 30 AddP _ 29 29 10 Foo+12 alias_index=4
duke@435 2699 //
duke@435 2700 // 40 StoreP 25 7 20 ... alias_index=4
duke@435 2701 // 50 StoreP 35 40 30 ... alias_index=4
duke@435 2702 // 60 StoreP 45 50 20 ... alias_index=4
duke@435 2703 // 70 LoadP _ 60 30 ... alias_index=4
duke@435 2704 // 80 Phi 75 50 60 Memory alias_index=4
duke@435 2705 // 90 LoadP _ 80 30 ... alias_index=4
duke@435 2706 // 100 LoadP _ 80 20 ... alias_index=4
duke@435 2707 //
duke@435 2708 //
duke@435 2709 // Phase 1 creates an instance type for node 29 assigning it an instance id of 24
duke@435 2710 // and creating a new alias index for node 30. This gives:
duke@435 2711 //
duke@435 2712 // 7 Parm #memory
duke@435 2713 // 10 ConI "12"
duke@435 2714 // 19 CheckCastPP "Foo"
duke@435 2715 // 20 AddP _ 19 19 10 Foo+12 alias_index=4
duke@435 2716 // 29 CheckCastPP "Foo" iid=24
duke@435 2717 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24
duke@435 2718 //
duke@435 2719 // 40 StoreP 25 7 20 ... alias_index=4
duke@435 2720 // 50 StoreP 35 40 30 ... alias_index=6
duke@435 2721 // 60 StoreP 45 50 20 ... alias_index=4
duke@435 2722 // 70 LoadP _ 60 30 ... alias_index=6
duke@435 2723 // 80 Phi 75 50 60 Memory alias_index=4
duke@435 2724 // 90 LoadP _ 80 30 ... alias_index=6
duke@435 2725 // 100 LoadP _ 80 20 ... alias_index=4
duke@435 2726 //
duke@435 2727 // In phase 2, new memory inputs are computed for the loads and stores,
duke@435 2728 // And a new version of the phi is created. In phase 4, the inputs to
duke@435 2729 // node 80 are updated and then the memory nodes are updated with the
duke@435 2730 // values computed in phase 2. This results in:
duke@435 2731 //
duke@435 2732 // 7 Parm #memory
duke@435 2733 // 10 ConI "12"
duke@435 2734 // 19 CheckCastPP "Foo"
duke@435 2735 // 20 AddP _ 19 19 10 Foo+12 alias_index=4
duke@435 2736 // 29 CheckCastPP "Foo" iid=24
duke@435 2737 // 30 AddP _ 29 29 10 Foo+12 alias_index=6 iid=24
duke@435 2738 //
duke@435 2739 // 40 StoreP 25 7 20 ... alias_index=4
duke@435 2740 // 50 StoreP 35 7 30 ... alias_index=6
duke@435 2741 // 60 StoreP 45 40 20 ... alias_index=4
duke@435 2742 // 70 LoadP _ 50 30 ... alias_index=6
duke@435 2743 // 80 Phi 75 40 60 Memory alias_index=4
duke@435 2744 // 120 Phi 75 50 50 Memory alias_index=6
duke@435 2745 // 90 LoadP _ 120 30 ... alias_index=6
duke@435 2746 // 100 LoadP _ 80 20 ... alias_index=4
duke@435 2747 //
duke@435 2748 void ConnectionGraph::split_unique_types(GrowableArray<Node *> &alloc_worklist) {
duke@435 2749 GrowableArray<Node *> memnode_worklist;
duke@435 2750 GrowableArray<PhiNode *> orig_phis;
kvn@2276 2751 PhaseIterGVN *igvn = _igvn;
duke@435 2752 uint new_index_start = (uint) _compile->num_alias_types();
kvn@1536 2753 Arena* arena = Thread::current()->resource_area();
kvn@1536 2754 VectorSet visited(arena);
kvn@3651 2755 ideal_nodes.clear(); // Reset for use with set_map/get_map.
kvn@3651 2756 uint unique_old = _compile->unique();
kvn@500 2757
kvn@500 2758 // Phase 1: Process possible allocations from alloc_worklist.
kvn@500 2759 // Create instance types for the CheckCastPP for allocations where possible.
kvn@679 2760 //
kvn@679 2761 // (Note: don't forget to change the order of the second AddP node on
kvn@679 2762 // the alloc_worklist if the order of the worklist processing is changed,
kvn@679 2763 // see the comment in find_second_addp().)
kvn@679 2764 //
duke@435 2765 while (alloc_worklist.length() != 0) {
duke@435 2766 Node *n = alloc_worklist.pop();
duke@435 2767 uint ni = n->_idx;
duke@435 2768 if (n->is_Call()) {
duke@435 2769 CallNode *alloc = n->as_Call();
duke@435 2770 // copy escape information to call node
kvn@679 2771 PointsToNode* ptn = ptnode_adr(alloc->_idx);
kvn@3651 2772 PointsToNode::EscapeState es = ptn->escape_state();
kvn@500 2773 // We have an allocation or call which returns a Java object,
kvn@500 2774 // see if it is unescaped.
kvn@3254 2775 if (es != PointsToNode::NoEscape || !ptn->scalar_replaceable())
duke@435 2776 continue;
kvn@1219 2777 // Find CheckCastPP for the allocate or for the return value of a call
kvn@1219 2778 n = alloc->result_cast();
kvn@1219 2779 if (n == NULL) { // No uses except Initialize node
kvn@1219 2780 if (alloc->is_Allocate()) {
kvn@1219 2781 // Set the scalar_replaceable flag for allocation
kvn@1219 2782 // so it could be eliminated if it has no uses.
kvn@1219 2783 alloc->as_Allocate()->_is_scalar_replaceable = true;
kvn@1219 2784 }
kvn@5110 2785 if (alloc->is_CallStaticJava()) {
kvn@5110 2786 // Set the scalar_replaceable flag for boxing method
kvn@5110 2787 // so it could be eliminated if it has no uses.
kvn@5110 2788 alloc->as_CallStaticJava()->_is_scalar_replaceable = true;
kvn@5110 2789 }
kvn@1219 2790 continue;
kvn@474 2791 }
kvn@1219 2792 if (!n->is_CheckCastPP()) { // not unique CheckCastPP.
kvn@1219 2793 assert(!alloc->is_Allocate(), "allocation should have unique type");
kvn@500 2794 continue;
kvn@1219 2795 }
kvn@1219 2796
kvn@500 2797 // The inline code for Object.clone() casts the allocation result to
kvn@682 2798 // java.lang.Object and then to the actual type of the allocated
kvn@500 2799 // object. Detect this case and use the second cast.
kvn@682 2800 // Also detect j.l.reflect.Array.newInstance(jobject, jint) case when
kvn@682 2801 // the allocation result is cast to java.lang.Object and then
kvn@682 2802 // to the actual Array type.
kvn@500 2803 if (alloc->is_Allocate() && n->as_Type()->type() == TypeInstPtr::NOTNULL
kvn@682 2804 && (alloc->is_AllocateArray() ||
kvn@682 2805 igvn->type(alloc->in(AllocateNode::KlassNode)) != TypeKlassPtr::OBJECT)) {
kvn@500 2806 Node *cast2 = NULL;
kvn@500 2807 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
kvn@500 2808 Node *use = n->fast_out(i);
kvn@500 2809 if (use->is_CheckCastPP()) {
kvn@500 2810 cast2 = use;
kvn@500 2811 break;
kvn@500 2812 }
kvn@500 2813 }
kvn@500 2814 if (cast2 != NULL) {
kvn@500 2815 n = cast2;
kvn@500 2816 } else {
kvn@1219 2817 // Non-scalar replaceable if the allocation type is unknown statically
kvn@1219 2818 // (reflection allocation), the object can't be restored during
kvn@1219 2819 // deoptimization without precise type.
kvn@500 2820 continue;
kvn@500 2821 }
kvn@500 2822 }
kvn@1219 2823 if (alloc->is_Allocate()) {
kvn@1219 2824 // Set the scalar_replaceable flag for allocation
kvn@1219 2825 // so it could be eliminated.
kvn@1219 2826 alloc->as_Allocate()->_is_scalar_replaceable = true;
kvn@1219 2827 }
kvn@5110 2828 if (alloc->is_CallStaticJava()) {
kvn@5110 2829 // Set the scalar_replaceable flag for boxing method
kvn@5110 2830 // so it could be eliminated.
kvn@5110 2831 alloc->as_CallStaticJava()->_is_scalar_replaceable = true;
kvn@5110 2832 }
kvn@3651 2833 set_escape_state(ptnode_adr(n->_idx), es); // CheckCastPP escape state
kvn@682 2834 // in order for an object to be scalar-replaceable, it must be:
kvn@500 2835 // - a direct allocation (not a call returning an object)
kvn@500 2836 // - non-escaping
kvn@500 2837 // - eligible to be a unique type
kvn@500 2838 // - not determined to be ineligible by escape analysis
kvn@3651 2839 set_map(alloc, n);
kvn@3651 2840 set_map(n, alloc);
kvn@500 2841 const TypeOopPtr *t = igvn->type(n)->isa_oopptr();
kvn@500 2842 if (t == NULL)
kvn@3254 2843 continue; // not a TypeOopPtr
kvn@3651 2844 const TypeOopPtr* tinst = t->cast_to_exactness(true)->is_oopptr()->cast_to_instance_id(ni);
duke@435 2845 igvn->hash_delete(n);
duke@435 2846 igvn->set_type(n, tinst);
duke@435 2847 n->raise_bottom_type(tinst);
duke@435 2848 igvn->hash_insert(n);
kvn@500 2849 record_for_optimizer(n);
kvn@3254 2850 if (alloc->is_Allocate() && (t->isa_instptr() || t->isa_aryptr())) {
kvn@598 2851
kvn@598 2852 // First, put on the worklist all Field edges from Connection Graph
kvn@598 2853 // which is more accurate then putting immediate users from Ideal Graph.
kvn@3651 2854 for (EdgeIterator e(ptn); e.has_next(); e.next()) {
kvn@3651 2855 PointsToNode* tgt = e.get();
kvn@3651 2856 Node* use = tgt->ideal_node();
kvn@3651 2857 assert(tgt->is_Field() && use->is_AddP(),
kvn@598 2858 "only AddP nodes are Field edges in CG");
kvn@598 2859 if (use->outcnt() > 0) { // Don't process dead nodes
kvn@598 2860 Node* addp2 = find_second_addp(use, use->in(AddPNode::Base));
kvn@598 2861 if (addp2 != NULL) {
kvn@598 2862 assert(alloc->is_AllocateArray(),"array allocation was expected");
kvn@598 2863 alloc_worklist.append_if_missing(addp2);
kvn@598 2864 }
kvn@598 2865 alloc_worklist.append_if_missing(use);
kvn@598 2866 }
kvn@598 2867 }
kvn@598 2868
kvn@500 2869 // An allocation may have an Initialize which has raw stores. Scan
kvn@500 2870 // the users of the raw allocation result and push AddP users
kvn@500 2871 // on alloc_worklist.
kvn@500 2872 Node *raw_result = alloc->proj_out(TypeFunc::Parms);
kvn@500 2873 assert (raw_result != NULL, "must have an allocation result");
kvn@500 2874 for (DUIterator_Fast imax, i = raw_result->fast_outs(imax); i < imax; i++) {
kvn@500 2875 Node *use = raw_result->fast_out(i);
kvn@500 2876 if (use->is_AddP() && use->outcnt() > 0) { // Don't process dead nodes
kvn@500 2877 Node* addp2 = find_second_addp(use, raw_result);
kvn@500 2878 if (addp2 != NULL) {
kvn@500 2879 assert(alloc->is_AllocateArray(),"array allocation was expected");
kvn@500 2880 alloc_worklist.append_if_missing(addp2);
kvn@500 2881 }
kvn@500 2882 alloc_worklist.append_if_missing(use);
kvn@1535 2883 } else if (use->is_MemBar()) {
kvn@500 2884 memnode_worklist.append_if_missing(use);
kvn@500 2885 }
kvn@500 2886 }
kvn@500 2887 }
duke@435 2888 } else if (n->is_AddP()) {
kvn@3651 2889 JavaObjectNode* jobj = unique_java_object(get_addp_base(n));
kvn@3651 2890 if (jobj == NULL || jobj == phantom_obj) {
kvn@3651 2891 #ifdef ASSERT
kvn@3651 2892 ptnode_adr(get_addp_base(n)->_idx)->dump();
kvn@3651 2893 ptnode_adr(n->_idx)->dump();
kvn@3651 2894 assert(jobj != NULL && jobj != phantom_obj, "escaped allocation");
kvn@3651 2895 #endif
kvn@3651 2896 _compile->record_failure(C2Compiler::retry_no_escape_analysis());
kvn@3651 2897 return;
kvn@1535 2898 }
kvn@3651 2899 Node *base = get_map(jobj->idx()); // CheckCastPP node
kvn@3651 2900 if (!split_AddP(n, base)) continue; // wrong type from dead path
kvn@500 2901 } else if (n->is_Phi() ||
kvn@500 2902 n->is_CheckCastPP() ||
kvn@603 2903 n->is_EncodeP() ||
kvn@603 2904 n->is_DecodeN() ||
kvn@500 2905 (n->is_ConstraintCast() && n->Opcode() == Op_CastPP)) {
duke@435 2906 if (visited.test_set(n->_idx)) {
duke@435 2907 assert(n->is_Phi(), "loops only through Phi's");
duke@435 2908 continue; // already processed
duke@435 2909 }
kvn@3651 2910 JavaObjectNode* jobj = unique_java_object(n);
kvn@3651 2911 if (jobj == NULL || jobj == phantom_obj) {
kvn@3651 2912 #ifdef ASSERT
kvn@3651 2913 ptnode_adr(n->_idx)->dump();
kvn@3651 2914 assert(jobj != NULL && jobj != phantom_obj, "escaped allocation");
kvn@3651 2915 #endif
kvn@3651 2916 _compile->record_failure(C2Compiler::retry_no_escape_analysis());
kvn@3651 2917 return;
kvn@3651 2918 } else {
kvn@3651 2919 Node *val = get_map(jobj->idx()); // CheckCastPP node
duke@435 2920 TypeNode *tn = n->as_Type();
kvn@3651 2921 const TypeOopPtr* tinst = igvn->type(val)->isa_oopptr();
kvn@658 2922 assert(tinst != NULL && tinst->is_known_instance() &&
kvn@3651 2923 tinst->instance_id() == jobj->idx() , "instance type expected.");
kvn@598 2924
kvn@598 2925 const Type *tn_type = igvn->type(tn);
kvn@658 2926 const TypeOopPtr *tn_t;
kvn@658 2927 if (tn_type->isa_narrowoop()) {
kvn@658 2928 tn_t = tn_type->make_ptr()->isa_oopptr();
kvn@658 2929 } else {
kvn@658 2930 tn_t = tn_type->isa_oopptr();
kvn@658 2931 }
kvn@1535 2932 if (tn_t != NULL && tinst->klass()->is_subtype_of(tn_t->klass())) {
kvn@598 2933 if (tn_type->isa_narrowoop()) {
kvn@598 2934 tn_type = tinst->make_narrowoop();
kvn@598 2935 } else {
kvn@598 2936 tn_type = tinst;
kvn@598 2937 }
duke@435 2938 igvn->hash_delete(tn);
kvn@598 2939 igvn->set_type(tn, tn_type);
kvn@598 2940 tn->set_type(tn_type);
duke@435 2941 igvn->hash_insert(tn);
kvn@500 2942 record_for_optimizer(n);
kvn@728 2943 } else {
kvn@1535 2944 assert(tn_type == TypePtr::NULL_PTR ||
kvn@1535 2945 tn_t != NULL && !tinst->klass()->is_subtype_of(tn_t->klass()),
kvn@1535 2946 "unexpected type");
kvn@1535 2947 continue; // Skip dead path with different type
duke@435 2948 }
duke@435 2949 }
duke@435 2950 } else {
kvn@1535 2951 debug_only(n->dump();)
kvn@1535 2952 assert(false, "EA: unexpected node");
duke@435 2953 continue;
duke@435 2954 }
kvn@1535 2955 // push allocation's users on appropriate worklist
duke@435 2956 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
duke@435 2957 Node *use = n->fast_out(i);
duke@435 2958 if(use->is_Mem() && use->in(MemNode::Address) == n) {
kvn@1535 2959 // Load/store to instance's field
kvn@500 2960 memnode_worklist.append_if_missing(use);
kvn@1535 2961 } else if (use->is_MemBar()) {
kvn@5110 2962 if (use->in(TypeFunc::Memory) == n) { // Ignore precedent edge
kvn@5110 2963 memnode_worklist.append_if_missing(use);
kvn@5110 2964 }
kvn@500 2965 } else if (use->is_AddP() && use->outcnt() > 0) { // No dead nodes
kvn@500 2966 Node* addp2 = find_second_addp(use, n);
kvn@500 2967 if (addp2 != NULL) {
kvn@500 2968 alloc_worklist.append_if_missing(addp2);
kvn@500 2969 }
kvn@500 2970 alloc_worklist.append_if_missing(use);
kvn@500 2971 } else if (use->is_Phi() ||
kvn@500 2972 use->is_CheckCastPP() ||
roland@4159 2973 use->is_EncodeNarrowPtr() ||
roland@4159 2974 use->is_DecodeNarrowPtr() ||
kvn@500 2975 (use->is_ConstraintCast() && use->Opcode() == Op_CastPP)) {
kvn@500 2976 alloc_worklist.append_if_missing(use);
kvn@1535 2977 #ifdef ASSERT
kvn@1535 2978 } else if (use->is_Mem()) {
kvn@1535 2979 assert(use->in(MemNode::Address) != n, "EA: missing allocation reference path");
kvn@1535 2980 } else if (use->is_MergeMem()) {
kvn@1535 2981 assert(_mergemem_worklist.contains(use->as_MergeMem()), "EA: missing MergeMem node in the worklist");
kvn@1535 2982 } else if (use->is_SafePoint()) {
kvn@1535 2983 // Look for MergeMem nodes for calls which reference unique allocation
kvn@1535 2984 // (through CheckCastPP nodes) even for debug info.
kvn@1535 2985 Node* m = use->in(TypeFunc::Memory);
kvn@1535 2986 if (m->is_MergeMem()) {
kvn@1535 2987 assert(_mergemem_worklist.contains(m->as_MergeMem()), "EA: missing MergeMem node in the worklist");
kvn@1535 2988 }
kvn@4479 2989 } else if (use->Opcode() == Op_EncodeISOArray) {
kvn@4479 2990 if (use->in(MemNode::Memory) == n || use->in(3) == n) {
kvn@4479 2991 // EncodeISOArray overwrites destination array
kvn@4479 2992 memnode_worklist.append_if_missing(use);
kvn@4479 2993 }
kvn@1535 2994 } else {
kvn@1535 2995 uint op = use->Opcode();
kvn@1535 2996 if (!(op == Op_CmpP || op == Op_Conv2B ||
kvn@1535 2997 op == Op_CastP2X || op == Op_StoreCM ||
kvn@1535 2998 op == Op_FastLock || op == Op_AryEq || op == Op_StrComp ||
kvn@1535 2999 op == Op_StrEquals || op == Op_StrIndexOf)) {
kvn@1535 3000 n->dump();
kvn@1535 3001 use->dump();
kvn@1535 3002 assert(false, "EA: missing allocation reference path");
kvn@1535 3003 }
kvn@1535 3004 #endif
duke@435 3005 }
duke@435 3006 }
duke@435 3007
duke@435 3008 }
kvn@500 3009 // New alias types were created in split_AddP().
duke@435 3010 uint new_index_end = (uint) _compile->num_alias_types();
kvn@3651 3011 assert(unique_old == _compile->unique(), "there should be no new ideal nodes after Phase 1");
duke@435 3012
duke@435 3013 // Phase 2: Process MemNode's from memnode_worklist. compute new address type and
duke@435 3014 // compute new values for Memory inputs (the Memory inputs are not
duke@435 3015 // actually updated until phase 4.)
duke@435 3016 if (memnode_worklist.length() == 0)
duke@435 3017 return; // nothing to do
duke@435 3018 while (memnode_worklist.length() != 0) {
duke@435 3019 Node *n = memnode_worklist.pop();
kvn@500 3020 if (visited.test_set(n->_idx))
kvn@500 3021 continue;
kvn@1535 3022 if (n->is_Phi() || n->is_ClearArray()) {
kvn@1535 3023 // we don't need to do anything, but the users must be pushed
kvn@1535 3024 } else if (n->is_MemBar()) { // Initialize, MemBar nodes
kvn@1535 3025 // we don't need to do anything, but the users must be pushed
kvn@1535 3026 n = n->as_MemBar()->proj_out(TypeFunc::Memory);
kvn@500 3027 if (n == NULL)
duke@435 3028 continue;
kvn@4479 3029 } else if (n->Opcode() == Op_EncodeISOArray) {
kvn@4479 3030 // get the memory projection
kvn@4479 3031 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
kvn@4479 3032 Node *use = n->fast_out(i);
kvn@4479 3033 if (use->Opcode() == Op_SCMemProj) {
kvn@4479 3034 n = use;
kvn@4479 3035 break;
kvn@4479 3036 }
kvn@4479 3037 }
kvn@4479 3038 assert(n->Opcode() == Op_SCMemProj, "memory projection required");
duke@435 3039 } else {
duke@435 3040 assert(n->is_Mem(), "memory node required.");
duke@435 3041 Node *addr = n->in(MemNode::Address);
duke@435 3042 const Type *addr_t = igvn->type(addr);
duke@435 3043 if (addr_t == Type::TOP)
duke@435 3044 continue;
duke@435 3045 assert (addr_t->isa_ptr() != NULL, "pointer type required.");
duke@435 3046 int alias_idx = _compile->get_alias_index(addr_t->is_ptr());
kvn@500 3047 assert ((uint)alias_idx < new_index_end, "wrong alias index");
kvn@3651 3048 Node *mem = find_inst_mem(n->in(MemNode::Memory), alias_idx, orig_phis);
kvn@473 3049 if (_compile->failing()) {
kvn@473 3050 return;
kvn@473 3051 }
kvn@500 3052 if (mem != n->in(MemNode::Memory)) {
kvn@1536 3053 // We delay the memory edge update since we need old one in
kvn@1536 3054 // MergeMem code below when instances memory slices are separated.
kvn@3651 3055 set_map(n, mem);
kvn@500 3056 }
duke@435 3057 if (n->is_Load()) {
duke@435 3058 continue; // don't push users
duke@435 3059 } else if (n->is_LoadStore()) {
duke@435 3060 // get the memory projection
duke@435 3061 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
duke@435 3062 Node *use = n->fast_out(i);
duke@435 3063 if (use->Opcode() == Op_SCMemProj) {
duke@435 3064 n = use;
duke@435 3065 break;
duke@435 3066 }
duke@435 3067 }
duke@435 3068 assert(n->Opcode() == Op_SCMemProj, "memory projection required");
duke@435 3069 }
duke@435 3070 }
duke@435 3071 // push user on appropriate worklist
duke@435 3072 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
duke@435 3073 Node *use = n->fast_out(i);
kvn@1535 3074 if (use->is_Phi() || use->is_ClearArray()) {
kvn@500 3075 memnode_worklist.append_if_missing(use);
kvn@4479 3076 } else if (use->is_Mem() && use->in(MemNode::Memory) == n) {
kvn@1535 3077 if (use->Opcode() == Op_StoreCM) // Ignore cardmark stores
kvn@1535 3078 continue;
kvn@500 3079 memnode_worklist.append_if_missing(use);
kvn@1535 3080 } else if (use->is_MemBar()) {
kvn@5110 3081 if (use->in(TypeFunc::Memory) == n) { // Ignore precedent edge
kvn@5110 3082 memnode_worklist.append_if_missing(use);
kvn@5110 3083 }
kvn@1535 3084 #ifdef ASSERT
kvn@1535 3085 } else if(use->is_Mem()) {
kvn@1535 3086 assert(use->in(MemNode::Memory) != n, "EA: missing memory path");
duke@435 3087 } else if (use->is_MergeMem()) {
kvn@1535 3088 assert(_mergemem_worklist.contains(use->as_MergeMem()), "EA: missing MergeMem node in the worklist");
kvn@4479 3089 } else if (use->Opcode() == Op_EncodeISOArray) {
kvn@4479 3090 if (use->in(MemNode::Memory) == n || use->in(3) == n) {
kvn@4479 3091 // EncodeISOArray overwrites destination array
kvn@4479 3092 memnode_worklist.append_if_missing(use);
kvn@4479 3093 }
kvn@1535 3094 } else {
kvn@1535 3095 uint op = use->Opcode();
kvn@1535 3096 if (!(op == Op_StoreCM ||
kvn@1535 3097 (op == Op_CallLeaf && use->as_CallLeaf()->_name != NULL &&
kvn@1535 3098 strcmp(use->as_CallLeaf()->_name, "g1_wb_pre") == 0) ||
kvn@1535 3099 op == Op_AryEq || op == Op_StrComp ||
kvn@1535 3100 op == Op_StrEquals || op == Op_StrIndexOf)) {
kvn@1535 3101 n->dump();
kvn@1535 3102 use->dump();
kvn@1535 3103 assert(false, "EA: missing memory path");
kvn@1535 3104 }
kvn@1535 3105 #endif
duke@435 3106 }
duke@435 3107 }
duke@435 3108 }
duke@435 3109
kvn@500 3110 // Phase 3: Process MergeMem nodes from mergemem_worklist.
kvn@1535 3111 // Walk each memory slice moving the first node encountered of each
kvn@500 3112 // instance type to the the input corresponding to its alias index.
kvn@1535 3113 uint length = _mergemem_worklist.length();
kvn@1535 3114 for( uint next = 0; next < length; ++next ) {
kvn@1535 3115 MergeMemNode* nmm = _mergemem_worklist.at(next);
kvn@1535 3116 assert(!visited.test_set(nmm->_idx), "should not be visited before");
duke@435 3117 // Note: we don't want to use MergeMemStream here because we only want to
kvn@1535 3118 // scan inputs which exist at the start, not ones we add during processing.
kvn@1535 3119 // Note 2: MergeMem may already contains instance memory slices added
kvn@1535 3120 // during find_inst_mem() call when memory nodes were processed above.
kvn@1535 3121 igvn->hash_delete(nmm);
duke@435 3122 uint nslices = nmm->req();
duke@435 3123 for (uint i = Compile::AliasIdxRaw+1; i < nslices; i++) {
kvn@500 3124 Node* mem = nmm->in(i);
kvn@500 3125 Node* cur = NULL;
duke@435 3126 if (mem == NULL || mem->is_top())
duke@435 3127 continue;
kvn@1536 3128 // First, update mergemem by moving memory nodes to corresponding slices
kvn@1536 3129 // if their type became more precise since this mergemem was created.
duke@435 3130 while (mem->is_Mem()) {
duke@435 3131 const Type *at = igvn->type(mem->in(MemNode::Address));
duke@435 3132 if (at != Type::TOP) {
duke@435 3133 assert (at->isa_ptr() != NULL, "pointer type required.");
duke@435 3134 uint idx = (uint)_compile->get_alias_index(at->is_ptr());
duke@435 3135 if (idx == i) {
duke@435 3136 if (cur == NULL)
duke@435 3137 cur = mem;
duke@435 3138 } else {
duke@435 3139 if (idx >= nmm->req() || nmm->is_empty_memory(nmm->in(idx))) {
duke@435 3140 nmm->set_memory_at(idx, mem);
duke@435 3141 }
duke@435 3142 }
duke@435 3143 }
duke@435 3144 mem = mem->in(MemNode::Memory);
duke@435 3145 }
duke@435 3146 nmm->set_memory_at(i, (cur != NULL) ? cur : mem);
kvn@500 3147 // Find any instance of the current type if we haven't encountered
kvn@1536 3148 // already a memory slice of the instance along the memory chain.
kvn@500 3149 for (uint ni = new_index_start; ni < new_index_end; ni++) {
kvn@500 3150 if((uint)_compile->get_general_index(ni) == i) {
kvn@500 3151 Node *m = (ni >= nmm->req()) ? nmm->empty_memory() : nmm->in(ni);
kvn@500 3152 if (nmm->is_empty_memory(m)) {
kvn@3651 3153 Node* result = find_inst_mem(mem, ni, orig_phis);
kvn@500 3154 if (_compile->failing()) {
kvn@500 3155 return;
kvn@500 3156 }
kvn@500 3157 nmm->set_memory_at(ni, result);
kvn@500 3158 }
kvn@500 3159 }
kvn@500 3160 }
kvn@500 3161 }
kvn@500 3162 // Find the rest of instances values
kvn@500 3163 for (uint ni = new_index_start; ni < new_index_end; ni++) {
kvn@1536 3164 const TypeOopPtr *tinst = _compile->get_adr_type(ni)->isa_oopptr();
kvn@500 3165 Node* result = step_through_mergemem(nmm, ni, tinst);
kvn@500 3166 if (result == nmm->base_memory()) {
kvn@500 3167 // Didn't find instance memory, search through general slice recursively.
kvn@1536 3168 result = nmm->memory_at(_compile->get_general_index(ni));
kvn@3651 3169 result = find_inst_mem(result, ni, orig_phis);
kvn@500 3170 if (_compile->failing()) {
kvn@500 3171 return;
kvn@500 3172 }
kvn@500 3173 nmm->set_memory_at(ni, result);
kvn@500 3174 }
kvn@500 3175 }
kvn@500 3176 igvn->hash_insert(nmm);
kvn@500 3177 record_for_optimizer(nmm);
duke@435 3178 }
duke@435 3179
kvn@500 3180 // Phase 4: Update the inputs of non-instance memory Phis and
kvn@500 3181 // the Memory input of memnodes
duke@435 3182 // First update the inputs of any non-instance Phi's from
duke@435 3183 // which we split out an instance Phi. Note we don't have
duke@435 3184 // to recursively process Phi's encounted on the input memory
duke@435 3185 // chains as is done in split_memory_phi() since they will
duke@435 3186 // also be processed here.
kvn@682 3187 for (int j = 0; j < orig_phis.length(); j++) {
kvn@682 3188 PhiNode *phi = orig_phis.at(j);
duke@435 3189 int alias_idx = _compile->get_alias_index(phi->adr_type());
duke@435 3190 igvn->hash_delete(phi);
duke@435 3191 for (uint i = 1; i < phi->req(); i++) {
duke@435 3192 Node *mem = phi->in(i);
kvn@3651 3193 Node *new_mem = find_inst_mem(mem, alias_idx, orig_phis);
kvn@500 3194 if (_compile->failing()) {
kvn@500 3195 return;
kvn@500 3196 }
duke@435 3197 if (mem != new_mem) {
duke@435 3198 phi->set_req(i, new_mem);
duke@435 3199 }
duke@435 3200 }
duke@435 3201 igvn->hash_insert(phi);
duke@435 3202 record_for_optimizer(phi);
duke@435 3203 }
duke@435 3204
duke@435 3205 // Update the memory inputs of MemNodes with the value we computed
kvn@1536 3206 // in Phase 2 and move stores memory users to corresponding memory slices.
kvn@2810 3207 // Disable memory split verification code until the fix for 6984348.
kvn@2810 3208 // Currently it produces false negative results since it does not cover all cases.
kvn@2810 3209 #if 0 // ifdef ASSERT
kvn@2556 3210 visited.Reset();
kvn@1536 3211 Node_Stack old_mems(arena, _compile->unique() >> 2);
kvn@1536 3212 #endif
kvn@3651 3213 for (uint i = 0; i < ideal_nodes.size(); i++) {
kvn@3651 3214 Node* n = ideal_nodes.at(i);
kvn@3651 3215 Node* nmem = get_map(n->_idx);
kvn@3651 3216 assert(nmem != NULL, "sanity");
kvn@3651 3217 if (n->is_Mem()) {
kvn@2810 3218 #if 0 // ifdef ASSERT
kvn@3651 3219 Node* old_mem = n->in(MemNode::Memory);
kvn@3651 3220 if (!visited.test_set(old_mem->_idx)) {
kvn@3651 3221 old_mems.push(old_mem, old_mem->outcnt());
kvn@3651 3222 }
kvn@1536 3223 #endif
kvn@3651 3224 assert(n->in(MemNode::Memory) != nmem, "sanity");
kvn@3651 3225 if (!n->is_Load()) {
kvn@3651 3226 // Move memory users of a store first.
kvn@3651 3227 move_inst_mem(n, orig_phis);
duke@435 3228 }
kvn@3651 3229 // Now update memory input
kvn@3651 3230 igvn->hash_delete(n);
kvn@3651 3231 n->set_req(MemNode::Memory, nmem);
kvn@3651 3232 igvn->hash_insert(n);
kvn@3651 3233 record_for_optimizer(n);
kvn@3651 3234 } else {
kvn@3651 3235 assert(n->is_Allocate() || n->is_CheckCastPP() ||
kvn@3651 3236 n->is_AddP() || n->is_Phi(), "unknown node used for set_map()");
duke@435 3237 }
duke@435 3238 }
kvn@2810 3239 #if 0 // ifdef ASSERT
kvn@1536 3240 // Verify that memory was split correctly
kvn@1536 3241 while (old_mems.is_nonempty()) {
kvn@1536 3242 Node* old_mem = old_mems.node();
kvn@1536 3243 uint old_cnt = old_mems.index();
kvn@1536 3244 old_mems.pop();
kvn@2810 3245 assert(old_cnt == old_mem->outcnt(), "old mem could be lost");
kvn@1536 3246 }
kvn@1536 3247 #endif
duke@435 3248 }
duke@435 3249
kvn@3651 3250 #ifndef PRODUCT
kvn@3651 3251 static const char *node_type_names[] = {
kvn@3651 3252 "UnknownType",
kvn@3651 3253 "JavaObject",
kvn@3651 3254 "LocalVar",
kvn@3651 3255 "Field",
kvn@3651 3256 "Arraycopy"
kvn@3651 3257 };
kvn@3651 3258
kvn@3651 3259 static const char *esc_names[] = {
kvn@3651 3260 "UnknownEscape",
kvn@3651 3261 "NoEscape",
kvn@3651 3262 "ArgEscape",
kvn@3651 3263 "GlobalEscape"
kvn@3651 3264 };
kvn@3651 3265
kvn@3651 3266 void PointsToNode::dump(bool print_state) const {
kvn@3651 3267 NodeType nt = node_type();
kvn@3651 3268 tty->print("%s ", node_type_names[(int) nt]);
kvn@3651 3269 if (print_state) {
kvn@3651 3270 EscapeState es = escape_state();
kvn@3651 3271 EscapeState fields_es = fields_escape_state();
kvn@3651 3272 tty->print("%s(%s) ", esc_names[(int)es], esc_names[(int)fields_es]);
kvn@3651 3273 if (nt == PointsToNode::JavaObject && !this->scalar_replaceable())
kvn@4255 3274 tty->print("NSR ");
kvn@3651 3275 }
kvn@3651 3276 if (is_Field()) {
kvn@3651 3277 FieldNode* f = (FieldNode*)this;
kvn@4255 3278 if (f->is_oop())
kvn@4255 3279 tty->print("oop ");
kvn@4255 3280 if (f->offset() > 0)
kvn@4255 3281 tty->print("+%d ", f->offset());
kvn@3651 3282 tty->print("(");
kvn@3651 3283 for (BaseIterator i(f); i.has_next(); i.next()) {
kvn@3651 3284 PointsToNode* b = i.get();
kvn@3651 3285 tty->print(" %d%s", b->idx(),(b->is_JavaObject() ? "P" : ""));
kvn@679 3286 }
kvn@3651 3287 tty->print(" )");
kvn@679 3288 }
kvn@3651 3289 tty->print("[");
kvn@3651 3290 for (EdgeIterator i(this); i.has_next(); i.next()) {
kvn@3651 3291 PointsToNode* e = i.get();
kvn@3651 3292 tty->print(" %d%s%s", e->idx(),(e->is_JavaObject() ? "P" : (e->is_Field() ? "F" : "")), e->is_Arraycopy() ? "cp" : "");
kvn@3651 3293 }
kvn@3651 3294 tty->print(" [");
kvn@3651 3295 for (UseIterator i(this); i.has_next(); i.next()) {
kvn@3651 3296 PointsToNode* u = i.get();
kvn@3651 3297 bool is_base = false;
kvn@3651 3298 if (PointsToNode::is_base_use(u)) {
kvn@3651 3299 is_base = true;
kvn@3651 3300 u = PointsToNode::get_use_node(u)->as_Field();
kvn@3651 3301 }
kvn@3651 3302 tty->print(" %d%s%s", u->idx(), is_base ? "b" : "", u->is_Arraycopy() ? "cp" : "");
kvn@3651 3303 }
kvn@3651 3304 tty->print(" ]] ");
kvn@3651 3305 if (_node == NULL)
kvn@3651 3306 tty->print_cr("<null>");
kvn@3651 3307 else
kvn@3651 3308 _node->dump();
kvn@679 3309 }
kvn@679 3310
kvn@3651 3311 void ConnectionGraph::dump(GrowableArray<PointsToNode*>& ptnodes_worklist) {
duke@435 3312 bool first = true;
kvn@3651 3313 int ptnodes_length = ptnodes_worklist.length();
kvn@3651 3314 for (int i = 0; i < ptnodes_length; i++) {
kvn@3651 3315 PointsToNode *ptn = ptnodes_worklist.at(i);
kvn@3651 3316 if (ptn == NULL || !ptn->is_JavaObject())
duke@435 3317 continue;
kvn@3651 3318 PointsToNode::EscapeState es = ptn->escape_state();
kvn@5110 3319 if ((es != PointsToNode::NoEscape) && !Verbose) {
kvn@5110 3320 continue;
kvn@5110 3321 }
kvn@5110 3322 Node* n = ptn->ideal_node();
kvn@5110 3323 if (n->is_Allocate() || (n->is_CallStaticJava() &&
kvn@5110 3324 n->as_CallStaticJava()->is_boxing_method())) {
kvn@500 3325 if (first) {
kvn@500 3326 tty->cr();
kvn@500 3327 tty->print("======== Connection graph for ");
kvn@679 3328 _compile->method()->print_short_name();
kvn@500 3329 tty->cr();
kvn@500 3330 first = false;
kvn@500 3331 }
kvn@500 3332 ptn->dump();
kvn@3651 3333 // Print all locals and fields which reference this allocation
kvn@3651 3334 for (UseIterator j(ptn); j.has_next(); j.next()) {
kvn@3651 3335 PointsToNode* use = j.get();
kvn@3651 3336 if (use->is_LocalVar()) {
kvn@3651 3337 use->dump(Verbose);
kvn@3651 3338 } else if (Verbose) {
kvn@3651 3339 use->dump();
kvn@500 3340 }
kvn@500 3341 }
kvn@500 3342 tty->cr();
duke@435 3343 }
duke@435 3344 }
duke@435 3345 }
duke@435 3346 #endif

mercurial