1 /*
   2  * Copyright (c) 2009, 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.vm.ci.code;
  24 
  25 import java.util.Objects;
  26 
  27 /**
  28  * Represents the debugging information for a particular point of execution. This information
  29  * includes:
  30  * <ul>
  31  * <li>a {@linkplain #getBytecodePosition() bytecode position}</li>
  32  * <li>a reference map for registers and stack slots in the current frame</li>
  33  * <li>a map from bytecode locals and operand stack slots to their values or locations from which
  34  * their values can be read</li>
  35  * <li>a map from the registers (in the caller's frame) to the slots where they are saved in the
  36  * current frame</li>
  37  * </ul>
  38  */
  39 public final class DebugInfo {
  40 
  41     private final BytecodePosition bytecodePosition;
  42     private ReferenceMap referenceMap;
  43     @SuppressWarnings("unused") private final VirtualObject[] virtualObjectMapping;
  44     private RegisterSaveLayout calleeSaveInfo;
  45 
  46     /**
  47      * Creates a new {@link DebugInfo} from the given values.
  48      *
  49      * @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame
  50      *            frame} info
  51      * @param virtualObjectMapping the mapping of {@link VirtualObject}s to their real values
  52      */
  53     public DebugInfo(BytecodePosition codePos, VirtualObject[] virtualObjectMapping) {
  54         this.bytecodePosition = codePos;
  55         this.virtualObjectMapping = virtualObjectMapping;
  56     }
  57 
  58     public DebugInfo(BytecodePosition codePos) {
  59         this(codePos, null);
  60     }
  61 
  62     public void setReferenceMap(ReferenceMap referenceMap) {
  63         this.referenceMap = referenceMap;
  64     }
  65 
  66     /**
  67      * @return {@code true} if this debug information has a frame
  68      */
  69     public boolean hasFrame() {
  70         return getBytecodePosition() instanceof BytecodeFrame;
  71     }
  72 
  73     /**
  74      * Gets the deoptimization information for each inlined frame (if available).
  75      *
  76      * @return {@code null} if no frame de-opt info is {@linkplain #hasFrame() available}
  77      */
  78     public BytecodeFrame frame() {
  79         if (hasFrame()) {
  80             return (BytecodeFrame) getBytecodePosition();
  81         }
  82         return null;
  83     }
  84 
  85     @Override
  86     public String toString() {
  87         return CodeUtil.append(new StringBuilder(100), this, null).toString();
  88     }
  89 
  90     /**
  91      * @return The code position (including all inlined methods) of this debug info. If this is a
  92      *         {@link BytecodeFrame} instance, then it is also the deoptimization information for
  93      *         each inlined frame.
  94      */
  95     public BytecodePosition getBytecodePosition() {
  96         return bytecodePosition;
  97     }
  98 
  99     public ReferenceMap getReferenceMap() {
 100         return referenceMap;
 101     }
 102 
 103     /**
 104      * Sets the map from the registers (in the caller's frame) to the slots where they are saved in
 105      * the current frame.
 106      */
 107     public void setCalleeSaveInfo(RegisterSaveLayout calleeSaveInfo) {
 108         this.calleeSaveInfo = calleeSaveInfo;
 109     }
 110 
 111     /**
 112      * Gets the map from the registers (in the caller's frame) to the slots where they are saved in
 113      * the current frame. If no such information is available, {@code null} is returned.
 114      */
 115     public RegisterSaveLayout getCalleeSaveInfo() {
 116         return calleeSaveInfo;
 117     }
 118 
 119     @Override
 120     public int hashCode() {
 121         throw new UnsupportedOperationException("hashCode");
 122     }
 123 
 124     @Override
 125     public boolean equals(Object obj) {
 126         if (this == obj) {
 127             return true;
 128         }
 129         if (obj instanceof DebugInfo) {
 130             DebugInfo that = (DebugInfo) obj;
 131             if (Objects.equals(this.bytecodePosition, that.bytecodePosition) && Objects.equals(this.calleeSaveInfo, that.calleeSaveInfo) && Objects.equals(this.referenceMap, that.referenceMap)) {
 132                 return true;
 133             }
 134         }
 135         return false;
 136     }
 137 }