src/hotspot/share/classfile/verificationType.hpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 53244 9807daeb47c4
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain 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: 52067
diff changeset
     2
 * Copyright (c) 2003, 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: 52067
diff changeset
    25
#ifndef SHARE_CLASSFILE_VERIFICATIONTYPE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52067
diff changeset
    26
#define SHARE_CLASSFILE_VERIFICATIONTYPE_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 "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "oops/instanceKlass.hpp"
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 27680
diff changeset
    30
#include "oops/oop.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    31
#include "oops/symbol.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "runtime/handles.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/signature.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // As specifed in the JVM spec
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  ITEM_Top = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  ITEM_Integer = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  ITEM_Float = 2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  ITEM_Double = 3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  ITEM_Long = 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  ITEM_Null = 5,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  ITEM_UninitializedThis = 6,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  ITEM_Object = 7,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  ITEM_Uninitialized = 8,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  ITEM_Bogus = (uint)-1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    49
class ClassVerifier;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    50
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47216
diff changeset
    51
class VerificationType {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    // Least significant bits of _handle are always 0, so we use these as
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    // the indicator that the _handle is valid.  Otherwise, the _data field
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    // contains encoded data (as specified below).  Should the VM change
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    // and the lower bits on oops aren't 0, the assert in the constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    // will catch this and we'll have to add a descriminator tag to this
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    // structure.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    union {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    60
      Symbol*   _sym;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      uintptr_t _data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    } _u;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      // These rest are not found in classfiles, but used by the verifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      ITEM_Boolean = 9, ITEM_Byte, ITEM_Short, ITEM_Char,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      ITEM_Long_2nd, ITEM_Double_2nd
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    // Enum for the _data field
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      // Bottom two bits determine if the type is a reference, primitive,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      // uninitialized or a query-type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
      TypeMask           = 0x00000003,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      // Topmost types encoding
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    77
      Reference          = 0x0,        // _sym contains the name
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
      Primitive          = 0x1,        // see below for primitive list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
      Uninitialized      = 0x2,        // 0x00ffff00 contains bci
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
      TypeQuery          = 0x3,        // Meta-types used for category testing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      // Utility flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      ReferenceFlag      = 0x00,       // For reference query types
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
      Category1Flag      = 0x01,       // One-word values
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      Category2Flag      = 0x02,       // First word of a two-word value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      Category2_2ndFlag  = 0x04,       // Second word of a two-word value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      // special reference values
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    89
      Null               = 0x00000000, // A reference with a 0 sym is null
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      // Primitives categories (the second byte determines the category)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      Category1          = (Category1Flag     << 1 * BitsPerByte) | Primitive,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      Category2          = (Category2Flag     << 1 * BitsPerByte) | Primitive,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      Category2_2nd      = (Category2_2ndFlag << 1 * BitsPerByte) | Primitive,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      // Primitive values (type descriminator stored in most-signifcant bytes)
41093
b7bbdd06976e 8149607: [Verifier] Do not verify pop, pop2, swap, dup* against top
hseigel
parents: 39713
diff changeset
    97
      // Bogus needs the " | Primitive".  Else, is_reference(Bogus) returns TRUE.
