Tue, 09 Oct 2012 10:09:34 -0700
7197424: update copyright year to match last edit in jdk8 hotspot repository
Summary: Update copyright year to 2012 for relevant files
Reviewed-by: dholmes, coleenp
duke@435 | 1 | /* |
coleenp@4037 | 2 | * Copyright (c) 2003, 2012, Oracle and/or its affiliates. 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 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 27 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 28 | #include "oops/oop.inline.hpp" |
stefank@2314 | 29 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 30 | #include "runtime/javaCalls.hpp" |
stefank@2314 | 31 | #include "services/lowMemoryDetector.hpp" |
stefank@2314 | 32 | #include "services/management.hpp" |
stefank@2314 | 33 | #include "services/memoryManager.hpp" |
stefank@2314 | 34 | #include "services/memoryPool.hpp" |
duke@435 | 35 | |
duke@435 | 36 | MemoryPool::MemoryPool(const char* name, |
duke@435 | 37 | PoolType type, |
duke@435 | 38 | size_t init_size, |
duke@435 | 39 | size_t max_size, |
duke@435 | 40 | bool support_usage_threshold, |
duke@435 | 41 | bool support_gc_threshold) { |
duke@435 | 42 | _name = name; |
duke@435 | 43 | _initial_size = init_size; |
duke@435 | 44 | _max_size = max_size; |
duke@435 | 45 | _memory_pool_obj = NULL; |
duke@435 | 46 | _available_for_allocation = true; |
duke@435 | 47 | _num_managers = 0; |
duke@435 | 48 | _type = type; |
duke@435 | 49 | |
duke@435 | 50 | // initialize the max and init size of collection usage |
duke@435 | 51 | _after_gc_usage = MemoryUsage(_initial_size, 0, 0, _max_size); |
duke@435 | 52 | |
duke@435 | 53 | _usage_sensor = NULL; |
duke@435 | 54 | _gc_usage_sensor = NULL; |
duke@435 | 55 | // usage threshold supports both high and low threshold |
duke@435 | 56 | _usage_threshold = new ThresholdSupport(support_usage_threshold, support_usage_threshold); |
duke@435 | 57 | // gc usage threshold supports only high threshold |
duke@435 | 58 | _gc_usage_threshold = new ThresholdSupport(support_gc_threshold, support_gc_threshold); |
duke@435 | 59 | } |
duke@435 | 60 | |
duke@435 | 61 | void MemoryPool::add_manager(MemoryManager* mgr) { |
duke@435 | 62 | assert(_num_managers < MemoryPool::max_num_managers, "_num_managers exceeds the max"); |
duke@435 | 63 | if (_num_managers < MemoryPool::max_num_managers) { |
duke@435 | 64 | _managers[_num_managers] = mgr; |
duke@435 | 65 | _num_managers++; |
duke@435 | 66 | } |
duke@435 | 67 | } |
duke@435 | 68 | |
duke@435 | 69 | |
duke@435 | 70 | // Returns an instanceHandle of a MemoryPool object. |
duke@435 | 71 | // It creates a MemoryPool instance when the first time |
duke@435 | 72 | // this function is called. |
duke@435 | 73 | instanceOop MemoryPool::get_memory_pool_instance(TRAPS) { |
duke@435 | 74 | // Must do an acquire so as to force ordering of subsequent |
duke@435 | 75 | // loads from anything _memory_pool_obj points to or implies. |
duke@435 | 76 | instanceOop pool_obj = (instanceOop)OrderAccess::load_ptr_acquire(&_memory_pool_obj); |
duke@435 | 77 | if (pool_obj == NULL) { |
duke@435 | 78 | // It's ok for more than one thread to execute the code up to the locked region. |
duke@435 | 79 | // Extra pool instances will just be gc'ed. |
coleenp@4037 | 80 | Klass* k = Management::sun_management_ManagementFactory_klass(CHECK_NULL); |
duke@435 | 81 | instanceKlassHandle ik(THREAD, k); |
duke@435 | 82 | |
duke@435 | 83 | Handle pool_name = java_lang_String::create_from_str(_name, CHECK_NULL); |
duke@435 | 84 | jlong usage_threshold_value = (_usage_threshold->is_high_threshold_supported() ? 0 : -1L); |
duke@435 | 85 | jlong gc_usage_threshold_value = (_gc_usage_threshold->is_high_threshold_supported() ? 0 : -1L); |
duke@435 | 86 | |
duke@435 | 87 | JavaValue result(T_OBJECT); |
duke@435 | 88 | JavaCallArguments args; |
duke@435 | 89 | args.push_oop(pool_name); // Argument 1 |
duke@435 | 90 | args.push_int((int) is_heap()); // Argument 2 |
duke@435 | 91 | |
coleenp@2497 | 92 | Symbol* method_name = vmSymbols::createMemoryPool_name(); |
coleenp@2497 | 93 | Symbol* signature = vmSymbols::createMemoryPool_signature(); |
duke@435 | 94 | |
duke@435 | 95 | args.push_long(usage_threshold_value); // Argument 3 |
duke@435 | 96 | args.push_long(gc_usage_threshold_value); // Argument 4 |
duke@435 | 97 | |
duke@435 | 98 | JavaCalls::call_static(&result, |
duke@435 | 99 | ik, |
duke@435 | 100 | method_name, |
duke@435 | 101 | signature, |
duke@435 | 102 | &args, |
duke@435 | 103 | CHECK_NULL); |
duke@435 | 104 | |
duke@435 | 105 | instanceOop p = (instanceOop) result.get_jobject(); |
duke@435 | 106 | instanceHandle pool(THREAD, p); |
duke@435 | 107 | |
duke@435 | 108 | { |
duke@435 | 109 | // Get lock since another thread may have create the instance |
duke@435 | 110 | MutexLocker ml(Management_lock); |
duke@435 | 111 | |
duke@435 | 112 | // Check if another thread has created the pool. We reload |
duke@435 | 113 | // _memory_pool_obj here because some other thread may have |
duke@435 | 114 | // initialized it while we were executing the code before the lock. |
duke@435 | 115 | // |
duke@435 | 116 | // The lock has done an acquire, so the load can't float above it, |
duke@435 | 117 | // but we need to do a load_acquire as above. |
duke@435 | 118 | pool_obj = (instanceOop)OrderAccess::load_ptr_acquire(&_memory_pool_obj); |
duke@435 | 119 | if (pool_obj != NULL) { |
duke@435 | 120 | return pool_obj; |
duke@435 | 121 | } |
duke@435 | 122 | |
duke@435 | 123 | // Get the address of the object we created via call_special. |
duke@435 | 124 | pool_obj = pool(); |
duke@435 | 125 | |
duke@435 | 126 | // Use store barrier to make sure the memory accesses associated |
duke@435 | 127 | // with creating the pool are visible before publishing its address. |
duke@435 | 128 | // The unlock will publish the store to _memory_pool_obj because |
duke@435 | 129 | // it does a release first. |
duke@435 | 130 | OrderAccess::release_store_ptr(&_memory_pool_obj, pool_obj); |
duke@435 | 131 | } |
duke@435 | 132 | } |
duke@435 | 133 | |
duke@435 | 134 | return pool_obj; |
duke@435 | 135 | } |
duke@435 | 136 | |
duke@435 | 137 | inline static size_t get_max_value(size_t val1, size_t val2) { |
duke@435 | 138 | return (val1 > val2 ? val1 : val2); |
duke@435 | 139 | } |
duke@435 | 140 | |
duke@435 | 141 | void MemoryPool::record_peak_memory_usage() { |
duke@435 | 142 | // Caller in JDK is responsible for synchronization - |
duke@435 | 143 | // acquire the lock for this memory pool before calling VM |
duke@435 | 144 | MemoryUsage usage = get_memory_usage(); |
duke@435 | 145 | size_t peak_used = get_max_value(usage.used(), _peak_usage.used()); |
duke@435 | 146 | size_t peak_committed = get_max_value(usage.committed(), _peak_usage.committed()); |
duke@435 | 147 | size_t peak_max_size = get_max_value(usage.max_size(), _peak_usage.max_size()); |
duke@435 | 148 | |
duke@435 | 149 | _peak_usage = MemoryUsage(initial_size(), peak_used, peak_committed, peak_max_size); |
duke@435 | 150 | } |
duke@435 | 151 | |
duke@435 | 152 | static void set_sensor_obj_at(SensorInfo** sensor_ptr, instanceHandle sh) { |
duke@435 | 153 | assert(*sensor_ptr == NULL, "Should be called only once"); |
duke@435 | 154 | SensorInfo* sensor = new SensorInfo(); |
duke@435 | 155 | sensor->set_sensor(sh()); |
duke@435 | 156 | *sensor_ptr = sensor; |
duke@435 | 157 | } |
duke@435 | 158 | |
duke@435 | 159 | void MemoryPool::set_usage_sensor_obj(instanceHandle sh) { |
duke@435 | 160 | set_sensor_obj_at(&_usage_sensor, sh); |
duke@435 | 161 | } |
duke@435 | 162 | |
duke@435 | 163 | void MemoryPool::set_gc_usage_sensor_obj(instanceHandle sh) { |
duke@435 | 164 | set_sensor_obj_at(&_gc_usage_sensor, sh); |
duke@435 | 165 | } |
duke@435 | 166 | |
duke@435 | 167 | void MemoryPool::oops_do(OopClosure* f) { |
duke@435 | 168 | f->do_oop((oop*) &_memory_pool_obj); |
duke@435 | 169 | if (_usage_sensor != NULL) { |
duke@435 | 170 | _usage_sensor->oops_do(f); |
duke@435 | 171 | } |
duke@435 | 172 | if (_gc_usage_sensor != NULL) { |
duke@435 | 173 | _gc_usage_sensor->oops_do(f); |
duke@435 | 174 | } |
duke@435 | 175 | } |
duke@435 | 176 | |
duke@435 | 177 | ContiguousSpacePool::ContiguousSpacePool(ContiguousSpace* space, |
duke@435 | 178 | const char* name, |
duke@435 | 179 | PoolType type, |
duke@435 | 180 | size_t max_size, |
duke@435 | 181 | bool support_usage_threshold) : |
duke@435 | 182 | CollectedMemoryPool(name, type, space->capacity(), max_size, |
duke@435 | 183 | support_usage_threshold), _space(space) { |
duke@435 | 184 | } |
duke@435 | 185 | |
duke@435 | 186 | MemoryUsage ContiguousSpacePool::get_memory_usage() { |
duke@435 | 187 | size_t maxSize = (available_for_allocation() ? max_size() : 0); |
duke@435 | 188 | size_t used = used_in_bytes(); |
duke@435 | 189 | size_t committed = _space->capacity(); |
duke@435 | 190 | |
duke@435 | 191 | return MemoryUsage(initial_size(), used, committed, maxSize); |
duke@435 | 192 | } |
duke@435 | 193 | |
duke@435 | 194 | SurvivorContiguousSpacePool::SurvivorContiguousSpacePool(DefNewGeneration* gen, |
duke@435 | 195 | const char* name, |
duke@435 | 196 | PoolType type, |
duke@435 | 197 | size_t max_size, |
duke@435 | 198 | bool support_usage_threshold) : |
duke@435 | 199 | CollectedMemoryPool(name, type, gen->from()->capacity(), max_size, |
duke@435 | 200 | support_usage_threshold), _gen(gen) { |
duke@435 | 201 | } |
duke@435 | 202 | |
duke@435 | 203 | MemoryUsage SurvivorContiguousSpacePool::get_memory_usage() { |
duke@435 | 204 | size_t maxSize = (available_for_allocation() ? max_size() : 0); |
duke@435 | 205 | size_t used = used_in_bytes(); |
duke@435 | 206 | size_t committed = committed_in_bytes(); |
duke@435 | 207 | |
duke@435 | 208 | return MemoryUsage(initial_size(), used, committed, maxSize); |
duke@435 | 209 | } |
duke@435 | 210 | |
duke@435 | 211 | #ifndef SERIALGC |
duke@435 | 212 | CompactibleFreeListSpacePool::CompactibleFreeListSpacePool(CompactibleFreeListSpace* space, |
duke@435 | 213 | const char* name, |
duke@435 | 214 | PoolType type, |
duke@435 | 215 | size_t max_size, |
duke@435 | 216 | bool support_usage_threshold) : |
duke@435 | 217 | CollectedMemoryPool(name, type, space->capacity(), max_size, |
duke@435 | 218 | support_usage_threshold), _space(space) { |
duke@435 | 219 | } |
duke@435 | 220 | |
duke@435 | 221 | MemoryUsage CompactibleFreeListSpacePool::get_memory_usage() { |
duke@435 | 222 | size_t maxSize = (available_for_allocation() ? max_size() : 0); |
duke@435 | 223 | size_t used = used_in_bytes(); |
duke@435 | 224 | size_t committed = _space->capacity(); |
duke@435 | 225 | |
duke@435 | 226 | return MemoryUsage(initial_size(), used, committed, maxSize); |
duke@435 | 227 | } |
duke@435 | 228 | #endif // SERIALGC |
duke@435 | 229 | |
duke@435 | 230 | GenerationPool::GenerationPool(Generation* gen, |
duke@435 | 231 | const char* name, |
duke@435 | 232 | PoolType type, |
duke@435 | 233 | bool support_usage_threshold) : |
duke@435 | 234 | CollectedMemoryPool(name, type, gen->capacity(), gen->max_capacity(), |
duke@435 | 235 | support_usage_threshold), _gen(gen) { |
duke@435 | 236 | } |
duke@435 | 237 | |
duke@435 | 238 | MemoryUsage GenerationPool::get_memory_usage() { |
duke@435 | 239 | size_t used = used_in_bytes(); |
duke@435 | 240 | size_t committed = _gen->capacity(); |
duke@435 | 241 | size_t maxSize = (available_for_allocation() ? max_size() : 0); |
duke@435 | 242 | |
duke@435 | 243 | return MemoryUsage(initial_size(), used, committed, maxSize); |
duke@435 | 244 | } |
duke@435 | 245 | |
duke@435 | 246 | CodeHeapPool::CodeHeapPool(CodeHeap* codeHeap, const char* name, bool support_usage_threshold) : |
duke@435 | 247 | MemoryPool(name, NonHeap, codeHeap->capacity(), codeHeap->max_capacity(), |
duke@435 | 248 | support_usage_threshold, false), _codeHeap(codeHeap) { |
duke@435 | 249 | } |
duke@435 | 250 | |
duke@435 | 251 | MemoryUsage CodeHeapPool::get_memory_usage() { |
duke@435 | 252 | size_t used = used_in_bytes(); |
duke@435 | 253 | size_t committed = _codeHeap->capacity(); |
duke@435 | 254 | size_t maxSize = (available_for_allocation() ? max_size() : 0); |
duke@435 | 255 | |
duke@435 | 256 | return MemoryUsage(initial_size(), used, committed, maxSize); |
duke@435 | 257 | } |