src/share/vm/services/memTrackWorker.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/services/memTrackWorker.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,118 @@
     1.4 +/*
     1.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_SERVICES_MEM_TRACK_WORKER_HPP
    1.29 +#define SHARE_VM_SERVICES_MEM_TRACK_WORKER_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +#include "runtime/thread.hpp"
    1.33 +#include "services/memRecorder.hpp"
    1.34 +
    1.35 +// Maximum MAX_GENERATIONS generation data can be tracked.
    1.36 +#define MAX_GENERATIONS  512
    1.37 +
    1.38 +class GenerationData VALUE_OBJ_CLASS_SPEC {
    1.39 + private:
    1.40 +  int           _number_of_classes;
    1.41 +  MemRecorder*  _recorder_list;
    1.42 +
    1.43 + public:
    1.44 +  GenerationData(): _number_of_classes(0), _recorder_list(NULL) { }
    1.45 +
    1.46 +  inline int  number_of_classes() const { return _number_of_classes; }
    1.47 +  inline void set_number_of_classes(long num) { _number_of_classes = num; }
    1.48 +
    1.49 +  inline MemRecorder* next_recorder() {
    1.50 +    if (_recorder_list == NULL) {
    1.51 +      return NULL;
    1.52 +    } else {
    1.53 +      MemRecorder* tmp = _recorder_list;
    1.54 +      _recorder_list = _recorder_list->next();
    1.55 +      return tmp;
    1.56 +    }
    1.57 +  }
    1.58 +
    1.59 +  inline bool has_more_recorder() const {
    1.60 +    return (_recorder_list != NULL);
    1.61 +  }
    1.62 +
    1.63 +  // add recorders to this generation
    1.64 +  void add_recorders(MemRecorder* head) {
    1.65 +    if (head != NULL) {
    1.66 +      if (_recorder_list == NULL) {
    1.67 +        _recorder_list = head;
    1.68 +      } else {
    1.69 +        MemRecorder* tmp = _recorder_list;
    1.70 +        for (; tmp->next() != NULL; tmp = tmp->next());
    1.71 +        tmp->set_next(head);
    1.72 +      }
    1.73 +    }
    1.74 +  }
    1.75 +
    1.76 +  void reset();
    1.77 +
    1.78 +  NOT_PRODUCT(MemRecorder* peek() const { return _recorder_list; })
    1.79 +};
    1.80 +
    1.81 +class MemTrackWorker : public NamedThread {
    1.82 + private:
    1.83 +  // circular buffer. This buffer contains generation data to be merged into global
    1.84 +  // snaphsot.
    1.85 +  // Each slot holds a generation
    1.86 +  GenerationData  _gen[MAX_GENERATIONS];
    1.87 +  int             _head, _tail; // head and tail pointers to above circular buffer
    1.88 +
    1.89 +  bool            _has_error;
    1.90 +
    1.91 +  MemSnapshot*    _snapshot;
    1.92 +
    1.93 + public:
    1.94 +  MemTrackWorker(MemSnapshot* snapshot);
    1.95 +  ~MemTrackWorker();
    1.96 +  _NOINLINE_ void* operator new(size_t size) throw();
    1.97 +  _NOINLINE_ void* operator new(size_t size, const std::nothrow_t& nothrow_constant) throw();
    1.98 +
    1.99 +  void start();
   1.100 +  void run();
   1.101 +
   1.102 +  inline bool has_error() const { return _has_error; }
   1.103 +
   1.104 +  // task at synchronization point
   1.105 +  void at_sync_point(MemRecorder* pending_recorders, int number_of_classes);
   1.106 +
   1.107 +  // for debugging purpose, they are not thread safe.
   1.108 +  NOT_PRODUCT(static int count_recorder(const MemRecorder* head);)
   1.109 +  NOT_PRODUCT(int count_pending_recorders() const;)
   1.110 +
   1.111 +  NOT_PRODUCT(int _sync_point_count;)
   1.112 +  NOT_PRODUCT(int _merge_count;)
   1.113 +  NOT_PRODUCT(int _last_gen_in_use;)
   1.114 +
   1.115 +  // how many generations are queued
   1.116 +  inline int generations_in_use() const {
   1.117 +    return (_tail >= _head ? (_tail - _head + 1) : (MAX_GENERATIONS - (_head - _tail) + 1));
   1.118 +  }
   1.119 +};
   1.120 +
   1.121 +#endif // SHARE_VM_SERVICES_MEM_TRACK_WORKER_HPP

mercurial