< prev index next >

src/hotspot/share/gc/shared/threadLocalAllocBuffer.cpp

Print this page
rev 47287 : Port 09.17.Thread_SMR_logging_update from JDK9 to JDK10
rev 47289 : eosterlund, stefank CR - refactor code into threadSMR.cpp and threadSMR.hpp
   1 /*
   2  * Copyright (c) 1999, 2015, 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 #include "precompiled.hpp"
  26 #include "gc/shared/genCollectedHeap.hpp"
  27 #include "gc/shared/threadLocalAllocBuffer.inline.hpp"
  28 #include "logging/log.hpp"
  29 #include "memory/resourceArea.hpp"
  30 #include "memory/universe.inline.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "runtime/thread.inline.hpp"

  33 #include "utilities/copy.hpp"
  34 
  35 // Thread-Local Edens support
  36 
  37 // static member initialization
  38 size_t           ThreadLocalAllocBuffer::_max_size       = 0;
  39 int              ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0;
  40 unsigned         ThreadLocalAllocBuffer::_target_refills = 0;
  41 GlobalTLABStats* ThreadLocalAllocBuffer::_global_stats   = NULL;
  42 
  43 void ThreadLocalAllocBuffer::clear_before_allocation() {
  44   _slow_refill_waste += (unsigned)remaining();
  45   make_parsable(true);   // also retire the TLAB
  46 }
  47 
  48 void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() {
  49   global_stats()->initialize();
  50 
  51   for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) {



  52     thread->tlab().accumulate_statistics();
  53     thread->tlab().initialize_statistics();
  54   }

  55 
  56   // Publish new stats if some allocation occurred.
  57   if (global_stats()->allocation() != 0) {
  58     global_stats()->publish();
  59     global_stats()->print();
  60   }
  61 }
  62 
  63 void ThreadLocalAllocBuffer::accumulate_statistics() {
  64   Thread* thread = myThread();
  65   size_t capacity = Universe::heap()->tlab_capacity(thread);
  66   size_t used     = Universe::heap()->tlab_used(thread);
  67 
  68   _gc_waste += (unsigned)remaining();
  69   size_t total_allocated = thread->allocated_bytes();
  70   size_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc;
  71   _allocated_before_last_gc = total_allocated;
  72 
  73   print_stats("gc");
  74 


 113     if (retire) {
 114       myThread()->incr_allocated_bytes(used_bytes());
 115     }
 116 
 117     CollectedHeap::fill_with_object(top(), hard_end(), retire && zap);
 118 
 119     if (retire || ZeroTLAB) {  // "Reset" the TLAB
 120       set_start(NULL);
 121       set_top(NULL);
 122       set_pf_top(NULL);
 123       set_end(NULL);
 124     }
 125   }
 126   assert(!(retire || ZeroTLAB)  ||
 127          (start() == NULL && end() == NULL && top() == NULL),
 128          "TLAB must be reset");
 129 }
 130 
 131 void ThreadLocalAllocBuffer::resize_all_tlabs() {
 132   if (ResizeTLAB) {
 133     for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) {


 134       thread->tlab().resize();
 135     }
 136   }
 137 }
 138 
 139 void ThreadLocalAllocBuffer::resize() {
 140   // Compute the next tlab size using expected allocation amount
 141   assert(ResizeTLAB, "Should not call this otherwise");
 142   size_t alloc = (size_t)(_allocation_fraction.average() *
 143                           (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize));
 144   size_t new_size = alloc / _target_refills;
 145 
 146   new_size = MIN2(MAX2(new_size, min_size()), max_size());
 147 
 148   size_t aligned_new_size = align_object_size(new_size);
 149 
 150   log_trace(gc, tlab)("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]"
 151                       " refills %d  alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT,
 152                       p2i(myThread()), myThread()->osthread()->thread_id(),
 153                       _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size);


   1 /*
   2  * Copyright (c) 1999, 2017, 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 #include "precompiled.hpp"
  26 #include "gc/shared/genCollectedHeap.hpp"
  27 #include "gc/shared/threadLocalAllocBuffer.inline.hpp"
  28 #include "logging/log.hpp"
  29 #include "memory/resourceArea.hpp"
  30 #include "memory/universe.inline.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "runtime/thread.inline.hpp"
  33 #include "runtime/threadSMR.hpp"
  34 #include "utilities/copy.hpp"
  35 
  36 // Thread-Local Edens support
  37 
  38 // static member initialization
  39 size_t           ThreadLocalAllocBuffer::_max_size       = 0;
  40 int              ThreadLocalAllocBuffer::_reserve_for_allocation_prefetch = 0;
  41 unsigned         ThreadLocalAllocBuffer::_target_refills = 0;
  42 GlobalTLABStats* ThreadLocalAllocBuffer::_global_stats   = NULL;
  43 
  44 void ThreadLocalAllocBuffer::clear_before_allocation() {
  45   _slow_refill_waste += (unsigned)remaining();
  46   make_parsable(true);   // also retire the TLAB
  47 }
  48 
  49 void ThreadLocalAllocBuffer::accumulate_statistics_before_gc() {
  50   global_stats()->initialize();
  51 
  52   {
  53     ThreadsListHandle tlh;
  54     JavaThreadIterator jti(tlh.list());
  55     for (JavaThread *thread = jti.first(); thread != NULL; thread = jti.next()) {
  56       thread->tlab().accumulate_statistics();
  57       thread->tlab().initialize_statistics();
  58     }
  59   }
  60 
  61   // Publish new stats if some allocation occurred.
  62   if (global_stats()->allocation() != 0) {
  63     global_stats()->publish();
  64     global_stats()->print();
  65   }
  66 }
  67 
  68 void ThreadLocalAllocBuffer::accumulate_statistics() {
  69   Thread* thread = myThread();
  70   size_t capacity = Universe::heap()->tlab_capacity(thread);
  71   size_t used     = Universe::heap()->tlab_used(thread);
  72 
  73   _gc_waste += (unsigned)remaining();
  74   size_t total_allocated = thread->allocated_bytes();
  75   size_t allocated_since_last_gc = total_allocated - _allocated_before_last_gc;
  76   _allocated_before_last_gc = total_allocated;
  77 
  78   print_stats("gc");
  79 


 118     if (retire) {
 119       myThread()->incr_allocated_bytes(used_bytes());
 120     }
 121 
 122     CollectedHeap::fill_with_object(top(), hard_end(), retire && zap);
 123 
 124     if (retire || ZeroTLAB) {  // "Reset" the TLAB
 125       set_start(NULL);
 126       set_top(NULL);
 127       set_pf_top(NULL);
 128       set_end(NULL);
 129     }
 130   }
 131   assert(!(retire || ZeroTLAB)  ||
 132          (start() == NULL && end() == NULL && top() == NULL),
 133          "TLAB must be reset");
 134 }
 135 
 136 void ThreadLocalAllocBuffer::resize_all_tlabs() {
 137   if (ResizeTLAB) {
 138     ThreadsListHandle tlh;
 139     JavaThreadIterator jti(tlh.list());
 140     for (JavaThread *thread = jti.first(); thread != NULL; thread = jti.next()) {
 141       thread->tlab().resize();
 142     }
 143   }
 144 }
 145 
 146 void ThreadLocalAllocBuffer::resize() {
 147   // Compute the next tlab size using expected allocation amount
 148   assert(ResizeTLAB, "Should not call this otherwise");
 149   size_t alloc = (size_t)(_allocation_fraction.average() *
 150                           (Universe::heap()->tlab_capacity(myThread()) / HeapWordSize));
 151   size_t new_size = alloc / _target_refills;
 152 
 153   new_size = MIN2(MAX2(new_size, min_size()), max_size());
 154 
 155   size_t aligned_new_size = align_object_size(new_size);
 156 
 157   log_trace(gc, tlab)("TLAB new size: thread: " INTPTR_FORMAT " [id: %2d]"
 158                       " refills %d  alloc: %8.6f desired_size: " SIZE_FORMAT " -> " SIZE_FORMAT,
 159                       p2i(myThread()), myThread()->osthread()->thread_id(),
 160                       _target_refills, _allocation_fraction.average(), desired_size(), aligned_new_size);


< prev index next >