1 /* 2 * Copyright (c) 2018, 2019, 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 25 #ifndef SHARE_MEMORY_METASPACE_METASPACEGC_HPP 26 #define SHARE_MEMORY_METASPACE_METASPACEGC_HPP 27 28 #include "memory/allocation.hpp" 29 #include "utilities/globalDefinitions.hpp" 30 31 namespace metaspace { 32 33 // Metaspace are deallocated when their class loader are GC'ed. 34 // This class implements a policy for inducing GC's to recover 35 // Metaspaces. 36 37 class MetaspaceGC : public AllStatic { 38 39 // The current high-water-mark for inducing a GC. 40 // When committed memory of all metaspaces reaches this value, 41 // a GC is induced and the value is increased. Size is in bytes. 42 static volatile size_t _capacity_until_GC; 43 44 // For a CMS collection, signal that a concurrent collection should 45 // be started. 46 static bool _should_concurrent_collect; 47 48 static uint _shrink_factor; 49 50 static size_t shrink_factor() { return _shrink_factor; } 51 void set_shrink_factor(uint v) { _shrink_factor = v; } 52 53 public: 54 55 static void initialize(); 56 static void post_initialize(); 57 58 static size_t capacity_until_GC(); 59 static bool inc_capacity_until_GC(size_t v, 60 size_t* new_cap_until_GC = NULL, 61 size_t* old_cap_until_GC = NULL, 62 bool* can_retry = NULL); 63 static size_t dec_capacity_until_GC(size_t v); 64 65 static bool should_concurrent_collect() { return _should_concurrent_collect; } 66 static void set_should_concurrent_collect(bool v) { 67 _should_concurrent_collect = v; 68 } 69 70 // The amount to increase the high-water-mark (_capacity_until_GC) 71 static size_t delta_capacity_until_GC(size_t bytes); 72 73 // Tells if we have can expand metaspace without hitting set limits. 74 static bool can_expand(size_t words, bool is_class); 75 76 // Returns amount that we can expand without hitting a GC, 77 // measured in words. 78 static size_t allowed_expansion(); 79 80 // Calculate the new high-water mark at which to induce 81 // a GC. 82 static void compute_new_size(); 83 }; 84 85 } // namespace metaspace 86 87 #endif // SHARE_MEMORY_METASPACE_METASPACEGC_HPP