001/* 002 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package jdk.internal.jvmci.code; 024 025import java.util.*; 026 027/** 028 * Represents the debugging information for a particular point of execution. This information 029 * includes: 030 * <ul> 031 * <li>a {@linkplain #getBytecodePosition() bytecode position}</li> 032 * <li>a reference map for registers and stack slots in the current frame</li> 033 * <li>a map from bytecode locals and operand stack slots to their values or locations from which 034 * their values can be read</li> 035 * <li>a map from the registers (in the caller's frame) to the slots where they are saved in the 036 * current frame</li> 037 * </ul> 038 */ 039public final class DebugInfo { 040 041 private final BytecodePosition bytecodePosition; 042 private ReferenceMap referenceMap; 043 @SuppressWarnings("unused") private final VirtualObject[] virtualObjectMapping; 044 private RegisterSaveLayout calleeSaveInfo; 045 046 /** 047 * Creates a new {@link DebugInfo} from the given values. 048 * 049 * @param codePos the {@linkplain BytecodePosition code position} or {@linkplain BytecodeFrame 050 * frame} info 051 * @param virtualObjectMapping the mapping of {@link VirtualObject}s to their real values 052 */ 053 public DebugInfo(BytecodePosition codePos, VirtualObject[] virtualObjectMapping) { 054 this.bytecodePosition = codePos; 055 this.virtualObjectMapping = virtualObjectMapping; 056 } 057 058 public DebugInfo(BytecodePosition codePos) { 059 this(codePos, null); 060 } 061 062 public void setReferenceMap(ReferenceMap referenceMap) { 063 this.referenceMap = referenceMap; 064 } 065 066 /** 067 * @return {@code true} if this debug information has a frame 068 */ 069 public boolean hasFrame() { 070 return getBytecodePosition() instanceof BytecodeFrame; 071 } 072 073 /** 074 * Gets the deoptimization information for each inlined frame (if available). 075 * 076 * @return {@code null} if no frame de-opt info is {@linkplain #hasFrame() available} 077 */ 078 public BytecodeFrame frame() { 079 if (hasFrame()) { 080 return (BytecodeFrame) getBytecodePosition(); 081 } 082 return null; 083 } 084 085 @Override 086 public String toString() { 087 return CodeUtil.append(new StringBuilder(100), this, null).toString(); 088 } 089 090 /** 091 * @return The code position (including all inlined methods) of this debug info. If this is a 092 * {@link BytecodeFrame} instance, then it is also the deoptimization information for 093 * each inlined frame. 094 */ 095 public BytecodePosition getBytecodePosition() { 096 return bytecodePosition; 097 } 098 099 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}