| 1 | /* |
| 2 | * Copyright (c) 2015, 2018, 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_ZOBJECTALLOCATOR_HPP |
| 25 | #define SHARE_GC_Z_ZOBJECTALLOCATOR_HPP |
| 26 | |
| 27 | #include "gc/z/zAllocationFlags.hpp" |
| 28 | #include "gc/z/zPage.hpp" |
| 29 | #include "gc/z/zValue.hpp" |
| 30 | #include "memory/allocation.hpp" |
| 31 | |
| 32 | class ZObjectAllocator { |
| 33 | private: |
| 34 | const uint _nworkers; |
| 35 | ZPerCPU<size_t> _used; |
| 36 | ZContended<ZPage*> _shared_medium_page; |
| 37 | ZPerCPU<ZPage*> _shared_small_page; |
| 38 | ZPerWorker<ZPage*> _worker_small_page; |
| 39 | |
| 40 | ZPage* alloc_page(uint8_t type, size_t size, ZAllocationFlags flags); |
| 41 | |
| 42 | // Allocate an object in a shared page. Allocate and |
| 43 | // atomically install a new page if necessary. |
| 44 | uintptr_t alloc_object_in_shared_page(ZPage** shared_page, |
| 45 | uint8_t page_type, |
| 46 | size_t page_size, |
| 47 | size_t size, |
| 48 | ZAllocationFlags flags); |
| 49 | |
| 50 | uintptr_t alloc_large_object(size_t size, ZAllocationFlags flags); |
| 51 | uintptr_t alloc_medium_object(size_t size, ZAllocationFlags flags); |
| 52 | uintptr_t alloc_small_object_from_nonworker(size_t size, ZAllocationFlags flags); |
| 53 | uintptr_t alloc_small_object_from_worker(size_t size, ZAllocationFlags flags); |
| 54 | uintptr_t alloc_small_object(size_t size, ZAllocationFlags flags); |
| 55 | uintptr_t alloc_object(size_t size, ZAllocationFlags flags); |
| 56 | |
| 57 | bool undo_alloc_large_object(ZPage* page); |
| 58 | bool undo_alloc_medium_object(ZPage* page, uintptr_t addr, size_t size); |
| 59 | bool undo_alloc_small_object_from_nonworker(ZPage* page, uintptr_t addr, size_t size); |
| 60 | bool undo_alloc_small_object_from_worker(ZPage* page, uintptr_t addr, size_t size); |
| 61 | bool undo_alloc_small_object(ZPage* page, uintptr_t addr, size_t size); |
| 62 | bool undo_alloc_object(ZPage* page, uintptr_t addr, size_t size); |
| 63 | |
| 64 | public: |
| 65 | ZObjectAllocator(uint nworkers); |
| 66 | |
| 67 | uintptr_t alloc_object(size_t size); |
| 68 | |
| 69 | uintptr_t alloc_object_for_relocation(size_t size); |
| 70 | void undo_alloc_object_for_relocation(ZPage* page, uintptr_t addr, size_t size); |
| 71 | |
| 72 | size_t used() const; |
| 73 | size_t remaining() const; |
| 74 | |
| 75 | void retire_pages(); |
| 76 | }; |
| 77 | |
| 78 | #endif // SHARE_GC_Z_ZOBJECTALLOCATOR_HPP |
| 79 | |