1 /*
  2  * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 #include "precompiled.hpp"
 25 #include "gc/z/zAddressSpaceLimit.hpp"
 26 #include "gc/z/zArguments.hpp"
 27 #include "gc/z/zCollectedHeap.hpp"
 28 #include "gc/z/zGlobals.hpp"
 29 #include "gc/z/zHeuristics.hpp"
 30 #include "gc/shared/gcArguments.hpp"
 31 #include "runtime/globals.hpp"
 32 #include "runtime/globals_extension.hpp"
 33 #include "runtime/java.hpp"
 34 
 35 void ZArguments::initialize_alignments() {
 36   SpaceAlignment = ZGranuleSize;
 37   HeapAlignment = SpaceAlignment;
 38 }
 39 
 40 void ZArguments::initialize() {
 41   GCArguments::initialize();
 42 
 43   // Check mark stack size
 44   const size_t mark_stack_space_limit = ZAddressSpaceLimit::mark_stack();
 45   if (ZMarkStackSpaceLimit > mark_stack_space_limit) {
 46     if (!FLAG_IS_DEFAULT(ZMarkStackSpaceLimit)) {
 47       vm_exit_during_initialization("ZMarkStackSpaceLimit too large for limited address space");
 48     }
 49     FLAG_SET_DEFAULT(ZMarkStackSpaceLimit, mark_stack_space_limit);
 50   }
 51 
 52   // Enable NUMA by default
 53   if (FLAG_IS_DEFAULT(UseNUMA)) {
 54     FLAG_SET_DEFAULT(UseNUMA, true);
 55   }
 56 
 57   // Select number of parallel threads
 58   if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 59     FLAG_SET_DEFAULT(ParallelGCThreads, ZHeuristics::nparallel_workers());
 60   }
 61 
 62   if (ParallelGCThreads == 0) {
 63     vm_exit_during_initialization("The flag -XX:+UseZGC can not be combined with -XX:ParallelGCThreads=0");
 64   }
 65 
 66   // Select number of concurrent threads
 67   if (FLAG_IS_DEFAULT(ConcGCThreads)) {
 68     FLAG_SET_DEFAULT(ConcGCThreads, ZHeuristics::nconcurrent_workers());
 69   }
 70 
 71   if (ConcGCThreads == 0) {
 72     vm_exit_during_initialization("The flag -XX:+UseZGC can not be combined with -XX:ConcGCThreads=0");
 73   }
 74 
 75   // Large page size must match granule size
 76   if (!FLAG_IS_DEFAULT(LargePageSizeInBytes) && LargePageSizeInBytes != ZGranuleSize) {
 77     vm_exit_during_initialization(err_msg("Incompatible -XX:LargePageSizeInBytes, only "
 78                                           SIZE_FORMAT "M large pages are supported by ZGC",
 79                                           ZGranuleSize / M));
 80   }
 81 
 82   // The heuristics used when UseDynamicNumberOfGCThreads is
 83   // enabled defaults to using a ZAllocationSpikeTolerance of 1.
 84   if (UseDynamicNumberOfGCThreads && FLAG_IS_DEFAULT(ZAllocationSpikeTolerance)) {
 85     FLAG_SET_DEFAULT(ZAllocationSpikeTolerance, 1);
 86   }
 87 
 88 #ifdef COMPILER2
 89   // Enable loop strip mining by default
 90   if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) {
 91     FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true);
 92     if (FLAG_IS_DEFAULT(LoopStripMiningIter)) {
 93       FLAG_SET_DEFAULT(LoopStripMiningIter, 1000);
 94     }
 95   }
 96 #endif
 97 
 98   // CompressedOops not supported
 99   FLAG_SET_DEFAULT(UseCompressedOops, false);
100 
101   // Verification before startup and after exit not (yet) supported
102   FLAG_SET_DEFAULT(VerifyDuringStartup, false);
103   FLAG_SET_DEFAULT(VerifyBeforeExit, false);
104 
105   if (VerifyBeforeGC || VerifyDuringGC || VerifyAfterGC) {
106     FLAG_SET_DEFAULT(ZVerifyRoots, true);
107     FLAG_SET_DEFAULT(ZVerifyObjects, true);
108   }
109 }
110 
111 size_t ZArguments::heap_virtual_to_physical_ratio() {
112   return ZHeapViews * ZVirtualToPhysicalRatio;
113 }
114 
115 size_t ZArguments::conservative_max_heap_alignment() {
116   return 0;
117 }
118 
119 CollectedHeap* ZArguments::create_heap() {
120   return new ZCollectedHeap();
121 }
122 
123 bool ZArguments::is_supported() const {
124   return is_os_supported();
125 }