1.1 --- a/src/share/vm/memory/universe.cpp Thu Aug 22 09:39:54 2013 -0700 1.2 +++ b/src/share/vm/memory/universe.cpp Thu Sep 05 11:04:39 2013 -0700 1.3 @@ -105,10 +105,9 @@ 1.4 Array<Klass*>* Universe::_the_array_interfaces_array = NULL; 1.5 oop Universe::_the_null_string = NULL; 1.6 oop Universe::_the_min_jint_string = NULL; 1.7 -LatestMethodOopCache* Universe::_finalizer_register_cache = NULL; 1.8 -LatestMethodOopCache* Universe::_loader_addClass_cache = NULL; 1.9 -LatestMethodOopCache* Universe::_pd_implies_cache = NULL; 1.10 -ActiveMethodOopsCache* Universe::_reflect_invoke_cache = NULL; 1.11 +LatestMethodCache* Universe::_finalizer_register_cache = NULL; 1.12 +LatestMethodCache* Universe::_loader_addClass_cache = NULL; 1.13 +LatestMethodCache* Universe::_pd_implies_cache = NULL; 1.14 oop Universe::_out_of_memory_error_java_heap = NULL; 1.15 oop Universe::_out_of_memory_error_metaspace = NULL; 1.16 oop Universe::_out_of_memory_error_class_metaspace = NULL; 1.17 @@ -146,8 +145,6 @@ 1.18 NarrowPtrStruct Universe::_narrow_klass = { NULL, 0, true }; 1.19 address Universe::_narrow_ptrs_base; 1.20 1.21 -size_t Universe::_class_metaspace_size; 1.22 - 1.23 void Universe::basic_type_classes_do(void f(Klass*)) { 1.24 f(boolArrayKlassObj()); 1.25 f(byteArrayKlassObj()); 1.26 @@ -225,7 +222,6 @@ 1.27 f->do_ptr((void**)&_the_empty_klass_array); 1.28 _finalizer_register_cache->serialize(f); 1.29 _loader_addClass_cache->serialize(f); 1.30 - _reflect_invoke_cache->serialize(f); 1.31 _pd_implies_cache->serialize(f); 1.32 } 1.33 1.34 @@ -643,16 +639,17 @@ 1.35 return status; 1.36 } 1.37 1.38 + Metaspace::global_initialize(); 1.39 + 1.40 // Create memory for metadata. Must be after initializing heap for 1.41 // DumpSharedSpaces. 1.42 ClassLoaderData::init_null_class_loader_data(); 1.43 1.44 // We have a heap so create the Method* caches before 1.45 // Metaspace::initialize_shared_spaces() tries to populate them. 1.46 - Universe::_finalizer_register_cache = new LatestMethodOopCache(); 1.47 - Universe::_loader_addClass_cache = new LatestMethodOopCache(); 1.48 - Universe::_pd_implies_cache = new LatestMethodOopCache(); 1.49 - Universe::_reflect_invoke_cache = new ActiveMethodOopsCache(); 1.50 + Universe::_finalizer_register_cache = new LatestMethodCache(); 1.51 + Universe::_loader_addClass_cache = new LatestMethodCache(); 1.52 + Universe::_pd_implies_cache = new LatestMethodCache(); 1.53 1.54 if (UseSharedSpaces) { 1.55 // Read the data structures supporting the shared spaces (shared 1.56 @@ -684,25 +681,27 @@ 1.57 // 32Gb 1.58 // OopEncodingHeapMax == NarrowOopHeapMax << LogMinObjAlignmentInBytes; 1.59 1.60 -char* Universe::preferred_heap_base(size_t heap_size, NARROW_OOP_MODE mode) { 1.61 +char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_OOP_MODE mode) { 1.62 + assert(is_size_aligned((size_t)OopEncodingHeapMax, alignment), "Must be"); 1.63 + assert(is_size_aligned((size_t)NarrowOopHeapMax, alignment), "Must be"); 1.64 + assert(is_size_aligned(heap_size, alignment), "Must be"); 1.65 + 1.66 + uintx heap_base_min_address_aligned = align_size_up(HeapBaseMinAddress, alignment); 1.67 + 1.68 size_t base = 0; 1.69 #ifdef _LP64 1.70 if (UseCompressedOops) { 1.71 assert(mode == UnscaledNarrowOop || 1.72 mode == ZeroBasedNarrowOop || 1.73 mode == HeapBasedNarrowOop, "mode is invalid"); 1.74 - const size_t total_size = heap_size + HeapBaseMinAddress; 1.75 + const size_t total_size = heap_size + heap_base_min_address_aligned; 1.76 // Return specified base for the first request. 1.77 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress) && (mode == UnscaledNarrowOop)) { 1.78 - base = HeapBaseMinAddress; 1.79 + base = heap_base_min_address_aligned; 1.80 1.81 - // If the total size and the metaspace size are small enough to allow 1.82 - // UnscaledNarrowOop then just use UnscaledNarrowOop. 1.83 - } else if ((total_size <= OopEncodingHeapMax) && (mode != HeapBasedNarrowOop) && 1.84 - (!UseCompressedKlassPointers || 1.85 - (((OopEncodingHeapMax - heap_size) + Universe::class_metaspace_size()) <= KlassEncodingMetaspaceMax))) { 1.86 - // We don't need to check the metaspace size here because it is always smaller 1.87 - // than total_size. 1.88 + // If the total size is small enough to allow UnscaledNarrowOop then 1.89 + // just use UnscaledNarrowOop. 1.90 + } else if ((total_size <= OopEncodingHeapMax) && (mode != HeapBasedNarrowOop)) { 1.91 if ((total_size <= NarrowOopHeapMax) && (mode == UnscaledNarrowOop) && 1.92 (Universe::narrow_oop_shift() == 0)) { 1.93 // Use 32-bits oops without encoding and 1.94 @@ -719,13 +718,6 @@ 1.95 base = (OopEncodingHeapMax - heap_size); 1.96 } 1.97 } 1.98 - 1.99 - // See if ZeroBaseNarrowOop encoding will work for a heap based at 1.100 - // (KlassEncodingMetaspaceMax - class_metaspace_size()). 1.101 - } else if (UseCompressedKlassPointers && (mode != HeapBasedNarrowOop) && 1.102 - (Universe::class_metaspace_size() + HeapBaseMinAddress <= KlassEncodingMetaspaceMax) && 1.103 - (KlassEncodingMetaspaceMax + heap_size - Universe::class_metaspace_size() <= OopEncodingHeapMax)) { 1.104 - base = (KlassEncodingMetaspaceMax - Universe::class_metaspace_size()); 1.105 } else { 1.106 // UnscaledNarrowOop encoding didn't work, and no base was found for ZeroBasedOops or 1.107 // HeapBasedNarrowOop encoding was requested. So, can't reserve below 32Gb. 1.108 @@ -735,8 +727,7 @@ 1.109 // Set narrow_oop_base and narrow_oop_use_implicit_null_checks 1.110 // used in ReservedHeapSpace() constructors. 1.111 // The final values will be set in initialize_heap() below. 1.112 - if ((base != 0) && ((base + heap_size) <= OopEncodingHeapMax) && 1.113 - (!UseCompressedKlassPointers || (base + Universe::class_metaspace_size()) <= KlassEncodingMetaspaceMax)) { 1.114 + if ((base != 0) && ((base + heap_size) <= OopEncodingHeapMax)) { 1.115 // Use zero based compressed oops 1.116 Universe::set_narrow_oop_base(NULL); 1.117 // Don't need guard page for implicit checks in indexed 1.118 @@ -757,6 +748,8 @@ 1.119 } 1.120 } 1.121 #endif 1.122 + 1.123 + assert(is_ptr_aligned((char*)base, alignment), "Must be"); 1.124 return (char*)base; // also return NULL (don't care) for 32-bit VM 1.125 } 1.126 1.127 @@ -819,9 +812,7 @@ 1.128 tty->print("heap address: " PTR_FORMAT ", size: " SIZE_FORMAT " MB", 1.129 Universe::heap()->base(), Universe::heap()->reserved_region().byte_size()/M); 1.130 } 1.131 - if (((uint64_t)Universe::heap()->reserved_region().end() > OopEncodingHeapMax) || 1.132 - (UseCompressedKlassPointers && 1.133 - ((uint64_t)Universe::heap()->base() + Universe::class_metaspace_size() > KlassEncodingMetaspaceMax))) { 1.134 + if (((uint64_t)Universe::heap()->reserved_region().end() > OopEncodingHeapMax)) { 1.135 // Can't reserve heap below 32Gb. 1.136 // keep the Universe::narrow_oop_base() set in Universe::reserve_heap() 1.137 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); 1.138 @@ -857,20 +848,16 @@ 1.139 } 1.140 } 1.141 } 1.142 + 1.143 if (verbose) { 1.144 tty->cr(); 1.145 tty->cr(); 1.146 } 1.147 - if (UseCompressedKlassPointers) { 1.148 - Universe::set_narrow_klass_base(Universe::narrow_oop_base()); 1.149 - Universe::set_narrow_klass_shift(MIN2(Universe::narrow_oop_shift(), LogKlassAlignmentInBytes)); 1.150 - } 1.151 Universe::set_narrow_ptrs_base(Universe::narrow_oop_base()); 1.152 } 1.153 - // Universe::narrow_oop_base() is one page below the metaspace 1.154 - // base. The actual metaspace base depends on alignment constraints 1.155 - // so we don't know its exact location here. 1.156 - assert((intptr_t)Universe::narrow_oop_base() <= (intptr_t)(Universe::heap()->base() - os::vm_page_size() - ClassMetaspaceSize) || 1.157 + // Universe::narrow_oop_base() is one page below the heap. 1.158 + assert((intptr_t)Universe::narrow_oop_base() <= (intptr_t)(Universe::heap()->base() - 1.159 + os::vm_page_size()) || 1.160 Universe::narrow_oop_base() == NULL, "invalid value"); 1.161 assert(Universe::narrow_oop_shift() == LogMinObjAlignmentInBytes || 1.162 Universe::narrow_oop_shift() == 0, "invalid value"); 1.163 @@ -890,35 +877,36 @@ 1.164 1.165 // Reserve the Java heap, which is now the same for all GCs. 1.166 ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { 1.167 - // Add in the class metaspace area so the classes in the headers can 1.168 - // be compressed the same as instances. 1.169 - // Need to round class space size up because it's below the heap and 1.170 - // the actual alignment depends on its size. 1.171 - Universe::set_class_metaspace_size(align_size_up(ClassMetaspaceSize, alignment)); 1.172 - size_t total_reserved = align_size_up(heap_size + Universe::class_metaspace_size(), alignment); 1.173 + size_t total_reserved = align_size_up(heap_size, alignment); 1.174 assert(!UseCompressedOops || (total_reserved <= (OopEncodingHeapMax - os::vm_page_size())), 1.175 "heap size is too big for compressed oops"); 1.176 - char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop); 1.177 1.178 - ReservedHeapSpace total_rs(total_reserved, alignment, UseLargePages, addr); 1.179 + bool use_large_pages = UseLargePages && is_size_aligned(alignment, os::large_page_size()); 1.180 + assert(!UseLargePages 1.181 + || UseParallelOldGC 1.182 + || use_large_pages, "Wrong alignment to use large pages"); 1.183 + 1.184 + char* addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::UnscaledNarrowOop); 1.185 + 1.186 + ReservedHeapSpace total_rs(total_reserved, alignment, use_large_pages, addr); 1.187 1.188 if (UseCompressedOops) { 1.189 if (addr != NULL && !total_rs.is_reserved()) { 1.190 // Failed to reserve at specified address - the requested memory 1.191 // region is taken already, for example, by 'java' launcher. 1.192 // Try again to reserver heap higher. 1.193 - addr = Universe::preferred_heap_base(total_reserved, Universe::ZeroBasedNarrowOop); 1.194 + addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::ZeroBasedNarrowOop); 1.195 1.196 ReservedHeapSpace total_rs0(total_reserved, alignment, 1.197 - UseLargePages, addr); 1.198 + use_large_pages, addr); 1.199 1.200 if (addr != NULL && !total_rs0.is_reserved()) { 1.201 // Failed to reserve at specified address again - give up. 1.202 - addr = Universe::preferred_heap_base(total_reserved, Universe::HeapBasedNarrowOop); 1.203 + addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::HeapBasedNarrowOop); 1.204 assert(addr == NULL, ""); 1.205 1.206 ReservedHeapSpace total_rs1(total_reserved, alignment, 1.207 - UseLargePages, addr); 1.208 + use_large_pages, addr); 1.209 total_rs = total_rs1; 1.210 } else { 1.211 total_rs = total_rs0; 1.212 @@ -931,28 +919,17 @@ 1.213 return total_rs; 1.214 } 1.215 1.216 - // Split the reserved space into main Java heap and a space for 1.217 - // classes so that they can be compressed using the same algorithm 1.218 - // as compressed oops. If compress oops and compress klass ptrs are 1.219 - // used we need the meta space first: if the alignment used for 1.220 - // compressed oops is greater than the one used for compressed klass 1.221 - // ptrs, a metadata space on top of the heap could become 1.222 - // unreachable. 1.223 - ReservedSpace class_rs = total_rs.first_part(Universe::class_metaspace_size()); 1.224 - ReservedSpace heap_rs = total_rs.last_part(Universe::class_metaspace_size(), alignment); 1.225 - Metaspace::initialize_class_space(class_rs); 1.226 - 1.227 if (UseCompressedOops) { 1.228 // Universe::initialize_heap() will reset this to NULL if unscaled 1.229 // or zero-based narrow oops are actually used. 1.230 address base = (address)(total_rs.base() - os::vm_page_size()); 1.231 Universe::set_narrow_oop_base(base); 1.232 } 1.233 - return heap_rs; 1.234 + return total_rs; 1.235 } 1.236 1.237 1.238 -// It's the caller's repsonsibility to ensure glitch-freedom 1.239 +// It's the caller's responsibility to ensure glitch-freedom 1.240 // (if required). 1.241 void Universe::update_heap_info_at_gc() { 1.242 _heap_capacity_at_last_gc = heap()->capacity(); 1.243 @@ -1093,35 +1070,21 @@ 1.244 vmSymbols::register_method_name(), 1.245 vmSymbols::register_method_signature()); 1.246 if (m == NULL || !m->is_static()) { 1.247 - THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), 1.248 - "java.lang.ref.Finalizer.register", false); 1.249 + tty->print_cr("Unable to link/verify Finalizer.register method"); 1.250 + return false; // initialization failed (cannot throw exception yet) 1.251 } 1.252 Universe::_finalizer_register_cache->init( 1.253 - SystemDictionary::Finalizer_klass(), m, CHECK_false); 1.254 - 1.255 - // Resolve on first use and initialize class. 1.256 - // Note: No race-condition here, since a resolve will always return the same result 1.257 - 1.258 - // Setup method for security checks 1.259 - k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_reflect_Method(), true, CHECK_false); 1.260 - k_h = instanceKlassHandle(THREAD, k); 1.261 - k_h->link_class(CHECK_false); 1.262 - m = k_h->find_method(vmSymbols::invoke_name(), vmSymbols::object_object_array_object_signature()); 1.263 - if (m == NULL || m->is_static()) { 1.264 - THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), 1.265 - "java.lang.reflect.Method.invoke", false); 1.266 - } 1.267 - Universe::_reflect_invoke_cache->init(k_h(), m, CHECK_false); 1.268 + SystemDictionary::Finalizer_klass(), m); 1.269 1.270 // Setup method for registering loaded classes in class loader vector 1.271 InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->link_class(CHECK_false); 1.272 m = InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->find_method(vmSymbols::addClass_name(), vmSymbols::class_void_signature()); 1.273 if (m == NULL || m->is_static()) { 1.274 - THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), 1.275 - "java.lang.ClassLoader.addClass", false); 1.276 + tty->print_cr("Unable to link/verify ClassLoader.addClass method"); 1.277 + return false; // initialization failed (cannot throw exception yet) 1.278 } 1.279 Universe::_loader_addClass_cache->init( 1.280 - SystemDictionary::ClassLoader_klass(), m, CHECK_false); 1.281 + SystemDictionary::ClassLoader_klass(), m); 1.282 1.283 // Setup method for checking protection domain 1.284 InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->link_class(CHECK_false); 1.285 @@ -1137,7 +1100,7 @@ 1.286 return false; // initialization failed 1.287 } 1.288 Universe::_pd_implies_cache->init( 1.289 - SystemDictionary::ProtectionDomain_klass(), m, CHECK_false);; 1.290 + SystemDictionary::ProtectionDomain_klass(), m);; 1.291 } 1.292 1.293 // The folowing is initializing converter functions for serialization in 1.294 @@ -1157,6 +1120,8 @@ 1.295 1.296 // Initialize performance counters for metaspaces 1.297 MetaspaceCounters::initialize_performance_counters(); 1.298 + CompressedClassSpaceCounters::initialize_performance_counters(); 1.299 + 1.300 MemoryService::add_metaspace_memory_pools(); 1.301 1.302 GC_locker::unlock(); // allow gc after bootstrapping 1.303 @@ -1460,7 +1425,7 @@ 1.304 } 1.305 1.306 1.307 -void CommonMethodOopCache::init(Klass* k, Method* m, TRAPS) { 1.308 +void LatestMethodCache::init(Klass* k, Method* m) { 1.309 if (!UseSharedSpaces) { 1.310 _klass = k; 1.311 } 1.312 @@ -1476,88 +1441,7 @@ 1.313 } 1.314 1.315 1.316 -ActiveMethodOopsCache::~ActiveMethodOopsCache() { 1.317 - if (_prev_methods != NULL) { 1.318 - delete _prev_methods; 1.319 - _prev_methods = NULL; 1.320 - } 1.321 -} 1.322 - 1.323 - 1.324 -void ActiveMethodOopsCache::add_previous_version(Method* method) { 1.325 - assert(Thread::current()->is_VM_thread(), 1.326 - "only VMThread can add previous versions"); 1.327 - 1.328 - // Only append the previous method if it is executing on the stack. 1.329 - if (method->on_stack()) { 1.330 - 1.331 - if (_prev_methods == NULL) { 1.332 - // This is the first previous version so make some space. 1.333 - // Start with 2 elements under the assumption that the class 1.334 - // won't be redefined much. 1.335 - _prev_methods = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Method*>(2, true); 1.336 - } 1.337 - 1.338 - // RC_TRACE macro has an embedded ResourceMark 1.339 - RC_TRACE(0x00000100, 1.340 - ("add: %s(%s): adding prev version ref for cached method @%d", 1.341 - method->name()->as_C_string(), method->signature()->as_C_string(), 1.342 - _prev_methods->length())); 1.343 - 1.344 - _prev_methods->append(method); 1.345 - } 1.346 - 1.347 - 1.348 - // Since the caller is the VMThread and we are at a safepoint, this is a good 1.349 - // time to clear out unused method references. 1.350 - 1.351 - if (_prev_methods == NULL) return; 1.352 - 1.353 - for (int i = _prev_methods->length() - 1; i >= 0; i--) { 1.354 - Method* method = _prev_methods->at(i); 1.355 - assert(method != NULL, "weak method ref was unexpectedly cleared"); 1.356 - 1.357 - if (!method->on_stack()) { 1.358 - // This method isn't running anymore so remove it 1.359 - _prev_methods->remove_at(i); 1.360 - MetadataFactory::free_metadata(method->method_holder()->class_loader_data(), method); 1.361 - } else { 1.362 - // RC_TRACE macro has an embedded ResourceMark 1.363 - RC_TRACE(0x00000400, 1.364 - ("add: %s(%s): previous cached method @%d is alive", 1.365 - method->name()->as_C_string(), method->signature()->as_C_string(), i)); 1.366 - } 1.367 - } 1.368 -} // end add_previous_version() 1.369 - 1.370 - 1.371 -bool ActiveMethodOopsCache::is_same_method(const Method* method) const { 1.372 - InstanceKlass* ik = InstanceKlass::cast(klass()); 1.373 - const Method* check_method = ik->method_with_idnum(method_idnum()); 1.374 - assert(check_method != NULL, "sanity check"); 1.375 - if (check_method == method) { 1.376 - // done with the easy case 1.377 - return true; 1.378 - } 1.379 - 1.380 - if (_prev_methods != NULL) { 1.381 - // The cached method has been redefined at least once so search 1.382 - // the previous versions for a match. 1.383 - for (int i = 0; i < _prev_methods->length(); i++) { 1.384 - check_method = _prev_methods->at(i); 1.385 - if (check_method == method) { 1.386 - // a previous version matches 1.387 - return true; 1.388 - } 1.389 - } 1.390 - } 1.391 - 1.392 - // either no previous versions or no previous version matched 1.393 - return false; 1.394 -} 1.395 - 1.396 - 1.397 -Method* LatestMethodOopCache::get_Method() { 1.398 +Method* LatestMethodCache::get_method() { 1.399 if (klass() == NULL) return NULL; 1.400 InstanceKlass* ik = InstanceKlass::cast(klass()); 1.401 Method* m = ik->method_with_idnum(method_idnum());