src/hotspot/share/utilities/sizes.hpp
author coleenp
Tue, 27 Mar 2018 11:53:23 -0400
changeset 49621 5ef28d560b6f
parent 49364 601146c66cad
child 53244 9807daeb47c4
permissions -rw-r--r--
8200276: Cleanup allocation.hpp includes Reviewed-by: stefank, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2018, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_UTILITIES_SIZES_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_UTILITIES_SIZES_HPP
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 "utilities/globalDefinitions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// The following two classes are used to represent 'sizes' and 'offsets' in the VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// they serve as 'unit' types. ByteSize is used for sizes measured in bytes, while
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// WordSize is used for sizes measured in machine words (i.e., 32bit or 64bit words
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// depending on platform).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// The classes are defined with friend functions operating on them instead of member
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// functions so that they (the classes) can be re-#define'd to int types in optimized
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// mode. This allows full type checking and maximum safety in debug mode, and full
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// optimizations (constant folding) and zero overhead (time and space wise) in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// optimized build (some compilers do not optimize one-element value classes but
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// instead create an object in memory - thus the overhead may be significant).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Note: 1) DO NOT add new overloaded friend functions that do not have a unique function
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//          function name but require signature types for resolution. This will not work
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//          in optimized mode as both, ByteSize and WordSize are mapped to the same type
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//          and thus the distinction would not be possible anymore (=> compiler errors).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//       2) DO NOT add non-static member functions as they cannot be mapped so something
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//          compilable in the optimized build. Static member functions could be added
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//          but require a corresponding class definition in the optimized build.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// These classes should help doing a transition from (currently) word-size based offsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// to byte-size based offsets in the VM (this will be important if we desire to pack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// objects more densely in the VM for 64bit machines). Such a transition should proceed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// in two steps to minimize the risk of introducing hard-to-find bugs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// a) first transition the whole VM into a form where all sizes are strongly typed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// b) change all WordSize's to ByteSize's where desired and fix the compilation errors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47216
diff changeset
    62
class ByteSize {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  int _size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Note: This constructor must be private to avoid implicit conversions!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  ByteSize(int size)                                  { _size = size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // constructors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  inline friend ByteSize in_ByteSize(int size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  inline friend int in_bytes(ByteSize x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // operators
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  friend ByteSize operator + (ByteSize x, ByteSize y) { return ByteSize(in_bytes(x) + in_bytes(y)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  friend ByteSize operator - (ByteSize x, ByteSize y) { return ByteSize(in_bytes(x) - in_bytes(y)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  friend ByteSize operator * (ByteSize x, int      y) { return ByteSize(in_bytes(x) * y          ); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  friend bool operator == (ByteSize x, ByteSize y)    { return in_bytes(x) == in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  friend bool operator != (ByteSize x, ByteSize y)    { return in_bytes(x) != in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  friend bool operator <  (ByteSize x, ByteSize y)    { return in_bytes(x) <  in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  friend bool operator <= (ByteSize x, ByteSize y)    { return in_bytes(x) <= in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  friend bool operator >  (ByteSize x, ByteSize y)    { return in_bytes(x) >  in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  friend bool operator >= (ByteSize x, ByteSize y)    { return in_bytes(x) >= in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
inline ByteSize in_ByteSize(int size) { return ByteSize(size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
inline int      in_bytes(ByteSize x)  { return x._size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47216
diff changeset
    94
class WordSize {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  int _size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // Note: This constructor must be private to avoid implicit conversions!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  WordSize(int size)                                  { _size = size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // constructors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  inline friend WordSize in_WordSize(int size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  inline friend int in_words(WordSize x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // operators
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  friend WordSize operator + (WordSize x, WordSize y) { return WordSize(in_words(x) + in_words(y)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  friend WordSize operator - (WordSize x, WordSize y) { return WordSize(in_words(x) - in_words(y)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  friend WordSize operator * (WordSize x, int      y) { return WordSize(in_words(x) * y          ); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  friend bool operator == (WordSize x, WordSize y)    { return in_words(x) == in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  friend bool operator != (WordSize x, WordSize y)    { return in_words(x) != in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  friend bool operator <  (WordSize x, WordSize y)    { return in_words(x) <  in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  friend bool operator <= (WordSize x, WordSize y)    { return in_words(x) <= in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  friend bool operator >  (WordSize x, WordSize y)    { return in_words(x) >  in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  friend bool operator >= (WordSize x, WordSize y)    { return in_words(x) >= in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
inline WordSize in_WordSize(int size) { return WordSize(size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
inline int      in_words(WordSize x)  { return x._size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
#else // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// The following definitions must match the corresponding friend declarations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// in the Byte/WordSize classes if they are typedef'ed to be int. This will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// be the case in optimized mode to ensure zero overhead for these types.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// Note: If a compiler does not inline these function calls away, one may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
//       want to use #define's to make sure full optimization (constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
//       folding in particular) is possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
typedef int ByteSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
inline ByteSize in_ByteSize(int size)                 { return size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
inline int      in_bytes   (ByteSize x)               { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
typedef int WordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
inline WordSize in_WordSize(int size)                 { return size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
inline int      in_words   (WordSize x)               { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// Use the following #define to get C++ field member offsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
#define byte_offset_of(klass,field)   in_ByteSize((int)offset_of(klass, field))
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   150
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   151
#endif // SHARE_VM_UTILITIES_SIZES_HPP