1 /*
  2  * Copyright (c) 2017, 2020, 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/zHeuristics.hpp"
 29 #include "gc/shared/gcArguments.hpp"
 30 #include "runtime/globals.hpp"
 31 #include "runtime/globals_extension.hpp"
 32 
 33 void ZArguments::initialize_alignments() {
 34   SpaceAlignment = ZGranuleSize;
 35   HeapAlignment = SpaceAlignment;
 36 }
 37 
 38 void ZArguments::initialize() {
 39   GCArguments::initialize();
 40 
 41   // Check mark stack size
 42   const size_t mark_stack_space_limit = ZAddressSpaceLimit::mark_stack();
 43   if (ZMarkStackSpaceLimit > mark_stack_space_limit) {
 44     if (!FLAG_IS_DEFAULT(ZMarkStackSpaceLimit)) {
 45       vm_exit_during_initialization("ZMarkStackSpaceLimit too large for limited address space");
 46     }
 47     FLAG_SET_DEFAULT(ZMarkStackSpaceLimit, mark_stack_space_limit);
 48   }
 49 
 50   // Enable NUMA by default
 51   if (FLAG_IS_DEFAULT(UseNUMA)) {
 52     FLAG_SET_DEFAULT(UseNUMA, true);
 53   }
 54 
 55   // Select number of parallel threads
 56   if (FLAG_IS_DEFAULT(ParallelGCThreads)) {
 57     FLAG_SET_DEFAULT(ParallelGCThreads, ZHeuristics::nparallel_workers());
 58   }
 59 
 60   if (ParallelGCThreads == 0) {
 61     vm_exit_during_initialization("The flag -XX:+UseZGC can not be combined with -XX:ParallelGCThreads=0");
 62   }
 63 
 64   // Select number of concurrent threads
 65   if (FLAG_IS_DEFAULT(ConcGCThreads)) {
 66     FLAG_SET_DEFAULT(ConcGCThreads, ZHeuristics::nconcurrent_workers());
 67   }
 68 
 69   if (ConcGCThreads == 0) {
 70     vm_exit_during_initialization("The flag -XX:+UseZGC can not be combined with -XX:ConcGCThreads=0");
 71   }
 72 
 73   // Select medium page size so that we can calculate the max reserve
 74   ZHeuristics::set_medium_page_size();
 75 
 76   // MinHeapSize/InitialHeapSize must be at least as large as the max reserve
 77   const size_t max_reserve = ZHeuristics::max_reserve();
 78   if (MinHeapSize < max_reserve) {
 79     FLAG_SET_ERGO(MinHeapSize, max_reserve);
 80   }
 81   if (InitialHeapSize < max_reserve) {
 82     FLAG_SET_ERGO(InitialHeapSize, max_reserve);
 83   }
 84 
 85 #ifdef COMPILER2
 86   // Enable loop strip mining by default
 87   if (FLAG_IS_DEFAULT(UseCountedLoopSafepoints)) {
 88     FLAG_SET_DEFAULT(UseCountedLoopSafepoints, true);
 89     if (FLAG_IS_DEFAULT(LoopStripMiningIter)) {
 90       FLAG_SET_DEFAULT(LoopStripMiningIter, 1000);
 91     }
 92   }
 93 #endif
 94 
 95   // CompressedOops not supported
 96   FLAG_SET_DEFAULT(UseCompressedOops, false);
 97 
 98   // Verification before startup and after exit not (yet) supported
 99   FLAG_SET_DEFAULT(VerifyDuringStartup, false);
100   FLAG_SET_DEFAULT(VerifyBeforeExit, false);
101 
102   // Verification before heap iteration not (yet) supported, for the
103   // same reason we need fixup_partial_loads
104   FLAG_SET_DEFAULT(VerifyBeforeIteration, false);
105 
106   if (VerifyBeforeGC || VerifyDuringGC || VerifyAfterGC) {
107     FLAG_SET_DEFAULT(ZVerifyRoots, true);
108     FLAG_SET_DEFAULT(ZVerifyObjects, true);
109   }
110 
111   // Verification of stacks not (yet) supported, for the same reason
112   // we need fixup_partial_loads
113   DEBUG_ONLY(FLAG_SET_DEFAULT(VerifyStack, false));
114 }
115 
116 size_t ZArguments::conservative_max_heap_alignment() {
117   return 0;
118 }
119 
120 CollectedHeap* ZArguments::create_heap() {
121   return new ZCollectedHeap();
122 }
123 
124 bool ZArguments::is_supported() const {
125   return is_os_supported();
126 }