Skip to content

Commit d117979

Browse files
committed
8300054: Use static_assert in basic_types_init
Reviewed-by: stefank, kbarrett
1 parent ce1193a commit d117979

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/hotspot/share/utilities/globalDefinitions.cpp

+32-32
Original file line numberDiff line numberDiff line change
@@ -78,35 +78,35 @@ extern bool signature_constants_sane();
7878
void basic_types_init() {
7979
#ifdef ASSERT
8080
#ifdef _LP64
81-
assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant");
82-
assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant");
83-
assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant");
84-
assert( 8 == sizeof( intx), "wrong size for basic type");
85-
assert( 8 == sizeof( jobject), "wrong size for basic type");
81+
static_assert(min_intx == (intx)CONST64(0x8000000000000000), "correct constant");
82+
static_assert(max_intx == CONST64(0x7FFFFFFFFFFFFFFF), "correct constant");
83+
static_assert(max_uintx == CONST64(0xFFFFFFFFFFFFFFFF), "correct constant");
84+
static_assert( 8 == sizeof( intx), "wrong size for basic type");
85+
static_assert( 8 == sizeof( jobject), "wrong size for basic type");
8686
#else
87-
assert(min_intx == (intx)0x80000000, "correct constant");
88-
assert(max_intx == 0x7FFFFFFF, "correct constant");
89-
assert(max_uintx == 0xFFFFFFFF, "correct constant");
90-
assert( 4 == sizeof( intx), "wrong size for basic type");
91-
assert( 4 == sizeof( jobject), "wrong size for basic type");
87+
static_assert(min_intx == (intx)0x80000000, "correct constant");
88+
static_assert(max_intx == 0x7FFFFFFF, "correct constant");
89+
static_assert(max_uintx == 0xFFFFFFFF, "correct constant");
90+
static_assert( 4 == sizeof( intx), "wrong size for basic type");
91+
static_assert( 4 == sizeof( jobject), "wrong size for basic type");
9292
#endif
93-
assert( (~max_juint) == 0, "max_juint has all its bits");
94-
assert( (~max_uintx) == 0, "max_uintx has all its bits");
95-
assert( (~max_julong) == 0, "max_julong has all its bits");
96-
assert( 1 == sizeof( jbyte), "wrong size for basic type");
97-
assert( 2 == sizeof( jchar), "wrong size for basic type");
98-
assert( 2 == sizeof( jshort), "wrong size for basic type");
99-
assert( 4 == sizeof( juint), "wrong size for basic type");
100-
assert( 4 == sizeof( jint), "wrong size for basic type");
101-
assert( 1 == sizeof( jboolean), "wrong size for basic type");
102-
assert( 8 == sizeof( jlong), "wrong size for basic type");
103-
assert( 4 == sizeof( jfloat), "wrong size for basic type");
104-
assert( 8 == sizeof( jdouble), "wrong size for basic type");
105-
assert( 1 == sizeof( u1), "wrong size for basic type");
106-
assert( 2 == sizeof( u2), "wrong size for basic type");
107-
assert( 4 == sizeof( u4), "wrong size for basic type");
108-
assert(wordSize == BytesPerWord, "should be the same since they're used interchangeably");
109-
assert(wordSize == HeapWordSize, "should be the same since they're also used interchangeably");
93+
static_assert( (~max_juint) == 0, "max_juint has all its bits");
94+
static_assert( (~max_uintx) == 0, "max_uintx has all its bits");
95+
static_assert( (~max_julong) == 0, "max_julong has all its bits");
96+
static_assert( 1 == sizeof( jbyte), "wrong size for basic type");
97+
static_assert( 2 == sizeof( jchar), "wrong size for basic type");
98+
static_assert( 2 == sizeof( jshort), "wrong size for basic type");
99+
static_assert( 4 == sizeof( juint), "wrong size for basic type");
100+
static_assert( 4 == sizeof( jint), "wrong size for basic type");
101+
static_assert( 1 == sizeof( jboolean), "wrong size for basic type");
102+
static_assert( 8 == sizeof( jlong), "wrong size for basic type");
103+
static_assert( 4 == sizeof( jfloat), "wrong size for basic type");
104+
static_assert( 8 == sizeof( jdouble), "wrong size for basic type");
105+
static_assert( 1 == sizeof( u1), "wrong size for basic type");
106+
static_assert( 2 == sizeof( u2), "wrong size for basic type");
107+
static_assert( 4 == sizeof( u4), "wrong size for basic type");
108+
static_assert(wordSize == BytesPerWord, "should be the same since they're used interchangeably");
109+
static_assert(wordSize == HeapWordSize, "should be the same since they're also used interchangeably");
110110

111111
assert(signature_constants_sane(), "");
112112

@@ -155,11 +155,11 @@ void basic_types_init() {
155155
}
156156
}
157157
// These are assumed, e.g., when filling HeapWords with juints.
158-
assert(is_power_of_2(sizeof(juint)), "juint must be power of 2");
159-
assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2");
160-
assert((size_t)HeapWordSize >= sizeof(juint),
161-
"HeapWord should be at least as large as juint");
162-
assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer");
158+
static_assert(is_power_of_2(sizeof(juint)), "juint must be power of 2");
159+
static_assert(is_power_of_2(HeapWordSize), "HeapWordSize must be power of 2");
160+
static_assert((size_t)HeapWordSize >= sizeof(juint),
161+
"HeapWord should be at least as large as juint");
162+
static_assert(sizeof(NULL) == sizeof(char*), "NULL must be same size as pointer");
163163
#endif
164164

165165
if( JavaPriority1_To_OSPriority != -1 )

0 commit comments

Comments
 (0)