1 /* 2 * Copyright (c) 1997, 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 25 #include "precompiled.hpp" 26 #include "utilities/constantTag.hpp" 27 #include "utilities/ostream.hpp" 28 29 #ifndef PRODUCT 30 31 void constantTag::print_on(outputStream* st) const { 32 st->print("%s", internal_name()); 33 } 34 35 #endif // PRODUCT 36 37 BasicType constantTag::basic_type() const { 38 switch (_tag) { 39 case JVM_CONSTANT_Integer : 40 return T_INT; 41 case JVM_CONSTANT_Float : 42 return T_FLOAT; 43 case JVM_CONSTANT_Long : 44 return T_LONG; 45 case JVM_CONSTANT_Double : 46 return T_DOUBLE; 47 48 case JVM_CONSTANT_Class : 49 case JVM_CONSTANT_String : 50 case JVM_CONSTANT_UnresolvedClass : 51 case JVM_CONSTANT_UnresolvedClassInError : 52 case JVM_CONSTANT_ClassIndex : 53 case JVM_CONSTANT_StringIndex : 54 case JVM_CONSTANT_MethodHandle : 55 case JVM_CONSTANT_MethodHandleInError : 56 case JVM_CONSTANT_MethodType : 57 case JVM_CONSTANT_MethodTypeInError : 58 return T_OBJECT; 59 60 case JVM_CONSTANT_Dynamic : 61 case JVM_CONSTANT_DynamicInError : 62 assert(false, "Dynamic constant has no fixed basic type"); 63 64 default: 65 ShouldNotReachHere(); 66 return T_ILLEGAL; 67 } 68 } 69 70 71 // value as specified in the classfile format 72 jbyte constantTag::classfile_value() const { 73 switch (_tag) { 74 case JVM_CONSTANT_ClassIndex: 75 case JVM_CONSTANT_UnresolvedClass: 76 case JVM_CONSTANT_UnresolvedClassInError: 77 return JVM_CONSTANT_Class; 78 case JVM_CONSTANT_StringIndex: 79 return JVM_CONSTANT_String; 80 case JVM_CONSTANT_MethodHandleInError: 81 return JVM_CONSTANT_MethodHandle; 82 case JVM_CONSTANT_MethodTypeInError: 83 return JVM_CONSTANT_MethodType; 84 case JVM_CONSTANT_DynamicInError: 85 return JVM_CONSTANT_Dynamic; 86 default: 87 // Return a zero tag for a gap after Long or Double, 88 // even though that doesn't exactly appear in a classfile. 89 assert(_tag >= 0 && _tag <= JVM_CONSTANT_ExternalMax, 90 "cannot interpret tag %d as a standard classfile tag", _tag); 91 return _tag; 92 } 93 } 94 95 96 jbyte constantTag::non_error_value() const { 97 switch (_tag) { 98 case JVM_CONSTANT_UnresolvedClassInError: 99 return JVM_CONSTANT_UnresolvedClass; 100 case JVM_CONSTANT_MethodHandleInError: 101 return JVM_CONSTANT_MethodHandle; 102 case JVM_CONSTANT_MethodTypeInError: 103 return JVM_CONSTANT_MethodType; 104 case JVM_CONSTANT_DynamicInError: 105 return JVM_CONSTANT_Dynamic; 106 default: 107 return _tag; 108 } 109 } 110 111 112 jbyte constantTag::error_value() const { 113 switch (_tag) { 114 case JVM_CONSTANT_UnresolvedClass: 115 return JVM_CONSTANT_UnresolvedClassInError; 116 case JVM_CONSTANT_MethodHandle: 117 return JVM_CONSTANT_MethodHandleInError; 118 case JVM_CONSTANT_MethodType: 119 return JVM_CONSTANT_MethodTypeInError; 120 case JVM_CONSTANT_Dynamic: 121 return JVM_CONSTANT_DynamicInError; 122 default: 123 ShouldNotReachHere(); 124 return JVM_CONSTANT_Invalid; 125 } 126 } 127 128 const char* constantTag::internal_name() const { 129 switch (_tag) { 130 case JVM_CONSTANT_Invalid : 131 return "Invalid index"; 132 case JVM_CONSTANT_Class : 133 return "Class"; 134 case JVM_CONSTANT_Fieldref : 135 return "Field"; 136 case JVM_CONSTANT_Methodref : 137 return "Method"; 138 case JVM_CONSTANT_InterfaceMethodref : 139 return "InterfaceMethod"; 140 case JVM_CONSTANT_String : 141 return "String"; 142 case JVM_CONSTANT_Integer : 143 return "Integer"; 144 case JVM_CONSTANT_Float : 145 return "Float"; 146 case JVM_CONSTANT_Long : 147 return "Long"; 148 case JVM_CONSTANT_Double : 149 return "Double"; 150 case JVM_CONSTANT_NameAndType : 151 return "NameAndType"; 152 case JVM_CONSTANT_MethodHandle : 153 return "MethodHandle"; 154 case JVM_CONSTANT_MethodHandleInError : 155 return "MethodHandle Error"; 156 case JVM_CONSTANT_MethodType : 157 return "MethodType"; 158 case JVM_CONSTANT_MethodTypeInError : 159 return "MethodType Error"; 160 case JVM_CONSTANT_Dynamic : 161 return "Dynamic"; 162 case JVM_CONSTANT_DynamicInError : 163 return "Dynamic Error"; 164 case JVM_CONSTANT_InvokeDynamic : 165 return "InvokeDynamic"; 166 case JVM_CONSTANT_Utf8 : 167 return "Utf8"; 168 case JVM_CONSTANT_UnresolvedClass : 169 return "Unresolved Class"; 170 case JVM_CONSTANT_UnresolvedClassInError : 171 return "Unresolved Class Error"; 172 case JVM_CONSTANT_ClassIndex : 173 return "Unresolved Class Index"; 174 case JVM_CONSTANT_StringIndex : 175 return "Unresolved String Index"; 176 default: 177 ShouldNotReachHere(); 178 return "Illegal"; 179 } 180 }