< prev index next >

src/share/vm/utilities/globalDefinitions.cpp

Print this page




 357 
 358     return size_t(result);
 359 }
 360 
 361 
 362 // Test that nth_bit macro and friends behave as
 363 // expected, even with low-precedence operators.
 364 
 365 STATIC_ASSERT(nth_bit(3)   == 0x8);
 366 STATIC_ASSERT(nth_bit(1|2) == 0x8);
 367 
 368 STATIC_ASSERT(right_n_bits(3)   == 0x7);
 369 STATIC_ASSERT(right_n_bits(1|2) == 0x7);
 370 
 371 STATIC_ASSERT(left_n_bits(3)   == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));
 372 STATIC_ASSERT(left_n_bits(1|2) == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));
 373 
 374 
 375 #ifndef PRODUCT
 376 // For unit testing only
 377 class GlobalDefinitions {
 378 public:
 379   static void test_globals();
 380 };
 381 
 382 void GlobalDefinitions::test_globals() {
 383   intptr_t page_sizes[] = { os::vm_page_size(), 4096, 8192, 65536, 2*1024*1024 };
 384   const int num_page_sizes = sizeof(page_sizes) / sizeof(page_sizes[0]);
 385 
 386   for (int i = 0; i < num_page_sizes; i++) {
 387     intptr_t page_size = page_sizes[i];
 388 
 389     address a_page = (address)(10*page_size);
 390 
 391     // Check that address within page is returned as is
 392     assert(clamp_address_in_page(a_page, a_page, page_size) == a_page, "incorrect");
 393     assert(clamp_address_in_page(a_page + 128, a_page, page_size) == a_page + 128, "incorrect");
 394     assert(clamp_address_in_page(a_page + page_size - 1, a_page, page_size) == a_page + page_size - 1, "incorrect");
 395 
 396     // Check that address above page returns start of next page
 397     assert(clamp_address_in_page(a_page + page_size, a_page, page_size) == a_page + page_size, "incorrect");
 398     assert(clamp_address_in_page(a_page + page_size + 1, a_page, page_size) == a_page + page_size, "incorrect");
 399     assert(clamp_address_in_page(a_page + page_size*5 + 1, a_page, page_size) == a_page + page_size, "incorrect");
 400 
 401     // Check that address below page returns start of page
 402     assert(clamp_address_in_page(a_page - 1, a_page, page_size) == a_page, "incorrect");
 403     assert(clamp_address_in_page(a_page - 2*page_size - 1, a_page, page_size) == a_page, "incorrect");
 404     assert(clamp_address_in_page(a_page - 5*page_size - 1, a_page, page_size) == a_page, "incorrect");
 405   }
 406 }




















































 407 
 408 void GlobalDefinitions_test() {
 409   GlobalDefinitions::test_globals();
 410 }
 411 
 412 #endif // PRODUCT


 357 
 358     return size_t(result);
 359 }
 360 
 361 
 362 // Test that nth_bit macro and friends behave as
 363 // expected, even with low-precedence operators.
 364 
 365 STATIC_ASSERT(nth_bit(3)   == 0x8);
 366 STATIC_ASSERT(nth_bit(1|2) == 0x8);
 367 
 368 STATIC_ASSERT(right_n_bits(3)   == 0x7);
 369 STATIC_ASSERT(right_n_bits(1|2) == 0x7);
 370 
 371 STATIC_ASSERT(left_n_bits(3)   == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));
 372 STATIC_ASSERT(left_n_bits(1|2) == (intptr_t) LP64_ONLY(0xE000000000000000) NOT_LP64(0xE0000000));
 373 
 374 
 375 #ifndef PRODUCT
 376 // For unit testing only
 377 class TestGlobalDefinitions {
 378 private:


 379 
 380   static void test_clamp_address_in_page() {
 381     intptr_t page_sizes[] = { os::vm_page_size(), 4096, 8192, 65536, 2*1024*1024 };
 382     const int num_page_sizes = sizeof(page_sizes) / sizeof(page_sizes[0]);
 383 
 384     for (int i = 0; i < num_page_sizes; i++) {
 385       intptr_t page_size = page_sizes[i];
 386 
 387       address a_page = (address)(10*page_size);
 388 
 389       // Check that address within page is returned as is
 390       assert(clamp_address_in_page(a_page, a_page, page_size) == a_page, "incorrect");
 391       assert(clamp_address_in_page(a_page + 128, a_page, page_size) == a_page + 128, "incorrect");
 392       assert(clamp_address_in_page(a_page + page_size - 1, a_page, page_size) == a_page + page_size - 1, "incorrect");
 393 
 394       // Check that address above page returns start of next page
 395       assert(clamp_address_in_page(a_page + page_size, a_page, page_size) == a_page + page_size, "incorrect");
 396       assert(clamp_address_in_page(a_page + page_size + 1, a_page, page_size) == a_page + page_size, "incorrect");
 397       assert(clamp_address_in_page(a_page + page_size*5 + 1, a_page, page_size) == a_page + page_size, "incorrect");
 398 
 399       // Check that address below page returns start of page
 400       assert(clamp_address_in_page(a_page - 1, a_page, page_size) == a_page, "incorrect");
 401       assert(clamp_address_in_page(a_page - 2*page_size - 1, a_page, page_size) == a_page, "incorrect");
 402       assert(clamp_address_in_page(a_page - 5*page_size - 1, a_page, page_size) == a_page, "incorrect");
 403     }
 404   }
 405 
 406   static void test_exact_unit_for_byte_size() {
 407     assert(strcmp(exact_unit_for_byte_size(0),     "B") == 0, "incorrect");
 408     assert(strcmp(exact_unit_for_byte_size(1),     "B") == 0, "incorrect");
 409     assert(strcmp(exact_unit_for_byte_size(K - 1), "B") == 0, "incorrect");
 410     assert(strcmp(exact_unit_for_byte_size(K),     "K") == 0, "incorrect");
 411     assert(strcmp(exact_unit_for_byte_size(K + 1), "B") == 0, "incorrect");
 412     assert(strcmp(exact_unit_for_byte_size(M - 1), "B") == 0, "incorrect");
 413     assert(strcmp(exact_unit_for_byte_size(M),     "M") == 0, "incorrect");
 414     assert(strcmp(exact_unit_for_byte_size(M + 1), "B") == 0, "incorrect");
 415     assert(strcmp(exact_unit_for_byte_size(M + K), "K") == 0, "incorrect");
 416 #ifdef LP64
 417     assert(strcmp(exact_unit_for_byte_size(G - 1),     "B") == 0, "incorrect");
 418     assert(strcmp(exact_unit_for_byte_size(G),         "G") == 0, "incorrect");
 419     assert(strcmp(exact_unit_for_byte_size(G + 1),     "B") == 0, "incorrect");
 420     assert(strcmp(exact_unit_for_byte_size(G + K),     "K") == 0, "incorrect");
 421     assert(strcmp(exact_unit_for_byte_size(G + M),     "M") == 0, "incorrect");
 422     assert(strcmp(exact_unit_for_byte_size(G + M + K), "K") == 0, "incorrect");
 423 #endif
 424   }
 425 
 426   static void test_byte_size_in_exact_unit() {
 427     assert(byte_size_in_exact_unit(0)     == 0,     "incorrect");
 428     assert(byte_size_in_exact_unit(1)     == 1,     "incorrect");
 429     assert(byte_size_in_exact_unit(K - 1) == K - 1, "incorrect");
 430     assert(byte_size_in_exact_unit(K)     == 1,     "incorrect");
 431     assert(byte_size_in_exact_unit(K + 1) == K + 1, "incorrect");
 432     assert(byte_size_in_exact_unit(M - 1) == M - 1, "incorrect");
 433     assert(byte_size_in_exact_unit(M)     == 1,     "incorrect");
 434     assert(byte_size_in_exact_unit(M + 1) == M + 1, "incorrect");
 435     assert(byte_size_in_exact_unit(M + K) == K + 1, "incorrect");
 436 #ifdef LP64
 437     assert(byte_size_in_exact_unit(G - 1)     == G - 1,     "incorrect");
 438     assert(byte_size_in_exact_unit(G)         == 1,         "incorrect");
 439     assert(byte_size_in_exact_unit(G + 1)     == G + 1,     "incorrect");
 440     assert(byte_size_in_exact_unit(G + K)     == M + 1,     "incorrect");
 441     assert(byte_size_in_exact_unit(G + M)     == K + 1,     "incorrect");
 442     assert(byte_size_in_exact_unit(G + M + K) == M + K + 1, "incorrect");
 443 #endif
 444   }
 445 
 446   static void test_exact_units() {
 447     test_exact_unit_for_byte_size();
 448     test_byte_size_in_exact_unit();
 449   }
 450 
 451 public:
 452   static void test() {
 453     test_clamp_address_in_page();
 454     test_exact_units();
 455   }
 456 };
 457 
 458 void TestGlobalDefinitions_test() {
 459   TestGlobalDefinitions::test();
 460 }
 461 
 462 #endif // PRODUCT
< prev index next >