1 /*
   2  * Copyright (c) 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  */
  23 package jdk.vm.ci.code.site;
  24 
  25 import java.util.Objects;
  26 
  27 import jdk.vm.ci.meta.VMConstant;
  28 
  29 /**
  30  * Represents a code site that references some data. The associated data can be either a
  31  * {@link DataSectionReference reference} to the data section, or it may be an inlined
  32  * {@link VMConstant} that needs to be patched.
  33  */
  34 public final class DataPatch extends Site {
  35 
  36     public Reference reference;
  37     public Object note;
  38 
  39     public DataPatch(int pcOffset, Reference reference) {
  40         super(pcOffset);
  41         this.reference = reference;
  42         this.note = null;
  43     }
  44 
  45     public DataPatch(int pcOffset, Reference reference, Object note) {
  46         super(pcOffset);
  47         this.reference = reference;
  48         this.note = note;
  49     }
  50 
  51     @Override
  52     public String toString() {
  53         if (note != null) {
  54             return String.format("%d[<data patch referring to %s>, note: %s]", pcOffset, reference.toString(), note.toString());
  55         } else {
  56             return String.format("%d[<data patch referring to %s>]", pcOffset, reference.toString());
  57         }
  58     }
  59 
  60     @Override
  61     public boolean equals(Object obj) {
  62         if (this == obj) {
  63             return true;
  64         }
  65         if (obj instanceof DataPatch) {
  66             DataPatch that = (DataPatch) obj;
  67             if (this.pcOffset == that.pcOffset && Objects.equals(this.reference, that.reference) && Objects.equals(this.note, that.note)) {
  68                 return true;
  69             }
  70         }
  71         return false;
  72     }
  73 }