Mon, 25 Jan 2010 18:03:29 -0500
6919980: G1: remove +UseG1GC from under experimental options (second attempt)
Summary: Trying this again, as the original change was lost.
Reviewed-by: ysr, jmasa
duke@435 | 1 | /* |
xdono@1014 | 2 | * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_memprofiler.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | #ifndef PRODUCT |
duke@435 | 29 | |
duke@435 | 30 | // -------------------------------------------------------- |
duke@435 | 31 | // MemProfilerTask |
duke@435 | 32 | |
duke@435 | 33 | class MemProfilerTask : public PeriodicTask { |
duke@435 | 34 | public: |
duke@435 | 35 | MemProfilerTask(int interval_time) : PeriodicTask(interval_time) {} |
duke@435 | 36 | void task(); |
duke@435 | 37 | }; |
duke@435 | 38 | |
duke@435 | 39 | |
duke@435 | 40 | void MemProfilerTask::task() { |
duke@435 | 41 | // Get thread lock to provide mutual exclusion, and so we can iterate safely over the thread list. |
duke@435 | 42 | MutexLocker mu(Threads_lock); |
duke@435 | 43 | MemProfiler::do_trace(); |
duke@435 | 44 | } |
duke@435 | 45 | |
duke@435 | 46 | |
duke@435 | 47 | //---------------------------------------------------------- |
duke@435 | 48 | // Implementation of MemProfiler |
duke@435 | 49 | |
duke@435 | 50 | MemProfilerTask* MemProfiler::_task = NULL; |
duke@435 | 51 | FILE* MemProfiler::_log_fp = NULL; |
duke@435 | 52 | |
duke@435 | 53 | |
duke@435 | 54 | bool MemProfiler::is_active() { |
duke@435 | 55 | return _task != NULL; |
duke@435 | 56 | } |
duke@435 | 57 | |
duke@435 | 58 | |
duke@435 | 59 | void MemProfiler::engage() { |
duke@435 | 60 | const char *log_name = "mprofile.log"; |
duke@435 | 61 | if (!is_active()) { |
duke@435 | 62 | // Create log file |
duke@435 | 63 | _log_fp = fopen(log_name , "w+"); |
duke@435 | 64 | if (_log_fp == NULL) { |
duke@435 | 65 | fatal1("MemProfiler: Cannot create log file: %s", log_name); |
duke@435 | 66 | } |
duke@435 | 67 | fprintf(_log_fp, "MemProfiler: sizes are in Kb, time is in seconds since startup\n\n"); |
duke@435 | 68 | fprintf(_log_fp, " time, #thr, #cls, heap, heap, perm, perm, code, hndls, rescs, oopmp\n"); |
duke@435 | 69 | fprintf(_log_fp, " used, total, used, total, total, total, total, total\n"); |
duke@435 | 70 | fprintf(_log_fp, "--------------------------------------------------------------------------\n"); |
duke@435 | 71 | |
duke@435 | 72 | _task = new MemProfilerTask(MemProfilingInterval); |
duke@435 | 73 | _task->enroll(); |
duke@435 | 74 | } |
duke@435 | 75 | } |
duke@435 | 76 | |
duke@435 | 77 | |
duke@435 | 78 | void MemProfiler::disengage() { |
duke@435 | 79 | if (!is_active()) return; |
duke@435 | 80 | // Do one last trace at disengage time |
duke@435 | 81 | do_trace(); |
duke@435 | 82 | |
duke@435 | 83 | // Close logfile |
duke@435 | 84 | fprintf(_log_fp, "MemProfiler detached\n"); |
duke@435 | 85 | fclose(_log_fp); |
duke@435 | 86 | |
duke@435 | 87 | // remove MemProfilerTask |
duke@435 | 88 | assert(_task != NULL, "sanity check"); |
duke@435 | 89 | _task->disenroll(); |
duke@435 | 90 | delete _task; |
duke@435 | 91 | _task = NULL; |
duke@435 | 92 | } |
duke@435 | 93 | |
duke@435 | 94 | |
duke@435 | 95 | void MemProfiler::do_trace() { |
duke@435 | 96 | // Calculate thread local sizes |
duke@435 | 97 | size_t handles_memory_usage = VMThread::vm_thread()->handle_area()->size_in_bytes(); |
duke@435 | 98 | size_t resource_memory_usage = VMThread::vm_thread()->resource_area()->size_in_bytes(); |
duke@435 | 99 | JavaThread *cur = Threads::first(); |
duke@435 | 100 | while (cur != NULL) { |
duke@435 | 101 | handles_memory_usage += cur->handle_area()->size_in_bytes(); |
duke@435 | 102 | resource_memory_usage += cur->resource_area()->size_in_bytes(); |
duke@435 | 103 | cur = cur->next(); |
duke@435 | 104 | } |
duke@435 | 105 | |
duke@435 | 106 | // Print trace line in log |
xlu@948 | 107 | fprintf(_log_fp, "%6.1f,%5d,%5d," UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) "," |
xlu@948 | 108 | UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",", |
xlu@948 | 109 | os::elapsedTime(), |
xlu@948 | 110 | Threads::number_of_threads(), |
xlu@948 | 111 | SystemDictionary::number_of_classes(), |
xlu@948 | 112 | Universe::heap()->used() / K, |
xlu@948 | 113 | Universe::heap()->capacity() / K, |
xlu@948 | 114 | Universe::heap()->permanent_used() / HWperKB, |
xlu@948 | 115 | Universe::heap()->permanent_capacity() / HWperKB); |
duke@435 | 116 | |
xlu@948 | 117 | fprintf(_log_fp, UINTX_FORMAT_W(6) ",", CodeCache::capacity() / K); |
duke@435 | 118 | |
xlu@948 | 119 | fprintf(_log_fp, UINTX_FORMAT_W(6) "," UINTX_FORMAT_W(6) ",%6ld\n", |
xlu@948 | 120 | handles_memory_usage / K, |
xlu@948 | 121 | resource_memory_usage / K, |
xlu@948 | 122 | OopMapCache::memory_usage() / K); |
duke@435 | 123 | fflush(_log_fp); |
duke@435 | 124 | } |
duke@435 | 125 | |
duke@435 | 126 | #endif |