Path: blob/master/src/hotspot/share/ci/ciConstant.hpp
40930 views
/*1* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_CI_CICONSTANT_HPP25#define SHARE_CI_CICONSTANT_HPP2627#include "ci/ciClassList.hpp"28#include "ci/ciNullObject.hpp"2930// ciConstant31//32// This class represents a constant value.33class ciConstant {34friend class VMStructs;35private:36friend class ciEnv;37friend class ciField;3839BasicType _type;40union {41jint _int;42jlong _long;43jfloat _float;44jdouble _double;45ciObject* _object;46} _value;4748public:4950ciConstant() {51_type = T_ILLEGAL; _value._long = -1;52}53ciConstant(BasicType type, jint value) {54assert(type != T_LONG && type != T_DOUBLE && type != T_FLOAT,55"using the wrong ciConstant constructor");56_type = type; _value._int = value;57}58ciConstant(jlong value) {59_type = T_LONG; _value._long = value;60}61ciConstant(jfloat value) {62_type = T_FLOAT; _value._float = value;63}64ciConstant(jdouble value) {65_type = T_DOUBLE; _value._double = value;66}67ciConstant(BasicType type, ciObject* p) {68_type = type; _value._object = p;69}7071BasicType basic_type() const { return _type; }7273jboolean as_boolean() {74assert(basic_type() == T_BOOLEAN, "wrong type");75return (jboolean)_value._int;76}77jchar as_char() {78assert(basic_type() == T_CHAR, "wrong type");79return (jchar)_value._int;80}81jbyte as_byte() {82assert(basic_type() == T_BYTE, "wrong type");83return (jbyte)_value._int;84}85jshort as_short() {86assert(basic_type() == T_SHORT, "wrong type");87return (jshort)_value._int;88}89jint as_int() {90assert(basic_type() == T_BOOLEAN || basic_type() == T_CHAR ||91basic_type() == T_BYTE || basic_type() == T_SHORT ||92basic_type() == T_INT, "wrong type");93return _value._int;94}95jlong as_long() {96assert(basic_type() == T_LONG, "wrong type");97return _value._long;98}99jfloat as_float() {100assert(basic_type() == T_FLOAT, "wrong type");101return _value._float;102}103jdouble as_double() {104assert(basic_type() == T_DOUBLE, "wrong type");105return _value._double;106}107ciObject* as_object() const {108assert(is_reference_type(basic_type()), "wrong type");109return _value._object;110}111112bool is_null_or_zero() const {113if (!is_java_primitive(basic_type())) {114return as_object()->is_null_object();115} else if (type2size[basic_type()] == 1) {116// treat float bits as int, to avoid comparison with -0 and NaN117return (_value._int == 0);118} else if (type2size[basic_type()] == 2) {119// treat double bits as long, to avoid comparison with -0 and NaN120return (_value._long == 0);121} else {122return false;123}124}125126bool is_valid() const {127return basic_type() != T_ILLEGAL;128}129// Debugging output130void print();131};132133#endif // SHARE_CI_CICONSTANT_HPP134135136