Mercurial > hg > truffle
annotate src/share/vm/utilities/globalDefinitions.cpp @ 1721:413ad0331a0c
6977924: Changes for 6975078 produce build error with certain gcc versions
Summary: The changes introduced for 6975078 assign badHeapOopVal to the _allocation field in the ResourceObj class. In 32 bit linux builds with certain versions of gcc this assignment will be flagged as an error while compiling allocation.cpp. In 32 bit builds the constant value badHeapOopVal (which is cast to an intptr_t) is negative. The _allocation field is typed as an unsigned intptr_t and gcc catches this as an error.
Reviewed-by: jcoomes, ysr, phh
author | johnc |
---|---|
date | Wed, 18 Aug 2010 10:59:06 -0700 |
parents | e9ff18c4ace7 |
children | f95d63e2154a |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
2 * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
196
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:
196
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_globalDefinitions.cpp.incl" | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
27 // Basic error support |
0 | 28 |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
29 // Info for oops within a java object. Defaults are zero so |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
30 // things will break badly if incorrectly initialized. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
31 int heapOopSize = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
32 int LogBytesPerHeapOop = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
33 int LogBitsPerHeapOop = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
34 int BytesPerHeapOop = 0; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
35 int BitsPerHeapOop = 0; |
0 | 36 |
1571
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
37 // Object alignment, in units of HeapWords. |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
38 // Defaults are -1 so things will break badly if incorrectly initialized. |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
39 int MinObjAlignment = -1; |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
40 int MinObjAlignmentInBytes = -1; |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
41 int MinObjAlignmentInBytesMask = 0; |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
42 |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
43 int LogMinObjAlignment = -1; |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
44 int LogMinObjAlignmentInBytes = -1; |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
45 |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
46 // Oop encoding heap max |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
47 uint64_t OopEncodingHeapMax = 0; |
2d127394260e
6916623: Align object to 16 bytes to use Compressed Oops with java heap up to 64Gb
kvn
parents:
196
diff
changeset
|
48 |
0 | 49 void basic_fatal(const char* msg) { |
50 fatal(msg); | |
51 } | |
52 | |
53 // Something to help porters sleep at night | |
54 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
55 void basic_types_init() { |
0 | 56 #ifdef ASSERT |
57 #ifdef _LP64 | |
58 assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant"); | |
59 assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant"); | |
60 assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant"); | |
61 assert( 8 == sizeof( intx), "wrong size for basic type"); | |
62 assert( 8 == sizeof( jobject), "wrong size for basic type"); | |
63 #else | |
64 assert(min_intx == (intx)0x80000000, "correct constant"); | |
65 assert(max_intx == 0x7FFFFFFF, "correct constant"); | |
66 assert(max_uintx == 0xFFFFFFFF, "correct constant"); | |
67 assert( 4 == sizeof( intx), "wrong size for basic type"); | |
68 assert( 4 == sizeof( jobject), "wrong size for basic type"); | |
69 #endif | |
70 assert( (~max_juint) == 0, "max_juint has all its bits"); | |
71 assert( (~max_uintx) == 0, "max_uintx has all its bits"); | |
72 assert( (~max_julong) == 0, "max_julong has all its bits"); | |
73 assert( 1 == sizeof( jbyte), "wrong size for basic type"); | |
74 assert( 2 == sizeof( jchar), "wrong size for basic type"); | |
75 assert( 2 == sizeof( jshort), "wrong size for basic type"); | |
76 assert( 4 == sizeof( juint), "wrong size for basic type"); | |
77 assert( 4 == sizeof( jint), "wrong size for basic type"); | |
78 assert( 1 == sizeof( jboolean), "wrong size for basic type"); | |
79 assert( 8 == sizeof( jlong), "wrong size for basic type"); | |
80 assert( 4 == sizeof( jfloat), "wrong size for basic type"); | |
81 assert( 8 == sizeof( jdouble), "wrong size for basic type"); | |
82 assert( 1 == sizeof( u1), "wrong size for basic type"); | |
83 assert( 2 == sizeof( u2), "wrong size for basic type"); | |
84 assert( 4 == sizeof( u4), "wrong size for basic type"); | |
85 | |
86 int num_type_chars = 0; | |
87 for (int i = 0; i < 99; i++) { | |
88 if (type2char((BasicType)i) != 0) { | |
89 assert(char2type(type2char((BasicType)i)) == i, "proper inverses"); | |
90 num_type_chars++; | |
91 } | |
92 } | |
93 assert(num_type_chars == 11, "must have tested the right number of mappings"); | |
94 assert(char2type(0) == T_ILLEGAL, "correct illegality"); | |
95 | |
96 { | |
97 for (int i = T_BOOLEAN; i <= T_CONFLICT; i++) { | |
98 BasicType vt = (BasicType)i; | |
99 BasicType ft = type2field[vt]; | |
100 switch (vt) { | |
101 // the following types might plausibly show up in memory layouts: | |
102 case T_BOOLEAN: | |
103 case T_BYTE: | |
104 case T_CHAR: | |
105 case T_SHORT: | |
106 case T_INT: | |
107 case T_FLOAT: | |
108 case T_DOUBLE: | |
109 case T_LONG: | |
110 case T_OBJECT: | |
111 case T_ADDRESS: // random raw pointer | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
112 case T_NARROWOOP: // compressed pointer |
0 | 113 case T_CONFLICT: // might as well support a bottom type |
114 case T_VOID: // padding or other unaddressed word | |
115 // layout type must map to itself | |
116 assert(vt == ft, ""); | |
117 break; | |
118 default: | |
119 // non-layout type must map to a (different) layout type | |
120 assert(vt != ft, ""); | |
121 assert(ft == type2field[ft], ""); | |
122 } | |
123 // every type must map to same-sized layout type: | |
124 assert(type2size[vt] == type2size[ft], ""); | |
125 } | |
126 } | |
127 // These are assumed, e.g., when filling HeapWords with juints. | |
128 assert(is_power_of_2(sizeof(juint)), "juint must be power of 2"); | |
129 assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2"); | |
130 assert((size_t)HeapWordSize >= sizeof(juint), | |
131 "HeapWord should be at least as large as juint"); | |
132 assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer"); | |
133 #endif | |
134 | |
135 if( JavaPriority1_To_OSPriority != -1 ) | |
136 os::java_to_os_priority[1] = JavaPriority1_To_OSPriority; | |
137 if( JavaPriority2_To_OSPriority != -1 ) | |
138 os::java_to_os_priority[2] = JavaPriority2_To_OSPriority; | |
139 if( JavaPriority3_To_OSPriority != -1 ) | |
140 os::java_to_os_priority[3] = JavaPriority3_To_OSPriority; | |
141 if( JavaPriority4_To_OSPriority != -1 ) | |
142 os::java_to_os_priority[4] = JavaPriority4_To_OSPriority; | |
143 if( JavaPriority5_To_OSPriority != -1 ) | |
144 os::java_to_os_priority[5] = JavaPriority5_To_OSPriority; | |
145 if( JavaPriority6_To_OSPriority != -1 ) | |
146 os::java_to_os_priority[6] = JavaPriority6_To_OSPriority; | |
147 if( JavaPriority7_To_OSPriority != -1 ) | |
148 os::java_to_os_priority[7] = JavaPriority7_To_OSPriority; | |
149 if( JavaPriority8_To_OSPriority != -1 ) | |
150 os::java_to_os_priority[8] = JavaPriority8_To_OSPriority; | |
151 if( JavaPriority9_To_OSPriority != -1 ) | |
152 os::java_to_os_priority[9] = JavaPriority9_To_OSPriority; | |
153 if(JavaPriority10_To_OSPriority != -1 ) | |
154 os::java_to_os_priority[10] = JavaPriority10_To_OSPriority; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
155 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
156 // Set the size of basic types here (after argument parsing but before |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
157 // stub generation). |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
158 if (UseCompressedOops) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
159 // Size info for oops within java objects is fixed |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
160 heapOopSize = jintSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
161 LogBytesPerHeapOop = LogBytesPerInt; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
162 LogBitsPerHeapOop = LogBitsPerInt; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
163 BytesPerHeapOop = BytesPerInt; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
164 BitsPerHeapOop = BitsPerInt; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
165 } else { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
166 heapOopSize = oopSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
167 LogBytesPerHeapOop = LogBytesPerWord; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
168 LogBitsPerHeapOop = LogBitsPerWord; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
169 BytesPerHeapOop = BytesPerWord; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
170 BitsPerHeapOop = BitsPerWord; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
171 } |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
172 _type2aelembytes[T_OBJECT] = heapOopSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
173 _type2aelembytes[T_ARRAY] = heapOopSize; |
0 | 174 } |
175 | |
176 | |
177 // Map BasicType to signature character | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
178 char type2char_tab[T_CONFLICT+1]={ 0, 0, 0, 0, 'Z', 'C', 'F', 'D', 'B', 'S', 'I', 'J', 'L', '[', 'V', 0, 0, 0}; |
0 | 179 |
180 // Map BasicType to Java type name | |
181 const char* type2name_tab[T_CONFLICT+1] = { | |
182 NULL, NULL, NULL, NULL, | |
183 "boolean", | |
184 "char", | |
185 "float", | |
186 "double", | |
187 "byte", | |
188 "short", | |
189 "int", | |
190 "long", | |
191 "object", | |
192 "array", | |
193 "void", | |
194 "*address*", | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
195 "*narrowoop*", |
0 | 196 "*conflict*" |
197 }; | |
198 | |
199 | |
200 BasicType name2type(const char* name) { | |
201 for (int i = T_BOOLEAN; i <= T_VOID; i++) { | |
202 BasicType t = (BasicType)i; | |
203 if (type2name_tab[t] != NULL && 0 == strcmp(type2name_tab[t], name)) | |
204 return t; | |
205 } | |
206 return T_ILLEGAL; | |
207 } | |
208 | |
209 | |
210 // Map BasicType to size in words | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
211 int type2size[T_CONFLICT+1]={ -1, 0, 0, 0, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, -1}; |
0 | 212 |
213 BasicType type2field[T_CONFLICT+1] = { | |
214 (BasicType)0, // 0, | |
215 (BasicType)0, // 1, | |
216 (BasicType)0, // 2, | |
217 (BasicType)0, // 3, | |
218 T_BOOLEAN, // T_BOOLEAN = 4, | |
219 T_CHAR, // T_CHAR = 5, | |
220 T_FLOAT, // T_FLOAT = 6, | |
221 T_DOUBLE, // T_DOUBLE = 7, | |
222 T_BYTE, // T_BYTE = 8, | |
223 T_SHORT, // T_SHORT = 9, | |
224 T_INT, // T_INT = 10, | |
225 T_LONG, // T_LONG = 11, | |
226 T_OBJECT, // T_OBJECT = 12, | |
227 T_OBJECT, // T_ARRAY = 13, | |
228 T_VOID, // T_VOID = 14, | |
229 T_ADDRESS, // T_ADDRESS = 15, | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
230 T_NARROWOOP, // T_NARROWOOP= 16, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
231 T_CONFLICT // T_CONFLICT = 17, |
0 | 232 }; |
233 | |
234 | |
235 BasicType type2wfield[T_CONFLICT+1] = { | |
236 (BasicType)0, // 0, | |
237 (BasicType)0, // 1, | |
238 (BasicType)0, // 2, | |
239 (BasicType)0, // 3, | |
240 T_INT, // T_BOOLEAN = 4, | |
241 T_INT, // T_CHAR = 5, | |
242 T_FLOAT, // T_FLOAT = 6, | |
243 T_DOUBLE, // T_DOUBLE = 7, | |
244 T_INT, // T_BYTE = 8, | |
245 T_INT, // T_SHORT = 9, | |
246 T_INT, // T_INT = 10, | |
247 T_LONG, // T_LONG = 11, | |
248 T_OBJECT, // T_OBJECT = 12, | |
249 T_OBJECT, // T_ARRAY = 13, | |
250 T_VOID, // T_VOID = 14, | |
251 T_ADDRESS, // T_ADDRESS = 15, | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
252 T_NARROWOOP, // T_NARROWOOP = 16, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
253 T_CONFLICT // T_CONFLICT = 17, |
0 | 254 }; |
255 | |
256 | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
257 int _type2aelembytes[T_CONFLICT+1] = { |
0 | 258 0, // 0 |
259 0, // 1 | |
260 0, // 2 | |
261 0, // 3 | |
262 T_BOOLEAN_aelem_bytes, // T_BOOLEAN = 4, | |
263 T_CHAR_aelem_bytes, // T_CHAR = 5, | |
264 T_FLOAT_aelem_bytes, // T_FLOAT = 6, | |
265 T_DOUBLE_aelem_bytes, // T_DOUBLE = 7, | |
266 T_BYTE_aelem_bytes, // T_BYTE = 8, | |
267 T_SHORT_aelem_bytes, // T_SHORT = 9, | |
268 T_INT_aelem_bytes, // T_INT = 10, | |
269 T_LONG_aelem_bytes, // T_LONG = 11, | |
270 T_OBJECT_aelem_bytes, // T_OBJECT = 12, | |
271 T_ARRAY_aelem_bytes, // T_ARRAY = 13, | |
272 0, // T_VOID = 14, | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
273 T_OBJECT_aelem_bytes, // T_ADDRESS = 15, |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
274 T_NARROWOOP_aelem_bytes,// T_NARROWOOP= 16, |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
275 0 // T_CONFLICT = 17, |
0 | 276 }; |
277 | |
29
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
278 #ifdef ASSERT |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
279 int type2aelembytes(BasicType t, bool allow_address) { |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
280 assert(allow_address || t != T_ADDRESS, " "); |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
281 return _type2aelembytes[t]; |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
282 } |
d5fc211aea19
6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents:
0
diff
changeset
|
283 #endif |
0 | 284 |
285 // Support for 64-bit integer arithmetic | |
286 | |
287 // The following code is mostly taken from JVM typedefs_md.h and system_md.c | |
288 | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
29
diff
changeset
|
289 static const jlong high_bit = (jlong)1 << (jlong)63; |
0 | 290 static const jlong other_bits = ~high_bit; |
291 | |
292 jlong float2long(jfloat f) { | |
293 jlong tmp = (jlong) f; | |
294 if (tmp != high_bit) { | |
295 return tmp; | |
296 } else { | |
297 if (g_isnan((jdouble)f)) { | |
298 return 0; | |
299 } | |
300 if (f < 0) { | |
301 return high_bit; | |
302 } else { | |
303 return other_bits; | |
304 } | |
305 } | |
306 } | |
307 | |
308 | |
309 jlong double2long(jdouble f) { | |
310 jlong tmp = (jlong) f; | |
311 if (tmp != high_bit) { | |
312 return tmp; | |
313 } else { | |
314 if (g_isnan(f)) { | |
315 return 0; | |
316 } | |
317 if (f < 0) { | |
318 return high_bit; | |
319 } else { | |
320 return other_bits; | |
321 } | |
322 } | |
323 } | |
324 | |
325 // least common multiple | |
326 size_t lcm(size_t a, size_t b) { | |
327 size_t cur, div, next; | |
328 | |
329 cur = MAX2(a, b); | |
330 div = MIN2(a, b); | |
331 | |
332 assert(div != 0, "lcm requires positive arguments"); | |
333 | |
334 | |
335 while ((next = cur % div) != 0) { | |
336 cur = div; div = next; | |
337 } | |
338 | |
339 | |
340 julong result = julong(a) * b / div; | |
341 assert(result <= (size_t)max_uintx, "Integer overflow in lcm"); | |
342 | |
343 return size_t(result); | |
344 } |