/* * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ #include "precompiled.hpp" #include "gc/z/zCPU.inline.hpp" #include "gc/z/zGlobals.hpp" #include "gc/z/zHeuristics.hpp" #include "gc/z/zUtils.inline.hpp" #include "logging/log.hpp" #include "runtime/globals.hpp" #include "runtime/os.hpp" void ZHeuristics::set_medium_page_size() { // Set ZPageSizeMedium so that a medium page occupies at most 3.125% of the // max heap size. ZPageSizeMedium is initially set to 0, which means medium // pages are effectively disabled. It is adjusted only if ZPageSizeMedium // becomes larger than ZPageSizeSmall. const size_t min = ZGranuleSize; const size_t max = ZGranuleSize * 16; const size_t unclamped = MaxHeapSize * 0.03125; const size_t clamped = MIN2(MAX2(min, unclamped), max); const size_t size = ZUtils::round_down_power_of_2(clamped); if (size > ZPageSizeSmall) { // Enable medium pages ZPageSizeMedium = size; ZPageSizeMediumShift = log2_intptr(ZPageSizeMedium); ZObjectSizeLimitMedium = ZPageSizeMedium / 8; ZObjectAlignmentMediumShift = ZPageSizeMediumShift - 13; ZObjectAlignmentMedium = 1 << ZObjectAlignmentMediumShift; log_info(gc, init)("Medium Page Size: " SIZE_FORMAT "M", ZPageSizeMedium / M); } else { log_info(gc, init)("Medium Page Size: N/A"); } } bool ZHeuristics::per_cpu_shared_small_page() { // Use per-CPU shared small pages only if these pages occupy at most 3.125% // of the max heap size. Otherwise fall back to using a single shared small // page. This is useful when using small heaps on large machines. const size_t per_cpu_share = (MaxHeapSize * 0.03125) / ZCPU::count(); return per_cpu_share >= ZPageSizeSmall; }