annotate src/share/vm/utilities/sizes.hpp @ 1972:f95d63e2154a

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