1 /*
2 * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // The following two classes are used to represent 'sizes' and 'offsets' in the VM;
26 // they serve as 'unit' types. ByteSize is used for sizes measured in bytes, while
27 // WordSize is used for sizes measured in machine words (i.e., 32bit or 64bit words
28 // depending on platform).
29 //
30 // The classes are defined with friend functions operating on them instead of member
31 // functions so that they (the classes) can be re-#define'd to int types in optimized
32 // mode. This allows full type checking and maximum safety in debug mode, and full
33 // optimizations (constant folding) and zero overhead (time and space wise) in the
34 // optimized build (some compilers do not optimize one-element value classes but
35 // instead create an object in memory - thus the overhead may be significant).
36 //
37 // Note: 1) DO NOT add new overloaded friend functions that do not have a unique function
38 // function name but require signature types for resolution. This will not work
39 // in optimized mode as both, ByteSize and WordSize are mapped to the same type
40 // and thus the distinction would not be possible anymore (=> compiler errors).
41 //
42 // 2) DO NOT add non-static member functions as they cannot be mapped so something
43 // compilable in the optimized build. Static member functions could be added
44 // but require a corresponding class definition in the optimized build.
125 // be the case in optimized mode to ensure zero overhead for these types.
126 //
127 // Note: If a compiler does not inline these function calls away, one may
128 // want to use #define's to make sure full optimization (constant
129 // folding in particular) is possible.
130
131 typedef int ByteSize;
132 inline ByteSize in_ByteSize(int size) { return size; }
133 inline int in_bytes (ByteSize x) { return x; }
134
135 typedef int WordSize;
136 inline WordSize in_WordSize(int size) { return size; }
137 inline int in_words (WordSize x) { return x; }
138
139 #endif // ASSERT
140
141
142 // Use the following #define to get C++ field member offsets
143
144 #define byte_offset_of(klass,field) in_ByteSize((int)offset_of(klass, field))
|
1 /*
2 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_UTILITIES_SIZES_HPP
26 #define SHARE_VM_UTILITIES_SIZES_HPP
27
28 #include "memory/allocation.hpp"
29 #include "utilities/globalDefinitions.hpp"
30
31 // The following two classes are used to represent 'sizes' and 'offsets' in the VM;
32 // they serve as 'unit' types. ByteSize is used for sizes measured in bytes, while
33 // WordSize is used for sizes measured in machine words (i.e., 32bit or 64bit words
34 // depending on platform).
35 //
36 // The classes are defined with friend functions operating on them instead of member
37 // functions so that they (the classes) can be re-#define'd to int types in optimized
38 // mode. This allows full type checking and maximum safety in debug mode, and full
39 // optimizations (constant folding) and zero overhead (time and space wise) in the
40 // optimized build (some compilers do not optimize one-element value classes but
41 // instead create an object in memory - thus the overhead may be significant).
42 //
43 // Note: 1) DO NOT add new overloaded friend functions that do not have a unique function
44 // function name but require signature types for resolution. This will not work
45 // in optimized mode as both, ByteSize and WordSize are mapped to the same type
46 // and thus the distinction would not be possible anymore (=> compiler errors).
47 //
48 // 2) DO NOT add non-static member functions as they cannot be mapped so something
49 // compilable in the optimized build. Static member functions could be added
50 // but require a corresponding class definition in the optimized build.
131 // be the case in optimized mode to ensure zero overhead for these types.
132 //
133 // Note: If a compiler does not inline these function calls away, one may
134 // want to use #define's to make sure full optimization (constant
135 // folding in particular) is possible.
136
137 typedef int ByteSize;
138 inline ByteSize in_ByteSize(int size) { return size; }
139 inline int in_bytes (ByteSize x) { return x; }
140
141 typedef int WordSize;
142 inline WordSize in_WordSize(int size) { return size; }
143 inline int in_words (WordSize x) { return x; }
144
145 #endif // ASSERT
146
147
148 // Use the following #define to get C++ field member offsets
149
150 #define byte_offset_of(klass,field) in_ByteSize((int)offset_of(klass, field))
151
152 #endif // SHARE_VM_UTILITIES_SIZES_HPP
|