< prev index next >

src/share/vm/opto/escape.cpp

Print this page


   1 /*
   2  * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 495     case Op_CompareAndExchangeN:
 496     case Op_GetAndSetP:
 497     case Op_GetAndSetN: {
 498       add_objload_to_connection_graph(n, delayed_worklist);
 499       // fallthrough
 500     }
 501     case Op_StoreP:
 502     case Op_StoreN:
 503     case Op_StoreNKlass:
 504     case Op_StorePConditional:
 505     case Op_WeakCompareAndSwapP:
 506     case Op_WeakCompareAndSwapN:
 507     case Op_CompareAndSwapP:
 508     case Op_CompareAndSwapN: {
 509       Node* adr = n->in(MemNode::Address);
 510       const Type *adr_type = igvn->type(adr);
 511       adr_type = adr_type->make_ptr();
 512       if (adr_type == NULL) {
 513         break; // skip dead nodes
 514       }
 515       if (adr_type->isa_oopptr() ||
 516           (opcode == Op_StoreP || opcode == Op_StoreN || opcode == Op_StoreNKlass) &&
 517                         (adr_type == TypeRawPtr::NOTNULL &&
 518                          adr->in(AddPNode::Address)->is_Proj() &&
 519                          adr->in(AddPNode::Address)->in(0)->is_Allocate())) {
 520         delayed_worklist->push(n); // Process it later.
 521 #ifdef ASSERT
 522         assert(adr->is_AddP(), "expecting an AddP");
 523         if (adr_type == TypeRawPtr::NOTNULL) {
 524           // Verify a raw address for a store captured by Initialize node.
 525           int offs = (int)igvn->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
 526           assert(offs != Type::OffsetBot, "offset must be a constant");
 527         }
 528 #endif
 529       } else {
 530         // Ignore copy the displaced header to the BoxNode (OSR compilation).
 531         if (adr->is_BoxLock())
 532           break;
 533         // Stored value escapes in unsafe access.
 534         if ((opcode == Op_StoreP) && adr_type->isa_rawptr()) {
 535           // Pointer stores in G1 barriers looks like unsafe access.
 536           // Ignore such stores to be able scalar replace non-escaping
 537           // allocations.
 538           if (UseG1GC && adr->is_AddP()) {
 539             Node* base = get_addp_base(adr);


 708     case Op_CompareAndSwapP:
 709     case Op_CompareAndSwapN:
 710     case Op_WeakCompareAndSwapP:
 711     case Op_WeakCompareAndSwapN:
 712     case Op_GetAndSetP:
 713     case Op_GetAndSetN: {
 714       Node* adr = n->in(MemNode::Address);
 715       const Type *adr_type = _igvn->type(adr);
 716       adr_type = adr_type->make_ptr();
 717 #ifdef ASSERT
 718       if (adr_type == NULL) {
 719         n->dump(1);
 720         assert(adr_type != NULL, "dead node should not be on list");
 721         break;
 722       }
 723 #endif
 724       if (opcode == Op_GetAndSetP || opcode == Op_GetAndSetN ||
 725           opcode == Op_CompareAndExchangeN || opcode == Op_CompareAndExchangeP) {
 726         add_local_var_and_edge(n, PointsToNode::NoEscape, adr, NULL);
 727       }
 728       if (adr_type->isa_oopptr() ||
 729           (opcode == Op_StoreP || opcode == Op_StoreN || opcode == Op_StoreNKlass) &&
 730                         (adr_type == TypeRawPtr::NOTNULL &&
 731                          adr->in(AddPNode::Address)->is_Proj() &&
 732                          adr->in(AddPNode::Address)->in(0)->is_Allocate())) {
 733         // Point Address to Value
 734         PointsToNode* adr_ptn = ptnode_adr(adr->_idx);
 735         assert(adr_ptn != NULL &&
 736                adr_ptn->as_Field()->is_oop(), "node should be registered");
 737         Node *val = n->in(MemNode::ValueIn);
 738         PointsToNode* ptn = ptnode_adr(val->_idx);
 739         assert(ptn != NULL, "node should be registered");
 740         add_edge(adr_ptn, ptn);
 741         break;
 742       } else if ((opcode == Op_StoreP) && adr_type->isa_rawptr()) {
 743         // Stored value escapes in unsafe access.
 744         Node *val = n->in(MemNode::ValueIn);
 745         PointsToNode* ptn = ptnode_adr(val->_idx);
 746         assert(ptn != NULL, "node should be registered");
 747         set_escape_state(ptn, PointsToNode::GlobalEscape);
 748         // Add edge to object for unsafe access with offset.
 749         PointsToNode* adr_ptn = ptnode_adr(adr->_idx);
 750         assert(adr_ptn != NULL, "node should be registered");
 751         if (adr_ptn->is_Field()) {
 752           assert(adr_ptn->as_Field()->is_oop(), "should be oop field");


1947       jobj2->ideal_node()->is_Con()) {
1948     // Klass or String constants compare. Need to be careful with
1949     // compressed pointers - compare types of ConN and ConP instead of nodes.
1950     const Type* t1 = jobj1->ideal_node()->get_ptr_type();
1951     const Type* t2 = jobj2->ideal_node()->get_ptr_type();
1952     if (t1->make_ptr() == t2->make_ptr()) {
1953       return _pcmp_eq;
1954     } else {
1955       return _pcmp_neq;
1956     }
1957   }
1958   if (ptn1->meet(ptn2)) {
1959     return NULL; // Sets are not disjoint
1960   }
1961 
1962   // Sets are disjoint.
1963   bool set1_has_unknown_ptr = ptn1->points_to(phantom_obj);
1964   bool set2_has_unknown_ptr = ptn2->points_to(phantom_obj);
1965   bool set1_has_null_ptr    = ptn1->points_to(null_obj);
1966   bool set2_has_null_ptr    = ptn2->points_to(null_obj);
1967   if (set1_has_unknown_ptr && set2_has_null_ptr ||
1968       set2_has_unknown_ptr && set1_has_null_ptr) {
1969     // Check nullness of unknown object.
1970     return NULL;
1971   }
1972 
1973   // Disjointness by itself is not sufficient since
1974   // alias analysis is not complete for escaped objects.
1975   // Disjoint sets are definitely unrelated only when
1976   // at least one set has only not escaping allocations.
1977   if (!set1_has_unknown_ptr && !set1_has_null_ptr) {
1978     if (ptn1->non_escaping_allocation()) {
1979       return _pcmp_neq;
1980     }
1981   }
1982   if (!set2_has_unknown_ptr && !set2_has_null_ptr) {
1983     if (ptn2->non_escaping_allocation()) {
1984       return _pcmp_neq;
1985     }
1986   }
1987   return NULL;
1988 }


2607       assert(n == mmem->memory_at(alias_idx), "should be on instance memory slice");
2608       if (n != mmem->memory_at(general_idx) || alias_idx == general_idx) {
2609         continue; // Nothing to do
2610       }
2611       // Replace previous general reference to mem node.
2612       uint orig_uniq = C->unique();
2613       Node* m = find_inst_mem(n, general_idx, orig_phis);
2614       assert(orig_uniq == C->unique(), "no new nodes");
2615       mmem->set_memory_at(general_idx, m);
2616       --imax;
2617       --i;
2618     } else if (use->is_MemBar()) {
2619       assert(!use->is_Initialize(), "initializing stores should not be moved");
2620       if (use->req() > MemBarNode::Precedent &&
2621           use->in(MemBarNode::Precedent) == n) {
2622         // Don't move related membars.
2623         record_for_optimizer(use);
2624         continue;
2625       }
2626       tp = use->as_MemBar()->adr_type()->isa_ptr();
2627       if (tp != NULL && C->get_alias_index(tp) == alias_idx ||
2628           alias_idx == general_idx) {
2629         continue; // Nothing to do
2630       }
2631       // Move to general memory slice.
2632       uint orig_uniq = C->unique();
2633       Node* m = find_inst_mem(n, general_idx, orig_phis);
2634       assert(orig_uniq == C->unique(), "no new nodes");
2635       igvn->hash_delete(use);
2636       imax -= use->replace_edge(n, m);
2637       igvn->hash_insert(use);
2638       record_for_optimizer(use);
2639       --i;
2640 #ifdef ASSERT
2641     } else if (use->is_Mem()) {
2642       if (use->Opcode() == Op_StoreCM && use->in(MemNode::OopStore) == n) {
2643         // Don't move related cardmark.
2644         continue;
2645       }
2646       // Memory nodes should have new memory input.
2647       tp = igvn->type(use->in(MemNode::Address))->isa_ptr();


   1 /*
   2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 495     case Op_CompareAndExchangeN:
 496     case Op_GetAndSetP:
 497     case Op_GetAndSetN: {
 498       add_objload_to_connection_graph(n, delayed_worklist);
 499       // fallthrough
 500     }
 501     case Op_StoreP:
 502     case Op_StoreN:
 503     case Op_StoreNKlass:
 504     case Op_StorePConditional:
 505     case Op_WeakCompareAndSwapP:
 506     case Op_WeakCompareAndSwapN:
 507     case Op_CompareAndSwapP:
 508     case Op_CompareAndSwapN: {
 509       Node* adr = n->in(MemNode::Address);
 510       const Type *adr_type = igvn->type(adr);
 511       adr_type = adr_type->make_ptr();
 512       if (adr_type == NULL) {
 513         break; // skip dead nodes
 514       }
 515       if (   adr_type->isa_oopptr()
 516           || (   (opcode == Op_StoreP || opcode == Op_StoreN || opcode == Op_StoreNKlass)
 517               && adr_type == TypeRawPtr::NOTNULL
 518               && adr->in(AddPNode::Address)->is_Proj()
 519               && adr->in(AddPNode::Address)->in(0)->is_Allocate())) {
 520         delayed_worklist->push(n); // Process it later.
 521 #ifdef ASSERT
 522         assert(adr->is_AddP(), "expecting an AddP");
 523         if (adr_type == TypeRawPtr::NOTNULL) {
 524           // Verify a raw address for a store captured by Initialize node.
 525           int offs = (int)igvn->find_intptr_t_con(adr->in(AddPNode::Offset), Type::OffsetBot);
 526           assert(offs != Type::OffsetBot, "offset must be a constant");
 527         }
 528 #endif
 529       } else {
 530         // Ignore copy the displaced header to the BoxNode (OSR compilation).
 531         if (adr->is_BoxLock())
 532           break;
 533         // Stored value escapes in unsafe access.
 534         if ((opcode == Op_StoreP) && adr_type->isa_rawptr()) {
 535           // Pointer stores in G1 barriers looks like unsafe access.
 536           // Ignore such stores to be able scalar replace non-escaping
 537           // allocations.
 538           if (UseG1GC && adr->is_AddP()) {
 539             Node* base = get_addp_base(adr);


 708     case Op_CompareAndSwapP:
 709     case Op_CompareAndSwapN:
 710     case Op_WeakCompareAndSwapP:
 711     case Op_WeakCompareAndSwapN:
 712     case Op_GetAndSetP:
 713     case Op_GetAndSetN: {
 714       Node* adr = n->in(MemNode::Address);
 715       const Type *adr_type = _igvn->type(adr);
 716       adr_type = adr_type->make_ptr();
 717 #ifdef ASSERT
 718       if (adr_type == NULL) {
 719         n->dump(1);
 720         assert(adr_type != NULL, "dead node should not be on list");
 721         break;
 722       }
 723 #endif
 724       if (opcode == Op_GetAndSetP || opcode == Op_GetAndSetN ||
 725           opcode == Op_CompareAndExchangeN || opcode == Op_CompareAndExchangeP) {
 726         add_local_var_and_edge(n, PointsToNode::NoEscape, adr, NULL);
 727       }
 728       if (   adr_type->isa_oopptr()
 729           || (   (opcode == Op_StoreP || opcode == Op_StoreN || opcode == Op_StoreNKlass)
 730               && adr_type == TypeRawPtr::NOTNULL
 731               && adr->in(AddPNode::Address)->is_Proj()
 732               && adr->in(AddPNode::Address)->in(0)->is_Allocate())) {
 733         // Point Address to Value
 734         PointsToNode* adr_ptn = ptnode_adr(adr->_idx);
 735         assert(adr_ptn != NULL &&
 736                adr_ptn->as_Field()->is_oop(), "node should be registered");
 737         Node *val = n->in(MemNode::ValueIn);
 738         PointsToNode* ptn = ptnode_adr(val->_idx);
 739         assert(ptn != NULL, "node should be registered");
 740         add_edge(adr_ptn, ptn);
 741         break;
 742       } else if ((opcode == Op_StoreP) && adr_type->isa_rawptr()) {
 743         // Stored value escapes in unsafe access.
 744         Node *val = n->in(MemNode::ValueIn);
 745         PointsToNode* ptn = ptnode_adr(val->_idx);
 746         assert(ptn != NULL, "node should be registered");
 747         set_escape_state(ptn, PointsToNode::GlobalEscape);
 748         // Add edge to object for unsafe access with offset.
 749         PointsToNode* adr_ptn = ptnode_adr(adr->_idx);
 750         assert(adr_ptn != NULL, "node should be registered");
 751         if (adr_ptn->is_Field()) {
 752           assert(adr_ptn->as_Field()->is_oop(), "should be oop field");


1947       jobj2->ideal_node()->is_Con()) {
1948     // Klass or String constants compare. Need to be careful with
1949     // compressed pointers - compare types of ConN and ConP instead of nodes.
1950     const Type* t1 = jobj1->ideal_node()->get_ptr_type();
1951     const Type* t2 = jobj2->ideal_node()->get_ptr_type();
1952     if (t1->make_ptr() == t2->make_ptr()) {
1953       return _pcmp_eq;
1954     } else {
1955       return _pcmp_neq;
1956     }
1957   }
1958   if (ptn1->meet(ptn2)) {
1959     return NULL; // Sets are not disjoint
1960   }
1961 
1962   // Sets are disjoint.
1963   bool set1_has_unknown_ptr = ptn1->points_to(phantom_obj);
1964   bool set2_has_unknown_ptr = ptn2->points_to(phantom_obj);
1965   bool set1_has_null_ptr    = ptn1->points_to(null_obj);
1966   bool set2_has_null_ptr    = ptn2->points_to(null_obj);
1967   if ((set1_has_unknown_ptr && set2_has_null_ptr) ||
1968       (set2_has_unknown_ptr && set1_has_null_ptr)) {
1969     // Check nullness of unknown object.
1970     return NULL;
1971   }
1972 
1973   // Disjointness by itself is not sufficient since
1974   // alias analysis is not complete for escaped objects.
1975   // Disjoint sets are definitely unrelated only when
1976   // at least one set has only not escaping allocations.
1977   if (!set1_has_unknown_ptr && !set1_has_null_ptr) {
1978     if (ptn1->non_escaping_allocation()) {
1979       return _pcmp_neq;
1980     }
1981   }
1982   if (!set2_has_unknown_ptr && !set2_has_null_ptr) {
1983     if (ptn2->non_escaping_allocation()) {
1984       return _pcmp_neq;
1985     }
1986   }
1987   return NULL;
1988 }


2607       assert(n == mmem->memory_at(alias_idx), "should be on instance memory slice");
2608       if (n != mmem->memory_at(general_idx) || alias_idx == general_idx) {
2609         continue; // Nothing to do
2610       }
2611       // Replace previous general reference to mem node.
2612       uint orig_uniq = C->unique();
2613       Node* m = find_inst_mem(n, general_idx, orig_phis);
2614       assert(orig_uniq == C->unique(), "no new nodes");
2615       mmem->set_memory_at(general_idx, m);
2616       --imax;
2617       --i;
2618     } else if (use->is_MemBar()) {
2619       assert(!use->is_Initialize(), "initializing stores should not be moved");
2620       if (use->req() > MemBarNode::Precedent &&
2621           use->in(MemBarNode::Precedent) == n) {
2622         // Don't move related membars.
2623         record_for_optimizer(use);
2624         continue;
2625       }
2626       tp = use->as_MemBar()->adr_type()->isa_ptr();
2627       if ((tp != NULL && C->get_alias_index(tp) == alias_idx) ||
2628           alias_idx == general_idx) {
2629         continue; // Nothing to do
2630       }
2631       // Move to general memory slice.
2632       uint orig_uniq = C->unique();
2633       Node* m = find_inst_mem(n, general_idx, orig_phis);
2634       assert(orig_uniq == C->unique(), "no new nodes");
2635       igvn->hash_delete(use);
2636       imax -= use->replace_edge(n, m);
2637       igvn->hash_insert(use);
2638       record_for_optimizer(use);
2639       --i;
2640 #ifdef ASSERT
2641     } else if (use->is_Mem()) {
2642       if (use->Opcode() == Op_StoreCM && use->in(MemNode::OopStore) == n) {
2643         // Don't move related cardmark.
2644         continue;
2645       }
2646       // Memory nodes should have new memory input.
2647       tp = igvn->type(use->in(MemNode::Address))->isa_ptr();


< prev index next >