1 /*
   2  * Copyright (c) 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 #include "gc/z/zStatTLAB.hpp"
  25 
  26 ZPerWorker<ThreadLocalAllocStats>* ZStatTLAB::_stats = NULL;
  27 
  28 void ZStatTLAB::initialize() {
  29   if (UseTLAB) {
  30     assert(_stats == NULL, "Already initialized");
  31     _stats = new ZPerWorker<ThreadLocalAllocStats>();
  32     reset();
  33   }
  34 }
  35 
  36 void ZStatTLAB::reset() {
  37   if (UseTLAB) {
  38     ZPerWorkerIterator<ThreadLocalAllocStats> iter(_stats);
  39     for (ThreadLocalAllocStats* stats; iter.next(&stats);) {
  40       stats->reset();
  41     }
  42   }
  43 }
  44 
  45 ThreadLocalAllocStats* ZStatTLAB::get() {
  46   if (UseTLAB) {
  47     return _stats->addr();
  48   }
  49 
  50   return NULL;
  51 }
  52 
  53 void ZStatTLAB::publish() {
  54   if (UseTLAB) {
  55     ThreadLocalAllocStats total;
  56 
  57     ZPerWorkerIterator<ThreadLocalAllocStats> iter(_stats);
  58     for (ThreadLocalAllocStats* stats; iter.next(&stats);) {
  59       total.update(*stats);
  60     }
  61 
  62     total.publish();
  63   }
  64 }