2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2013-12-24 11:48:39 -08:00
|
|
|
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#ifndef SHARE_VM_SERVICES_MEMORYMANAGER_HPP
|
|
|
|
#define SHARE_VM_SERVICES_MEMORYMANAGER_HPP
|
|
|
|
|
|
|
|
#include "memory/allocation.hpp"
|
|
|
|
#include "runtime/timer.hpp"
|
|
|
|
#include "services/memoryUsage.hpp"
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// A memory manager is responsible for managing one or more memory pools.
|
|
|
|
// The garbage collector is one type of memory managers responsible
|
|
|
|
// for reclaiming memory occupied by unreachable objects. A Java virtual
|
|
|
|
// machine may have one or more memory managers. It may
|
|
|
|
// add or remove memory managers during execution.
|
|
|
|
// A memory pool can be managed by more than one memory managers.
|
|
|
|
|
|
|
|
class MemoryPool;
|
|
|
|
class GCMemoryManager;
|
|
|
|
class OopClosure;
|
|
|
|
|
2012-06-28 17:03:16 -04:00
|
|
|
class MemoryManager : public CHeapObj<mtInternal> {
|
2007-12-01 00:00:00 +00:00
|
|
|
private:
|
|
|
|
enum {
|
|
|
|
max_num_pools = 10
|
|
|
|
};
|
|
|
|
|
|
|
|
MemoryPool* _pools[max_num_pools];
|
|
|
|
int _num_pools;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
volatile instanceOop _memory_mgr_obj;
|
|
|
|
|
|
|
|
public:
|
|
|
|
MemoryManager();
|
|
|
|
|
|
|
|
int num_memory_pools() const { return _num_pools; }
|
|
|
|
MemoryPool* get_memory_pool(int index) {
|
|
|
|
assert(index >= 0 && index < _num_pools, "Invalid index");
|
|
|
|
return _pools[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_pool(MemoryPool* pool);
|
|
|
|
|
|
|
|
bool is_manager(instanceHandle mh) { return mh() == _memory_mgr_obj; }
|
|
|
|
|
|
|
|
virtual instanceOop get_memory_manager_instance(TRAPS);
|
|
|
|
virtual bool is_gc_memory_manager() { return false; }
|
|
|
|
virtual const char* name() = 0;
|
|
|
|
|
|
|
|
// GC support
|
|
|
|
void oops_do(OopClosure* f);
|
|
|
|
|
|
|
|
// Static factory methods to get a memory manager of a specific type
|
|
|
|
static MemoryManager* get_code_cache_memory_manager();
|
2013-06-26 16:58:37 +02:00
|
|
|
static MemoryManager* get_metaspace_memory_manager();
|
2007-12-01 00:00:00 +00:00
|
|
|
static GCMemoryManager* get_copy_memory_manager();
|
|
|
|
static GCMemoryManager* get_msc_memory_manager();
|
|
|
|
static GCMemoryManager* get_parnew_memory_manager();
|
|
|
|
static GCMemoryManager* get_cms_memory_manager();
|
|
|
|
static GCMemoryManager* get_psScavenge_memory_manager();
|
|
|
|
static GCMemoryManager* get_psMarkSweep_memory_manager();
|
2009-11-20 14:47:01 -05:00
|
|
|
static GCMemoryManager* get_g1YoungGen_memory_manager();
|
|
|
|
static GCMemoryManager* get_g1OldGen_memory_manager();
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CodeCacheMemoryManager : public MemoryManager {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
CodeCacheMemoryManager() : MemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "CodeCacheManager"; }
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
2013-06-26 16:58:37 +02:00
|
|
|
class MetaspaceMemoryManager : public MemoryManager {
|
|
|
|
public:
|
|
|
|
MetaspaceMemoryManager() : MemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "Metaspace Manager"; }
|
2013-06-26 16:58:37 +02:00
|
|
|
};
|
|
|
|
|
2012-01-25 02:29:05 +04:00
|
|
|
class GCStatInfo : public ResourceObj {
|
2007-12-01 00:00:00 +00:00
|
|
|
private:
|
|
|
|
size_t _index;
|
|
|
|
jlong _start_time;
|
|
|
|
jlong _end_time;
|
|
|
|
|
|
|
|
// We keep memory usage of all memory pools
|
|
|
|
MemoryUsage* _before_gc_usage_array;
|
|
|
|
MemoryUsage* _after_gc_usage_array;
|
|
|
|
int _usage_array_size;
|
|
|
|
|
|
|
|
void set_gc_usage(int pool_index, MemoryUsage, bool before_gc);
|
|
|
|
|
|
|
|
public:
|
|
|
|
GCStatInfo(int num_pools);
|
|
|
|
~GCStatInfo();
|
|
|
|
|
|
|
|
size_t gc_index() { return _index; }
|
|
|
|
jlong start_time() { return _start_time; }
|
|
|
|
jlong end_time() { return _end_time; }
|
|
|
|
int usage_array_size() { return _usage_array_size; }
|
|
|
|
MemoryUsage before_gc_usage_for_pool(int pool_index) {
|
|
|
|
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
|
|
|
|
return _before_gc_usage_array[pool_index];
|
|
|
|
}
|
|
|
|
MemoryUsage after_gc_usage_for_pool(int pool_index) {
|
|
|
|
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
|
|
|
|
return _after_gc_usage_array[pool_index];
|
|
|
|
}
|
|
|
|
|
2010-07-30 22:43:50 +01:00
|
|
|
MemoryUsage* before_gc_usage_array() { return _before_gc_usage_array; }
|
|
|
|
MemoryUsage* after_gc_usage_array() { return _after_gc_usage_array; }
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
void set_index(size_t index) { _index = index; }
|
|
|
|
void set_start_time(jlong time) { _start_time = time; }
|
|
|
|
void set_end_time(jlong time) { _end_time = time; }
|
|
|
|
void set_before_gc_usage(int pool_index, MemoryUsage usage) {
|
|
|
|
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
|
|
|
|
set_gc_usage(pool_index, usage, true /* before gc */);
|
|
|
|
}
|
|
|
|
void set_after_gc_usage(int pool_index, MemoryUsage usage) {
|
|
|
|
assert(pool_index >= 0 && pool_index < _usage_array_size, "Range checking");
|
|
|
|
set_gc_usage(pool_index, usage, false /* after gc */);
|
|
|
|
}
|
|
|
|
|
2010-07-30 22:43:50 +01:00
|
|
|
void clear();
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GCMemoryManager : public MemoryManager {
|
|
|
|
private:
|
|
|
|
// TODO: We should unify the GCCounter and GCMemoryManager statistic
|
|
|
|
size_t _num_collections;
|
|
|
|
elapsedTimer _accumulated_timer;
|
|
|
|
elapsedTimer _gc_timer; // for measuring every GC duration
|
|
|
|
GCStatInfo* _last_gc_stat;
|
2010-07-30 22:43:50 +01:00
|
|
|
Mutex* _last_gc_lock;
|
|
|
|
GCStatInfo* _current_gc_stat;
|
2007-12-01 00:00:00 +00:00
|
|
|
int _num_gc_threads;
|
2011-05-12 10:30:11 -07:00
|
|
|
volatile bool _notification_enabled;
|
2007-12-01 00:00:00 +00:00
|
|
|
public:
|
|
|
|
GCMemoryManager();
|
|
|
|
~GCMemoryManager();
|
|
|
|
|
|
|
|
void initialize_gc_stat_info();
|
|
|
|
|
|
|
|
bool is_gc_memory_manager() { return true; }
|
|
|
|
jlong gc_time_ms() { return _accumulated_timer.milliseconds(); }
|
|
|
|
size_t gc_count() { return _num_collections; }
|
|
|
|
int num_gc_threads() { return _num_gc_threads; }
|
|
|
|
void set_num_gc_threads(int count) { _num_gc_threads = count; }
|
|
|
|
|
2010-07-30 22:43:50 +01:00
|
|
|
void gc_begin(bool recordGCBeginTime, bool recordPreGCUsage,
|
|
|
|
bool recordAccumulatedGCTime);
|
|
|
|
void gc_end(bool recordPostGCUsage, bool recordAccumulatedGCTime,
|
2011-05-12 10:30:11 -07:00
|
|
|
bool recordGCEndTime, bool countCollection, GCCause::Cause cause);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
void reset_gc_stat() { _num_collections = 0; _accumulated_timer.reset(); }
|
2010-07-30 22:43:50 +01:00
|
|
|
|
|
|
|
// Copy out _last_gc_stat to the given destination, returning
|
|
|
|
// the collection count. Zero signifies no gc has taken place.
|
|
|
|
size_t get_last_gc_stat(GCStatInfo* dest);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2011-05-12 10:30:11 -07:00
|
|
|
void set_notification_enabled(bool enabled) { _notification_enabled = enabled; }
|
|
|
|
bool is_notification_enabled() { return _notification_enabled; }
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// These subclasses of GCMemoryManager are defined to include
|
|
|
|
// GC-specific information.
|
|
|
|
// TODO: Add GC-specific information
|
|
|
|
class CopyMemoryManager : public GCMemoryManager {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
CopyMemoryManager() : GCMemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "Copy"; }
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MSCMemoryManager : public GCMemoryManager {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
MSCMemoryManager() : GCMemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "MarkSweepCompact"; }
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ParNewMemoryManager : public GCMemoryManager {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
ParNewMemoryManager() : GCMemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "ParNew"; }
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CMSMemoryManager : public GCMemoryManager {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
CMSMemoryManager() : GCMemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "ConcurrentMarkSweep";}
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PSScavengeMemoryManager : public GCMemoryManager {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
PSScavengeMemoryManager() : GCMemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "PS Scavenge"; }
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PSMarkSweepMemoryManager : public GCMemoryManager {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
PSMarkSweepMemoryManager() : GCMemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "PS MarkSweep"; }
|
2007-12-01 00:00:00 +00:00
|
|
|
};
|
2009-11-20 14:47:01 -05:00
|
|
|
|
|
|
|
class G1YoungGenMemoryManager : public GCMemoryManager {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
G1YoungGenMemoryManager() : GCMemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "G1 Young Generation"; }
|
2009-11-20 14:47:01 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class G1OldGenMemoryManager : public GCMemoryManager {
|
|
|
|
private:
|
|
|
|
public:
|
|
|
|
G1OldGenMemoryManager() : GCMemoryManager() {}
|
|
|
|
|
2015-04-02 09:14:16 +02:00
|
|
|
const char* name() { return "G1 Old Generation"; }
|
2009-11-20 14:47:01 -05:00
|
|
|
};
|
2010-11-23 13:22:55 -08:00
|
|
|
|
|
|
|
#endif // SHARE_VM_SERVICES_MEMORYMANAGER_HPP
|