hotspot/src/share/vm/utilities/sizes.hpp
author dcubed
Wed, 12 Mar 2008 18:07:46 -0700
changeset 221 ec745a0fe922
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure Summary: Add should_not_be_cached() to markOop and methodOop and query that status inOopMapCache::lookup() Reviewed-by: coleenp, sspitsyn, jmasa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2004 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// The following two classes are used to represent 'sizes' and 'offsets' in the VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// they serve as 'unit' types. ByteSize is used for sizes measured in bytes, while
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// WordSize is used for sizes measured in machine words (i.e., 32bit or 64bit words
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// depending on platform).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// The classes are defined with friend functions operating on them instead of member
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// functions so that they (the classes) can be re-#define'd to int types in optimized
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// mode. This allows full type checking and maximum safety in debug mode, and full
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// optimizations (constant folding) and zero overhead (time and space wise) in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// optimized build (some compilers do not optimize one-element value classes but
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// instead create an object in memory - thus the overhead may be significant).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Note: 1) DO NOT add new overloaded friend functions that do not have a unique function
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//          function name but require signature types for resolution. This will not work
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//          in optimized mode as both, ByteSize and WordSize are mapped to the same type
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//          and thus the distinction would not be possible anymore (=> compiler errors).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//       2) DO NOT add non-static member functions as they cannot be mapped so something
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//          compilable in the optimized build. Static member functions could be added
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//          but require a corresponding class definition in the optimized build.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// These classes should help doing a transition from (currently) word-size based offsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// to byte-size based offsets in the VM (this will be important if we desire to pack
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// objects more densely in the VM for 64bit machines). Such a transition should proceed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// in two steps to minimize the risk of introducing hard-to-find bugs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// a) first transition the whole VM into a form where all sizes are strongly typed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// b) change all WordSize's to ByteSize's where desired and fix the compilation errors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
class ByteSize VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  int _size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // Note: This constructor must be private to avoid implicit conversions!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  ByteSize(int size)                                  { _size = size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // constructors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  inline friend ByteSize in_ByteSize(int size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  inline friend int in_bytes(ByteSize x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // operators
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  friend ByteSize operator + (ByteSize x, ByteSize y) { return ByteSize(in_bytes(x) + in_bytes(y)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  friend ByteSize operator - (ByteSize x, ByteSize y) { return ByteSize(in_bytes(x) - in_bytes(y)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  friend ByteSize operator * (ByteSize x, int      y) { return ByteSize(in_bytes(x) * y          ); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  friend bool operator == (ByteSize x, ByteSize y)    { return in_bytes(x) == in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  friend bool operator != (ByteSize x, ByteSize y)    { return in_bytes(x) != in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  friend bool operator <  (ByteSize x, ByteSize y)    { return in_bytes(x) <  in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  friend bool operator <= (ByteSize x, ByteSize y)    { return in_bytes(x) <= in_bytes(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  friend bool operator >  (ByteSize x, ByteSize y)    { return in_bytes(x) >  in_bytes(y); }
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
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
inline ByteSize in_ByteSize(int size) { return ByteSize(size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
inline int      in_bytes(ByteSize x)  { return x._size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
class WordSize VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  int _size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Note: This constructor must be private to avoid implicit conversions!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  WordSize(int size)                                  { _size = size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // constructors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  inline friend WordSize in_WordSize(int size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  inline friend int in_words(WordSize x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // operators
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  friend WordSize operator + (WordSize x, WordSize y) { return WordSize(in_words(x) + in_words(y)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  friend WordSize operator - (WordSize x, WordSize y) { return WordSize(in_words(x) - in_words(y)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  friend WordSize operator * (WordSize x, int      y) { return WordSize(in_words(x) * y          ); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  friend bool operator == (WordSize x, WordSize y)    { return in_words(x) == in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  friend bool operator != (WordSize x, WordSize y)    { return in_words(x) != in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  friend bool operator <  (WordSize x, WordSize y)    { return in_words(x) <  in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  friend bool operator <= (WordSize x, WordSize y)    { return in_words(x) <= in_words(y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  friend bool operator >  (WordSize x, WordSize y)    { return in_words(x) >  in_words(y); }
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
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
inline WordSize in_WordSize(int size) { return WordSize(size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
inline int      in_words(WordSize x)  { return x._size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
#else // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// The following definitions must match the corresponding friend declarations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// in the Byte/WordSize classes if they are typedef'ed to be int. This will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// be the case in optimized mode to ensure zero overhead for these types.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// Note: If a compiler does not inline these function calls away, one may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
//       want to use #define's to make sure full optimization (constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
//       folding in particular) is possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
typedef int ByteSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
inline ByteSize in_ByteSize(int size)                 { return size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
inline int      in_bytes   (ByteSize x)               { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
typedef int WordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
inline WordSize in_WordSize(int size)                 { return size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
inline int      in_words   (WordSize x)               { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
// Use the following #define to get C++ field member offsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#define byte_offset_of(klass,field)   in_ByteSize((int)offset_of(klass, field))