src/share/vm/utilities/sizes.hpp

Tue, 05 Apr 2011 14:12:31 -0700

author
trims
date
Tue, 05 Apr 2011 14:12:31 -0700
changeset 2708
1d1603768966
parent 2314
f95d63e2154a
child 6876
710a3c8b516e
permissions
-rw-r--r--

7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
Summary: Update the copyright to be 2010 on all changed files in OpenJDK
Reviewed-by: ohair

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_UTILITIES_SIZES_HPP
stefank@2314 26 #define SHARE_VM_UTILITIES_SIZES_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.hpp"
stefank@2314 29 #include "utilities/globalDefinitions.hpp"
stefank@2314 30
duke@435 31 // The following two classes are used to represent 'sizes' and 'offsets' in the VM;
duke@435 32 // they serve as 'unit' types. ByteSize is used for sizes measured in bytes, while
duke@435 33 // WordSize is used for sizes measured in machine words (i.e., 32bit or 64bit words
duke@435 34 // depending on platform).
duke@435 35 //
duke@435 36 // The classes are defined with friend functions operating on them instead of member
duke@435 37 // functions so that they (the classes) can be re-#define'd to int types in optimized
duke@435 38 // mode. This allows full type checking and maximum safety in debug mode, and full
duke@435 39 // optimizations (constant folding) and zero overhead (time and space wise) in the
duke@435 40 // optimized build (some compilers do not optimize one-element value classes but
duke@435 41 // instead create an object in memory - thus the overhead may be significant).
duke@435 42 //
duke@435 43 // Note: 1) DO NOT add new overloaded friend functions that do not have a unique function
duke@435 44 // function name but require signature types for resolution. This will not work
duke@435 45 // in optimized mode as both, ByteSize and WordSize are mapped to the same type
duke@435 46 // and thus the distinction would not be possible anymore (=> compiler errors).
duke@435 47 //
duke@435 48 // 2) DO NOT add non-static member functions as they cannot be mapped so something
duke@435 49 // compilable in the optimized build. Static member functions could be added
duke@435 50 // but require a corresponding class definition in the optimized build.
duke@435 51 //
duke@435 52 // These classes should help doing a transition from (currently) word-size based offsets
duke@435 53 // to byte-size based offsets in the VM (this will be important if we desire to pack
duke@435 54 // objects more densely in the VM for 64bit machines). Such a transition should proceed
duke@435 55 // in two steps to minimize the risk of introducing hard-to-find bugs:
duke@435 56 //
duke@435 57 // a) first transition the whole VM into a form where all sizes are strongly typed
duke@435 58 // b) change all WordSize's to ByteSize's where desired and fix the compilation errors
duke@435 59
duke@435 60
duke@435 61 #ifdef ASSERT
duke@435 62
duke@435 63 class ByteSize VALUE_OBJ_CLASS_SPEC {
duke@435 64 private:
duke@435 65 int _size;
duke@435 66
duke@435 67 // Note: This constructor must be private to avoid implicit conversions!
duke@435 68 ByteSize(int size) { _size = size; }
duke@435 69
duke@435 70 public:
duke@435 71 // constructors
duke@435 72 inline friend ByteSize in_ByteSize(int size);
duke@435 73
duke@435 74 // accessors
duke@435 75 inline friend int in_bytes(ByteSize x);
duke@435 76
duke@435 77 // operators
duke@435 78 friend ByteSize operator + (ByteSize x, ByteSize y) { return ByteSize(in_bytes(x) + in_bytes(y)); }
duke@435 79 friend ByteSize operator - (ByteSize x, ByteSize y) { return ByteSize(in_bytes(x) - in_bytes(y)); }
duke@435 80 friend ByteSize operator * (ByteSize x, int y) { return ByteSize(in_bytes(x) * y ); }
duke@435 81
duke@435 82 // comparison
duke@435 83 friend bool operator == (ByteSize x, ByteSize y) { return in_bytes(x) == in_bytes(y); }
duke@435 84 friend bool operator != (ByteSize x, ByteSize y) { return in_bytes(x) != in_bytes(y); }
duke@435 85 friend bool operator < (ByteSize x, ByteSize y) { return in_bytes(x) < in_bytes(y); }
duke@435 86 friend bool operator <= (ByteSize x, ByteSize y) { return in_bytes(x) <= in_bytes(y); }
duke@435 87 friend bool operator > (ByteSize x, ByteSize y) { return in_bytes(x) > in_bytes(y); }
duke@435 88 friend bool operator >= (ByteSize x, ByteSize y) { return in_bytes(x) >= in_bytes(y); }
duke@435 89 };
duke@435 90
duke@435 91 inline ByteSize in_ByteSize(int size) { return ByteSize(size); }
duke@435 92 inline int in_bytes(ByteSize x) { return x._size; }
duke@435 93
duke@435 94
duke@435 95 class WordSize VALUE_OBJ_CLASS_SPEC {
duke@435 96 private:
duke@435 97 int _size;
duke@435 98
duke@435 99 // Note: This constructor must be private to avoid implicit conversions!
duke@435 100 WordSize(int size) { _size = size; }
duke@435 101
duke@435 102 public:
duke@435 103 // constructors
duke@435 104 inline friend WordSize in_WordSize(int size);
duke@435 105
duke@435 106 // accessors
duke@435 107 inline friend int in_words(WordSize x);
duke@435 108
duke@435 109 // operators
duke@435 110 friend WordSize operator + (WordSize x, WordSize y) { return WordSize(in_words(x) + in_words(y)); }
duke@435 111 friend WordSize operator - (WordSize x, WordSize y) { return WordSize(in_words(x) - in_words(y)); }
duke@435 112 friend WordSize operator * (WordSize x, int y) { return WordSize(in_words(x) * y ); }
duke@435 113
duke@435 114 // comparison
duke@435 115 friend bool operator == (WordSize x, WordSize y) { return in_words(x) == in_words(y); }
duke@435 116 friend bool operator != (WordSize x, WordSize y) { return in_words(x) != in_words(y); }
duke@435 117 friend bool operator < (WordSize x, WordSize y) { return in_words(x) < in_words(y); }
duke@435 118 friend bool operator <= (WordSize x, WordSize y) { return in_words(x) <= in_words(y); }
duke@435 119 friend bool operator > (WordSize x, WordSize y) { return in_words(x) > in_words(y); }
duke@435 120 friend bool operator >= (WordSize x, WordSize y) { return in_words(x) >= in_words(y); }
duke@435 121 };
duke@435 122
duke@435 123 inline WordSize in_WordSize(int size) { return WordSize(size); }
duke@435 124 inline int in_words(WordSize x) { return x._size; }
duke@435 125
duke@435 126
duke@435 127 #else // ASSERT
duke@435 128
duke@435 129 // The following definitions must match the corresponding friend declarations
duke@435 130 // in the Byte/WordSize classes if they are typedef'ed to be int. This will
duke@435 131 // be the case in optimized mode to ensure zero overhead for these types.
duke@435 132 //
duke@435 133 // Note: If a compiler does not inline these function calls away, one may
duke@435 134 // want to use #define's to make sure full optimization (constant
duke@435 135 // folding in particular) is possible.
duke@435 136
duke@435 137 typedef int ByteSize;
duke@435 138 inline ByteSize in_ByteSize(int size) { return size; }
duke@435 139 inline int in_bytes (ByteSize x) { return x; }
duke@435 140
duke@435 141 typedef int WordSize;
duke@435 142 inline WordSize in_WordSize(int size) { return size; }
duke@435 143 inline int in_words (WordSize x) { return x; }
duke@435 144
duke@435 145 #endif // ASSERT
duke@435 146
duke@435 147
duke@435 148 // Use the following #define to get C++ field member offsets
duke@435 149
duke@435 150 #define byte_offset_of(klass,field) in_ByteSize((int)offset_of(klass, field))
stefank@2314 151
stefank@2314 152 #endif // SHARE_VM_UTILITIES_SIZES_HPP

mercurial