b7bbdd06976e 8149607: [Verifier] Do not verify pop, pop2, swap, dup* against top
hseigel
parents: 39713
diff changeset
    98
      Bogus              = (ITEM_Bogus      << 2 * BitsPerByte) | Primitive,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      Boolean            = (ITEM_Boolean    << 2 * BitsPerByte) | Category1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      Byte               = (ITEM_Byte       << 2 * BitsPerByte) | Category1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      Short              = (ITEM_Short      << 2 * BitsPerByte) | Category1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      Char               = (ITEM_Char       << 2 * BitsPerByte) | Category1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      Integer            = (ITEM_Integer    << 2 * BitsPerByte) | Category1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      Float              = (ITEM_Float      << 2 * BitsPerByte) | Category1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      Long               = (ITEM_Long       << 2 * BitsPerByte) | Category2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      Double             = (ITEM_Double     << 2 * BitsPerByte) | Category2,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      Long_2nd           = (ITEM_Long_2nd   << 2 * BitsPerByte) | Category2_2nd,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      Double_2nd         = (ITEM_Double_2nd << 2 * BitsPerByte) | Category2_2nd,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      // Used by Uninitialized (second and third bytes hold the bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      BciMask            = 0xffff << 1 * BitsPerByte,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      BciForThis         = ((u2)-1),   // A bci of -1 is an Unintialized-This
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      // Query values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      ReferenceQuery     = (ReferenceFlag     << 1 * BitsPerByte) | TypeQuery,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      Category1Query     = (Category1Flag     << 1 * BitsPerByte) | TypeQuery,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      Category2Query     = (Category2Flag     << 1 * BitsPerByte) | TypeQuery,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      Category2_2ndQuery = (Category2_2ndFlag << 1 * BitsPerByte) | TypeQuery
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  VerificationType(uintptr_t raw_data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    _u._data = raw_data;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  VerificationType() { *this = bogus_type(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // Create verification types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  static VerificationType bogus_type() { return VerificationType(Bogus); }
8477
e6f1e62b9e23 7020118: Alter frame assignability to allow for exception handler coverage of invokespecial <init>
kamg
parents: 8076
diff changeset
   131
  static VerificationType top_type() { return bogus_type(); } // alias
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  static VerificationType null_type() { return VerificationType(Null); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  static VerificationType integer_type() { return VerificationType(Integer); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  static VerificationType float_type() { return VerificationType(Float); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  static VerificationType long_type() { return VerificationType(Long); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  static VerificationType long2_type() { return VerificationType(Long_2nd); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  static VerificationType double_type() { return VerificationType(Double); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  static VerificationType boolean_type() { return VerificationType(Boolean); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static VerificationType byte_type() { return VerificationType(Byte); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  static VerificationType char_type() { return VerificationType(Char); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  static VerificationType short_type() { return VerificationType(Short); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  static VerificationType double2_type()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    { return VerificationType(Double_2nd); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // "check" types are used for queries.  A "check" type is not assignable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // to anything, but the specified types are assignable to a "check".  For
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // example, any category1 primitive is assignable to category1_check and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // any reference is assignable to reference_check.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  static VerificationType reference_check()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    { return VerificationType(ReferenceQuery); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  static VerificationType category1_check()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    { return VerificationType(Category1Query); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static VerificationType category2_check()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    { return VerificationType(Category2Query); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  static VerificationType category2_2nd_check()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    { return VerificationType(Category2_2ndQuery); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   158
  // For reference types, store the actual Symbol
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   159
  static VerificationType reference_type(Symbol* sh) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   160
      assert(((uintptr_t)sh & 0x3) == 0, "Symbols must be aligned");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      // If the above assert fails in the future because oop* isn't aligned,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      // then this type encoding system will have to change to have a tag value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      // to descriminate between oops and primitives.
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   164
      return VerificationType((uintptr_t)sh);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  static VerificationType uninitialized_type(u2 bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    { return VerificationType(bci << 1 * BitsPerByte | Uninitialized); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  static VerificationType uninitialized_this_type()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    { return uninitialized_type(BciForThis); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // Create based on u1 read from classfile
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  static VerificationType from_tag(u1 tag);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  bool is_bogus() const     { return (_u._data == Bogus); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  bool is_null() const      { return (_u._data == Null); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  bool is_boolean() const   { return (_u._data == Boolean); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  bool is_byte() const      { return (_u._data == Byte); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  bool is_char() const      { return (_u._data == Char); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  bool is_short() const     { return (_u._data == Short); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  bool is_integer() const   { return (_u._data == Integer); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  bool is_long() const      { return (_u._data == Long); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  bool is_float() const     { return (_u._data == Float); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  bool is_double() const    { return (_u._data == Double); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  bool is_long2() const     { return (_u._data == Long_2nd); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  bool is_double2() const   { return (_u._data == Double_2nd); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  bool is_reference() const { return ((_u._data & TypeMask) == Reference); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  bool is_category1() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    // This should return true for all one-word types, which are category1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    // primitives, and references (including uninitialized refs).  Though
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    // the 'query' types should technically return 'false' here, if we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    // allow this to return true, we can perform the test using only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    // 2 operations rather than 8 (3 masks, 3 compares and 2 logical 'ands').
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    // Since noone should call this on a query type anyway, this is ok.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    assert(!is_check(), "Must not be a check type (wrong value returned)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    return ((_u._data & Category1) != Primitive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    // should only return false if it's a primitive, and the category1 flag
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    // is not set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  bool is_category2() const { return ((_u._data & Category2) == Category2); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  bool is_category2_2nd() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    return ((_u._data & Category2_2nd) == Category2_2nd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  bool is_reference_check() const { return _u._data == ReferenceQuery; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  bool is_category1_check() const { return _u._data == Category1Query; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  bool is_category2_check() const { return _u._data == Category2Query; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  bool is_category2_2nd_check() const { return _u._data == Category2_2ndQuery; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  bool is_check() const { return (_u._data & TypeQuery) == TypeQuery; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  bool is_x_array(char sig) const {
51997
9ce37fa2e179 8209138: Symbol constructor uses u1 as the element type of its name argument
hseigel
parents: 49621
diff changeset
   210
    return is_null() || (is_array() && (name()->char_at(1) == sig));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   212
  bool is_int_array() const { return is_x_array(JVM_SIGNATURE_INT); }
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   213
  bool is_byte_array() const { return is_x_array(JVM_SIGNATURE_BYTE); }
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   214
  bool is_bool_array() const { return is_x_array(JVM_SIGNATURE_BOOLEAN); }
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   215
  bool is_char_array() const { return is_x_array(JVM_SIGNATURE_CHAR); }
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   216
  bool is_short_array() const { return is_x_array(JVM_SIGNATURE_SHORT); }
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   217
  bool is_long_array() const { return is_x_array(JVM_SIGNATURE_LONG); }
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   218
  bool is_float_array() const { return is_x_array(JVM_SIGNATURE_FLOAT); }
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   219
  bool is_double_array() const { return is_x_array(JVM_SIGNATURE_DOUBLE); }
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   220
  bool is_object_array() const { return is_x_array(JVM_SIGNATURE_CLASS); }
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   221
  bool is_array_array() const { return is_x_array(JVM_SIGNATURE_ARRAY); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  bool is_reference_array() const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    { return is_object_array() || is_array_array(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  bool is_object() const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    { return (is_reference() && !is_null() && name()->utf8_length() >= 1 &&
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   226
              name()->char_at(0) != JVM_SIGNATURE_ARRAY); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  bool is_array() const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    { return (is_reference() && !is_null() && name()->utf8_length() >= 2 &&
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   229
              name()->char_at(0) == JVM_SIGNATURE_ARRAY); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  bool is_uninitialized() const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    { return ((_u._data & Uninitialized) == Uninitialized); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  bool is_uninitialized_this() const
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    { return is_uninitialized() && bci() == BciForThis; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  VerificationType to_category2_2nd() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    assert(is_category2(), "Must be a double word");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    return VerificationType(is_long() ? Long_2nd : Double_2nd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  u2 bci() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    assert(is_uninitialized(), "Must be uninitialized type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    return ((_u._data & BciMask) >> 1 * BitsPerByte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   245
  Symbol* name() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    assert(is_reference() && !is_null(), "Must be a non-null reference");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   247
    return _u._sym;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  bool equals(const VerificationType& t) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    return (_u._data == t._u._data ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      (is_reference() && t.is_reference() && !is_null() && !t.is_null() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
       name() == t.name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  bool operator ==(const VerificationType& t) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    return equals(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  bool operator !=(const VerificationType& t) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    return !equals(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // The whole point of this type system - check to see if one type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // is assignable to another.  Returns true if one can assign 'from' to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  // this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  bool is_assignable_from(
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 23998
diff changeset
   268
      const VerificationType& from, ClassVerifier* context,
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 23998
diff changeset
   269
      bool from_field_is_protected, TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    if (equals(from) || is_bogus()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      switch(_u._data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
        case Category1Query:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
          return from.is_category1();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
        case Category2Query:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
          return from.is_category2();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
        case Category2_2ndQuery:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
          return from.is_category2_2nd();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
        case ReferenceQuery:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
          return from.is_reference() || from.is_uninitialized();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
        case Boolean:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
        case Byte:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
        case Char:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        case Short:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
          // An int can be assigned to boolean, byte, char or short values.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
          return from.is_integer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
        default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
          if (is_reference() && from.is_reference()) {
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 23998
diff changeset
   290
            return is_reference_assignable_from(from, context,
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 23998
diff changeset
   291
                                                from_field_is_protected,
27680
8ecc0871c18e 8064811: Use THREAD instead of CHECK_NULL in return statements
stefank
parents: 27022
diff changeset
   292
                                                THREAD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
            return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
31966
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   300
  // Check to see if one array component type is assignable to another.
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   301
  // Same as is_assignable_from() except int primitives must be identical.
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   302
  bool is_component_assignable_from(
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   303
      const VerificationType& from, ClassVerifier* context,
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   304
      bool from_field_is_protected, TRAPS) const {
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   305
    if (equals(from) || is_bogus()) {
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   306
      return true;
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   307
    } else {
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   308
      switch(_u._data) {
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   309
        case Boolean:
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   310
        case Byte:
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   311
        case Char:
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   312
        case Short:
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   313
          return false;
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   314
        default:
52067
2e72562697bf 8211394: CHECK_ must be used in the rhs of an assignment statement within a block
dholmes
parents: 51997
diff changeset
   315
          return is_assignable_from(from, context, from_field_is_protected, THREAD);
31966
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   316
      }
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   317
    }
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   318
  }
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 29081
diff changeset
   319
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   320
  VerificationType get_component(ClassVerifier* context, TRAPS) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  int dimensions() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    assert(is_array(), "Must be an array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    int index = 0;
58722
cba8afa5cfed 8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently
lfoltan
parents: 53244
diff changeset
   325
    while (name()->char_at(index) == JVM_SIGNATURE_ARRAY) index++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    return index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   329
  void print_on(outputStream* st) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  bool is_reference_assignable_from(
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 23998
diff changeset
   334
    const VerificationType&, ClassVerifier*, bool from_field_is_protected,
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 23998
diff changeset
   335
    TRAPS) const;
39713
29ece76096cb 8150752: Share Class Data
iklam
parents: 31966
diff changeset
   336
29ece76096cb 8150752: Share Class Data
iklam
parents: 31966
diff changeset
   337
 public:
46329
53ccc37bda19 8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents: 41093
diff changeset
   338
  static bool resolve_and_check_assignability(InstanceKlass* klass, Symbol* name,
39713
29ece76096cb 8150752: Share Class Data
iklam
parents: 31966
diff changeset
   339
                                              Symbol* from_name, bool from_field_is_protected,
29ece76096cb 8150752: Share Class Data
iklam
parents: 31966
diff changeset
   340
                                              bool from_is_array, bool from_is_object,
29ece76096cb 8150752: Share Class Data
iklam
parents: 31966
diff changeset
   341
                                              TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   343
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52067
diff changeset
   344
#endif // SHARE_CLASSFILE_VERIFICATIONTYPE_HPP