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