22 * 23 */ 24 25 #ifndef SHARE_VM_OPTO_MEMNODE_HPP 26 #define SHARE_VM_OPTO_MEMNODE_HPP 27 28 #include "opto/multnode.hpp" 29 #include "opto/node.hpp" 30 #include "opto/opcodes.hpp" 31 #include "opto/type.hpp" 32 33 // Portions of code courtesy of Clifford Click 34 35 class MultiNode; 36 class PhaseCCP; 37 class PhaseTransform; 38 39 //------------------------------MemNode---------------------------------------- 40 // Load or Store, possibly throwing a NULL pointer exception 41 class MemNode : public Node { 42 protected: 43 #ifdef ASSERT 44 const TypePtr* _adr_type; // What kind of memory is being addressed? 45 #endif 46 virtual uint size_of() const; // Size is bigger (ASSERT only) 47 public: 48 enum { Control, // When is it safe to do this load? 49 Memory, // Chunk of memory is being loaded from 50 Address, // Actually address, derived from base 51 ValueIn, // Value to store 52 OopStore // Preceeding oop store, only in StoreCM 53 }; 54 typedef enum { unordered = 0, 55 acquire, // Load has to acquire or be succeeded by MemBarAcquire. 56 release // Store has to release or be preceded by MemBarRelease. 57 } MemOrd; 58 protected: 59 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at ) 60 : Node(c0,c1,c2 ) { 61 init_class_id(Class_Mem); 62 debug_only(_adr_type=at; adr_type();) 63 } 64 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3 ) 65 : Node(c0,c1,c2,c3) { 66 init_class_id(Class_Mem); 67 debug_only(_adr_type=at; adr_type();) 68 } 69 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3, Node *c4) 70 : Node(c0,c1,c2,c3,c4) { 71 init_class_id(Class_Mem); 72 debug_only(_adr_type=at; adr_type();) 73 } 74 75 public: 76 // Helpers for the optimizer. Documented in memnode.cpp. 77 static bool detect_ptr_independence(Node* p1, AllocateNode* a1, 78 Node* p2, AllocateNode* a2, 79 PhaseTransform* phase); 80 static bool adr_phi_is_loop_invariant(Node* adr_phi, Node* cast); 81 82 static Node *optimize_simple_memory_chain(Node *mchain, const TypeOopPtr *t_oop, Node *load, PhaseGVN *phase); 83 static Node *optimize_memory_chain(Node *mchain, const TypePtr *t_adr, Node *load, PhaseGVN *phase); 84 // This one should probably be a phase-specific function: 85 static bool all_controls_dominate(Node* dom, Node* sub); 86 87 // Find any cast-away of null-ness and keep its control. 88 static Node *Ideal_common_DU_postCCP( PhaseCCP *ccp, Node* n, Node* adr ); 89 virtual Node *Ideal_DU_postCCP( PhaseCCP *ccp ); 90 111 virtual int store_Opcode() const { return -1; } 112 113 // What is the type of the value in memory? (T_VOID mean "unspecified".) 114 virtual BasicType memory_type() const = 0; 115 virtual int memory_size() const { 116 #ifdef ASSERT 117 return type2aelembytes(memory_type(), true); 118 #else 119 return type2aelembytes(memory_type()); 120 #endif 121 } 122 123 // Search through memory states which precede this node (load or store). 124 // Look for an exact match for the address, with no intervening 125 // aliased stores. 126 Node* find_previous_store(PhaseTransform* phase); 127 128 // Can this node (load or store) accurately see a stored value in 129 // the given memory state? (The state may or may not be in(Memory).) 130 Node* can_see_stored_value(Node* st, PhaseTransform* phase) const; 131 132 #ifndef PRODUCT 133 static void dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st); 134 virtual void dump_spec(outputStream *st) const; 135 #endif 136 }; 137 138 //------------------------------LoadNode--------------------------------------- 139 // Load value; requires Memory and Address 140 class LoadNode : public MemNode { 141 public: 142 // Some loads (from unsafe) should be pinned: they don't depend only 143 // on the dominating test. The boolean field _depends_only_on_test 144 // below records whether that node depends only on the dominating 145 // test. 146 // Methods used to build LoadNodes pass an argument of type enum 147 // ControlDependency instead of a boolean because those methods 148 // typically have multiple boolean parameters with default values: 149 // passing the wrong boolean to one of these parameters by mistake 150 // goes easily unnoticed. Using an enum, the compiler can check that | 22 * 23 */ 24 25 #ifndef SHARE_VM_OPTO_MEMNODE_HPP 26 #define SHARE_VM_OPTO_MEMNODE_HPP 27 28 #include "opto/multnode.hpp" 29 #include "opto/node.hpp" 30 #include "opto/opcodes.hpp" 31 #include "opto/type.hpp" 32 33 // Portions of code courtesy of Clifford Click 34 35 class MultiNode; 36 class PhaseCCP; 37 class PhaseTransform; 38 39 //------------------------------MemNode---------------------------------------- 40 // Load or Store, possibly throwing a NULL pointer exception 41 class MemNode : public Node { 42 private: 43 bool _unaligned_access; // Unaligned access from unsafe 44 bool _mismatched_access; // Mismatched access from unsafe: byte read in integer array for instance 45 protected: 46 #ifdef ASSERT 47 const TypePtr* _adr_type; // What kind of memory is being addressed? 48 #endif 49 virtual uint size_of() const; 50 public: 51 enum { Control, // When is it safe to do this load? 52 Memory, // Chunk of memory is being loaded from 53 Address, // Actually address, derived from base 54 ValueIn, // Value to store 55 OopStore // Preceeding oop store, only in StoreCM 56 }; 57 typedef enum { unordered = 0, 58 acquire, // Load has to acquire or be succeeded by MemBarAcquire. 59 release // Store has to release or be preceded by MemBarRelease. 60 } MemOrd; 61 protected: 62 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at ) 63 : Node(c0,c1,c2 ), _unaligned_access(false), _mismatched_access(false) { 64 init_class_id(Class_Mem); 65 debug_only(_adr_type=at; adr_type();) 66 } 67 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3 ) 68 : Node(c0,c1,c2,c3), _unaligned_access(false), _mismatched_access(false) { 69 init_class_id(Class_Mem); 70 debug_only(_adr_type=at; adr_type();) 71 } 72 MemNode( Node *c0, Node *c1, Node *c2, const TypePtr* at, Node *c3, Node *c4) 73 : Node(c0,c1,c2,c3,c4), _unaligned_access(false), _mismatched_access(false) { 74 init_class_id(Class_Mem); 75 debug_only(_adr_type=at; adr_type();) 76 } 77 78 public: 79 // Helpers for the optimizer. Documented in memnode.cpp. 80 static bool detect_ptr_independence(Node* p1, AllocateNode* a1, 81 Node* p2, AllocateNode* a2, 82 PhaseTransform* phase); 83 static bool adr_phi_is_loop_invariant(Node* adr_phi, Node* cast); 84 85 static Node *optimize_simple_memory_chain(Node *mchain, const TypeOopPtr *t_oop, Node *load, PhaseGVN *phase); 86 static Node *optimize_memory_chain(Node *mchain, const TypePtr *t_adr, Node *load, PhaseGVN *phase); 87 // This one should probably be a phase-specific function: 88 static bool all_controls_dominate(Node* dom, Node* sub); 89 90 // Find any cast-away of null-ness and keep its control. 91 static Node *Ideal_common_DU_postCCP( PhaseCCP *ccp, Node* n, Node* adr ); 92 virtual Node *Ideal_DU_postCCP( PhaseCCP *ccp ); 93 114 virtual int store_Opcode() const { return -1; } 115 116 // What is the type of the value in memory? (T_VOID mean "unspecified".) 117 virtual BasicType memory_type() const = 0; 118 virtual int memory_size() const { 119 #ifdef ASSERT 120 return type2aelembytes(memory_type(), true); 121 #else 122 return type2aelembytes(memory_type()); 123 #endif 124 } 125 126 // Search through memory states which precede this node (load or store). 127 // Look for an exact match for the address, with no intervening 128 // aliased stores. 129 Node* find_previous_store(PhaseTransform* phase); 130 131 // Can this node (load or store) accurately see a stored value in 132 // the given memory state? (The state may or may not be in(Memory).) 133 Node* can_see_stored_value(Node* st, PhaseTransform* phase) const; 134 135 void set_unaligned_access() { _unaligned_access = true; } 136 bool is_unaligned_access() const { return _unaligned_access; } 137 void set_mismatched_access() { _mismatched_access = true; } 138 bool is_mismatched_access() const { return _mismatched_access; } 139 140 #ifndef PRODUCT 141 static void dump_adr_type(const Node* mem, const TypePtr* adr_type, outputStream *st); 142 virtual void dump_spec(outputStream *st) const; 143 #endif 144 }; 145 146 //------------------------------LoadNode--------------------------------------- 147 // Load value; requires Memory and Address 148 class LoadNode : public MemNode { 149 public: 150 // Some loads (from unsafe) should be pinned: they don't depend only 151 // on the dominating test. The boolean field _depends_only_on_test 152 // below records whether that node depends only on the dominating 153 // test. 154 // Methods used to build LoadNodes pass an argument of type enum 155 // ControlDependency instead of a boolean because those methods 156 // typically have multiple boolean parameters with default values: 157 // passing the wrong boolean to one of these parameters by mistake 158 // goes easily unnoticed. Using an enum, the compiler can check that |