< prev index next >

hotspot/src/share/vm/utilities/globalDefinitions.cpp

Print this page
rev 12348 : 8166132: Convert TestGlobalDefinitions_test to GTest


 351 
 352 
 353     julong result = julong(a) * b / div;
 354     assert(result <= (size_t)max_uintx, "Integer overflow in lcm");
 355 
 356     return size_t(result);
 357 }
 358 
 359 
 360 // Test that nth_bit macro and friends behave as
 361 // expected, even with low-precedence operators.
 362 
 363 STATIC_ASSERT(nth_bit(3)   == 0x8);
 364 STATIC_ASSERT(nth_bit(1|2) == 0x8);
 365 
 366 STATIC_ASSERT(right_n_bits(3)   == 0x7);
 367 STATIC_ASSERT(right_n_bits(1|2) == 0x7);
 368 
 369 STATIC_ASSERT(left_n_bits(3)   == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));
 370 STATIC_ASSERT(left_n_bits(1|2) == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));
 371 
 372 
 373 #ifndef PRODUCT
 374 // For unit testing only
 375 class TestGlobalDefinitions {
 376 private:
 377 
 378   static void test_clamp_address_in_page() {
 379     intptr_t page_sizes[] = { os::vm_page_size(), 4096, 8192, 65536, 2*1024*1024 };
 380     const int num_page_sizes = sizeof(page_sizes) / sizeof(page_sizes[0]);
 381 
 382     for (int i = 0; i < num_page_sizes; i++) {
 383       intptr_t page_size = page_sizes[i];
 384 
 385       address a_page = (address)(10*page_size);
 386 
 387       // Check that address within page is returned as is
 388       assert(clamp_address_in_page(a_page, a_page, page_size) == a_page, "incorrect");
 389       assert(clamp_address_in_page(a_page + 128, a_page, page_size) == a_page + 128, "incorrect");
 390       assert(clamp_address_in_page(a_page + page_size - 1, a_page, page_size) == a_page + page_size - 1, "incorrect");
 391 
 392       // Check that address above page returns start of next page
 393       assert(clamp_address_in_page(a_page + page_size, a_page, page_size) == a_page + page_size, "incorrect");
 394       assert(clamp_address_in_page(a_page + page_size + 1, a_page, page_size) == a_page + page_size, "incorrect");
 395       assert(clamp_address_in_page(a_page + page_size*5 + 1, a_page, page_size) == a_page + page_size, "incorrect");
 396 
 397       // Check that address below page returns start of page
 398       assert(clamp_address_in_page(a_page - 1, a_page, page_size) == a_page, "incorrect");
 399       assert(clamp_address_in_page(a_page - 2*page_size - 1, a_page, page_size) == a_page, "incorrect");
 400       assert(clamp_address_in_page(a_page - 5*page_size - 1, a_page, page_size) == a_page, "incorrect");
 401     }
 402   }
 403 
 404   static void test_exact_unit_for_byte_size() {
 405     assert(strcmp(exact_unit_for_byte_size(0),     "B") == 0, "incorrect");
 406     assert(strcmp(exact_unit_for_byte_size(1),     "B") == 0, "incorrect");
 407     assert(strcmp(exact_unit_for_byte_size(K - 1), "B") == 0, "incorrect");
 408     assert(strcmp(exact_unit_for_byte_size(K),     "K") == 0, "incorrect");
 409     assert(strcmp(exact_unit_for_byte_size(K + 1), "B") == 0, "incorrect");
 410     assert(strcmp(exact_unit_for_byte_size(M - 1), "B") == 0, "incorrect");
 411     assert(strcmp(exact_unit_for_byte_size(M),     "M") == 0, "incorrect");
 412     assert(strcmp(exact_unit_for_byte_size(M + 1), "B") == 0, "incorrect");
 413     assert(strcmp(exact_unit_for_byte_size(M + K), "K") == 0, "incorrect");
 414 #ifdef LP64
 415     assert(strcmp(exact_unit_for_byte_size(G - 1),     "B") == 0, "incorrect");
 416     assert(strcmp(exact_unit_for_byte_size(G),         "G") == 0, "incorrect");
 417     assert(strcmp(exact_unit_for_byte_size(G + 1),     "B") == 0, "incorrect");
 418     assert(strcmp(exact_unit_for_byte_size(G + K),     "K") == 0, "incorrect");
 419     assert(strcmp(exact_unit_for_byte_size(G + M),     "M") == 0, "incorrect");
 420     assert(strcmp(exact_unit_for_byte_size(G + M + K), "K") == 0, "incorrect");
 421 #endif
 422   }
 423 
 424   static void test_byte_size_in_exact_unit() {
 425     assert(byte_size_in_exact_unit(0)     == 0,     "incorrect");
 426     assert(byte_size_in_exact_unit(1)     == 1,     "incorrect");
 427     assert(byte_size_in_exact_unit(K - 1) == K - 1, "incorrect");
 428     assert(byte_size_in_exact_unit(K)     == 1,     "incorrect");
 429     assert(byte_size_in_exact_unit(K + 1) == K + 1, "incorrect");
 430     assert(byte_size_in_exact_unit(M - 1) == M - 1, "incorrect");
 431     assert(byte_size_in_exact_unit(M)     == 1,     "incorrect");
 432     assert(byte_size_in_exact_unit(M + 1) == M + 1, "incorrect");
 433     assert(byte_size_in_exact_unit(M + K) == K + 1, "incorrect");
 434 #ifdef LP64
 435     assert(byte_size_in_exact_unit(G - 1)     == G - 1,     "incorrect");
 436     assert(byte_size_in_exact_unit(G)         == 1,         "incorrect");
 437     assert(byte_size_in_exact_unit(G + 1)     == G + 1,     "incorrect");
 438     assert(byte_size_in_exact_unit(G + K)     == M + 1,     "incorrect");
 439     assert(byte_size_in_exact_unit(G + M)     == K + 1,     "incorrect");
 440     assert(byte_size_in_exact_unit(G + M + K) == M + K + 1, "incorrect");
 441 #endif
 442   }
 443 
 444   static void test_exact_units() {
 445     test_exact_unit_for_byte_size();
 446     test_byte_size_in_exact_unit();
 447   }
 448 
 449 public:
 450   static void test() {
 451     test_clamp_address_in_page();
 452     test_exact_units();
 453   }
 454 };
 455 
 456 void TestGlobalDefinitions_test() {
 457   TestGlobalDefinitions::test();
 458 }
 459 
 460 #endif // PRODUCT


 351 
 352 
 353     julong result = julong(a) * b / div;
 354     assert(result <= (size_t)max_uintx, "Integer overflow in lcm");
 355 
 356     return size_t(result);
 357 }
 358 
 359 
 360 // Test that nth_bit macro and friends behave as
 361 // expected, even with low-precedence operators.
 362 
 363 STATIC_ASSERT(nth_bit(3)   == 0x8);
 364 STATIC_ASSERT(nth_bit(1|2) == 0x8);
 365 
 366 STATIC_ASSERT(right_n_bits(3)   == 0x7);
 367 STATIC_ASSERT(right_n_bits(1|2) == 0x7);
 368 
 369 STATIC_ASSERT(left_n_bits(3)   == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));
 370 STATIC_ASSERT(left_n_bits(1|2) == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));


























































































< prev index next >