memTrackWorker.hpp revision 3897
3863N/A/*
3863N/A * Copyright (c) 2012, 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
3863N/A
3863N/Aclass MemTrackWorker : public NamedThread {
3863N/A private:
3863N/A // circular buffer. This buffer contains recorders to be merged into global
3863N/A // snaphsot.
3863N/A // Each slot holds a linked list of memory recorders, that contains one
3863N/A // generation of memory data.
3863N/A MemRecorder* _gen[MAX_GENERATIONS];
3863N/A int _head, _tail; // head and tail pointers to above circular buffer
3863N/A
3863N/A bool _has_error;
3863N/A
3863N/A public:
3863N/A MemTrackWorker();
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
3863N/A void at_sync_point(MemRecorder* pending_recorders);
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
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