src/hotspot/share/ci/ciConstant.hpp
author lfoltan
Mon, 23 Sep 2019 14:49:04 -0400
changeset 58273 08a5148e7c4e
parent 53244 9807daeb47c4
permissions -rw-r--r--
8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type Summary: Consistently use is_reference_type when comparing type for T_OBJECT or T_ARRAY. Reviewed-by: dlong, coleenp, hseigel Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49373
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49373
diff changeset
    25
#ifndef SHARE_CI_CICONSTANT_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49373
diff changeset
    26
#define SHARE_CI_CICONSTANT_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "ci/ciClassList.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "ci/ciNullObject.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// ciConstant
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// This class represents a constant value.
49373
47b5652f2928 8199283: Remove ValueObj class for allocation subclassing for compiler code
coleenp
parents: 47216
diff changeset
    34
class ciConstant {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 10508
diff changeset
    35
  friend class VMStructs;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  friend class ciEnv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  friend class ciField;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  BasicType _type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  union {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    jint      _int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    jlong     _long;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    jfloat    _float;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    jdouble   _double;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    ciObject* _object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  } _value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  ciConstant() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    _type = T_ILLEGAL; _value._long = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  ciConstant(BasicType type, jint value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    assert(type != T_LONG && type != T_DOUBLE && type != T_FLOAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
           "using the wrong ciConstant constructor");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    _type = type; _value._int = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  ciConstant(jlong value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    _type = T_LONG; _value._long = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  ciConstant(jfloat value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    _type = T_FLOAT; _value._float = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  ciConstant(jdouble value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _type = T_DOUBLE; _value._double = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  ciConstant(BasicType type, ciObject* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    _type = type; _value._object = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  BasicType basic_type() const { return _type; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  jboolean  as_boolean() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    assert(basic_type() == T_BOOLEAN, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    return (jboolean)_value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  jchar     as_char() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    assert(basic_type() == T_CHAR, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    return (jchar)_value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  jbyte     as_byte() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    assert(basic_type() == T_BYTE, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    return (jbyte)_value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  jshort    as_short() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    assert(basic_type() == T_SHORT, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    return (jshort)_value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  jint      as_int() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    assert(basic_type() == T_BOOLEAN || basic_type() == T_CHAR  ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
           basic_type() == T_BYTE    || basic_type() == T_SHORT ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
           basic_type() == T_INT, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    return _value._int;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  jlong     as_long() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    assert(basic_type() == T_LONG, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    return _value._long;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  jfloat    as_float() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    assert(basic_type() == T_FLOAT, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    return _value._float;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  jdouble   as_double() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    assert(basic_type() == T_DOUBLE, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    return _value._double;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  ciObject* as_object() const {
58273
08a5148e7c4e 8230505: Replace JVM type comparisons to T_OBJECT and T_ARRAY with call to is_reference_type
lfoltan
parents: 53244
diff changeset
   109
    assert(is_reference_type(basic_type()), "wrong type");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    return _value._object;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
19770
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   113
  bool      is_null_or_zero() const {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   114
    if (!is_java_primitive(basic_type())) {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   115
      return as_object()->is_null_object();
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   116
    } else if (type2size[basic_type()] == 1) {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   117
      // treat float bits as int, to avoid comparison with -0 and NaN
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   118
      return (_value._int == 0);
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   119
    } else if (type2size[basic_type()] == 2) {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   120
      // treat double bits as long, to avoid comparison with -0 and NaN
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   121
      return (_value._long == 0);
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   122
    } else {
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   123
      return false;
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   124
    }
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   125
  }
7cb9f982ea81 8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents: 10547
diff changeset
   126
38030
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   127
  bool is_valid() const {
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   128
    return basic_type() != T_ILLEGAL;
93f24e7b3c43 8152590: C2: @Stable support doesn't always work w/ incremental inlining
vlivanov
parents: 22234
diff changeset
   129
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Debugging output
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   133
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49373
diff changeset
   134
#endif // SHARE_CI_CICONSTANT_HPP