1 /*
   2  * Copyright (c) 2011, 2015, 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 package jdk.internal.jvmci.code;
  24 
  25 import jdk.internal.jvmci.meta.*;
  26 import static jdk.internal.jvmci.code.ValueUtil.*;
  27 
  28 /**
  29  * Represents lock information in the debug information.
  30  */
  31 public final class StackLockValue implements JavaValue {
  32 
  33     private JavaValue owner;
  34     private StackSlotValue slot;
  35     private final boolean eliminated;
  36 
  37     public StackLockValue(JavaValue object, StackSlotValue slot, boolean eliminated) {
  38         this.owner = object;
  39         this.slot = slot;
  40         this.eliminated = eliminated;
  41     }
  42 
  43     public JavaValue getOwner() {
  44         return owner;
  45     }
  46 
  47     public void setOwner(JavaValue newOwner) {
  48         this.owner = newOwner;
  49     }
  50 
  51     public Value getSlot() {
  52         return slot;
  53     }
  54 
  55     public boolean isEliminated() {
  56         return eliminated;
  57     }
  58 
  59     @Override
  60     public String toString() {
  61         return "monitor[" + owner + (slot != null ? ", " + slot : "") + (eliminated ? ", eliminated" : "") + "]";
  62     }
  63 
  64     @Override
  65     public int hashCode() {
  66         final int prime = 43;
  67         int result = super.hashCode();
  68         result = prime * result + (eliminated ? 1231 : 1237);
  69         result = prime * result + owner.hashCode();
  70         result = prime * result + slot.hashCode();
  71         return result;
  72     }
  73 
  74     @Override
  75     public boolean equals(Object obj) {
  76         if (obj instanceof StackLockValue) {
  77             StackLockValue other = (StackLockValue) obj;
  78             return super.equals(obj) && eliminated == other.eliminated && owner.equals(other.owner) && slot.equals(other.slot);
  79         }
  80         return false;
  81     }
  82 
  83     public void setSlot(StackSlotValue stackSlot) {
  84         assert slot == null || (isVirtualStackSlot(slot) && (slot.equals(stackSlot) || isStackSlot(stackSlot))) : String.format("Can not set slot for %s to %s", this, stackSlot);
  85         slot = stackSlot;
  86     }
  87 }