aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #ifndef SHARE_VM_CI_CICONSTANT_HPP aoqi@0: #define SHARE_VM_CI_CICONSTANT_HPP aoqi@0: aoqi@0: #include "ci/ciClassList.hpp" aoqi@0: #include "ci/ciNullObject.hpp" aoqi@0: aoqi@0: // ciConstant aoqi@0: // aoqi@0: // This class represents a constant value. aoqi@0: class ciConstant VALUE_OBJ_CLASS_SPEC { aoqi@0: friend class VMStructs; aoqi@0: private: aoqi@0: friend class ciEnv; aoqi@0: friend class ciField; aoqi@0: aoqi@0: BasicType _type; aoqi@0: union { aoqi@0: jint _int; aoqi@0: jlong _long; aoqi@0: jfloat _float; aoqi@0: jdouble _double; aoqi@0: ciObject* _object; aoqi@0: } _value; aoqi@0: aoqi@0: public: aoqi@0: aoqi@0: ciConstant() { aoqi@0: _type = T_ILLEGAL; _value._long = -1; aoqi@0: } aoqi@0: ciConstant(BasicType type, jint value) { aoqi@0: assert(type != T_LONG && type != T_DOUBLE && type != T_FLOAT, aoqi@0: "using the wrong ciConstant constructor"); aoqi@0: _type = type; _value._int = value; aoqi@0: } aoqi@0: ciConstant(jlong value) { aoqi@0: _type = T_LONG; _value._long = value; aoqi@0: } aoqi@0: ciConstant(jfloat value) { aoqi@0: _type = T_FLOAT; _value._float = value; aoqi@0: } aoqi@0: ciConstant(jdouble value) { aoqi@0: _type = T_DOUBLE; _value._double = value; aoqi@0: } aoqi@0: ciConstant(BasicType type, ciObject* p) { aoqi@0: _type = type; _value._object = p; aoqi@0: } aoqi@0: aoqi@0: BasicType basic_type() const { return _type; } aoqi@0: aoqi@0: jboolean as_boolean() { aoqi@0: assert(basic_type() == T_BOOLEAN, "wrong type"); aoqi@0: return (jboolean)_value._int; aoqi@0: } aoqi@0: jchar as_char() { aoqi@0: assert(basic_type() == T_CHAR, "wrong type"); aoqi@0: return (jchar)_value._int; aoqi@0: } aoqi@0: jbyte as_byte() { aoqi@0: assert(basic_type() == T_BYTE, "wrong type"); aoqi@0: return (jbyte)_value._int; aoqi@0: } aoqi@0: jshort as_short() { aoqi@0: assert(basic_type() == T_SHORT, "wrong type"); aoqi@0: return (jshort)_value._int; aoqi@0: } aoqi@0: jint as_int() { aoqi@0: assert(basic_type() == T_BOOLEAN || basic_type() == T_CHAR || aoqi@0: basic_type() == T_BYTE || basic_type() == T_SHORT || aoqi@0: basic_type() == T_INT, "wrong type"); aoqi@0: return _value._int; aoqi@0: } aoqi@0: jlong as_long() { aoqi@0: assert(basic_type() == T_LONG, "wrong type"); aoqi@0: return _value._long; aoqi@0: } aoqi@0: jfloat as_float() { aoqi@0: assert(basic_type() == T_FLOAT, "wrong type"); aoqi@0: return _value._float; aoqi@0: } aoqi@0: jdouble as_double() { aoqi@0: assert(basic_type() == T_DOUBLE, "wrong type"); aoqi@0: return _value._double; aoqi@0: } aoqi@0: ciObject* as_object() const { aoqi@0: assert(basic_type() == T_OBJECT || basic_type() == T_ARRAY, "wrong type"); aoqi@0: return _value._object; aoqi@0: } aoqi@0: aoqi@0: bool is_null_or_zero() const { aoqi@0: if (!is_java_primitive(basic_type())) { aoqi@0: return as_object()->is_null_object(); aoqi@0: } else if (type2size[basic_type()] == 1) { aoqi@0: // treat float bits as int, to avoid comparison with -0 and NaN aoqi@0: return (_value._int == 0); aoqi@0: } else if (type2size[basic_type()] == 2) { aoqi@0: // treat double bits as long, to avoid comparison with -0 and NaN aoqi@0: return (_value._long == 0); aoqi@0: } else { aoqi@0: return false; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Debugging output aoqi@0: void print(); aoqi@0: }; aoqi@0: aoqi@0: #endif // SHARE_VM_CI_CICONSTANT_HPP