1 /* 2 * Copyright (c) 1999, 2023, 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 * 23 */ 24 25 #ifndef SHARE_OPTO_LOCKNODE_HPP 26 #define SHARE_OPTO_LOCKNODE_HPP 27 28 #include "opto/node.hpp" 29 #include "opto/opcodes.hpp" 30 #include "opto/subnode.hpp" 31 32 class RTMLockingCounters; 33 34 //------------------------------BoxLockNode------------------------------------ 35 class BoxLockNode : public Node { 36 const int _slot; // stack slot 37 RegMask _inmask; // OptoReg corresponding to stack slot 38 bool _is_eliminated; // Associated locks were safely eliminated 39 40 public: 41 BoxLockNode( int lock ); 42 virtual int Opcode() const; 43 virtual void emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const; 44 virtual uint size(PhaseRegAlloc *ra_) const; 45 virtual const RegMask &in_RegMask(uint) const; 46 virtual const RegMask &out_RegMask() const; 47 virtual uint size_of() const; 48 virtual uint hash() const; 49 virtual bool cmp( const Node &n ) const; 50 virtual const class Type *bottom_type() const { return TypeRawPtr::BOTTOM; } 51 virtual uint ideal_reg() const { return Op_RegP; } 52 53 static OptoReg::Name reg(Node* box_node); 54 static BoxLockNode* box_node(Node* box_node); 55 static bool same_slot(Node* box1, Node* box2) { 56 return box1->as_BoxLock()->_slot == box2->as_BoxLock()->_slot; 57 } 58 int stack_slot() const { return _slot; } 59 60 bool is_eliminated() const { return _is_eliminated; } 61 // mark lock as eliminated. 62 void set_eliminated() { _is_eliminated = true; } 63 64 // Is BoxLock node used for one simple lock region? 65 bool is_simple_lock_region(LockNode** unique_lock, Node* obj, Node** bad_lock); 66 67 #ifndef PRODUCT 68 virtual void format( PhaseRegAlloc *, outputStream *st ) const; 69 virtual void dump_spec(outputStream *st) const { st->print(" Lock %d",_slot); } 70 #endif 71 }; 72 73 //------------------------------FastLockNode----------------------------------- 74 class FastLockNode: public CmpNode { 75 private: 76 RTMLockingCounters* _rtm_counters; // RTM lock counters for inflated locks 77 RTMLockingCounters* _stack_rtm_counters; // RTM lock counters for stack locks 78 79 public: 80 FastLockNode(Node *ctrl, Node *oop, Node *box) : CmpNode(oop,box) { 81 init_req(0,ctrl); 82 init_class_id(Class_FastLock); 83 _rtm_counters = nullptr; 84 _stack_rtm_counters = nullptr; 85 } 86 Node* obj_node() const { return in(1); } 87 Node* box_node() const { return in(2); } 88 void set_box_node(Node* box) { set_req(2, box); } 89 90 // FastLock and FastUnlockNode do not hash, we need one for each corresponding 91 // LockNode/UnLockNode to avoid creating Phi's. 92 virtual uint hash() const ; // { return NO_HASH; } 93 virtual uint size_of() const; 94 virtual bool cmp( const Node &n ) const ; // Always fail, except on self 95 virtual int Opcode() const; 96 virtual const Type* Value(PhaseGVN* phase) const { return TypeInt::CC; } 97 const Type *sub(const Type *t1, const Type *t2) const { return TypeInt::CC;} 98 99 void create_rtm_lock_counter(JVMState* state); 100 RTMLockingCounters* rtm_counters() const { return _rtm_counters; } 101 RTMLockingCounters* stack_rtm_counters() const { return _stack_rtm_counters; } 102 }; 103 104 105 //------------------------------FastUnlockNode--------------------------------- 106 class FastUnlockNode: public CmpNode { 107 public: 108 FastUnlockNode(Node *ctrl, Node *oop, Node *box) : CmpNode(oop,box) { 109 init_req(0,ctrl); 110 init_class_id(Class_FastUnlock); 111 } 112 Node* obj_node() const { return in(1); } 113 Node* box_node() const { return in(2); } 114 115 116 // FastLock and FastUnlockNode do not hash, we need one for each corresponding 117 // LockNode/UnLockNode to avoid creating Phi's. 118 virtual uint hash() const ; // { return NO_HASH; } 119 virtual bool cmp( const Node &n ) const ; // Always fail, except on self 120 virtual int Opcode() const; 121 virtual const Type* Value(PhaseGVN* phase) const { return TypeInt::CC; } 122 const Type *sub(const Type *t1, const Type *t2) const { return TypeInt::CC;} 123 124 }; 125 126 #endif // SHARE_OPTO_LOCKNODE_HPP