Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@0 | 25 | #ifndef SHARE_VM_CI_CICONSTANT_HPP |
aoqi@0 | 26 | #define SHARE_VM_CI_CICONSTANT_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "ci/ciClassList.hpp" |
aoqi@0 | 29 | #include "ci/ciNullObject.hpp" |
aoqi@0 | 30 | |
aoqi@0 | 31 | // ciConstant |
aoqi@0 | 32 | // |
aoqi@0 | 33 | // This class represents a constant value. |
aoqi@0 | 34 | class ciConstant VALUE_OBJ_CLASS_SPEC { |
aoqi@0 | 35 | friend class VMStructs; |
aoqi@0 | 36 | private: |
aoqi@0 | 37 | friend class ciEnv; |
aoqi@0 | 38 | friend class ciField; |
aoqi@0 | 39 | |
aoqi@0 | 40 | BasicType _type; |
aoqi@0 | 41 | union { |
aoqi@0 | 42 | jint _int; |
aoqi@0 | 43 | jlong _long; |
aoqi@0 | 44 | jfloat _float; |
aoqi@0 | 45 | jdouble _double; |
aoqi@0 | 46 | ciObject* _object; |
aoqi@0 | 47 | } _value; |
aoqi@0 | 48 | |
aoqi@0 | 49 | public: |
aoqi@0 | 50 | |
aoqi@0 | 51 | ciConstant() { |
aoqi@0 | 52 | _type = T_ILLEGAL; _value._long = -1; |
aoqi@0 | 53 | } |
aoqi@0 | 54 | ciConstant(BasicType type, jint value) { |
aoqi@0 | 55 | assert(type != T_LONG && type != T_DOUBLE && type != T_FLOAT, |
aoqi@0 | 56 | "using the wrong ciConstant constructor"); |
aoqi@0 | 57 | _type = type; _value._int = value; |
aoqi@0 | 58 | } |
aoqi@0 | 59 | ciConstant(jlong value) { |
aoqi@0 | 60 | _type = T_LONG; _value._long = value; |
aoqi@0 | 61 | } |
aoqi@0 | 62 | ciConstant(jfloat value) { |
aoqi@0 | 63 | _type = T_FLOAT; _value._float = value; |
aoqi@0 | 64 | } |
aoqi@0 | 65 | ciConstant(jdouble value) { |
aoqi@0 | 66 | _type = T_DOUBLE; _value._double = value; |
aoqi@0 | 67 | } |
aoqi@0 | 68 | ciConstant(BasicType type, ciObject* p) { |
aoqi@0 | 69 | _type = type; _value._object = p; |
aoqi@0 | 70 | } |
aoqi@0 | 71 | |
aoqi@0 | 72 | BasicType basic_type() const { return _type; } |
aoqi@0 | 73 | |
aoqi@0 | 74 | jboolean as_boolean() { |
aoqi@0 | 75 | assert(basic_type() == T_BOOLEAN, "wrong type"); |
aoqi@0 | 76 | return (jboolean)_value._int; |
aoqi@0 | 77 | } |
aoqi@0 | 78 | jchar as_char() { |
aoqi@0 | 79 | assert(basic_type() == T_CHAR, "wrong type"); |
aoqi@0 | 80 | return (jchar)_value._int; |
aoqi@0 | 81 | } |
aoqi@0 | 82 | jbyte as_byte() { |
aoqi@0 | 83 | assert(basic_type() == T_BYTE, "wrong type"); |
aoqi@0 | 84 | return (jbyte)_value._int; |
aoqi@0 | 85 | } |
aoqi@0 | 86 | jshort as_short() { |
aoqi@0 | 87 | assert(basic_type() == T_SHORT, "wrong type"); |
aoqi@0 | 88 | return (jshort)_value._int; |
aoqi@0 | 89 | } |
aoqi@0 | 90 | jint as_int() { |
aoqi@0 | 91 | assert(basic_type() == T_BOOLEAN || basic_type() == T_CHAR || |
aoqi@0 | 92 | basic_type() == T_BYTE || basic_type() == T_SHORT || |
aoqi@0 | 93 | basic_type() == T_INT, "wrong type"); |
aoqi@0 | 94 | return _value._int; |
aoqi@0 | 95 | } |
aoqi@0 | 96 | jlong as_long() { |
aoqi@0 | 97 | assert(basic_type() == T_LONG, "wrong type"); |
aoqi@0 | 98 | return _value._long; |
aoqi@0 | 99 | } |
aoqi@0 | 100 | jfloat as_float() { |
aoqi@0 | 101 | assert(basic_type() == T_FLOAT, "wrong type"); |
aoqi@0 | 102 | return _value._float; |
aoqi@0 | 103 | } |
aoqi@0 | 104 | jdouble as_double() { |
aoqi@0 | 105 | assert(basic_type() == T_DOUBLE, "wrong type"); |
aoqi@0 | 106 | return _value._double; |
aoqi@0 | 107 | } |
aoqi@0 | 108 | ciObject* as_object() const { |
aoqi@0 | 109 | assert(basic_type() == T_OBJECT || basic_type() == T_ARRAY, "wrong type"); |
aoqi@0 | 110 | return _value._object; |
aoqi@0 | 111 | } |
aoqi@0 | 112 | |
aoqi@0 | 113 | bool is_null_or_zero() const { |
aoqi@0 | 114 | if (!is_java_primitive(basic_type())) { |
aoqi@0 | 115 | return as_object()->is_null_object(); |
aoqi@0 | 116 | } else if (type2size[basic_type()] == 1) { |
aoqi@0 | 117 | // treat float bits as int, to avoid comparison with -0 and NaN |
aoqi@0 | 118 | return (_value._int == 0); |
aoqi@0 | 119 | } else if (type2size[basic_type()] == 2) { |
aoqi@0 | 120 | // treat double bits as long, to avoid comparison with -0 and NaN |
aoqi@0 | 121 | return (_value._long == 0); |
aoqi@0 | 122 | } else { |
aoqi@0 | 123 | return false; |
aoqi@0 | 124 | } |
aoqi@0 | 125 | } |
aoqi@0 | 126 | |
aoqi@0 | 127 | // Debugging output |
aoqi@0 | 128 | void print(); |
aoqi@0 | 129 | }; |
aoqi@0 | 130 | |
aoqi@0 | 131 | #endif // SHARE_VM_CI_CICONSTANT_HPP |