Skip to content

Commit 0e4ea6c

Browse files
committed
8365606: Container code should not be using jlong/julong
1 parent a1a37bd commit 0e4ea6c

16 files changed

+1139
-772
lines changed

src/hotspot/os/linux/cgroupSubsystem_linux.cpp

Lines changed: 86 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -627,54 +627,66 @@ void CgroupSubsystemFactory::cleanup(CgroupInfo* cg_infos) {
627627
* number of active processors in the system.
628628
*
629629
* If quotas have been specified, the resulting number
630-
* returned will never exceed the number of active processors.
630+
* set in the result reference will never exceed the number
631+
* of active processors.
631632
*
632633
* return:
633-
* number of CPUs
634+
* true if there were no errors. false otherwise.
634635
*/
635-
int CgroupSubsystem::active_processor_count() {
636-
int quota_count = 0;
636+
bool CgroupSubsystem::active_processor_count(int& value) {
637637
int cpu_count;
638-
int result;
638+
int result = -1;
639639

640640
// We use a cache with a timeout to avoid performing expensive
641641
// computations in the event this function is called frequently.
642642
// [See 8227006].
643643
CachingCgroupController<CgroupCpuController>* contrl = cpu_controller();
644644
CachedMetric* cpu_limit = contrl->metrics_cache();
645645
if (!cpu_limit->should_check_metric()) {
646-
int val = (int)cpu_limit->value();
647-
log_trace(os, container)("CgroupSubsystem::active_processor_count (cached): %d", val);
648-
return val;
646+
value = (int)cpu_limit->value();
647+
log_trace(os, container)("CgroupSubsystem::active_processor_count (cached): %d", value);
648+
return true;
649649
}
650650

651651
cpu_count = os::Linux::active_processor_count();
652-
result = CgroupUtil::processor_count(contrl->controller(), cpu_count);
652+
if (!CgroupUtil::processor_count(contrl->controller(), cpu_count, result)) {
653+
return false;
654+
}
655+
assert(result > 0 && result <= cpu_count, "must be");
653656
// Update cached metric to avoid re-reading container settings too often
654657
cpu_limit->set_value(result, OSCONTAINER_CACHE_TIMEOUT);
658+
value = result;
655659

656-
return result;
660+
return true;
657661
}
658662

659663
/* memory_limit_in_bytes
660664
*
661-
* Return the limit of available memory for this process.
665+
* Return the limit of available memory for this process in the provided
666+
* physical_memory_size_type reference. If there was no limit value set in the underlying
667+
* interface files value_unlimited is returned.
662668
*
663669
* return:
664-
* memory limit in bytes or
665-
* -1 for unlimited
666-
* OSCONTAINER_ERROR for not supported
670+
* false if retrieving the value failed
671+
* true if retrieving the value was successfull and the value was
672+
* set in the 'value' reference.
667673
*/
668-
jlong CgroupSubsystem::memory_limit_in_bytes(julong upper_bound) {
674+
bool CgroupSubsystem::memory_limit_in_bytes(physical_memory_size_type upper_bound,
675+
physical_memory_size_type& value) {
669676
CachingCgroupController<CgroupMemoryController>* contrl = memory_controller();
670677
CachedMetric* memory_limit = contrl->metrics_cache();
671678
if (!memory_limit->should_check_metric()) {
672-
return memory_limit->value();
679+
value = memory_limit->value();
680+
return true;
681+
}
682+
physical_memory_size_type mem_limit = 0;
683+
if (!contrl->controller()->read_memory_limit_in_bytes(upper_bound, mem_limit)) {
684+
return false;
673685
}
674-
jlong mem_limit = contrl->controller()->read_memory_limit_in_bytes(upper_bound);
675686
// Update cached metric to avoid re-reading container settings too often
676687
memory_limit->set_value(mem_limit, OSCONTAINER_CACHE_TIMEOUT);
677-
return mem_limit;
688+
value = mem_limit;
689+
return true;
678690
}
679691

680692
bool CgroupController::read_string(const char* filename, char* buf, size_t buf_size) {
@@ -719,36 +731,35 @@ bool CgroupController::read_string(const char* filename, char* buf, size_t buf_s
719731
return true;
720732
}
721733

722-
bool CgroupController::read_number(const char* filename, julong* result) {
734+
bool CgroupController::read_number(const char* filename, uint64_t& result) {
723735
char buf[1024];
724736
bool is_ok = read_string(filename, buf, 1024);
725737
if (!is_ok) {
726738
return false;
727739
}
728-
int matched = sscanf(buf, JULONG_FORMAT, result);
740+
int matched = sscanf(buf, "%zu", &result);
729741
if (matched == 1) {
730742
return true;
731743
}
732744
return false;
733745
}
734746

735-
bool CgroupController::read_number_handle_max(const char* filename, jlong* result) {
747+
bool CgroupController::read_number_handle_max(const char* filename, uint64_t& result) {
736748
char buf[1024];
737749
bool is_ok = read_string(filename, buf, 1024);
738750
if (!is_ok) {
739751
return false;
740752
}
741-
jlong val = limit_from_str(buf);
742-
if (val == OSCONTAINER_ERROR) {
753+
uint64_t val = 0;
754+
if (!limit_from_str(buf, val)) {
743755
return false;
744756
}
745-
*result = val;
757+
result = val;
746758
return true;
747759
}
748760

749-
bool CgroupController::read_numerical_key_value(const char* filename, const char* key, julong* result) {
761+
bool CgroupController::read_numerical_key_value(const char* filename, const char* key, uint64_t& result) {
750762
assert(key != nullptr, "key must be given");
751-
assert(result != nullptr, "result pointer must not be null");
752763
assert(filename != nullptr, "file to search in must be given");
753764
const char* s_path = subsystem_path();
754765
if (s_path == nullptr) {
@@ -786,7 +797,7 @@ bool CgroupController::read_numerical_key_value(const char* filename, const char
786797
&& after_key != '\n') {
787798
// Skip key, skip space
788799
const char* value_substr = line + key_len + 1;
789-
int matched = sscanf(value_substr, JULONG_FORMAT, result);
800+
int matched = sscanf(value_substr, UINT64_FORMAT, &result);
790801
found_match = matched == 1;
791802
if (found_match) {
792803
break;
@@ -797,12 +808,12 @@ bool CgroupController::read_numerical_key_value(const char* filename, const char
797808
if (found_match) {
798809
return true;
799810
}
800-
log_debug(os, container)("Type %s (key == %s) not found in file %s", JULONG_FORMAT,
811+
log_debug(os, container)("Type %s (key == %s) not found in file %s", UINT64_FORMAT,
801812
key, absolute_path);
802813
return false;
803814
}
804815

805-
bool CgroupController::read_numerical_tuple_value(const char* filename, bool use_first, jlong* result) {
816+
bool CgroupController::read_numerical_tuple_value(const char* filename, bool use_first, uint64_t& result) {
806817
char buf[1024];
807818
bool is_ok = read_string(filename, buf, 1024);
808819
if (!is_ok) {
@@ -813,80 +824,90 @@ bool CgroupController::read_numerical_tuple_value(const char* filename, bool use
813824
if (matched != 1) {
814825
return false;
815826
}
816-
jlong val = limit_from_str(token);
817-
if (val == OSCONTAINER_ERROR) {
827+
uint64_t val = 0;
828+
if (!limit_from_str(token, val)) {
818829
return false;
819830
}
820-
*result = val;
831+
result = val;
821832
return true;
822833
}
823834

824-
jlong CgroupController::limit_from_str(char* limit_str) {
835+
bool CgroupController::limit_from_str(char* limit_str, uint64_t& value) {
825836
if (limit_str == nullptr) {
826-
return OSCONTAINER_ERROR;
837+
return false;
827838
}
828839
// Unlimited memory in cgroups is the literal string 'max' for
829840
// some controllers, for example the pids controller.
830841
if (strcmp("max", limit_str) == 0) {
831-
return (jlong)-1;
842+
value = value_unlimited;
843+
return true;
832844
}
833-
julong limit;
834-
if (sscanf(limit_str, JULONG_FORMAT, &limit) != 1) {
835-
return OSCONTAINER_ERROR;
845+
uint64_t limit;
846+
if (sscanf(limit_str, UINT64_FORMAT, &limit) != 1) {
847+
return false;
836848
}
837-
return (jlong)limit;
849+
value = limit;
850+
return true;
838851
}
839852

840853
// CgroupSubsystem implementations
841-
842-
jlong CgroupSubsystem::memory_and_swap_limit_in_bytes(julong upper_mem_bound, julong upper_swap_bound) {
843-
return memory_controller()->controller()->memory_and_swap_limit_in_bytes(upper_mem_bound, upper_swap_bound);
854+
bool CgroupSubsystem::memory_and_swap_limit_in_bytes(physical_memory_size_type upper_mem_bound,
855+
physical_memory_size_type upper_swap_bound,
856+
physical_memory_size_type& value) {
857+
return memory_controller()->controller()->memory_and_swap_limit_in_bytes(upper_mem_bound,
858+
upper_swap_bound,
859+
value);
844860
}
845861

846-
jlong CgroupSubsystem::memory_and_swap_usage_in_bytes(julong upper_mem_bound, julong upper_swap_bound) {
847-
return memory_controller()->controller()->memory_and_swap_usage_in_bytes(upper_mem_bound, upper_swap_bound);
862+
bool CgroupSubsystem::memory_and_swap_usage_in_bytes(physical_memory_size_type upper_mem_bound,
863+
physical_memory_size_type upper_swap_bound,
864+
physical_memory_size_type& value) {
865+
return memory_controller()->controller()->memory_and_swap_usage_in_bytes(upper_mem_bound,
866+
upper_swap_bound,
867+
value);
848868
}
849869

850-
jlong CgroupSubsystem::memory_soft_limit_in_bytes(julong upper_bound) {
851-
return memory_controller()->controller()->memory_soft_limit_in_bytes(upper_bound);
870+
bool CgroupSubsystem::memory_soft_limit_in_bytes(physical_memory_size_type upper_bound,
871+
physical_memory_size_type& value) {
872+
return memory_controller()->controller()->memory_soft_limit_in_bytes(upper_bound, value);
852873
}
853874

854-
jlong CgroupSubsystem::memory_throttle_limit_in_bytes() {
855-
return memory_controller()->controller()->memory_throttle_limit_in_bytes();
875+
bool CgroupSubsystem::memory_throttle_limit_in_bytes(physical_memory_size_type& value) {
876+
return memory_controller()->controller()->memory_throttle_limit_in_bytes(value);
856877
}
857878

858-
jlong CgroupSubsystem::memory_usage_in_bytes() {
859-
return memory_controller()->controller()->memory_usage_in_bytes();
879+
bool CgroupSubsystem::memory_usage_in_bytes(physical_memory_size_type& value) {
880+
return memory_controller()->controller()->memory_usage_in_bytes(value);
860881
}
861882

862-
jlong CgroupSubsystem::memory_max_usage_in_bytes() {
863-
return memory_controller()->controller()->memory_max_usage_in_bytes();
883+
bool CgroupSubsystem::memory_max_usage_in_bytes(physical_memory_size_type& value) {
884+
return memory_controller()->controller()->memory_max_usage_in_bytes(value);
864885
}
865886

866-
jlong CgroupSubsystem::rss_usage_in_bytes() {
867-
return memory_controller()->controller()->rss_usage_in_bytes();
887+
bool CgroupSubsystem::rss_usage_in_bytes(physical_memory_size_type& value) {
888+
return memory_controller()->controller()->rss_usage_in_bytes(value);
868889
}
869890

870-
jlong CgroupSubsystem::cache_usage_in_bytes() {
871-
return memory_controller()->controller()->cache_usage_in_bytes();
891+
bool CgroupSubsystem::cache_usage_in_bytes(physical_memory_size_type& value) {
892+
return memory_controller()->controller()->cache_usage_in_bytes(value);
872893
}
873894

874-
int CgroupSubsystem::cpu_quota() {
875-
return cpu_controller()->controller()->cpu_quota();
895+
bool CgroupSubsystem::cpu_quota(int& value) {
896+
return cpu_controller()->controller()->cpu_quota(value);
876897
}
877898

878-
int CgroupSubsystem::cpu_period() {
879-
return cpu_controller()->controller()->cpu_period();
899+
bool CgroupSubsystem::cpu_period(int& value) {
900+
return cpu_controller()->controller()->cpu_period(value);
880901
}
881902

882-
int CgroupSubsystem::cpu_shares() {
883-
return cpu_controller()->controller()->cpu_shares();
903+
bool CgroupSubsystem::cpu_shares(int& value) {
904+
return cpu_controller()->controller()->cpu_shares(value);
884905
}
885906

886-
jlong CgroupSubsystem::cpu_usage_in_micros() {
887-
return cpuacct_controller()->cpu_usage_in_micros();
907+
bool CgroupSubsystem::cpu_usage_in_micros(uint64_t& value) {
908+
return cpuacct_controller()->cpu_usage_in_micros(value);
888909
}
889910

890-
void CgroupSubsystem::print_version_specific_info(outputStream* st, julong upper_mem_bound) {
911+
void CgroupSubsystem::print_version_specific_info(outputStream* st, physical_memory_size_type upper_mem_bound) {
891912
memory_controller()->controller()->print_version_specific_info(st, upper_mem_bound);
892913
}

0 commit comments

Comments
 (0)