11/*
2- * Copyright (c) 2012, 2020 , 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
@@ -393,34 +393,40 @@ static julong divide_with_user_unit(Argument& memory_argument, julong value) {
393393 return value;
394394}
395395
396- template <typename Argument>
397- static void log_lower_than_min_value (Argument& memory_argument, julong min_value) {
396+ static const char higher_than_msg[] = " This value is higher than the maximum size limited " ;
397+ static const char lower_than_msg[] = " This value is lower than the minimum size required " ;
398+ template <typename Argument, char const *msg>
399+ static void log_out_of_range_value (Argument& memory_argument, julong min_value) {
398400 if (memory_argument.value ()._size != memory_argument.value ()._val ) {
399401 // has multiplier
400402 log_error (arguments) (
401- " This value is lower than the minimum size required " JULONG_FORMAT " %c" ,
403+ " %s " JULONG_FORMAT " %c" , msg ,
402404 divide_with_user_unit (memory_argument, min_value),
403405 memory_argument.value ()._multiplier );
404406 return ;
405407 }
406408 log_error (arguments) (
407- " This value is lower than the minimum size required " JULONG_FORMAT,
409+ " %s " JULONG_FORMAT, msg ,
408410 divide_with_user_unit (memory_argument, min_value));
409411}
410412
413+ static const char default_val_msg[] = " Value default for option " ;
414+ static const char specified_val_msg[] = " Value specified for option " ;
411415template <typename Argument>
412416static void log_set_value (Argument& memory_argument) {
413417 if (memory_argument.value ()._size != memory_argument.value ()._val ) {
414418 // has multiplier
415419 log_error (arguments) (
416- " Value specified for option \" %s\" is " JULONG_FORMAT " %c" ,
420+ " %s\" %s\" is " JULONG_FORMAT " %c" ,
421+ memory_argument.is_set () ? specified_val_msg: default_val_msg,
417422 memory_argument.name (),
418423 memory_argument.value ()._val ,
419424 memory_argument.value ()._multiplier );
420425 return ;
421426 }
422427 log_error (arguments) (
423- " Value specified for option \" %s\" is " JULONG_FORMAT,
428+ " %s\" %s\" is " JULONG_FORMAT,
429+ memory_argument.is_set () ? specified_val_msg: default_val_msg,
424430 memory_argument.name (), memory_argument.value ()._val );
425431}
426432
@@ -541,6 +547,10 @@ static bool valid_memory_relations(const JfrMemoryOptions& options) {
541547 return false ;
542548 }
543549 }
550+ } else if (options.thread_buffer_size_configured && options.memory_size_configured ) {
551+ if (!ensure_first_gteq_second (_dcmd_memorysize, _dcmd_threadbuffersize)) {
552+ return false ;
553+ }
544554 }
545555 return true ;
546556}
@@ -609,7 +619,7 @@ template <typename Argument>
609619static bool ensure_gteq (Argument& memory_argument, const jlong value) {
610620 if ((jlong)memory_argument.value ()._size < value) {
611621 log_set_value (memory_argument);
612- log_lower_than_min_value (memory_argument, value);
622+ log_out_of_range_value<Argument, lower_than_msg> (memory_argument, value);
613623 return false ;
614624 }
615625 return true ;
@@ -640,14 +650,38 @@ static bool ensure_valid_minimum_sizes() {
640650 return true ;
641651}
642652
653+ template <typename Argument>
654+ static bool ensure_lteq (Argument& memory_argument, const jlong value) {
655+ if ((jlong)memory_argument.value ()._size > value) {
656+ log_set_value (memory_argument);
657+ log_out_of_range_value<Argument, higher_than_msg>(memory_argument, value);
658+ return false ;
659+ }
660+ return true ;
661+ }
662+
663+ static bool ensure_valid_maximum_sizes () {
664+ if (_dcmd_globalbuffersize.is_set ()) {
665+ if (!ensure_lteq (_dcmd_globalbuffersize, MAX_GLOBAL_BUFFER_SIZE)) {
666+ return false ;
667+ }
668+ }
669+ if (_dcmd_threadbuffersize.is_set ()) {
670+ if (!ensure_lteq (_dcmd_threadbuffersize, MAX_THREAD_BUFFER_SIZE)) {
671+ return false ;
672+ }
673+ }
674+ return true ;
675+ }
676+
643677/* *
644678 * Starting with the initial set of memory values from the user,
645679 * sanitize, enforce min/max rules and adjust to a set of consistent options.
646680 *
647681 * Adjusted memory sizes will be page aligned.
648682 */
649683bool JfrOptionSet::adjust_memory_options () {
650- if (!ensure_valid_minimum_sizes ()) {
684+ if (!ensure_valid_minimum_sizes () || ! ensure_valid_maximum_sizes () ) {
651685 return false ;
652686 }
653687 JfrMemoryOptions options;
@@ -656,6 +690,24 @@ bool JfrOptionSet::adjust_memory_options() {
656690 return false ;
657691 }
658692 if (!JfrMemorySizer::adjust_options (&options)) {
693+ if (options.buffer_count < MIN_BUFFER_COUNT || options.global_buffer_size < options.thread_buffer_size ) {
694+ log_set_value (_dcmd_memorysize);
695+ log_set_value (_dcmd_globalbuffersize);
696+ log_error (arguments) (" %s \" %s\" is " JLONG_FORMAT,
697+ _dcmd_numglobalbuffers.is_set () ? specified_val_msg: default_val_msg,
698+ _dcmd_numglobalbuffers.name (), _dcmd_numglobalbuffers.value ());
699+ log_set_value (_dcmd_threadbuffersize);
700+ if (options.buffer_count < MIN_BUFFER_COUNT) {
701+ log_error (arguments) (" numglobalbuffers " JULONG_FORMAT " is less than minimal value " JULONG_FORMAT,
702+ options.buffer_count , MIN_BUFFER_COUNT);
703+ log_error (arguments) (" Decrease globalbuffersize/threadbuffersize or increase memorysize" );
704+ } else {
705+ log_error (arguments) (" globalbuffersize " JULONG_FORMAT " is less than threadbuffersize" JULONG_FORMAT,
706+ options.global_buffer_size , options.thread_buffer_size );
707+ log_error (arguments) (" Decrease globalbuffersize or increase memorysize or adjust global/threadbuffersize" );
708+ }
709+ return false ;
710+ }
659711 if (!check_for_ambiguity (_dcmd_memorysize, _dcmd_globalbuffersize, _dcmd_numglobalbuffers)) {
660712 return false ;
661713 }
0 commit comments