src/hotspot/share/utilities/fakeRttiSupport.hpp
author mr
Tue, 29 Oct 2019 13:52:04 -0700
changeset 58850 f4290bf1cc21
parent 53244 9807daeb47c4
permissions -rw-r--r--
8233137: runtime/ErrorHandling/VeryEarlyAssertTest.java fails after 8232080 Reviewed-by: stuefe, iignatyev, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29325
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49364
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
29325
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
     4
 *
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
     8
 *
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    13
 * accompanied this code).
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    14
 *
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    18
 *
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    21
 * questions.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    22
 *
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    23
 */
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49364
diff changeset
    25
#ifndef SHARE_UTILITIES_FAKERTTISUPPORT_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49364
diff changeset
    26
#define SHARE_UTILITIES_FAKERTTISUPPORT_HPP
29325
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    27
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    28
#include "utilities/globalDefinitions.hpp"
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    29
#include "utilities/debug.hpp"
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    30
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    31
// Provides support for checked downcasts in a hierarchy of classes.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    32
// The base class provides a member of this type, specialized on that
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    33
// base class and an associated tag type.  Tags are small non-negative
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    34
// integer values uniquely associated with distinct classes in the
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    35
// hierarchy.  A tag type is often an enum type.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    36
//
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    37
// The concrete class specifies the concrete tag.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    38
//
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    39
// The tag set specifies the set of classes in the derivation
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    40
// sequence.  Classes in the derivation sequence add their associated
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    41
// tag during construction.  Given the tag associated with a class, an
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    42
// object is an instance of that class if the tag is included in the
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    43
// object's set of recorded tags.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    44
//
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    45
// A tag T is present in a tag set if the T'th bit of the tag set is
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    46
// one.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    47
//
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    48
// Note: The representation of a tag set being uintx sets an upper
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    49
// bound on the size of a class hierarchy this utility can be used
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    50
// with.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    51
template<typename T, typename TagType>
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47216
diff changeset
    52
class FakeRttiSupport {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 31033
diff changeset
    53
  friend class VMStructs;
29325
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    54
public:
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    55
  // Construct with the indicated concrete tag, and include the
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    56
  // concrete tag in the associated tag set.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    57
  explicit FakeRttiSupport(TagType concrete_tag) :
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    58
    _tag_set(tag_bit(concrete_tag)), _concrete_tag(concrete_tag) { }
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    59
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    60
  // Construct with the indicated concrete tag and tag set.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    61
  // Note: This constructor is public only to allow clients to set up
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    62
  // "unusual" (or perhaps buggy) fake RTTI configurations.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    63
  FakeRttiSupport(TagType concrete_tag, uintx tag_set) :
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    64
    _tag_set(tag_set), _concrete_tag(validate_tag(concrete_tag)) { }
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    65
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    66
  // Get the concrete tag.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    67
  TagType concrete_tag() const { return _concrete_tag; }
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    68
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    69
  // Test whether tag is in the tag set.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    70
  bool has_tag(TagType tag) const {
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    71
    return (_tag_set & tag_bit(tag)) != 0;
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    72
  }
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    73
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    74
  // Return a new support object which is the same as this, except tag
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    75
  // has been added to the tag set.  The tag must not already be
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    76
  // present in the tag set.
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    77
  FakeRttiSupport add_tag(TagType tag) const {
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    78
    uintx tbit = tag_bit(tag);
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    79
    assert((_tag_set & tbit) == 0,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31033
diff changeset
    80
           "Tag " UINTX_FORMAT " is already present in tag set: " UINTX_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31033
diff changeset
    81
           (uintx)tag, _tag_set);
29325
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    82
    return FakeRttiSupport(_concrete_tag, _tag_set | tbit);
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    83
  }
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    84
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    85
private:
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    86
  uintx _tag_set;
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    87
  TagType _concrete_tag;
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    88
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    89
  static uintx tag_bit(TagType tag) {
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    90
    return ((uintx)1) << validate_tag(tag);
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    91
  }
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    92
31033
5b6d0c94767a 8079093: Remove FakeRttiSupport workaround for gcc -Wtype-limits
kbarrett
parents: 29325
diff changeset
    93
  static TagType validate_tag(TagType tag) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31033
diff changeset
    94
    assert(0 <= tag, "Tag " INTX_FORMAT " is negative", (intx)tag);
31033
5b6d0c94767a 8079093: Remove FakeRttiSupport workaround for gcc -Wtype-limits
kbarrett
parents: 29325
diff changeset
    95
    assert(tag < BitsPerWord,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31033
diff changeset
    96
           "Tag " UINTX_FORMAT " is too large", (uintx)tag);
31033
5b6d0c94767a 8079093: Remove FakeRttiSupport workaround for gcc -Wtype-limits
kbarrett
parents: 29325
diff changeset
    97
    return tag;
29325
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    98
  }
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
    99
};
0e86e64c66e5 8069016: Add BarrierSet downcast support
kbarrett
parents:
diff changeset
   100
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49364
diff changeset
   101
#endif // SHARE_UTILITIES_FAKERTTISUPPORT_HPP