| 1 | /* | 
|---|
| 2 | * Copyright (c) 2017, 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 | #ifndef SHARE_GC_Z_ZRELOCATIONSETSELECTOR_HPP | 
|---|
| 25 | #define SHARE_GC_Z_ZRELOCATIONSETSELECTOR_HPP | 
|---|
| 26 |  | 
|---|
| 27 | #include "gc/z/zArray.hpp" | 
|---|
| 28 | #include "memory/allocation.hpp" | 
|---|
| 29 |  | 
|---|
| 30 | class ZPage; | 
|---|
| 31 | class ZRelocationSet; | 
|---|
| 32 |  | 
|---|
| 33 | class ZRelocationSetSelectorGroup { | 
|---|
| 34 | private: | 
|---|
| 35 | const char* const _name; | 
|---|
| 36 | const size_t      _page_size; | 
|---|
| 37 | const size_t      _object_size_limit; | 
|---|
| 38 | const size_t      _fragmentation_limit; | 
|---|
| 39 |  | 
|---|
| 40 | ZArray<ZPage*>    _registered_pages; | 
|---|
| 41 | ZPage**           _sorted_pages; | 
|---|
| 42 | size_t            _nselected; | 
|---|
| 43 | size_t            _relocating; | 
|---|
| 44 | size_t            _fragmentation; | 
|---|
| 45 |  | 
|---|
| 46 | void semi_sort(); | 
|---|
| 47 |  | 
|---|
| 48 | public: | 
|---|
| 49 | ZRelocationSetSelectorGroup(const char* name, | 
|---|
| 50 | size_t page_size, | 
|---|
| 51 | size_t object_size_limit); | 
|---|
| 52 | ~ZRelocationSetSelectorGroup(); | 
|---|
| 53 |  | 
|---|
| 54 | void register_live_page(ZPage* page, size_t garbage); | 
|---|
| 55 | void select(); | 
|---|
| 56 |  | 
|---|
| 57 | ZPage* const* selected() const; | 
|---|
| 58 | size_t nselected() const; | 
|---|
| 59 | size_t relocating() const; | 
|---|
| 60 | size_t fragmentation() const; | 
|---|
| 61 | }; | 
|---|
| 62 |  | 
|---|
| 63 | class ZRelocationSetSelector : public StackObj { | 
|---|
| 64 | private: | 
|---|
| 65 | ZRelocationSetSelectorGroup _small; | 
|---|
| 66 | ZRelocationSetSelectorGroup _medium; | 
|---|
| 67 | size_t                      _live; | 
|---|
| 68 | size_t                      _garbage; | 
|---|
| 69 | size_t                      _fragmentation; | 
|---|
| 70 |  | 
|---|
| 71 | public: | 
|---|
| 72 | ZRelocationSetSelector(); | 
|---|
| 73 |  | 
|---|
| 74 | void register_live_page(ZPage* page); | 
|---|
| 75 | void register_garbage_page(ZPage* page); | 
|---|
| 76 | void select(ZRelocationSet* relocation_set); | 
|---|
| 77 |  | 
|---|
| 78 | size_t live() const; | 
|---|
| 79 | size_t garbage() const; | 
|---|
| 80 | size_t relocating() const; | 
|---|
| 81 | size_t fragmentation() const; | 
|---|
| 82 | }; | 
|---|
| 83 |  | 
|---|
| 84 | #endif // SHARE_GC_Z_ZRELOCATIONSETSELECTOR_HPP | 
|---|
| 85 |  | 
|---|