Mercurial > hg > graal-jvmci-8
comparison src/share/vm/runtime/virtualspace.cpp @ 12236:c4c768305a8f
8024638: Count and expose the amount of committed memory in the metaspaces
Reviewed-by: brutisso, ehelin
author | stefank |
---|---|
date | Thu, 12 Sep 2013 10:15:54 +0200 |
parents | 4c84d351cca9 |
children | 8c5e6482cbfc |
comparison
equal
deleted
inserted
replaced
12235:d6c266999345 | 12236:c4c768305a8f |
---|---|
451 | 451 |
452 size_t VirtualSpace::uncommitted_size() const { | 452 size_t VirtualSpace::uncommitted_size() const { |
453 return reserved_size() - committed_size(); | 453 return reserved_size() - committed_size(); |
454 } | 454 } |
455 | 455 |
456 size_t VirtualSpace::actual_committed_size() const { | |
457 // Special VirtualSpaces commit all reserved space up front. | |
458 if (special()) { | |
459 return reserved_size(); | |
460 } | |
461 | |
462 size_t committed_low = pointer_delta(_lower_high, _low_boundary, sizeof(char)); | |
463 size_t committed_middle = pointer_delta(_middle_high, _lower_high_boundary, sizeof(char)); | |
464 size_t committed_high = pointer_delta(_upper_high, _middle_high_boundary, sizeof(char)); | |
465 | |
466 #ifdef ASSERT | |
467 size_t lower = pointer_delta(_lower_high_boundary, _low_boundary, sizeof(char)); | |
468 size_t middle = pointer_delta(_middle_high_boundary, _lower_high_boundary, sizeof(char)); | |
469 size_t upper = pointer_delta(_upper_high_boundary, _middle_high_boundary, sizeof(char)); | |
470 | |
471 if (committed_high > 0) { | |
472 assert(committed_low == lower, "Must be"); | |
473 assert(committed_middle == middle, "Must be"); | |
474 } | |
475 | |
476 if (committed_middle > 0) { | |
477 assert(committed_low == lower, "Must be"); | |
478 } | |
479 if (committed_middle < middle) { | |
480 assert(committed_high == 0, "Must be"); | |
481 } | |
482 | |
483 if (committed_low < lower) { | |
484 assert(committed_high == 0, "Must be"); | |
485 assert(committed_middle == 0, "Must be"); | |
486 } | |
487 #endif | |
488 | |
489 return committed_low + committed_middle + committed_high; | |
490 } | |
491 | |
456 | 492 |
457 bool VirtualSpace::contains(const void* p) const { | 493 bool VirtualSpace::contains(const void* p) const { |
458 return low() <= (const char*) p && (const char*) p < high(); | 494 return low() <= (const char*) p && (const char*) p < high(); |
459 } | 495 } |
460 | 496 |
908 | 944 |
909 void TestReservedSpace_test() { | 945 void TestReservedSpace_test() { |
910 TestReservedSpace::test_reserved_space(); | 946 TestReservedSpace::test_reserved_space(); |
911 } | 947 } |
912 | 948 |
949 #define assert_equals(actual, expected) \ | |
950 assert(actual == expected, \ | |
951 err_msg("Got " SIZE_FORMAT " expected " \ | |
952 SIZE_FORMAT, actual, expected)); | |
953 | |
954 #define assert_ge(value1, value2) \ | |
955 assert(value1 >= value2, \ | |
956 err_msg("'" #value1 "': " SIZE_FORMAT " '" \ | |
957 #value2 "': " SIZE_FORMAT, value1, value2)); | |
958 | |
959 #define assert_lt(value1, value2) \ | |
960 assert(value1 < value2, \ | |
961 err_msg("'" #value1 "': " SIZE_FORMAT " '" \ | |
962 #value2 "': " SIZE_FORMAT, value1, value2)); | |
963 | |
964 | |
965 class TestVirtualSpace : AllStatic { | |
966 public: | |
967 static void test_virtual_space_actual_committed_space(size_t reserve_size, size_t commit_size) { | |
968 size_t granularity = os::vm_allocation_granularity(); | |
969 size_t reserve_size_aligned = align_size_up(reserve_size, granularity); | |
970 | |
971 ReservedSpace reserved(reserve_size_aligned); | |
972 | |
973 assert(reserved.is_reserved(), "Must be"); | |
974 | |
975 VirtualSpace vs; | |
976 bool initialized = vs.initialize(reserved, 0); | |
977 assert(initialized, "Failed to initialize VirtualSpace"); | |
978 | |
979 vs.expand_by(commit_size, false); | |
980 | |
981 if (vs.special()) { | |
982 assert_equals(vs.actual_committed_size(), reserve_size_aligned); | |
983 } else { | |
984 assert_ge(vs.actual_committed_size(), commit_size); | |
985 // Approximate the commit granularity. | |
986 size_t commit_granularity = UseLargePages ? os::large_page_size() : os::vm_page_size(); | |
987 assert_lt(vs.actual_committed_size(), commit_size + commit_granularity); | |
988 } | |
989 | |
990 reserved.release(); | |
991 } | |
992 | |
993 static void test_virtual_space_actual_committed_space_one_large_page() { | |
994 if (!UseLargePages) { | |
995 return; | |
996 } | |
997 | |
998 size_t large_page_size = os::large_page_size(); | |
999 | |
1000 ReservedSpace reserved(large_page_size, large_page_size, true, false); | |
1001 | |
1002 assert(reserved.is_reserved(), "Must be"); | |
1003 | |
1004 VirtualSpace vs; | |
1005 bool initialized = vs.initialize(reserved, 0); | |
1006 assert(initialized, "Failed to initialize VirtualSpace"); | |
1007 | |
1008 vs.expand_by(large_page_size, false); | |
1009 | |
1010 assert_equals(vs.actual_committed_size(), large_page_size); | |
1011 | |
1012 reserved.release(); | |
1013 } | |
1014 | |
1015 static void test_virtual_space_actual_committed_space() { | |
1016 test_virtual_space_actual_committed_space(4 * K, 0); | |
1017 test_virtual_space_actual_committed_space(4 * K, 4 * K); | |
1018 test_virtual_space_actual_committed_space(8 * K, 0); | |
1019 test_virtual_space_actual_committed_space(8 * K, 4 * K); | |
1020 test_virtual_space_actual_committed_space(8 * K, 8 * K); | |
1021 test_virtual_space_actual_committed_space(12 * K, 0); | |
1022 test_virtual_space_actual_committed_space(12 * K, 4 * K); | |
1023 test_virtual_space_actual_committed_space(12 * K, 8 * K); | |
1024 test_virtual_space_actual_committed_space(12 * K, 12 * K); | |
1025 test_virtual_space_actual_committed_space(64 * K, 0); | |
1026 test_virtual_space_actual_committed_space(64 * K, 32 * K); | |
1027 test_virtual_space_actual_committed_space(64 * K, 64 * K); | |
1028 test_virtual_space_actual_committed_space(2 * M, 0); | |
1029 test_virtual_space_actual_committed_space(2 * M, 4 * K); | |
1030 test_virtual_space_actual_committed_space(2 * M, 64 * K); | |
1031 test_virtual_space_actual_committed_space(2 * M, 1 * M); | |
1032 test_virtual_space_actual_committed_space(2 * M, 2 * M); | |
1033 test_virtual_space_actual_committed_space(10 * M, 0); | |
1034 test_virtual_space_actual_committed_space(10 * M, 4 * K); | |
1035 test_virtual_space_actual_committed_space(10 * M, 8 * K); | |
1036 test_virtual_space_actual_committed_space(10 * M, 1 * M); | |
1037 test_virtual_space_actual_committed_space(10 * M, 2 * M); | |
1038 test_virtual_space_actual_committed_space(10 * M, 5 * M); | |
1039 test_virtual_space_actual_committed_space(10 * M, 10 * M); | |
1040 } | |
1041 | |
1042 static void test_virtual_space() { | |
1043 test_virtual_space_actual_committed_space(); | |
1044 test_virtual_space_actual_committed_space_one_large_page(); | |
1045 } | |
1046 }; | |
1047 | |
1048 void TestVirtualSpace_test() { | |
1049 TestVirtualSpace::test_virtual_space(); | |
1050 } | |
1051 | |
913 #endif // PRODUCT | 1052 #endif // PRODUCT |
914 | 1053 |
915 #endif | 1054 #endif |