src/share/vm/runtime/arguments.cpp

changeset 9413
5aa3d728164a
parent 9348
cb9634ab2906
child 9358
6a4a6c499e89
     1.1 --- a/src/share/vm/runtime/arguments.cpp	Tue Jul 10 18:31:51 2018 +0100
     1.2 +++ b/src/share/vm/runtime/arguments.cpp	Fri Jul 06 18:50:13 2018 +0000
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -1801,20 +1801,34 @@
    1.11      }
    1.12    }
    1.13  
    1.14 +  // Convert Fraction to Precentage values
    1.15 +  if (FLAG_IS_DEFAULT(MaxRAMPercentage) &&
    1.16 +      !FLAG_IS_DEFAULT(MaxRAMFraction))
    1.17 +    MaxRAMPercentage = 100.0 / MaxRAMFraction;
    1.18 +
    1.19 +   if (FLAG_IS_DEFAULT(MinRAMPercentage) &&
    1.20 +       !FLAG_IS_DEFAULT(MinRAMFraction))
    1.21 +     MinRAMPercentage = 100.0 / MinRAMFraction;
    1.22 +
    1.23 +   if (FLAG_IS_DEFAULT(InitialRAMPercentage) &&
    1.24 +       !FLAG_IS_DEFAULT(InitialRAMFraction))
    1.25 +     InitialRAMPercentage = 100.0 / InitialRAMFraction;
    1.26 +
    1.27    // If the maximum heap size has not been set with -Xmx,
    1.28    // then set it as fraction of the size of physical memory,
    1.29    // respecting the maximum and minimum sizes of the heap.
    1.30    if (FLAG_IS_DEFAULT(MaxHeapSize)) {
    1.31 -    julong reasonable_max = phys_mem / MaxRAMFraction;
    1.32 -
    1.33 -    if (phys_mem <= MaxHeapSize * MinRAMFraction) {
    1.34 +    julong reasonable_max = (julong)((phys_mem * MaxRAMPercentage) / 100);
    1.35 +    const julong reasonable_min = (julong)((phys_mem * MinRAMPercentage) / 100);
    1.36 +    if (reasonable_min < MaxHeapSize) {
    1.37        // Small physical memory, so use a minimum fraction of it for the heap
    1.38 -      reasonable_max = phys_mem / MinRAMFraction;
    1.39 +      reasonable_max = reasonable_min;
    1.40      } else {
    1.41        // Not-small physical memory, so require a heap at least
    1.42        // as large as MaxHeapSize
    1.43        reasonable_max = MAX2(reasonable_max, (julong)MaxHeapSize);
    1.44      }
    1.45 +
    1.46      if (!FLAG_IS_DEFAULT(ErgoHeapSizeLimit) && ErgoHeapSizeLimit != 0) {
    1.47        // Limit the heap size to ErgoHeapSizeLimit
    1.48        reasonable_max = MIN2(reasonable_max, (julong)ErgoHeapSizeLimit);
    1.49 @@ -1856,7 +1870,7 @@
    1.50      reasonable_minimum = limit_by_allocatable_memory(reasonable_minimum);
    1.51  
    1.52      if (InitialHeapSize == 0) {
    1.53 -      julong reasonable_initial = phys_mem / InitialRAMFraction;
    1.54 +      julong reasonable_initial = (julong)((phys_mem * InitialRAMPercentage) / 100);
    1.55  
    1.56        reasonable_initial = MAX3(reasonable_initial, reasonable_minimum, (julong)min_heap_size());
    1.57        reasonable_initial = MIN2(reasonable_initial, (julong)MaxHeapSize);
    1.58 @@ -1881,6 +1895,94 @@
    1.59    }
    1.60  }
    1.61  
    1.62 +// This option inspects the machine and attempts to set various
    1.63 +// parameters to be optimal for long-running, memory allocation
    1.64 +// intensive jobs.  It is intended for machines with large
    1.65 +// amounts of cpu and memory.
    1.66 +jint Arguments::set_aggressive_heap_flags() {
    1.67 +  // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
    1.68 +  // VM, but we may not be able to represent the total physical memory
    1.69 +  // available (like having 8gb of memory on a box but using a 32bit VM).
    1.70 +  // Thus, we need to make sure we're using a julong for intermediate
    1.71 +  // calculations.
    1.72 +  julong initHeapSize;
    1.73 +  julong total_memory = os::physical_memory();
    1.74 +
    1.75 +  if (total_memory < (julong) 256 * M) {
    1.76 +    jio_fprintf(defaultStream::error_stream(),
    1.77 +            "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
    1.78 +    vm_exit(1);
    1.79 +  }
    1.80 +
    1.81 +  // The heap size is half of available memory, or (at most)
    1.82 +  // all of possible memory less 160mb (leaving room for the OS
    1.83 +  // when using ISM).  This is the maximum; because adaptive sizing
    1.84 +  // is turned on below, the actual space used may be smaller.
    1.85 +
    1.86 +  initHeapSize = MIN2(total_memory / (julong) 2,
    1.87 +                      total_memory - (julong) 160 * M);
    1.88 +
    1.89 +  initHeapSize = limit_by_allocatable_memory(initHeapSize);
    1.90 +
    1.91 +  if (FLAG_IS_DEFAULT(MaxHeapSize)) {
    1.92 +    FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize);
    1.93 +    FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize);
    1.94 +    // Currently the minimum size and the initial heap sizes are the same.
    1.95 +    set_min_heap_size(initHeapSize);
    1.96 +  }
    1.97 +  if (FLAG_IS_DEFAULT(NewSize)) {
    1.98 +    // Make the young generation 3/8ths of the total heap.
    1.99 +    FLAG_SET_CMDLINE(uintx, NewSize,
   1.100 +            ((julong) MaxHeapSize / (julong) 8) * (julong) 3);
   1.101 +    FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
   1.102 +  }
   1.103 +
   1.104 +#ifndef _ALLBSD_SOURCE  // UseLargePages is not yet supported on BSD.
   1.105 +  FLAG_SET_DEFAULT(UseLargePages, true);
   1.106 +#endif
   1.107 +
   1.108 +  // Increase some data structure sizes for efficiency
   1.109 +  FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
   1.110 +  FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
   1.111 +  FLAG_SET_CMDLINE(uintx, TLABSize, 256 * K);
   1.112 +
   1.113 +  // See the OldPLABSize comment below, but replace 'after promotion'
   1.114 +  // with 'after copying'.  YoungPLABSize is the size of the survivor
   1.115 +  // space per-gc-thread buffers.  The default is 4kw.
   1.116 +  FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256 * K);     // Note: this is in words
   1.117 +
   1.118 +  // OldPLABSize is the size of the buffers in the old gen that
   1.119 +  // UseParallelGC uses to promote live data that doesn't fit in the
   1.120 +  // survivor spaces.  At any given time, there's one for each gc thread.
   1.121 +  // The default size is 1kw. These buffers are rarely used, since the
   1.122 +  // survivor spaces are usually big enough.  For specjbb, however, there
   1.123 +  // are occasions when there's lots of live data in the young gen
   1.124 +  // and we end up promoting some of it.  We don't have a definite
   1.125 +  // explanation for why bumping OldPLABSize helps, but the theory
   1.126 +  // is that a bigger PLAB results in retaining something like the
   1.127 +  // original allocation order after promotion, which improves mutator
   1.128 +  // locality.  A minor effect may be that larger PLABs reduce the
   1.129 +  // number of PLAB allocation events during gc.  The value of 8kw
   1.130 +  // was arrived at by experimenting with specjbb.
   1.131 +  FLAG_SET_CMDLINE(uintx, OldPLABSize, 8 * K);      // Note: this is in words
   1.132 +
   1.133 +  // Enable parallel GC and adaptive generation sizing
   1.134 +  FLAG_SET_CMDLINE(bool, UseParallelGC, true);
   1.135 +
   1.136 +  // Encourage steady state memory management
   1.137 +  FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
   1.138 +
   1.139 +  // This appears to improve mutator locality
   1.140 +  FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
   1.141 +
   1.142 +  // Get around early Solaris scheduling bug
   1.143 +  // (affinity vs other jobs on system)
   1.144 +  // but disallow DR and offlining (5008695).
   1.145 +  FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
   1.146 +
   1.147 +  return JNI_OK;
   1.148 +}
   1.149 +
   1.150  // This must be called after ergonomics because we want bytecode rewriting
   1.151  // if the server compiler is used, or if UseSharedSpaces is disabled.
   1.152  void Arguments::set_bytecode_flags() {
   1.153 @@ -2644,6 +2746,14 @@
   1.154      return result;
   1.155    }
   1.156  
   1.157 +  // We need to ensure processor and memory resources have been properly
   1.158 +  // configured - which may rely on arguments we just processed - before
   1.159 +  // doing the final argument processing. Any argument processing that
   1.160 +  // needs to know about processor and memory resources must occur after
   1.161 +  // this point.
   1.162 +
   1.163 +  os::init_container_support();
   1.164 +
   1.165    // Do final processing now that all arguments have been parsed
   1.166    result = finalize_vm_init_args(&scp, scp_assembly_required);
   1.167    if (result != JNI_OK) {
   1.168 @@ -3117,94 +3227,6 @@
   1.169        _exit_hook = CAST_TO_FN_PTR(exit_hook_t, option->extraInfo);
   1.170      } else if (match_option(option, "abort", &tail)) {
   1.171        _abort_hook = CAST_TO_FN_PTR(abort_hook_t, option->extraInfo);
   1.172 -    // -XX:+AggressiveHeap
   1.173 -    } else if (match_option(option, "-XX:+AggressiveHeap", &tail)) {
   1.174 -
   1.175 -      // This option inspects the machine and attempts to set various
   1.176 -      // parameters to be optimal for long-running, memory allocation
   1.177 -      // intensive jobs.  It is intended for machines with large
   1.178 -      // amounts of cpu and memory.
   1.179 -
   1.180 -      // initHeapSize is needed since _initial_heap_size is 4 bytes on a 32 bit
   1.181 -      // VM, but we may not be able to represent the total physical memory
   1.182 -      // available (like having 8gb of memory on a box but using a 32bit VM).
   1.183 -      // Thus, we need to make sure we're using a julong for intermediate
   1.184 -      // calculations.
   1.185 -      julong initHeapSize;
   1.186 -      julong total_memory = os::physical_memory();
   1.187 -
   1.188 -      if (total_memory < (julong)256*M) {
   1.189 -        jio_fprintf(defaultStream::error_stream(),
   1.190 -                    "You need at least 256mb of memory to use -XX:+AggressiveHeap\n");
   1.191 -        vm_exit(1);
   1.192 -      }
   1.193 -
   1.194 -      // The heap size is half of available memory, or (at most)
   1.195 -      // all of possible memory less 160mb (leaving room for the OS
   1.196 -      // when using ISM).  This is the maximum; because adaptive sizing
   1.197 -      // is turned on below, the actual space used may be smaller.
   1.198 -
   1.199 -      initHeapSize = MIN2(total_memory / (julong)2,
   1.200 -                          total_memory - (julong)160*M);
   1.201 -
   1.202 -      initHeapSize = limit_by_allocatable_memory(initHeapSize);
   1.203 -
   1.204 -      if (FLAG_IS_DEFAULT(MaxHeapSize)) {
   1.205 -         FLAG_SET_CMDLINE(uintx, MaxHeapSize, initHeapSize);
   1.206 -         FLAG_SET_CMDLINE(uintx, InitialHeapSize, initHeapSize);
   1.207 -         // Currently the minimum size and the initial heap sizes are the same.
   1.208 -         set_min_heap_size(initHeapSize);
   1.209 -      }
   1.210 -      if (FLAG_IS_DEFAULT(NewSize)) {
   1.211 -         // Make the young generation 3/8ths of the total heap.
   1.212 -         FLAG_SET_CMDLINE(uintx, NewSize,
   1.213 -                                ((julong)MaxHeapSize / (julong)8) * (julong)3);
   1.214 -         FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
   1.215 -      }
   1.216 -
   1.217 -#ifndef _ALLBSD_SOURCE  // UseLargePages is not yet supported on BSD.
   1.218 -      FLAG_SET_DEFAULT(UseLargePages, true);
   1.219 -#endif
   1.220 -
   1.221 -      // Increase some data structure sizes for efficiency
   1.222 -      FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
   1.223 -      FLAG_SET_CMDLINE(bool, ResizeTLAB, false);
   1.224 -      FLAG_SET_CMDLINE(uintx, TLABSize, 256*K);
   1.225 -
   1.226 -      // See the OldPLABSize comment below, but replace 'after promotion'
   1.227 -      // with 'after copying'.  YoungPLABSize is the size of the survivor
   1.228 -      // space per-gc-thread buffers.  The default is 4kw.
   1.229 -      FLAG_SET_CMDLINE(uintx, YoungPLABSize, 256*K);      // Note: this is in words
   1.230 -
   1.231 -      // OldPLABSize is the size of the buffers in the old gen that
   1.232 -      // UseParallelGC uses to promote live data that doesn't fit in the
   1.233 -      // survivor spaces.  At any given time, there's one for each gc thread.
   1.234 -      // The default size is 1kw. These buffers are rarely used, since the
   1.235 -      // survivor spaces are usually big enough.  For specjbb, however, there
   1.236 -      // are occasions when there's lots of live data in the young gen
   1.237 -      // and we end up promoting some of it.  We don't have a definite
   1.238 -      // explanation for why bumping OldPLABSize helps, but the theory
   1.239 -      // is that a bigger PLAB results in retaining something like the
   1.240 -      // original allocation order after promotion, which improves mutator
   1.241 -      // locality.  A minor effect may be that larger PLABs reduce the
   1.242 -      // number of PLAB allocation events during gc.  The value of 8kw
   1.243 -      // was arrived at by experimenting with specjbb.
   1.244 -      FLAG_SET_CMDLINE(uintx, OldPLABSize, 8*K);  // Note: this is in words
   1.245 -
   1.246 -      // Enable parallel GC and adaptive generation sizing
   1.247 -      FLAG_SET_CMDLINE(bool, UseParallelGC, true);
   1.248 -
   1.249 -      // Encourage steady state memory management
   1.250 -      FLAG_SET_CMDLINE(uintx, ThresholdTolerance, 100);
   1.251 -
   1.252 -      // This appears to improve mutator locality
   1.253 -      FLAG_SET_CMDLINE(bool, ScavengeBeforeFullGC, false);
   1.254 -
   1.255 -      // Get around early Solaris scheduling bug
   1.256 -      // (affinity vs other jobs on system)
   1.257 -      // but disallow DR and offlining (5008695).
   1.258 -      FLAG_SET_CMDLINE(bool, BindGCTaskThreadsToCPUs, true);
   1.259 -
   1.260      } else if (match_option(option, "-XX:+NeverTenure", &tail)) {
   1.261        // The last option must always win.
   1.262        FLAG_SET_CMDLINE(bool, AlwaysTenure, false);
   1.263 @@ -3605,6 +3627,15 @@
   1.264      return JNI_ERR;
   1.265    }
   1.266  
   1.267 +  // This must be done after all arguments have been processed
   1.268 +  // and the container support has been initialized since AggressiveHeap
   1.269 +  // relies on the amount of total memory available.
   1.270 +  if (AggressiveHeap) {
   1.271 +    jint result = set_aggressive_heap_flags();
   1.272 +    if (result != JNI_OK) {
   1.273 +      return result;
   1.274 +    }
   1.275 +  }
   1.276    // This must be done after all arguments have been processed.
   1.277    // java_compiler() true means set to "NONE" or empty.
   1.278    if (java_compiler() && !xdebug_mode()) {

mercurial