src/hotspot/share/gc/z/zObjectAllocator.cpp
changeset 59149 3b998574be4b
parent 58706 d8e211419aaf
child 59247 56bf71d64d51
equal deleted inserted replaced
59148:877c000fd688 59149:3b998574be4b
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    23 
    23 
    24 #include "precompiled.hpp"
    24 #include "precompiled.hpp"
    25 #include "gc/z/zCollectedHeap.hpp"
    25 #include "gc/z/zCollectedHeap.hpp"
    26 #include "gc/z/zGlobals.hpp"
    26 #include "gc/z/zGlobals.hpp"
    27 #include "gc/z/zHeap.inline.hpp"
    27 #include "gc/z/zHeap.inline.hpp"
       
    28 #include "gc/z/zHeuristics.hpp"
    28 #include "gc/z/zObjectAllocator.hpp"
    29 #include "gc/z/zObjectAllocator.hpp"
    29 #include "gc/z/zPage.inline.hpp"
    30 #include "gc/z/zPage.inline.hpp"
    30 #include "gc/z/zStat.hpp"
    31 #include "gc/z/zStat.hpp"
    31 #include "gc/z/zThread.inline.hpp"
    32 #include "gc/z/zThread.inline.hpp"
    32 #include "gc/z/zUtils.inline.hpp"
    33 #include "gc/z/zUtils.inline.hpp"
    41 
    42 
    42 static const ZStatCounter ZCounterUndoObjectAllocationSucceeded("Memory", "Undo Object Allocation Succeeded", ZStatUnitOpsPerSecond);
    43 static const ZStatCounter ZCounterUndoObjectAllocationSucceeded("Memory", "Undo Object Allocation Succeeded", ZStatUnitOpsPerSecond);
    43 static const ZStatCounter ZCounterUndoObjectAllocationFailed("Memory", "Undo Object Allocation Failed", ZStatUnitOpsPerSecond);
    44 static const ZStatCounter ZCounterUndoObjectAllocationFailed("Memory", "Undo Object Allocation Failed", ZStatUnitOpsPerSecond);
    44 
    45 
    45 ZObjectAllocator::ZObjectAllocator() :
    46 ZObjectAllocator::ZObjectAllocator() :
       
    47     _use_per_cpu_shared_small_pages(ZHeuristics::use_per_cpu_shared_small_pages()),
    46     _used(0),
    48     _used(0),
    47     _undone(0),
    49     _undone(0),
    48     _shared_medium_page(NULL),
    50     _shared_medium_page(NULL),
    49     _shared_small_page(NULL),
    51     _shared_small_page(NULL),
    50     _worker_small_page(NULL) {}
    52     _worker_small_page(NULL) {}
       
    53 
       
    54 ZPage** ZObjectAllocator::shared_small_page_addr() {
       
    55   return _use_per_cpu_shared_small_pages ? _shared_small_page.addr() : _shared_small_page.addr(0);
       
    56 }
       
    57 
       
    58 ZPage* const* ZObjectAllocator::shared_small_page_addr() const {
       
    59   return _use_per_cpu_shared_small_pages ? _shared_small_page.addr() : _shared_small_page.addr(0);
       
    60 }
    51 
    61 
    52 ZPage* ZObjectAllocator::alloc_page(uint8_t type, size_t size, ZAllocationFlags flags) {
    62 ZPage* ZObjectAllocator::alloc_page(uint8_t type, size_t size, ZAllocationFlags flags) {
    53   ZPage* const page = ZHeap::heap()->alloc_page(type, size, flags);
    63   ZPage* const page = ZHeap::heap()->alloc_page(type, size, flags);
    54   if (page != NULL) {
    64   if (page != NULL) {
    55     // Increment used bytes
    65     // Increment used bytes
    70                                                         uint8_t page_type,
    80                                                         uint8_t page_type,
    71                                                         size_t page_size,
    81                                                         size_t page_size,
    72                                                         size_t size,
    82                                                         size_t size,
    73                                                         ZAllocationFlags flags) {
    83                                                         ZAllocationFlags flags) {
    74   uintptr_t addr = 0;
    84   uintptr_t addr = 0;
    75   ZPage* page = *shared_page;
    85   ZPage* page = OrderAccess::load_acquire(shared_page);
    76 
    86 
    77   if (page != NULL) {
    87   if (page != NULL) {
    78     addr = page->alloc_object_atomic(size);
    88     addr = page->alloc_object_atomic(size);
    79   }
    89   }
    80 
    90 
   140          "Should be a Java, VM or Runtime worker thread");
   150          "Should be a Java, VM or Runtime worker thread");
   141 
   151 
   142   // Non-worker small page allocation can never use the reserve
   152   // Non-worker small page allocation can never use the reserve
   143   flags.set_no_reserve();
   153   flags.set_no_reserve();
   144 
   154 
   145   return alloc_object_in_shared_page(_shared_small_page.addr(), ZPageTypeSmall, ZPageSizeSmall, size, flags);
   155   return alloc_object_in_shared_page(shared_small_page_addr(), ZPageTypeSmall, ZPageSizeSmall, size, flags);
   146 }
   156 }
   147 
   157 
   148 uintptr_t ZObjectAllocator::alloc_small_object_from_worker(size_t size, ZAllocationFlags flags) {
   158 uintptr_t ZObjectAllocator::alloc_small_object_from_worker(size_t size, ZAllocationFlags flags) {
   149   assert(ZThread::is_worker(), "Should be a worker thread");
   159   assert(ZThread::is_worker(), "Should be a worker thread");
   150 
   160 
   292 }
   302 }
   293 
   303 
   294 size_t ZObjectAllocator::remaining() const {
   304 size_t ZObjectAllocator::remaining() const {
   295   assert(ZThread::is_java(), "Should be a Java thread");
   305   assert(ZThread::is_java(), "Should be a Java thread");
   296 
   306 
   297   ZPage* page = _shared_small_page.get();
   307   const ZPage* const page = OrderAccess::load_acquire(shared_small_page_addr());
   298   if (page != NULL) {
   308   if (page != NULL) {
   299     return page->remaining();
   309     return page->remaining();
   300   }
   310   }
   301 
   311 
   302   return 0;
   312   return 0;