3863N/A/*
4168N/A * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3863N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3863N/A *
3863N/A * This code is free software; you can redistribute it and/or modify it
3863N/A * under the terms of the GNU General Public License version 2 only, as
3863N/A * published by the Free Software Foundation.
3863N/A *
3863N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3863N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3863N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3863N/A * version 2 for more details (a copy is included in the LICENSE file that
3863N/A * accompanied this code).
3863N/A *
3863N/A * You should have received a copy of the GNU General Public License version
3863N/A * 2 along with this work; if not, write to the Free Software Foundation,
3863N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3863N/A *
3863N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3863N/A * or visit www.oracle.com if you need additional information or have any
3863N/A * questions.
3863N/A *
3863N/A */
3863N/A
3863N/A#ifndef SHARE_VM_SERVICES_MEM_TRACK_WORKER_HPP
3863N/A#define SHARE_VM_SERVICES_MEM_TRACK_WORKER_HPP
3863N/A
3863N/A#include "memory/allocation.hpp"
3863N/A#include "runtime/thread.hpp"
3863N/A#include "services/memRecorder.hpp"
3863N/A
3863N/A// Maximum MAX_GENERATIONS generation data can be tracked.
3863N/A#define MAX_GENERATIONS 512
3863N/A
4168N/Aclass GenerationData : public _ValueObj {
4168N/A private:
4168N/A int _number_of_classes;
4168N/A MemRecorder* _recorder_list;
4168N/A
4168N/A public:
4168N/A GenerationData(): _number_of_classes(0), _recorder_list(NULL) { }
4168N/A
4168N/A inline int number_of_classes() const { return _number_of_classes; }
4168N/A inline void set_number_of_classes(long num) { _number_of_classes = num; }
4168N/A
4168N/A inline MemRecorder* next_recorder() {
4168N/A if (_recorder_list == NULL) {
4168N/A return NULL;
4168N/A } else {
4168N/A MemRecorder* tmp = _recorder_list;
4168N/A _recorder_list = _recorder_list->next();
4168N/A return tmp;
4168N/A }
4168N/A }
4168N/A
4168N/A inline bool has_more_recorder() const {
4168N/A return (_recorder_list != NULL);
4168N/A }
4168N/A
4168N/A // add recorders to this generation
4168N/A void add_recorders(MemRecorder* head) {
4168N/A if (head != NULL) {
4168N/A if (_recorder_list == NULL) {
4168N/A _recorder_list = head;
4168N/A } else {
4168N/A MemRecorder* tmp = _recorder_list;
4168N/A for (; tmp->next() != NULL; tmp = tmp->next());
4168N/A tmp->set_next(head);
4168N/A }
4168N/A }
4168N/A }
4168N/A
4168N/A void reset();
4168N/A
4168N/A NOT_PRODUCT(MemRecorder* peek() const { return _recorder_list; })
4168N/A};
3863N/A
3863N/Aclass MemTrackWorker : public NamedThread {
3863N/A private:
4168N/A // circular buffer. This buffer contains generation data to be merged into global
3863N/A // snaphsot.
4168N/A // Each slot holds a generation
4168N/A GenerationData _gen[MAX_GENERATIONS];
4168N/A int _head, _tail; // head and tail pointers to above circular buffer
3863N/A
4168N/A bool _has_error;
3863N/A
4413N/A MemSnapshot* _snapshot;
4413N/A
3863N/A public:
4413N/A MemTrackWorker(MemSnapshot* snapshot);
3863N/A ~MemTrackWorker();
3863N/A _NOINLINE_ void* operator new(size_t size);
3863N/A _NOINLINE_ void* operator new(size_t size, const std::nothrow_t& nothrow_constant);
3863N/A
3863N/A void start();
3863N/A void run();
3863N/A
3863N/A inline bool has_error() const { return _has_error; }
3863N/A
3863N/A // task at synchronization point
4168N/A void at_sync_point(MemRecorder* pending_recorders, int number_of_classes);
3863N/A
3863N/A // for debugging purpose, they are not thread safe.
3863N/A NOT_PRODUCT(static int count_recorder(const MemRecorder* head);)
3863N/A NOT_PRODUCT(int count_pending_recorders() const;)
3863N/A
3863N/A NOT_PRODUCT(int _sync_point_count;)
3863N/A NOT_PRODUCT(int _merge_count;)
3863N/A NOT_PRODUCT(int _last_gen_in_use;)
3863N/A
4186N/A // how many generations are queued
3863N/A inline int generations_in_use() const {
3897N/A return (_tail >= _head ? (_tail - _head + 1) : (MAX_GENERATIONS - (_head - _tail) + 1));
3863N/A }
3863N/A};
3863N/A
3863N/A#endif // SHARE_VM_SERVICES_MEM_TRACK_WORKER_HPP