| 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 | jbyte constantTag::non_error_value() const { |
| 72 | switch (_tag) { |
| 73 | case JVM_CONSTANT_UnresolvedClassInError: |
| 74 | return JVM_CONSTANT_UnresolvedClass; |
| 75 | case JVM_CONSTANT_MethodHandleInError: |
| 76 | return JVM_CONSTANT_MethodHandle; |
| 77 | case JVM_CONSTANT_MethodTypeInError: |
| 78 | return JVM_CONSTANT_MethodType; |
| 79 | case JVM_CONSTANT_DynamicInError: |
| 80 | return JVM_CONSTANT_Dynamic; |
| 81 | default: |
| 82 | return _tag; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | |
| 87 | jbyte constantTag::error_value() const { |
| 88 | switch (_tag) { |
| 89 | case JVM_CONSTANT_UnresolvedClass: |
| 90 | return JVM_CONSTANT_UnresolvedClassInError; |
| 91 | case JVM_CONSTANT_MethodHandle: |
| 92 | return JVM_CONSTANT_MethodHandleInError; |
| 93 | case JVM_CONSTANT_MethodType: |
| 94 | return JVM_CONSTANT_MethodTypeInError; |
| 95 | case JVM_CONSTANT_Dynamic: |
| 96 | return JVM_CONSTANT_DynamicInError; |
| 97 | default: |
| 98 | ShouldNotReachHere(); |
| 99 | return JVM_CONSTANT_Invalid; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | const char* constantTag::internal_name() const { |
| 104 | switch (_tag) { |
| 105 | case JVM_CONSTANT_Invalid : |
| 106 | return "Invalid index" ; |
| 107 | case JVM_CONSTANT_Class : |
| 108 | return "Class" ; |
| 109 | case JVM_CONSTANT_Fieldref : |
| 110 | return "Field" ; |
| 111 | case JVM_CONSTANT_Methodref : |
| 112 | return "Method" ; |
| 113 | case JVM_CONSTANT_InterfaceMethodref : |
| 114 | return "InterfaceMethod" ; |
| 115 | case JVM_CONSTANT_String : |
| 116 | return "String" ; |
| 117 | case JVM_CONSTANT_Integer : |
| 118 | return "Integer" ; |
| 119 | case JVM_CONSTANT_Float : |
| 120 | return "Float" ; |
| 121 | case JVM_CONSTANT_Long : |
| 122 | return "Long" ; |
| 123 | case JVM_CONSTANT_Double : |
| 124 | return "Double" ; |
| 125 | case JVM_CONSTANT_NameAndType : |
| 126 | return "NameAndType" ; |
| 127 | case JVM_CONSTANT_MethodHandle : |
| 128 | return "MethodHandle" ; |
| 129 | case JVM_CONSTANT_MethodHandleInError : |
| 130 | return "MethodHandle Error" ; |
| 131 | case JVM_CONSTANT_MethodType : |
| 132 | return "MethodType" ; |
| 133 | case JVM_CONSTANT_MethodTypeInError : |
| 134 | return "MethodType Error" ; |
| 135 | case JVM_CONSTANT_Dynamic : |
| 136 | return "Dynamic" ; |
| 137 | case JVM_CONSTANT_DynamicInError : |
| 138 | return "Dynamic Error" ; |
| 139 | case JVM_CONSTANT_InvokeDynamic : |
| 140 | return "InvokeDynamic" ; |
| 141 | case JVM_CONSTANT_Utf8 : |
| 142 | return "Utf8" ; |
| 143 | case JVM_CONSTANT_UnresolvedClass : |
| 144 | return "Unresolved Class" ; |
| 145 | case JVM_CONSTANT_UnresolvedClassInError : |
| 146 | return "Unresolved Class Error" ; |
| 147 | case JVM_CONSTANT_ClassIndex : |
| 148 | return "Unresolved Class Index" ; |
| 149 | case JVM_CONSTANT_StringIndex : |
| 150 | return "Unresolved String Index" ; |
| 151 | default: |
| 152 | ShouldNotReachHere(); |
| 153 | return "Illegal" ; |
| 154 | } |
| 155 | } |
| 156 | |