1 /* 2 * Copyright (c) 1997, 2025, 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 "utilities/constantTag.hpp" 26 #include "utilities/ostream.hpp" 27 28 #ifndef PRODUCT 29 30 void constantTag::print_on(outputStream* st) const { 31 st->print("%s", internal_name()); 32 } 33 34 #endif // PRODUCT 35 36 BasicType constantTag::basic_type() const { 37 switch (_tag) { 38 case JVM_CONSTANT_Integer : 39 return T_INT; 40 case JVM_CONSTANT_Float : 41 return T_FLOAT; 42 case JVM_CONSTANT_Long : 43 return T_LONG; 44 case JVM_CONSTANT_Double : 45 return T_DOUBLE; 46 47 case JVM_CONSTANT_Class : 48 case JVM_CONSTANT_String : 49 case JVM_CONSTANT_UnresolvedClass : 50 case JVM_CONSTANT_UnresolvedClassInError : 51 case JVM_CONSTANT_ClassIndex : 52 case JVM_CONSTANT_StringIndex : 53 case JVM_CONSTANT_MethodHandle : 54 case JVM_CONSTANT_MethodHandleInError : 55 case JVM_CONSTANT_MethodType : 56 case JVM_CONSTANT_MethodTypeInError : 57 return T_OBJECT; 58 59 case JVM_CONSTANT_Dynamic : 60 case JVM_CONSTANT_DynamicInError : 61 assert(false, "Dynamic constant has no fixed basic type"); 62 63 default: 64 ShouldNotReachHere(); 65 return T_ILLEGAL; 66 } 67 } 68 69 70 jbyte constantTag::non_error_value() const { 71 switch (_tag) { 72 case JVM_CONSTANT_UnresolvedClassInError: 73 return JVM_CONSTANT_UnresolvedClass; 74 case JVM_CONSTANT_MethodHandleInError: 75 return JVM_CONSTANT_MethodHandle; 76 case JVM_CONSTANT_MethodTypeInError: 77 return JVM_CONSTANT_MethodType; 78 case JVM_CONSTANT_DynamicInError: 79 return JVM_CONSTANT_Dynamic; 80 default: 81 return _tag; 82 } 83 } 84 85 86 jbyte constantTag::error_value() const { 87 switch (_tag) { 88 case JVM_CONSTANT_UnresolvedClass: 89 return JVM_CONSTANT_UnresolvedClassInError; 90 case JVM_CONSTANT_MethodHandle: 91 return JVM_CONSTANT_MethodHandleInError; 92 case JVM_CONSTANT_MethodType: 93 return JVM_CONSTANT_MethodTypeInError; 94 case JVM_CONSTANT_Dynamic: 95 return JVM_CONSTANT_DynamicInError; 96 default: 97 ShouldNotReachHere(); 98 return JVM_CONSTANT_Invalid; 99 } 100 } 101 102 const char* constantTag::internal_name() const { 103 switch (_tag) { 104 case JVM_CONSTANT_Invalid : 105 return "Invalid index"; 106 case JVM_CONSTANT_Class : 107 return "Class"; 108 case JVM_CONSTANT_Fieldref : 109 return "Field"; 110 case JVM_CONSTANT_Methodref : 111 return "Method"; 112 case JVM_CONSTANT_InterfaceMethodref : 113 return "InterfaceMethod"; 114 case JVM_CONSTANT_String : 115 return "String"; 116 case JVM_CONSTANT_Integer : 117 return "Integer"; 118 case JVM_CONSTANT_Float : 119 return "Float"; 120 case JVM_CONSTANT_Long : 121 return "Long"; 122 case JVM_CONSTANT_Double : 123 return "Double"; 124 case JVM_CONSTANT_NameAndType : 125 return "NameAndType"; 126 case JVM_CONSTANT_MethodHandle : 127 return "MethodHandle"; 128 case JVM_CONSTANT_MethodHandleInError : 129 return "MethodHandle Error"; 130 case JVM_CONSTANT_MethodType : 131 return "MethodType"; 132 case JVM_CONSTANT_MethodTypeInError : 133 return "MethodType Error"; 134 case JVM_CONSTANT_Dynamic : 135 return "Dynamic"; 136 case JVM_CONSTANT_DynamicInError : 137 return "Dynamic Error"; 138 case JVM_CONSTANT_InvokeDynamic : 139 return "InvokeDynamic"; 140 case JVM_CONSTANT_Utf8 : 141 return "Utf8"; 142 case JVM_CONSTANT_UnresolvedClass : 143 return "Unresolved Class"; 144 case JVM_CONSTANT_UnresolvedClassInError : 145 return "Unresolved Class Error"; 146 case JVM_CONSTANT_ClassIndex : 147 return "Unresolved Class Index"; 148 case JVM_CONSTANT_StringIndex : 149 return "Unresolved String Index"; 150 default: 151 ShouldNotReachHere(); 152 return "Illegal"; 153 } 154 }