11/*
2- * Copyright (c) 2012, 2019 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2012, 2021 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -391,34 +391,41 @@ static julong divide_with_user_unit(Argument& memory_argument, julong value) {
391391 return value;
392392}
393393
394- template <typename Argument>
395- static void log_lower_than_min_value (Argument& memory_argument, julong min_value) {
394+ static const char higher_than_msg[] = " This value is higher than the maximum size limited " ;
395+ static const char lower_than_msg[] = " This value is lower than the minimum size required " ;
396+ template <typename Argument, bool lower>
397+ static void log_out_of_range_value (Argument& memory_argument, julong min_value) {
398+ const char * msg = lower ? lower_than_msg : higher_than_msg;
396399 if (memory_argument.value ()._size != memory_argument.value ()._val ) {
397400 // has multiplier
398401 log_error (arguments) (
399- " This value is lower than the minimum size required " JULONG_FORMAT " %c" ,
402+ " %s " JULONG_FORMAT " %c" , msg ,
400403 divide_with_user_unit (memory_argument, min_value),
401404 memory_argument.value ()._multiplier );
402405 return ;
403406 }
404407 log_error (arguments) (
405- " This value is lower than the minimum size required " JULONG_FORMAT,
408+ " %s " JULONG_FORMAT, msg ,
406409 divide_with_user_unit (memory_argument, min_value));
407410}
408411
412+ static const char default_val_msg[] = " Value default for option " ;
413+ static const char specified_val_msg[] = " Value specified for option " ;
409414template <typename Argument>
410415static void log_set_value (Argument& memory_argument) {
411416 if (memory_argument.value ()._size != memory_argument.value ()._val ) {
412417 // has multiplier
413418 log_error (arguments) (
414- " Value specified for option \" %s\" is " JULONG_FORMAT " %c" ,
419+ " %s\" %s\" is " JULONG_FORMAT " %c" ,
420+ memory_argument.is_set () ? specified_val_msg: default_val_msg,
415421 memory_argument.name (),
416422 memory_argument.value ()._val ,
417423 memory_argument.value ()._multiplier );
418424 return ;
419425 }
420426 log_error (arguments) (
421- " Value specified for option \" %s\" is " JULONG_FORMAT,
427+ " %s\" %s\" is " JULONG_FORMAT,
428+ memory_argument.is_set () ? specified_val_msg: default_val_msg,
422429 memory_argument.name (), memory_argument.value ()._val );
423430}
424431
@@ -539,6 +546,10 @@ static bool valid_memory_relations(const JfrMemoryOptions& options) {
539546 return false ;
540547 }
541548 }
549+ } else if (options.thread_buffer_size_configured && options.memory_size_configured ) {
550+ if (!ensure_first_gteq_second (_dcmd_memorysize, _dcmd_threadbuffersize)) {
551+ return false ;
552+ }
542553 }
543554 return true ;
544555}
@@ -607,7 +618,7 @@ template <typename Argument>
607618static bool ensure_gteq (Argument& memory_argument, const jlong value) {
608619 if ((jlong)memory_argument.value ()._size < value) {
609620 log_set_value (memory_argument);
610- log_lower_than_min_value (memory_argument, value);
621+ log_out_of_range_value<Argument, true > (memory_argument, value);
611622 return false ;
612623 }
613624 return true ;
@@ -638,14 +649,38 @@ static bool ensure_valid_minimum_sizes() {
638649 return true ;
639650}
640651
652+ template <typename Argument>
653+ static bool ensure_lteq (Argument& memory_argument, const jlong value) {
654+ if ((jlong)memory_argument.value ()._size > value) {
655+ log_set_value (memory_argument);
656+ log_out_of_range_value<Argument, false >(memory_argument, value);
657+ return false ;
658+ }
659+ return true ;
660+ }
661+
662+ static bool ensure_valid_maximum_sizes () {
663+ if (_dcmd_globalbuffersize.is_set ()) {
664+ if (!ensure_lteq (_dcmd_globalbuffersize, MAX_GLOBAL_BUFFER_SIZE)) {
665+ return false ;
666+ }
667+ }
668+ if (_dcmd_threadbuffersize.is_set ()) {
669+ if (!ensure_lteq (_dcmd_threadbuffersize, MAX_THREAD_BUFFER_SIZE)) {
670+ return false ;
671+ }
672+ }
673+ return true ;
674+ }
675+
641676/* *
642677 * Starting with the initial set of memory values from the user,
643678 * sanitize, enforce min/max rules and adjust to a set of consistent options.
644679 *
645680 * Adjusted memory sizes will be page aligned.
646681 */
647682bool JfrOptionSet::adjust_memory_options () {
648- if (!ensure_valid_minimum_sizes ()) {
683+ if (!ensure_valid_minimum_sizes () || ! ensure_valid_maximum_sizes () ) {
649684 return false ;
650685 }
651686 JfrMemoryOptions options;
@@ -654,6 +689,24 @@ bool JfrOptionSet::adjust_memory_options() {
654689 return false ;
655690 }
656691 if (!JfrMemorySizer::adjust_options (&options)) {
692+ if (options.buffer_count < MIN_BUFFER_COUNT || options.global_buffer_size < options.thread_buffer_size ) {
693+ log_set_value (_dcmd_memorysize);
694+ log_set_value (_dcmd_globalbuffersize);
695+ log_error (arguments) (" %s \" %s\" is " JLONG_FORMAT,
696+ _dcmd_numglobalbuffers.is_set () ? specified_val_msg: default_val_msg,
697+ _dcmd_numglobalbuffers.name (), _dcmd_numglobalbuffers.value ());
698+ log_set_value (_dcmd_threadbuffersize);
699+ if (options.buffer_count < MIN_BUFFER_COUNT) {
700+ log_error (arguments) (" numglobalbuffers " JULONG_FORMAT " is less than minimal value " JULONG_FORMAT,
701+ options.buffer_count , MIN_BUFFER_COUNT);
702+ log_error (arguments) (" Decrease globalbuffersize/threadbuffersize or increase memorysize" );
703+ } else {
704+ log_error (arguments) (" globalbuffersize " JULONG_FORMAT " is less than threadbuffersize" JULONG_FORMAT,
705+ options.global_buffer_size , options.thread_buffer_size );
706+ log_error (arguments) (" Decrease globalbuffersize or increase memorysize or adjust global/threadbuffersize" );
707+ }
708+ return false ;
709+ }
657710 if (!check_for_ambiguity (_dcmd_memorysize, _dcmd_globalbuffersize, _dcmd_numglobalbuffers)) {
658711 return false ;
659712 }
0 commit comments