1 /* 2 * Copyright (c) 2016, 2017, 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 package jdk.tools.jaotc.binformat; 25 26 import java.util.Objects; 27 28 import jdk.tools.jaotc.binformat.NativeSymbol; 29 30 public class Symbol { 31 32 public enum Binding { 33 UNDEFINED, 34 LOCAL, 35 GLOBAL 36 } 37 38 public enum Kind { 39 UNDEFINED, 40 NATIVE_FUNCTION, 41 JAVA_FUNCTION, 42 STATIC_STUB_CALL, // static call stub inside the text section 43 OBJECT, 44 NOTYPE 45 } 46 47 private final String name; 48 private final int size; 49 private final int offset; 50 private final Binding binding; 51 private final Kind kind; 52 53 private ByteContainer section; 54 private NativeSymbol nativeSymbol; 55 56 /** 57 * Create symbol info. 58 * 59 * @param offset section offset for the defined symbol 60 * @param kind kind of the symbol (UNDEFINED, FUNC, etc) 61 * @param binding binding of the symbol (LOCAL, GLOBAL, ...) 62 * @param section section in which this symbol is "defined" 63 * @param size size of the symbol 64 * @param name name of the symbol 65 */ 66 67 public Symbol(int offset, Kind kind, Binding binding, ByteContainer section, int size, String name) { 68 this.binding = binding; 69 this.kind = kind; 70 this.section = section; 71 this.size = size; 72 this.offset = offset; 73 this.name = name; 74 } 75 76 public String getName() { 77 return name; 78 } 79 80 public NativeSymbol getNativeSymbol() { 81 return nativeSymbol; 82 } 83 84 public void setNativeSymbol(NativeSymbol nativeSym) { 85 this.nativeSymbol = nativeSym; 86 } 87 88 public Binding getBinding() { 89 return binding; 90 } 91 92 public Kind getKind() { 93 return kind; 94 } 95 96 public int getSize() { 97 return size; 98 } 99 100 public ByteContainer getSection() { 101 return section; 102 } 103 104 public int getOffset() { 105 return offset; 106 } 107 108 @Override 109 public boolean equals(Object obj) { 110 if (this == obj) { 111 return true; 112 } 113 if (!(obj instanceof Symbol)) { 114 return false; 115 } 116 if (getClass() != obj.getClass()) { 117 return false; 118 } 119 120 Symbol symbol = (Symbol) obj; 121 122 if (size != symbol.size) { 123 return false; 124 } 125 if (offset != symbol.offset) { 126 return false; 127 } 128 if (!name.equals(symbol.name)) { 129 return false; 130 } 131 if (binding != symbol.binding) { 132 return false; 133 } 134 if (kind != symbol.kind) { 135 return false; 136 } 137 return !(section != null ? !section.equals(symbol.section) : symbol.section != null); 138 } 139 140 @Override 141 public int hashCode() { 142 int result = Objects.hash(name, binding, kind, section); 143 result = 31 * result + size; 144 result = 31 * result + offset; 145 return result; 146 } 147 148 @Override 149 public String toString() { 150 return "[" + name + ", " + size + ", " + offset + ", " + binding + ", " + kind + ", " + section + "]"; 151 } 152 153 }