annotate src/share/vm/memory/universe.cpp @ 5699:9d15b81d5d1b

8016839: JSR292: AME instead of IAE when calling a method Summary: Catch missing-because-illegal case for itable entries and use an exception-throwing method instead of null. Reviewed-by: acorn, jrose, coleenp
author drchase
date Tue, 26 Nov 2013 18:16:04 -0500
parents 610be0309a79
children
rev   line source
duke@0 1 /*
hseigel@4030 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1472 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1472 20 * or visit www.oracle.com if you need additional information or have any
trims@1472 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1879 25 #include "precompiled.hpp"
stefank@1879 26 #include "classfile/classLoader.hpp"
coleenp@3602 27 #include "classfile/classLoaderData.hpp"
stefank@1879 28 #include "classfile/javaClasses.hpp"
stefank@1879 29 #include "classfile/symbolTable.hpp"
stefank@1879 30 #include "classfile/systemDictionary.hpp"
stefank@1879 31 #include "classfile/vmSymbols.hpp"
stefank@1879 32 #include "code/codeCache.hpp"
stefank@1879 33 #include "code/dependencies.hpp"
stefank@1879 34 #include "gc_interface/collectedHeap.inline.hpp"
stefank@1879 35 #include "interpreter/interpreter.hpp"
stefank@1879 36 #include "memory/cardTableModRefBS.hpp"
stefank@1879 37 #include "memory/gcLocker.inline.hpp"
stefank@1879 38 #include "memory/genCollectedHeap.hpp"
stefank@1879 39 #include "memory/genRemSet.hpp"
stefank@1879 40 #include "memory/generation.hpp"
coleenp@3602 41 #include "memory/metadataFactory.hpp"
coleenp@3602 42 #include "memory/metaspaceShared.hpp"
stefank@1879 43 #include "memory/oopFactory.hpp"
stefank@1879 44 #include "memory/space.hpp"
stefank@1879 45 #include "memory/universe.hpp"
stefank@1879 46 #include "memory/universe.inline.hpp"
coleenp@3602 47 #include "oops/constantPool.hpp"
coleenp@3602 48 #include "oops/instanceClassLoaderKlass.hpp"
stefank@1879 49 #include "oops/instanceKlass.hpp"
never@2223 50 #include "oops/instanceMirrorKlass.hpp"
stefank@1879 51 #include "oops/instanceRefKlass.hpp"
stefank@1879 52 #include "oops/oop.inline.hpp"
stefank@1879 53 #include "oops/typeArrayKlass.hpp"
stefank@1879 54 #include "prims/jvmtiRedefineClassesTrace.hpp"
stefank@1879 55 #include "runtime/arguments.hpp"
stefank@1879 56 #include "runtime/deoptimization.hpp"
stefank@1879 57 #include "runtime/fprofiler.hpp"
stefank@1879 58 #include "runtime/handles.inline.hpp"
stefank@1879 59 #include "runtime/init.hpp"
stefank@1879 60 #include "runtime/java.hpp"
stefank@1879 61 #include "runtime/javaCalls.hpp"
stefank@1879 62 #include "runtime/sharedRuntime.hpp"
stefank@1879 63 #include "runtime/synchronizer.hpp"
stefank@3864 64 #include "runtime/thread.inline.hpp"
stefank@1879 65 #include "runtime/timer.hpp"
stefank@1879 66 #include "runtime/vm_operations.hpp"
stefank@1879 67 #include "services/memoryService.hpp"
stefank@1879 68 #include "utilities/copy.hpp"
stefank@1879 69 #include "utilities/events.hpp"
stefank@1879 70 #include "utilities/hashtable.inline.hpp"
stefank@1879 71 #include "utilities/preserveException.hpp"
jprovino@4107 72 #include "utilities/macros.hpp"
jprovino@4107 73 #if INCLUDE_ALL_GCS
stefank@1879 74 #include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
stefank@1879 75 #include "gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.hpp"
stefank@1879 76 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
stefank@1879 77 #include "gc_implementation/g1/g1CollectorPolicy.hpp"
stefank@1879 78 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
jprovino@4107 79 #endif // INCLUDE_ALL_GCS
duke@0 80
duke@0 81 // Known objects
coleenp@3602 82 Klass* Universe::_boolArrayKlassObj = NULL;
coleenp@3602 83 Klass* Universe::_byteArrayKlassObj = NULL;
coleenp@3602 84 Klass* Universe::_charArrayKlassObj = NULL;
coleenp@3602 85 Klass* Universe::_intArrayKlassObj = NULL;
coleenp@3602 86 Klass* Universe::_shortArrayKlassObj = NULL;
coleenp@3602 87 Klass* Universe::_longArrayKlassObj = NULL;
coleenp@3602 88 Klass* Universe::_singleArrayKlassObj = NULL;
coleenp@3602 89 Klass* Universe::_doubleArrayKlassObj = NULL;
coleenp@3602 90 Klass* Universe::_typeArrayKlassObjs[T_VOID+1] = { NULL /*, NULL...*/ };
coleenp@3602 91 Klass* Universe::_objectArrayKlassObj = NULL;
jcoomes@481 92 oop Universe::_int_mirror = NULL;
jcoomes@481 93 oop Universe::_float_mirror = NULL;
jcoomes@481 94 oop Universe::_double_mirror = NULL;
jcoomes@481 95 oop Universe::_byte_mirror = NULL;
jcoomes@481 96 oop Universe::_bool_mirror = NULL;
jcoomes@481 97 oop Universe::_char_mirror = NULL;
jcoomes@481 98 oop Universe::_long_mirror = NULL;
jcoomes@481 99 oop Universe::_short_mirror = NULL;
jcoomes@481 100 oop Universe::_void_mirror = NULL;
jcoomes@481 101 oop Universe::_mirrors[T_VOID+1] = { NULL /*, NULL...*/ };
duke@0 102 oop Universe::_main_thread_group = NULL;
duke@0 103 oop Universe::_system_thread_group = NULL;
duke@0 104 objArrayOop Universe::_the_empty_class_klass_array = NULL;
coleenp@3602 105 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
never@1080 106 oop Universe::_the_null_string = NULL;
never@1080 107 oop Universe::_the_min_jint_string = NULL;
coleenp@5073 108 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
coleenp@5073 109 LatestMethodCache* Universe::_loader_addClass_cache = NULL;
coleenp@5073 110 LatestMethodCache* Universe::_pd_implies_cache = NULL;
duke@0 111 oop Universe::_out_of_memory_error_java_heap = NULL;
coleenp@4902 112 oop Universe::_out_of_memory_error_metaspace = NULL;
coleenp@4902 113 oop Universe::_out_of_memory_error_class_metaspace = NULL;
duke@0 114 oop Universe::_out_of_memory_error_array_size = NULL;
duke@0 115 oop Universe::_out_of_memory_error_gc_overhead_limit = NULL;
duke@0 116 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
duke@0 117 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
duke@0 118 bool Universe::_verify_in_progress = false;
duke@0 119 oop Universe::_null_ptr_exception_instance = NULL;
duke@0 120 oop Universe::_arithmetic_exception_instance = NULL;
duke@0 121 oop Universe::_virtual_machine_error_instance = NULL;
duke@0 122 oop Universe::_vm_exception = NULL;
drchase@5699 123 Method* Universe::_throw_illegal_access_error = NULL;
coleenp@3602 124 Array<int>* Universe::_the_empty_int_array = NULL;
coleenp@3602 125 Array<u2>* Universe::_the_empty_short_array = NULL;
coleenp@3602 126 Array<Klass*>* Universe::_the_empty_klass_array = NULL;
coleenp@3602 127 Array<Method*>* Universe::_the_empty_method_array = NULL;
duke@0 128
duke@0 129 // These variables are guarded by FullGCALot_lock.
duke@0 130 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
duke@0 131 debug_only(int Universe::_fullgc_alot_dummy_next = 0;)
duke@0 132
duke@0 133 // Heap
duke@0 134 int Universe::_verify_count = 0;
duke@0 135
duke@0 136 int Universe::_base_vtable_size = 0;
duke@0 137 bool Universe::_bootstrapping = false;
duke@0 138 bool Universe::_fully_initialized = false;
duke@0 139
duke@0 140 size_t Universe::_heap_capacity_at_last_gc;
ysr@453 141 size_t Universe::_heap_used_at_last_gc = 0;
duke@0 142
duke@0 143 CollectedHeap* Universe::_collectedHeap = NULL;
kvn@642 144
roland@3724 145 NarrowPtrStruct Universe::_narrow_oop = { NULL, 0, true };
roland@3724 146 NarrowPtrStruct Universe::_narrow_klass = { NULL, 0, true };
roland@3724 147 address Universe::_narrow_ptrs_base;
duke@0 148
coleenp@3602 149 void Universe::basic_type_classes_do(void f(Klass*)) {
duke@0 150 f(boolArrayKlassObj());
duke@0 151 f(byteArrayKlassObj());
duke@0 152 f(charArrayKlassObj());
duke@0 153 f(intArrayKlassObj());
duke@0 154 f(shortArrayKlassObj());
duke@0 155 f(longArrayKlassObj());
duke@0 156 f(singleArrayKlassObj());
duke@0 157 f(doubleArrayKlassObj());
duke@0 158 }
duke@0 159
duke@0 160 void Universe::oops_do(OopClosure* f, bool do_all) {
duke@0 161
duke@0 162 f->do_oop((oop*) &_int_mirror);
duke@0 163 f->do_oop((oop*) &_float_mirror);
duke@0 164 f->do_oop((oop*) &_double_mirror);
duke@0 165 f->do_oop((oop*) &_byte_mirror);
duke@0 166 f->do_oop((oop*) &_bool_mirror);
duke@0 167 f->do_oop((oop*) &_char_mirror);
duke@0 168 f->do_oop((oop*) &_long_mirror);
duke@0 169 f->do_oop((oop*) &_short_mirror);
duke@0 170 f->do_oop((oop*) &_void_mirror);
duke@0 171
duke@0 172 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
duke@0 173 f->do_oop((oop*) &_mirrors[i]);
duke@0 174 }
duke@0 175 assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking");
duke@0 176
duke@0 177 f->do_oop((oop*)&_the_empty_class_klass_array);
never@1080 178 f->do_oop((oop*)&_the_null_string);
never@1080 179 f->do_oop((oop*)&_the_min_jint_string);
duke@0 180 f->do_oop((oop*)&_out_of_memory_error_java_heap);
coleenp@4902 181 f->do_oop((oop*)&_out_of_memory_error_metaspace);
coleenp@4902 182 f->do_oop((oop*)&_out_of_memory_error_class_metaspace);
duke@0 183 f->do_oop((oop*)&_out_of_memory_error_array_size);
duke@0 184 f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit);
duke@0 185 f->do_oop((oop*)&_preallocated_out_of_memory_error_array);
duke@0 186 f->do_oop((oop*)&_null_ptr_exception_instance);
duke@0 187 f->do_oop((oop*)&_arithmetic_exception_instance);
duke@0 188 f->do_oop((oop*)&_virtual_machine_error_instance);
duke@0 189 f->do_oop((oop*)&_main_thread_group);
duke@0 190 f->do_oop((oop*)&_system_thread_group);
duke@0 191 f->do_oop((oop*)&_vm_exception);
duke@0 192 debug_only(f->do_oop((oop*)&_fullgc_alot_dummy_array);)
duke@0 193 }
duke@0 194
coleenp@3602 195 // Serialize metadata in and out of CDS archive, not oops.
coleenp@3602 196 void Universe::serialize(SerializeClosure* f, bool do_all) {
coleenp@3602 197
coleenp@3602 198 f->do_ptr((void**)&_boolArrayKlassObj);
coleenp@3602 199 f->do_ptr((void**)&_byteArrayKlassObj);
coleenp@3602 200 f->do_ptr((void**)&_charArrayKlassObj);
coleenp@3602 201 f->do_ptr((void**)&_intArrayKlassObj);
coleenp@3602 202 f->do_ptr((void**)&_shortArrayKlassObj);
coleenp@3602 203 f->do_ptr((void**)&_longArrayKlassObj);
coleenp@3602 204 f->do_ptr((void**)&_singleArrayKlassObj);
coleenp@3602 205 f->do_ptr((void**)&_doubleArrayKlassObj);
coleenp@3602 206 f->do_ptr((void**)&_objectArrayKlassObj);
coleenp@3602 207
coleenp@3602 208 {
coleenp@3602 209 for (int i = 0; i < T_VOID+1; i++) {
coleenp@3602 210 if (_typeArrayKlassObjs[i] != NULL) {
coleenp@3602 211 assert(i >= T_BOOLEAN, "checking");
coleenp@3602 212 f->do_ptr((void**)&_typeArrayKlassObjs[i]);
coleenp@3602 213 } else if (do_all) {
coleenp@3602 214 f->do_ptr((void**)&_typeArrayKlassObjs[i]);
coleenp@3602 215 }
coleenp@3602 216 }
coleenp@3602 217 }
coleenp@3602 218
coleenp@3602 219 f->do_ptr((void**)&_the_array_interfaces_array);
coleenp@3602 220 f->do_ptr((void**)&_the_empty_int_array);
coleenp@3602 221 f->do_ptr((void**)&_the_empty_short_array);
coleenp@3602 222 f->do_ptr((void**)&_the_empty_method_array);
coleenp@3602 223 f->do_ptr((void**)&_the_empty_klass_array);
coleenp@3602 224 _finalizer_register_cache->serialize(f);
coleenp@3627 225 _loader_addClass_cache->serialize(f);
mullan@4807 226 _pd_implies_cache->serialize(f);
coleenp@3602 227 }
duke@0 228
duke@0 229 void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
duke@0 230 if (size < alignment || size % alignment != 0) {
tamao@4756 231 vm_exit_during_initialization(
tamao@4756 232 err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
duke@0 233 }
duke@0 234 }
duke@0 235
coleenp@3602 236 void initialize_basic_type_klass(Klass* k, TRAPS) {
coleenp@3602 237 Klass* ok = SystemDictionary::Object_klass();
coleenp@3602 238 if (UseSharedSpaces) {
coleenp@3602 239 assert(k->super() == ok, "u3");
coleenp@3602 240 k->restore_unshareable_info(CHECK);
coleenp@3602 241 } else {
coleenp@3602 242 k->initialize_supers(ok, CHECK);
coleenp@3602 243 }
coleenp@3602 244 k->append_to_sibling_list();
coleenp@3602 245 }
duke@0 246
duke@0 247 void Universe::genesis(TRAPS) {
duke@0 248 ResourceMark rm;
coleenp@3602 249
duke@0 250 { FlagSetting fs(_bootstrapping, true);
duke@0 251
duke@0 252 { MutexLocker mc(Compile_lock);
duke@0 253
duke@0 254 // determine base vtable size; without that we cannot create the array klasses
duke@0 255 compute_base_vtable_size();
duke@0 256
duke@0 257 if (!UseSharedSpaces) {
coleenp@3707 258 _boolArrayKlassObj = TypeArrayKlass::create_klass(T_BOOLEAN, sizeof(jboolean), CHECK);
coleenp@3707 259 _charArrayKlassObj = TypeArrayKlass::create_klass(T_CHAR, sizeof(jchar), CHECK);
coleenp@3707 260 _singleArrayKlassObj = TypeArrayKlass::create_klass(T_FLOAT, sizeof(jfloat), CHECK);
coleenp@3707 261 _doubleArrayKlassObj = TypeArrayKlass::create_klass(T_DOUBLE, sizeof(jdouble), CHECK);
coleenp@3707 262 _byteArrayKlassObj = TypeArrayKlass::create_klass(T_BYTE, sizeof(jbyte), CHECK);
coleenp@3707 263 _shortArrayKlassObj = TypeArrayKlass::create_klass(T_SHORT, sizeof(jshort), CHECK);
coleenp@3707 264 _intArrayKlassObj = TypeArrayKlass::create_klass(T_INT, sizeof(jint), CHECK);
coleenp@3707 265 _longArrayKlassObj = TypeArrayKlass::create_klass(T_LONG, sizeof(jlong), CHECK);
duke@0 266
duke@0 267 _typeArrayKlassObjs[T_BOOLEAN] = _boolArrayKlassObj;
duke@0 268 _typeArrayKlassObjs[T_CHAR] = _charArrayKlassObj;
duke@0 269 _typeArrayKlassObjs[T_FLOAT] = _singleArrayKlassObj;
duke@0 270 _typeArrayKlassObjs[T_DOUBLE] = _doubleArrayKlassObj;
duke@0 271 _typeArrayKlassObjs[T_BYTE] = _byteArrayKlassObj;
duke@0 272 _typeArrayKlassObjs[T_SHORT] = _shortArrayKlassObj;
duke@0 273 _typeArrayKlassObjs[T_INT] = _intArrayKlassObj;
duke@0 274 _typeArrayKlassObjs[T_LONG] = _longArrayKlassObj;
duke@0 275
coleenp@3602 276 ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data();
duke@0 277
coleenp@3602 278 _the_array_interfaces_array = MetadataFactory::new_array<Klass*>(null_cld, 2, NULL, CHECK);
coleenp@3602 279 _the_empty_int_array = MetadataFactory::new_array<int>(null_cld, 0, CHECK);
coleenp@3602 280 _the_empty_short_array = MetadataFactory::new_array<u2>(null_cld, 0, CHECK);
coleenp@3602 281 _the_empty_method_array = MetadataFactory::new_array<Method*>(null_cld, 0, CHECK);
coleenp@3602 282 _the_empty_klass_array = MetadataFactory::new_array<Klass*>(null_cld, 0, CHECK);
duke@0 283 }
duke@0 284 }
duke@0 285
duke@0 286 vmSymbols::initialize(CHECK);
duke@0 287
duke@0 288 SystemDictionary::initialize(CHECK);
duke@0 289
coleenp@3602 290 Klass* ok = SystemDictionary::Object_klass();
duke@0 291
never@1080 292 _the_null_string = StringTable::intern("null", CHECK);
never@1080 293 _the_min_jint_string = StringTable::intern("-2147483648", CHECK);
never@1080 294
duke@0 295 if (UseSharedSpaces) {
duke@0 296 // Verify shared interfaces array.
coleenp@3602 297 assert(_the_array_interfaces_array->at(0) ==
never@1142 298 SystemDictionary::Cloneable_klass(), "u3");
coleenp@3602 299 assert(_the_array_interfaces_array->at(1) ==
never@1142 300 SystemDictionary::Serializable_klass(), "u3");
duke@0 301 } else {
duke@0 302 // Set up shared interfaces array. (Do this before supers are set up.)
coleenp@3602 303 _the_array_interfaces_array->at_put(0, SystemDictionary::Cloneable_klass());
coleenp@3602 304 _the_array_interfaces_array->at_put(1, SystemDictionary::Serializable_klass());
duke@0 305 }
duke@0 306
coleenp@3602 307 initialize_basic_type_klass(boolArrayKlassObj(), CHECK);
coleenp@3602 308 initialize_basic_type_klass(charArrayKlassObj(), CHECK);
coleenp@3602 309 initialize_basic_type_klass(singleArrayKlassObj(), CHECK);
coleenp@3602 310 initialize_basic_type_klass(doubleArrayKlassObj(), CHECK);
coleenp@3602 311 initialize_basic_type_klass(byteArrayKlassObj(), CHECK);
coleenp@3602 312 initialize_basic_type_klass(shortArrayKlassObj(), CHECK);
coleenp@3602 313 initialize_basic_type_klass(intArrayKlassObj(), CHECK);
coleenp@3602 314 initialize_basic_type_klass(longArrayKlassObj(), CHECK);
duke@0 315 } // end of core bootstrapping
duke@0 316
coleenp@3602 317 // Maybe this could be lifted up now that object array can be initialized
coleenp@3602 318 // during the bootstrapping.
coleenp@3602 319
coleenp@3602 320 // OLD
duke@0 321 // Initialize _objectArrayKlass after core bootstraping to make
duke@0 322 // sure the super class is set up properly for _objectArrayKlass.
coleenp@3602 323 // ---
coleenp@3602 324 // NEW
coleenp@3602 325 // Since some of the old system object arrays have been converted to
coleenp@3602 326 // ordinary object arrays, _objectArrayKlass will be loaded when
coleenp@3602 327 // SystemDictionary::initialize(CHECK); is run. See the extra check
coleenp@3602 328 // for Object_klass_loaded in objArrayKlassKlass::allocate_objArray_klass_impl.
coleenp@3602 329 _objectArrayKlassObj = InstanceKlass::
never@1142 330 cast(SystemDictionary::Object_klass())->array_klass(1, CHECK);
coleenp@3602 331 // OLD
duke@0 332 // Add the class to the class hierarchy manually to make sure that
duke@0 333 // its vtable is initialized after core bootstrapping is completed.
coleenp@3602 334 // ---
coleenp@3602 335 // New
coleenp@3602 336 // Have already been initialized.
hseigel@3843 337 _objectArrayKlassObj->append_to_sibling_list();
duke@0 338
duke@0 339 // Compute is_jdk version flags.
duke@0 340 // Only 1.3 or later has the java.lang.Shutdown class.
duke@0 341 // Only 1.4 or later has the java.lang.CharSequence interface.
duke@0 342 // Only 1.5 or later has the java.lang.management.MemoryUsage class.
kamg@242 343 if (JDK_Version::is_partially_initialized()) {
kamg@242 344 uint8_t jdk_version;
coleenp@3602 345 Klass* k = SystemDictionary::resolve_or_null(
coleenp@2062 346 vmSymbols::java_lang_management_MemoryUsage(), THREAD);
duke@0 347 CLEAR_PENDING_EXCEPTION; // ignore exceptions
duke@0 348 if (k == NULL) {
kamg@242 349 k = SystemDictionary::resolve_or_null(
coleenp@2062 350 vmSymbols::java_lang_CharSequence(), THREAD);
duke@0 351 CLEAR_PENDING_EXCEPTION; // ignore exceptions
duke@0 352 if (k == NULL) {
kamg@242 353 k = SystemDictionary::resolve_or_null(
coleenp@2062 354 vmSymbols::java_lang_Shutdown(), THREAD);
duke@0 355 CLEAR_PENDING_EXCEPTION; // ignore exceptions
duke@0 356 if (k == NULL) {
kamg@242 357 jdk_version = 2;
duke@0 358 } else {
kamg@242 359 jdk_version = 3;
duke@0 360 }
duke@0 361 } else {
kamg@242 362 jdk_version = 4;
duke@0 363 }
duke@0 364 } else {
kamg@242 365 jdk_version = 5;
duke@0 366 }
kamg@242 367 JDK_Version::fully_initialize(jdk_version);
duke@0 368 }
duke@0 369
duke@0 370 #ifdef ASSERT
duke@0 371 if (FullGCALot) {
duke@0 372 // Allocate an array of dummy objects.
duke@0 373 // We'd like these to be at the bottom of the old generation,
duke@0 374 // so that when we free one and then collect,
duke@0 375 // (almost) the whole heap moves
duke@0 376 // and we find out if we actually update all the oops correctly.
duke@0 377 // But we can't allocate directly in the old generation,
duke@0 378 // so we allocate wherever, and hope that the first collection
duke@0 379 // moves these objects to the bottom of the old generation.
duke@0 380 // We can allocate directly in the permanent generation, so we do.
duke@0 381 int size;
duke@0 382 if (UseConcMarkSweepGC) {
duke@0 383 warning("Using +FullGCALot with concurrent mark sweep gc "
duke@0 384 "will not force all objects to relocate");
duke@0 385 size = FullGCALotDummies;
duke@0 386 } else {
duke@0 387 size = FullGCALotDummies * 2;
duke@0 388 }
coleenp@3602 389 objArrayOop naked_array = oopFactory::new_objArray(SystemDictionary::Object_klass(), size, CHECK);
duke@0 390 objArrayHandle dummy_array(THREAD, naked_array);
duke@0 391 int i = 0;
duke@0 392 while (i < size) {
duke@0 393 // Allocate dummy in old generation
coleenp@3602 394 oop dummy = InstanceKlass::cast(SystemDictionary::Object_klass())->allocate_instance(CHECK);
duke@0 395 dummy_array->obj_at_put(i++, dummy);
duke@0 396 }
duke@0 397 {
duke@0 398 // Only modify the global variable inside the mutex.
duke@0 399 // If we had a race to here, the other dummy_array instances
duke@0 400 // and their elements just get dropped on the floor, which is fine.
duke@0 401 MutexLocker ml(FullGCALot_lock);
duke@0 402 if (_fullgc_alot_dummy_array == NULL) {
duke@0 403 _fullgc_alot_dummy_array = dummy_array();
duke@0 404 }
duke@0 405 }
duke@0 406 assert(i == _fullgc_alot_dummy_array->length(), "just checking");
duke@0 407 }
duke@0 408 #endif
coleenp@3869 409
coleenp@3869 410 // Initialize dependency array for null class loader
coleenp@3869 411 ClassLoaderData::the_null_class_loader_data()->init_dependencies(CHECK);
coleenp@3869 412
duke@0 413 }
duke@0 414
coleenp@3602 415 // CDS support for patching vtables in metadata in the shared archive.
coleenp@3602 416 // All types inherited from Metadata have vtables, but not types inherited
coleenp@3602 417 // from MetaspaceObj, because the latter does not have virtual functions.
coleenp@3602 418 // If the metadata type has a vtable, it cannot be shared in the read-only
coleenp@3602 419 // section of the CDS archive, because the vtable pointer is patched.
coleenp@2062 420 static inline void add_vtable(void** list, int* n, void* o, int count) {
coleenp@2062 421 guarantee((*n) < count, "vtable list too small");
coleenp@3860 422 void* vtable = dereference_vptr(o);
coleenp@3860 423 assert(*(void**)(vtable) != NULL, "invalid vtable");
coleenp@2062 424 list[(*n)++] = vtable;
coleenp@2062 425 }
duke@0 426
duke@0 427 void Universe::init_self_patching_vtbl_list(void** list, int count) {
duke@0 428 int n = 0;
coleenp@3602 429 { InstanceKlass o; add_vtable(list, &n, &o, count); }
coleenp@3612 430 { InstanceClassLoaderKlass o; add_vtable(list, &n, &o, count); }
coleenp@3612 431 { InstanceMirrorKlass o; add_vtable(list, &n, &o, count); }
coleenp@3612 432 { InstanceRefKlass o; add_vtable(list, &n, &o, count); }
coleenp@3707 433 { TypeArrayKlass o; add_vtable(list, &n, &o, count); }
coleenp@3707 434 { ObjArrayKlass o; add_vtable(list, &n, &o, count); }
coleenp@3602 435 { Method o; add_vtable(list, &n, &o, count); }
coleenp@3602 436 { ConstantPool o; add_vtable(list, &n, &o, count); }
duke@0 437 }
duke@0 438
duke@0 439 void Universe::initialize_basic_type_mirrors(TRAPS) {
duke@0 440 assert(_int_mirror==NULL, "basic type mirrors already initialized");
duke@0 441 _int_mirror =
duke@0 442 java_lang_Class::create_basic_type_mirror("int", T_INT, CHECK);
duke@0 443 _float_mirror =
duke@0 444 java_lang_Class::create_basic_type_mirror("float", T_FLOAT, CHECK);
duke@0 445 _double_mirror =
duke@0 446 java_lang_Class::create_basic_type_mirror("double", T_DOUBLE, CHECK);
duke@0 447 _byte_mirror =
duke@0 448 java_lang_Class::create_basic_type_mirror("byte", T_BYTE, CHECK);
duke@0 449 _bool_mirror =
duke@0 450 java_lang_Class::create_basic_type_mirror("boolean",T_BOOLEAN, CHECK);
duke@0 451 _char_mirror =
duke@0 452 java_lang_Class::create_basic_type_mirror("char", T_CHAR, CHECK);
duke@0 453 _long_mirror =
duke@0 454 java_lang_Class::create_basic_type_mirror("long", T_LONG, CHECK);
duke@0 455 _short_mirror =
duke@0 456 java_lang_Class::create_basic_type_mirror("short", T_SHORT, CHECK);
duke@0 457 _void_mirror =
duke@0 458 java_lang_Class::create_basic_type_mirror("void", T_VOID, CHECK);
duke@0 459
duke@0 460 _mirrors[T_INT] = _int_mirror;
duke@0 461 _mirrors[T_FLOAT] = _float_mirror;
duke@0 462 _mirrors[T_DOUBLE] = _double_mirror;
duke@0 463 _mirrors[T_BYTE] = _byte_mirror;
duke@0 464 _mirrors[T_BOOLEAN] = _bool_mirror;
duke@0 465 _mirrors[T_CHAR] = _char_mirror;
duke@0 466 _mirrors[T_LONG] = _long_mirror;
duke@0 467 _mirrors[T_SHORT] = _short_mirror;
duke@0 468 _mirrors[T_VOID] = _void_mirror;
coleenp@3602 469 //_mirrors[T_OBJECT] = InstanceKlass::cast(_object_klass)->java_mirror();
coleenp@3602 470 //_mirrors[T_ARRAY] = InstanceKlass::cast(_object_klass)->java_mirror();
duke@0 471 }
duke@0 472
duke@0 473 void Universe::fixup_mirrors(TRAPS) {
duke@0 474 // Bootstrap problem: all classes gets a mirror (java.lang.Class instance) assigned eagerly,
duke@0 475 // but we cannot do that for classes created before java.lang.Class is loaded. Here we simply
duke@0 476 // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note
duke@0 477 // that the number of objects allocated at this point is very small.
never@1142 478 assert(SystemDictionary::Class_klass_loaded(), "java.lang.Class should be loaded");
coleenp@3602 479 HandleMark hm(THREAD);
never@2223 480 // Cache the start of the static fields
coleenp@3612 481 InstanceMirrorKlass::init_offset_of_static_fields();
never@2223 482
coleenp@3602 483 GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list();
coleenp@3602 484 int list_length = list->length();
coleenp@3602 485 for (int i = 0; i < list_length; i++) {
coleenp@3602 486 Klass* k = list->at(i);
coleenp@3602 487 assert(k->is_klass(), "List should only hold classes");
coleenp@3602 488 EXCEPTION_MARK;
coleenp@3602 489 KlassHandle kh(THREAD, k);
coleenp@3602 490 java_lang_Class::fixup_mirror(kh, CATCH);
duke@0 491 }
coleenp@3602 492 delete java_lang_Class::fixup_mirror_list();
coleenp@3602 493 java_lang_Class::set_fixup_mirror_list(NULL);
coleenp@3602 494 }
duke@0 495
duke@0 496 static bool has_run_finalizers_on_exit = false;
duke@0 497
duke@0 498 void Universe::run_finalizers_on_exit() {
duke@0 499 if (has_run_finalizers_on_exit) return;
duke@0 500 has_run_finalizers_on_exit = true;
duke@0 501
duke@0 502 // Called on VM exit. This ought to be run in a separate thread.
duke@0 503 if (TraceReferenceGC) tty->print_cr("Callback to run finalizers on exit");
duke@0 504 {
duke@0 505 PRESERVE_EXCEPTION_MARK;
never@1142 506 KlassHandle finalizer_klass(THREAD, SystemDictionary::Finalizer_klass());
duke@0 507 JavaValue result(T_VOID);
duke@0 508 JavaCalls::call_static(
duke@0 509 &result,
duke@0 510 finalizer_klass,
coleenp@2062 511 vmSymbols::run_finalizers_on_exit_name(),
coleenp@2062 512 vmSymbols::void_method_signature(),
duke@0 513 THREAD
duke@0 514 );
duke@0 515 // Ignore any pending exceptions
duke@0 516 CLEAR_PENDING_EXCEPTION;
duke@0 517 }
duke@0 518 }
duke@0 519
duke@0 520
duke@0 521 // initialize_vtable could cause gc if
duke@0 522 // 1) we specified true to initialize_vtable and
duke@0 523 // 2) this ran after gc was enabled
duke@0 524 // In case those ever change we use handles for oops
duke@0 525 void Universe::reinitialize_vtable_of(KlassHandle k_h, TRAPS) {
duke@0 526 // init vtable of k and all subclasses
coleenp@3602 527 Klass* ko = k_h();
duke@0 528 klassVtable* vt = ko->vtable();
duke@0 529 if (vt) vt->initialize_vtable(false, CHECK);
duke@0 530 if (ko->oop_is_instance()) {
coleenp@3602 531 InstanceKlass* ik = (InstanceKlass*)ko;
ccheung@4824 532 for (KlassHandle s_h(THREAD, ik->subklass());
ccheung@4824 533 s_h() != NULL;
ccheung@4824 534 s_h = KlassHandle(THREAD, s_h()->next_sibling())) {
duke@0 535 reinitialize_vtable_of(s_h, CHECK);
duke@0 536 }
duke@0 537 }
duke@0 538 }
duke@0 539
duke@0 540
coleenp@3602 541 void initialize_itable_for_klass(Klass* k, TRAPS) {
coleenp@3602 542 InstanceKlass::cast(k)->itable()->initialize_itable(false, CHECK);
duke@0 543 }
duke@0 544
duke@0 545
duke@0 546 void Universe::reinitialize_itables(TRAPS) {
duke@0 547 SystemDictionary::classes_do(initialize_itable_for_klass, CHECK);
duke@0 548
duke@0 549 }
duke@0 550
duke@0 551
duke@0 552 bool Universe::on_page_boundary(void* addr) {
duke@0 553 return ((uintptr_t) addr) % os::vm_page_size() == 0;
duke@0 554 }
duke@0 555
duke@0 556
duke@0 557 bool Universe::should_fill_in_stack_trace(Handle throwable) {
duke@0 558 // never attempt to fill in the stack trace of preallocated errors that do not have
duke@0 559 // backtrace. These errors are kept alive forever and may be "re-used" when all
duke@0 560 // preallocated errors with backtrace have been consumed. Also need to avoid
duke@0 561 // a potential loop which could happen if an out of memory occurs when attempting
duke@0 562 // to allocate the backtrace.
duke@0 563 return ((throwable() != Universe::_out_of_memory_error_java_heap) &&
coleenp@4902 564 (throwable() != Universe::_out_of_memory_error_metaspace) &&
coleenp@4902 565 (throwable() != Universe::_out_of_memory_error_class_metaspace) &&
duke@0 566 (throwable() != Universe::_out_of_memory_error_array_size) &&
duke@0 567 (throwable() != Universe::_out_of_memory_error_gc_overhead_limit));
duke@0 568 }
duke@0 569
duke@0 570
duke@0 571 oop Universe::gen_out_of_memory_error(oop default_err) {
duke@0 572 // generate an out of memory error:
duke@0 573 // - if there is a preallocated error with backtrace available then return it wth
duke@0 574 // a filled in stack trace.
duke@0 575 // - if there are no preallocated errors with backtrace available then return
duke@0 576 // an error without backtrace.
duke@0 577 int next;
duke@0 578 if (_preallocated_out_of_memory_error_avail_count > 0) {
duke@0 579 next = (int)Atomic::add(-1, &_preallocated_out_of_memory_error_avail_count);
duke@0 580 assert(next < (int)PreallocatedOutOfMemoryErrorCount, "avail count is corrupt");
duke@0 581 } else {
duke@0 582 next = -1;
duke@0 583 }
duke@0 584 if (next < 0) {
duke@0 585 // all preallocated errors have been used.
duke@0 586 // return default
duke@0 587 return default_err;
duke@0 588 } else {
duke@0 589 // get the error object at the slot and set set it to NULL so that the
duke@0 590 // array isn't keeping it alive anymore.
duke@0 591 oop exc = preallocated_out_of_memory_errors()->obj_at(next);
duke@0 592 assert(exc != NULL, "slot has been used already");
duke@0 593 preallocated_out_of_memory_errors()->obj_at_put(next, NULL);
duke@0 594
duke@0 595 // use the message from the default error
duke@0 596 oop msg = java_lang_Throwable::message(default_err);
duke@0 597 assert(msg != NULL, "no message");
duke@0 598 java_lang_Throwable::set_message(exc, msg);
duke@0 599
duke@0 600 // populate the stack trace and return it.
duke@0 601 java_lang_Throwable::fill_in_stack_trace_of_preallocated_backtrace(exc);
duke@0 602 return exc;
duke@0 603 }
duke@0 604 }
duke@0 605
twisti@5291 606 intptr_t Universe::_non_oop_bits = 0;
duke@0 607
duke@0 608 void* Universe::non_oop_word() {
duke@0 609 // Neither the high bits nor the low bits of this value is allowed
duke@0 610 // to look like (respectively) the high or low bits of a real oop.
duke@0 611 //
duke@0 612 // High and low are CPU-specific notions, but low always includes
duke@0 613 // the low-order bit. Since oops are always aligned at least mod 4,
duke@0 614 // setting the low-order bit will ensure that the low half of the
duke@0 615 // word will never look like that of a real oop.
duke@0 616 //
duke@0 617 // Using the OS-supplied non-memory-address word (usually 0 or -1)
duke@0 618 // will take care of the high bits, however many there are.
duke@0 619
twisti@5291 620 if (_non_oop_bits == 0) {
twisti@5291 621 _non_oop_bits = (intptr_t)os::non_memory_address_word() | 1;
duke@0 622 }
duke@0 623
twisti@5291 624 return (void*)_non_oop_bits;
duke@0 625 }
duke@0 626
duke@0 627 jint universe_init() {
duke@0 628 assert(!Universe::_fully_initialized, "called after initialize_vtables");
duke@0 629 guarantee(1 << LogHeapWordSize == sizeof(HeapWord),
duke@0 630 "LogHeapWordSize is incorrect.");
duke@0 631 guarantee(sizeof(oop) >= sizeof(HeapWord), "HeapWord larger than oop?");
duke@0 632 guarantee(sizeof(oop) % sizeof(HeapWord) == 0,
coleenp@113 633 "oop size is not not a multiple of HeapWord size");
duke@0 634 TraceTime timer("Genesis", TraceStartupTime);
duke@0 635 GC_locker::lock(); // do not allow gc during bootstrapping
duke@0 636 JavaClasses::compute_hard_coded_offsets();
duke@0 637
duke@0 638 jint status = Universe::initialize_heap();
duke@0 639 if (status != JNI_OK) {
duke@0 640 return status;
duke@0 641 }
duke@0 642
hseigel@5093 643 Metaspace::global_initialize();
hseigel@5093 644
coleenp@3602 645 // Create memory for metadata. Must be after initializing heap for
coleenp@3602 646 // DumpSharedSpaces.
coleenp@3602 647 ClassLoaderData::init_null_class_loader_data();
coleenp@3602 648
coleenp@3602 649 // We have a heap so create the Method* caches before
coleenp@3602 650 // Metaspace::initialize_shared_spaces() tries to populate them.
coleenp@5073 651 Universe::_finalizer_register_cache = new LatestMethodCache();
coleenp@5073 652 Universe::_loader_addClass_cache = new LatestMethodCache();
coleenp@5073 653 Universe::_pd_implies_cache = new LatestMethodCache();
duke@0 654
duke@0 655 if (UseSharedSpaces) {
duke@0 656 // Read the data structures supporting the shared spaces (shared
duke@0 657 // system dictionary, symbol table, etc.). After that, access to
duke@0 658 // the file (other than the mapped regions) is no longer needed, and
duke@0 659 // the file is closed. Closing the file does not affect the
duke@0 660 // currently mapped regions.
coleenp@3602 661 MetaspaceShared::initialize_shared_spaces();
coleenp@3602 662 StringTable::create_table();
duke@0 663 } else {
duke@0 664 SymbolTable::create_table();
duke@0 665 StringTable::create_table();
duke@0 666 ClassLoader::create_package_info_table();
duke@0 667 }
duke@0 668
duke@0 669 return JNI_OK;
duke@0 670 }
duke@0 671
kvn@642 672 // Choose the heap base address and oop encoding mode
kvn@642 673 // when compressed oops are used:
kvn@642 674 // Unscaled - Use 32-bits oops without encoding when
kvn@642 675 // NarrowOopHeapBaseMin + heap_size < 4Gb
kvn@642 676 // ZeroBased - Use zero based compressed oops with encoding when
kvn@642 677 // NarrowOopHeapBaseMin + heap_size < 32Gb
kvn@642 678 // HeapBased - Use compressed oops with heap base + encoding.
kvn@642 679
kvn@642 680 // 4Gb
coleenp@5594 681 static const uint64_t UnscaledOopHeapMax = (uint64_t(max_juint) + 1);
kvn@642 682 // 32Gb
coleenp@5594 683 // OopEncodingHeapMax == UnscaledOopHeapMax << LogMinObjAlignmentInBytes;
kvn@642 684
stefank@5143 685 char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_OOP_MODE mode) {
stefank@5143 686 assert(is_size_aligned((size_t)OopEncodingHeapMax, alignment), "Must be");
coleenp@5594 687 assert(is_size_aligned((size_t)UnscaledOopHeapMax, alignment), "Must be");
stefank@5143 688 assert(is_size_aligned(heap_size, alignment), "Must be");
stefank@5143 689
stefank@5143 690 uintx heap_base_min_address_aligned = align_size_up(HeapBaseMinAddress, alignment);
stefank@5143 691
kvn@1057 692 size_t base = 0;
kvn@642 693 #ifdef _LP64
kvn@642 694 if (UseCompressedOops) {
kvn@642 695 assert(mode == UnscaledNarrowOop ||
kvn@642 696 mode == ZeroBasedNarrowOop ||
kvn@642 697 mode == HeapBasedNarrowOop, "mode is invalid");
stefank@5143 698 const size_t total_size = heap_size + heap_base_min_address_aligned;
kvn@922 699 // Return specified base for the first request.
kvn@922 700 if (!FLAG_IS_DEFAULT(HeapBaseMinAddress) && (mode == UnscaledNarrowOop)) {
stefank@5143 701 base = heap_base_min_address_aligned;
hseigel@4088 702
hseigel@5093 703 // If the total size is small enough to allow UnscaledNarrowOop then
hseigel@5093 704 // just use UnscaledNarrowOop.
hseigel@5093 705 } else if ((total_size <= OopEncodingHeapMax) && (mode != HeapBasedNarrowOop)) {
coleenp@5594 706 if ((total_size <= UnscaledOopHeapMax) && (mode == UnscaledNarrowOop) &&
kvn@642 707 (Universe::narrow_oop_shift() == 0)) {
kvn@642 708 // Use 32-bits oops without encoding and
kvn@642 709 // place heap's top on the 4Gb boundary
coleenp@5594 710 base = (UnscaledOopHeapMax - heap_size);
kvn@642 711 } else {
kvn@642 712 // Can't reserve with NarrowOopShift == 0
kvn@642 713 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
coleenp@5594 714
kvn@642 715 if (mode == UnscaledNarrowOop ||
coleenp@5594 716 mode == ZeroBasedNarrowOop && total_size <= UnscaledOopHeapMax) {
coleenp@5594 717
kvn@642 718 // Use zero based compressed oops with encoding and
kvn@642 719 // place heap's top on the 32Gb boundary in case
kvn@642 720 // total_size > 4Gb or failed to reserve below 4Gb.
coleenp@5594 721 uint64_t heap_top = OopEncodingHeapMax;
coleenp@5594 722
coleenp@5594 723 // For small heaps, save some space for compressed class pointer
coleenp@5594 724 // space so it can be decoded with no base.
coleenp@5594 725 if (UseCompressedClassPointers && !UseSharedSpaces &&
coleenp@5594 726 OopEncodingHeapMax <= 32*G) {
coleenp@5594 727
coleenp@5594 728 uint64_t class_space = align_size_up(CompressedClassSpaceSize, alignment);
coleenp@5594 729 assert(is_size_aligned((size_t)OopEncodingHeapMax-class_space,
coleenp@5594 730 alignment), "difference must be aligned too");
coleenp@5594 731 uint64_t new_top = OopEncodingHeapMax-class_space;
coleenp@5594 732
coleenp@5594 733 if (total_size <= new_top) {
coleenp@5594 734 heap_top = new_top;
coleenp@5594 735 }
coleenp@5594 736 }
coleenp@5594 737
coleenp@5594 738 // Align base to the adjusted top of the heap
coleenp@5594 739 base = heap_top - heap_size;
kvn@642 740 }
kvn@642 741 }
kvn@642 742 } else {
hseigel@4088 743 // UnscaledNarrowOop encoding didn't work, and no base was found for ZeroBasedOops or
hseigel@4088 744 // HeapBasedNarrowOop encoding was requested. So, can't reserve below 32Gb.
kvn@642 745 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
kvn@642 746 }
hseigel@4088 747
kvn@1057 748 // Set narrow_oop_base and narrow_oop_use_implicit_null_checks
kvn@1057 749 // used in ReservedHeapSpace() constructors.
kvn@1057 750 // The final values will be set in initialize_heap() below.
hseigel@5093 751 if ((base != 0) && ((base + heap_size) <= OopEncodingHeapMax)) {
kvn@1057 752 // Use zero based compressed oops
kvn@1057 753 Universe::set_narrow_oop_base(NULL);
kvn@1057 754 // Don't need guard page for implicit checks in indexed
kvn@1057 755 // addressing mode with zero based Compressed Oops.
kvn@1057 756 Universe::set_narrow_oop_use_implicit_null_checks(true);
kvn@1057 757 } else {
kvn@1057 758 // Set to a non-NULL value so the ReservedSpace ctor computes
kvn@1057 759 // the correct no-access prefix.
kvn@1057 760 // The final value will be set in initialize_heap() below.
coleenp@5594 761 Universe::set_narrow_oop_base((address)UnscaledOopHeapMax);
kvn@1057 762 #ifdef _WIN64
kvn@1057 763 if (UseLargePages) {
kvn@1057 764 // Cannot allocate guard pages for implicit checks in indexed
kvn@1057 765 // addressing mode when large pages are specified on windows.
kvn@1057 766 Universe::set_narrow_oop_use_implicit_null_checks(false);
kvn@1057 767 }
kvn@1057 768 #endif // _WIN64
kvn@1057 769 }
kvn@642 770 }
kvn@642 771 #endif
stefank@5143 772
stefank@5143 773 assert(is_ptr_aligned((char*)base, alignment), "Must be");
kvn@1057 774 return (char*)base; // also return NULL (don't care) for 32-bit VM
kvn@642 775 }
kvn@642 776
duke@0 777 jint Universe::initialize_heap() {
duke@0 778
duke@0 779 if (UseParallelGC) {
jprovino@4107 780 #if INCLUDE_ALL_GCS
duke@0 781 Universe::_collectedHeap = new ParallelScavengeHeap();
jprovino@4107 782 #else // INCLUDE_ALL_GCS
jprovino@3730 783 fatal("UseParallelGC not supported in this VM.");
jprovino@4107 784 #endif // INCLUDE_ALL_GCS
duke@0 785
ysr@342 786 } else if (UseG1GC) {
jprovino@4107 787 #if INCLUDE_ALL_GCS
tonyp@2774 788 G1CollectorPolicy* g1p = new G1CollectorPolicy();
jwilhelm@5650 789 g1p->initialize_all();
ysr@342 790 G1CollectedHeap* g1h = new G1CollectedHeap(g1p);
ysr@342 791 Universe::_collectedHeap = g1h;
jprovino@4107 792 #else // INCLUDE_ALL_GCS
ysr@342 793 fatal("UseG1GC not supported in java kernel vm.");
jprovino@4107 794 #endif // INCLUDE_ALL_GCS
ysr@342 795
duke@0 796 } else {
duke@0 797 GenCollectorPolicy *gc_policy;
duke@0 798
duke@0 799 if (UseSerialGC) {
duke@0 800 gc_policy = new MarkSweepPolicy();
duke@0 801 } else if (UseConcMarkSweepGC) {
jprovino@4107 802 #if INCLUDE_ALL_GCS
duke@0 803 if (UseAdaptiveSizePolicy) {
duke@0 804 gc_policy = new ASConcurrentMarkSweepPolicy();
duke@0 805 } else {
duke@0 806 gc_policy = new ConcurrentMarkSweepPolicy();
duke@0 807 }
jprovino@4107 808 #else // INCLUDE_ALL_GCS
jprovino@3730 809 fatal("UseConcMarkSweepGC not supported in this VM.");
jprovino@4107 810 #endif // INCLUDE_ALL_GCS
duke@0 811 } else { // default old generation
duke@0 812 gc_policy = new MarkSweepPolicy();
duke@0 813 }
jwilhelm@5650 814 gc_policy->initialize_all();
duke@0 815
duke@0 816 Universe::_collectedHeap = new GenCollectedHeap(gc_policy);
duke@0 817 }
duke@0 818
duke@0 819 jint status = Universe::heap()->initialize();
duke@0 820 if (status != JNI_OK) {
duke@0 821 return status;
duke@0 822 }
kvn@642 823
kvn@642 824 #ifdef _LP64
coleenp@113 825 if (UseCompressedOops) {
coleenp@113 826 // Subtract a page because something can get allocated at heap base.
coleenp@113 827 // This also makes implicit null checking work, because the
coleenp@113 828 // memory+1 page below heap_base needs to cause a signal.
coleenp@113 829 // See needs_explicit_null_check.
coleenp@113 830 // Only set the heap base for compressed oops because it indicates
coleenp@113 831 // compressed oops for pstack code.
kvn@1968 832 bool verbose = PrintCompressedOopsMode || (PrintMiscellaneous && Verbose);
kvn@1968 833 if (verbose) {
kvn@642 834 tty->cr();
kvn@1870 835 tty->print("heap address: " PTR_FORMAT ", size: " SIZE_FORMAT " MB",
kvn@1870 836 Universe::heap()->base(), Universe::heap()->reserved_region().byte_size()/M);
kvn@642 837 }
hseigel@5093 838 if (((uint64_t)Universe::heap()->reserved_region().end() > OopEncodingHeapMax)) {
kvn@642 839 // Can't reserve heap below 32Gb.
roland@3724 840 // keep the Universe::narrow_oop_base() set in Universe::reserve_heap()
kvn@642 841 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
kvn@1968 842 if (verbose) {
sla@4802 843 tty->print(", %s: "PTR_FORMAT,
sla@4802 844 narrow_oop_mode_to_string(HeapBasedNarrowOop),
sla@4802 845 Universe::narrow_oop_base());
kvn@642 846 }
kvn@642 847 } else {
kvn@642 848 Universe::set_narrow_oop_base(0);
kvn@1968 849 if (verbose) {
sla@4802 850 tty->print(", %s", narrow_oop_mode_to_string(ZeroBasedNarrowOop));
kvn@642 851 }
kvn@642 852 #ifdef _WIN64
kvn@642 853 if (!Universe::narrow_oop_use_implicit_null_checks()) {
kvn@642 854 // Don't need guard page for implicit checks in indexed addressing
kvn@642 855 // mode with zero based Compressed Oops.
kvn@642 856 Universe::set_narrow_oop_use_implicit_null_checks(true);
kvn@642 857 }
kvn@642 858 #endif // _WIN64
coleenp@5594 859 if((uint64_t)Universe::heap()->reserved_region().end() > UnscaledOopHeapMax) {
kvn@642 860 // Can't reserve heap below 4Gb.
kvn@642 861 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
kvn@642 862 } else {
kvn@922 863 Universe::set_narrow_oop_shift(0);
kvn@1968 864 if (verbose) {
sla@4802 865 tty->print(", %s", narrow_oop_mode_to_string(UnscaledNarrowOop));
kvn@642 866 }
kvn@642 867 }
kvn@642 868 }
hseigel@5093 869
kvn@1968 870 if (verbose) {
kvn@642 871 tty->cr();
kvn@642 872 tty->cr();
kvn@642 873 }
roland@3724 874 Universe::set_narrow_ptrs_base(Universe::narrow_oop_base());
coleenp@113 875 }
hseigel@5093 876 // Universe::narrow_oop_base() is one page below the heap.
hseigel@5093 877 assert((intptr_t)Universe::narrow_oop_base() <= (intptr_t)(Universe::heap()->base() -
hseigel@5093 878 os::vm_page_size()) ||
kvn@642 879 Universe::narrow_oop_base() == NULL, "invalid value");
kvn@642 880 assert(Universe::narrow_oop_shift() == LogMinObjAlignmentInBytes ||
kvn@642 881 Universe::narrow_oop_shift() == 0, "invalid value");
kvn@642 882 #endif
duke@0 883
duke@0 884 // We will never reach the CATCH below since Exceptions::_throw will cause
duke@0 885 // the VM to exit if an exception is thrown during initialization
duke@0 886
duke@0 887 if (UseTLAB) {
duke@0 888 assert(Universe::heap()->supports_tlab_allocation(),
duke@0 889 "Should support thread-local allocation buffers");
duke@0 890 ThreadLocalAllocBuffer::startup_initialization();
duke@0 891 }
duke@0 892 return JNI_OK;
duke@0 893 }
duke@0 894
coleenp@3602 895
coleenp@3602 896 // Reserve the Java heap, which is now the same for all GCs.
coleenp@3602 897 ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) {
tschatzl@5266 898 assert(alignment <= Arguments::conservative_max_heap_alignment(),
tschatzl@5266 899 err_msg("actual alignment "SIZE_FORMAT" must be within maximum heap alignment "SIZE_FORMAT,
tschatzl@5266 900 alignment, Arguments::conservative_max_heap_alignment()));
hseigel@5093 901 size_t total_reserved = align_size_up(heap_size, alignment);
brutisso@4306 902 assert(!UseCompressedOops || (total_reserved <= (OopEncodingHeapMax - os::vm_page_size())),
brutisso@4306 903 "heap size is too big for compressed oops");
coleenp@3602 904
stefank@5143 905 bool use_large_pages = UseLargePages && is_size_aligned(alignment, os::large_page_size());
stefank@5143 906 assert(!UseLargePages
tschatzl@5276 907 || UseParallelGC
stefank@5143 908 || use_large_pages, "Wrong alignment to use large pages");
stefank@5143 909
stefank@5143 910 char* addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::UnscaledNarrowOop);
stefank@5143 911
stefank@5143 912 ReservedHeapSpace total_rs(total_reserved, alignment, use_large_pages, addr);
coleenp@3602 913
coleenp@3602 914 if (UseCompressedOops) {
coleenp@3602 915 if (addr != NULL && !total_rs.is_reserved()) {
coleenp@3602 916 // Failed to reserve at specified address - the requested memory
coleenp@3602 917 // region is taken already, for example, by 'java' launcher.
coleenp@3602 918 // Try again to reserver heap higher.
stefank@5143 919 addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::ZeroBasedNarrowOop);
coleenp@3602 920
coleenp@3602 921 ReservedHeapSpace total_rs0(total_reserved, alignment,
stefank@5143 922 use_large_pages, addr);
coleenp@3602 923
coleenp@3602 924 if (addr != NULL && !total_rs0.is_reserved()) {
coleenp@3602 925 // Failed to reserve at specified address again - give up.
stefank@5143 926 addr = Universe::preferred_heap_base(total_reserved, alignment, Universe::HeapBasedNarrowOop);
coleenp@3602 927 assert(addr == NULL, "");
coleenp@3602 928
coleenp@3602 929 ReservedHeapSpace total_rs1(total_reserved, alignment,
stefank@5143 930 use_large_pages, addr);
coleenp@3602 931 total_rs = total_rs1;
coleenp@3602 932 } else {
coleenp@3602 933 total_rs = total_rs0;
coleenp@3602 934 }
coleenp@3602 935 }
coleenp@3602 936 }
coleenp@3602 937
coleenp@3602 938 if (!total_rs.is_reserved()) {
tamao@4756 939 vm_exit_during_initialization(err_msg("Could not reserve enough space for " SIZE_FORMAT "KB object heap", total_reserved/K));
coleenp@3602 940 return total_rs;
coleenp@3602 941 }
coleenp@3602 942
roland@3724 943 if (UseCompressedOops) {
roland@3724 944 // Universe::initialize_heap() will reset this to NULL if unscaled
roland@3724 945 // or zero-based narrow oops are actually used.
roland@3724 946 address base = (address)(total_rs.base() - os::vm_page_size());
roland@3724 947 Universe::set_narrow_oop_base(base);
roland@3724 948 }
hseigel@5093 949 return total_rs;
coleenp@3602 950 }
coleenp@3602 951
coleenp@3602 952
hseigel@5093 953 // It's the caller's responsibility to ensure glitch-freedom
duke@0 954 // (if required).
duke@0 955 void Universe::update_heap_info_at_gc() {
duke@0 956 _heap_capacity_at_last_gc = heap()->capacity();
duke@0 957 _heap_used_at_last_gc = heap()->used();
duke@0 958 }
duke@0 959
duke@0 960
sla@4802 961 const char* Universe::narrow_oop_mode_to_string(Universe::NARROW_OOP_MODE mode) {
sla@4802 962 switch (mode) {
sla@4802 963 case UnscaledNarrowOop:
sla@4802 964 return "32-bits Oops";
sla@4802 965 case ZeroBasedNarrowOop:
sla@4802 966 return "zero based Compressed Oops";
sla@4802 967 case HeapBasedNarrowOop:
sla@4802 968 return "Compressed Oops with base";
sla@4802 969 }
sla@4802 970
sla@4802 971 ShouldNotReachHere();
sla@4802 972 return "";
sla@4802 973 }
sla@4802 974
sla@4802 975
sla@4802 976 Universe::NARROW_OOP_MODE Universe::narrow_oop_mode() {
sla@4802 977 if (narrow_oop_base() != 0) {
sla@4802 978 return HeapBasedNarrowOop;
sla@4802 979 }
sla@4802 980
sla@4802 981 if (narrow_oop_shift() != 0) {
sla@4802 982 return ZeroBasedNarrowOop;
sla@4802 983 }
sla@4802 984
sla@4802 985 return UnscaledNarrowOop;
sla@4802 986 }
sla@4802 987
duke@0 988
duke@0 989 void universe2_init() {
duke@0 990 EXCEPTION_MARK;
duke@0 991 Universe::genesis(CATCH);
duke@0 992 }
duke@0 993
duke@0 994
duke@0 995 // This function is defined in JVM.cpp
duke@0 996 extern void initialize_converter_functions();
duke@0 997
duke@0 998 bool universe_post_init() {
ysr@1866 999 assert(!is_init_completed(), "Error: initialization not yet completed!");
duke@0 1000 Universe::_fully_initialized = true;
duke@0 1001 EXCEPTION_MARK;
duke@0 1002 { ResourceMark rm;
duke@0 1003 Interpreter::initialize(); // needed for interpreter entry points
duke@0 1004 if (!UseSharedSpaces) {
coleenp@3602 1005 HandleMark hm(THREAD);
never@1142 1006 KlassHandle ok_h(THREAD, SystemDictionary::Object_klass());
duke@0 1007 Universe::reinitialize_vtable_of(ok_h, CHECK_false);
duke@0 1008 Universe::reinitialize_itables(CHECK_false);
duke@0 1009 }
duke@0 1010 }
duke@0 1011
coleenp@3602 1012 HandleMark hm(THREAD);
coleenp@3602 1013 Klass* k;
duke@0 1014 instanceKlassHandle k_h;
duke@0 1015 // Setup preallocated empty java.lang.Class array
never@1142 1016 Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_false);
coleenp@3602 1017
duke@0 1018 // Setup preallocated OutOfMemoryError errors
coleenp@2062 1019 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false);
duke@0 1020 k_h = instanceKlassHandle(THREAD, k);
coleenp@3602 1021 Universe::_out_of_memory_error_java_heap = k_h->allocate_instance(CHECK_false);
coleenp@4902 1022 Universe::_out_of_memory_error_metaspace = k_h->allocate_instance(CHECK_false);
coleenp@4902 1023 Universe::_out_of_memory_error_class_metaspace = k_h->allocate_instance(CHECK_false);
coleenp@3602 1024 Universe::_out_of_memory_error_array_size = k_h->allocate_instance(CHECK_false);
duke@0 1025 Universe::_out_of_memory_error_gc_overhead_limit =
coleenp@3602 1026 k_h->allocate_instance(CHECK_false);
duke@0 1027
duke@0 1028 // Setup preallocated NullPointerException
duke@0 1029 // (this is currently used for a cheap & dirty solution in compiler exception handling)
coleenp@2062 1030 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false);
coleenp@3602 1031 Universe::_null_ptr_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
duke@0 1032 // Setup preallocated ArithmeticException
duke@0 1033 // (this is currently used for a cheap & dirty solution in compiler exception handling)
coleenp@2062 1034 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false);
coleenp@3602 1035 Universe::_arithmetic_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
duke@0 1036 // Virtual Machine Error for when we get into a situation we can't resolve
duke@0 1037 k = SystemDictionary::resolve_or_fail(
coleenp@2062 1038 vmSymbols::java_lang_VirtualMachineError(), true, CHECK_false);
coleenp@3602 1039 bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
duke@0 1040 if (!linked) {
duke@0 1041 tty->print_cr("Unable to link/verify VirtualMachineError class");
duke@0 1042 return false; // initialization failed
duke@0 1043 }
duke@0 1044 Universe::_virtual_machine_error_instance =
coleenp@3602 1045 InstanceKlass::cast(k)->allocate_instance(CHECK_false);
coleenp@2062 1046
jwilhelm@5649 1047 Universe::_vm_exception = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
coleenp@2062 1048
duke@0 1049 if (!DumpSharedSpaces) {
duke@0 1050 // These are the only Java fields that are currently set during shared space dumping.
duke@0 1051 // We prefer to not handle this generally, so we always reinitialize these detail messages.
duke@0 1052 Handle msg = java_lang_String::create_from_str("Java heap space", CHECK_false);
duke@0 1053 java_lang_Throwable::set_message(Universe::_out_of_memory_error_java_heap, msg());
duke@0 1054
hseigel@5592 1055 msg = java_lang_String::create_from_str("Metaspace", CHECK_false);
coleenp@4902 1056 java_lang_Throwable::set_message(Universe::_out_of_memory_error_metaspace, msg());
ehelin@5259 1057 msg = java_lang_String::create_from_str("Compressed class space", CHECK_false);
coleenp@4902 1058 java_lang_Throwable::set_message(Universe::_out_of_memory_error_class_metaspace, msg());
duke@0 1059
duke@0 1060 msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false);
duke@0 1061 java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg());
duke@0 1062
duke@0 1063 msg = java_lang_String::create_from_str("GC overhead limit exceeded", CHECK_false);
duke@0 1064 java_lang_Throwable::set_message(Universe::_out_of_memory_error_gc_overhead_limit, msg());
duke@0 1065
duke@0 1066 msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
duke@0 1067 java_lang_Throwable::set_message(Universe::_arithmetic_exception_instance, msg());
duke@0 1068
duke@0 1069 // Setup the array of errors that have preallocated backtrace
duke@0 1070 k = Universe::_out_of_memory_error_java_heap->klass();
coleenp@3602 1071 assert(k->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error");
duke@0 1072 k_h = instanceKlassHandle(THREAD, k);
duke@0 1073
duke@0 1074 int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0;
duke@0 1075 Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(k_h(), len, CHECK_false);
duke@0 1076 for (int i=0; i<len; i++) {
coleenp@3602 1077 oop err = k_h->allocate_instance(CHECK_false);
duke@0 1078 Handle err_h = Handle(THREAD, err);
duke@0 1079 java_lang_Throwable::allocate_backtrace(err_h, CHECK_false);
duke@0 1080 Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h());
duke@0 1081 }
duke@0 1082 Universe::_preallocated_out_of_memory_error_avail_count = (jint)len;
duke@0 1083 }
duke@0 1084
duke@0 1085
duke@0 1086 // Setup static method for registering finalizers
duke@0 1087 // The finalizer klass must be linked before looking up the method, in
duke@0 1088 // case it needs to get rewritten.
coleenp@3602 1089 InstanceKlass::cast(SystemDictionary::Finalizer_klass())->link_class(CHECK_false);
coleenp@3602 1090 Method* m = InstanceKlass::cast(SystemDictionary::Finalizer_klass())->find_method(
duke@0 1091 vmSymbols::register_method_name(),
duke@0 1092 vmSymbols::register_method_signature());
duke@0 1093 if (m == NULL || !m->is_static()) {
coleenp@5073 1094 tty->print_cr("Unable to link/verify Finalizer.register method");
coleenp@5073 1095 return false; // initialization failed (cannot throw exception yet)
duke@0 1096 }
duke@0 1097 Universe::_finalizer_register_cache->init(
coleenp@5073 1098 SystemDictionary::Finalizer_klass(), m);
duke@0 1099
drchase@5699 1100 InstanceKlass::cast(SystemDictionary::misc_Unsafe_klass())->link_class(CHECK_false);
drchase@5699 1101 m = InstanceKlass::cast(SystemDictionary::misc_Unsafe_klass())->find_method(
drchase@5699 1102 vmSymbols::throwIllegalAccessError_name(),
drchase@5699 1103 vmSymbols::void_method_signature());
drchase@5699 1104 if (m != NULL && !m->is_static()) {
drchase@5699 1105 // Note null is okay; this method is used in itables, and if it is null,
drchase@5699 1106 // then AbstractMethodError is thrown instead.
drchase@5699 1107 tty->print_cr("Unable to link/verify Unsafe.throwIllegalAccessError method");
drchase@5699 1108 return false; // initialization failed (cannot throw exception yet)
drchase@5699 1109 }
drchase@5699 1110 Universe::_throw_illegal_access_error = m;
drchase@5699 1111
coleenp@3627 1112 // Setup method for registering loaded classes in class loader vector
coleenp@3627 1113 InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->link_class(CHECK_false);
coleenp@3627 1114 m = InstanceKlass::cast(SystemDictionary::ClassLoader_klass())->find_method(vmSymbols::addClass_name(), vmSymbols::class_void_signature());
coleenp@3627 1115 if (m == NULL || m->is_static()) {
coleenp@5073 1116 tty->print_cr("Unable to link/verify ClassLoader.addClass method");
coleenp@5073 1117 return false; // initialization failed (cannot throw exception yet)
coleenp@3627 1118 }
coleenp@3627 1119 Universe::_loader_addClass_cache->init(
coleenp@5073 1120 SystemDictionary::ClassLoader_klass(), m);
coleenp@3627 1121
mullan@4807 1122 // Setup method for checking protection domain
mullan@4807 1123 InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->link_class(CHECK_false);
mullan@4807 1124 m = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->
mullan@4807 1125 find_method(vmSymbols::impliesCreateAccessControlContext_name(),
mullan@4807 1126 vmSymbols::void_boolean_signature());
mullan@4807 1127 // Allow NULL which should only happen with bootstrapping.
mullan@4807 1128 if (m != NULL) {
mullan@4807 1129 if (m->is_static()) {
mullan@4807 1130 // NoSuchMethodException doesn't actually work because it tries to run the
mullan@4807 1131 // <init> function before java_lang_Class is linked. Print error and exit.
mullan@4807 1132 tty->print_cr("ProtectionDomain.impliesCreateAccessControlContext() has the wrong linkage");
mullan@4807 1133 return false; // initialization failed
mullan@4807 1134 }
mullan@4807 1135 Universe::_pd_implies_cache->init(
coleenp@5073 1136 SystemDictionary::ProtectionDomain_klass(), m);;
mullan@4807 1137 }
mullan@4807 1138
duke@0 1139 // The folowing is initializing converter functions for serialization in
duke@0 1140 // JVM.cpp. If we clean up the StrictMath code above we may want to find
duke@0 1141 // a better solution for this as well.
duke@0 1142 initialize_converter_functions();
duke@0 1143
duke@0 1144 // This needs to be done before the first scavenge/gc, since
duke@0 1145 // it's an input to soft ref clearing policy.
ysr@342 1146 {
ysr@342 1147 MutexLocker x(Heap_lock);
ysr@342 1148 Universe::update_heap_info_at_gc();
ysr@342 1149 }
duke@0 1150
duke@0 1151 // ("weak") refs processing infrastructure initialization
duke@0 1152 Universe::heap()->post_initialize();
duke@0 1153
coleenp@3602 1154 // Initialize performance counters for metaspaces
coleenp@3602 1155 MetaspaceCounters::initialize_performance_counters();
ehelin@5096 1156 CompressedClassSpaceCounters::initialize_performance_counters();
ehelin@5096 1157
ehelin@4877 1158 MemoryService::add_metaspace_memory_pools();
coleenp@3602 1159
duke@0 1160 GC_locker::unlock(); // allow gc after bootstrapping
duke@0 1161
duke@0 1162 MemoryService::set_universe_heap(Universe::_collectedHeap);
duke@0 1163 return true;
duke@0 1164 }
duke@0 1165
duke@0 1166
duke@0 1167 void Universe::compute_base_vtable_size() {
duke@0 1168 _base_vtable_size = ClassLoader::compute_Object_vtable();
duke@0 1169 }
duke@0 1170
duke@0 1171
duke@0 1172 // %%% The Universe::flush_foo methods belong in CodeCache.
duke@0 1173
duke@0 1174 // Flushes compiled methods dependent on dependee.
duke@0 1175 void Universe::flush_dependents_on(instanceKlassHandle dependee) {
duke@0 1176 assert_lock_strong(Compile_lock);
duke@0 1177
duke@0 1178 if (CodeCache::number_of_nmethods_with_dependencies() == 0) return;
duke@0 1179
duke@0 1180 // CodeCache can only be updated by a thread_in_VM and they will all be
duke@0 1181 // stopped dring the safepoint so CodeCache will be safe to update without
duke@0 1182 // holding the CodeCache_lock.
duke@0 1183
twisti@2615 1184 KlassDepChange changes(dependee);
duke@0 1185
duke@0 1186 // Compute the dependent nmethods
duke@0 1187 if (CodeCache::mark_for_deoptimization(changes) > 0) {
duke@0 1188 // At least one nmethod has been marked for deoptimization
duke@0 1189 VM_Deoptimize op;
duke@0 1190 VMThread::execute(&op);
duke@0 1191 }
duke@0 1192 }
duke@0 1193
twisti@2615 1194 // Flushes compiled methods dependent on a particular CallSite
twisti@2615 1195 // instance when its target is different than the given MethodHandle.
twisti@2615 1196 void Universe::flush_dependents_on(Handle call_site, Handle method_handle) {
twisti@2615 1197 assert_lock_strong(Compile_lock);
twisti@2615 1198
twisti@2615 1199 if (CodeCache::number_of_nmethods_with_dependencies() == 0) return;
twisti@2615 1200
twisti@2615 1201 // CodeCache can only be updated by a thread_in_VM and they will all be
twisti@2615 1202 // stopped dring the safepoint so CodeCache will be safe to update without
twisti@2615 1203 // holding the CodeCache_lock.
twisti@2615 1204
twisti@2615 1205 CallSiteDepChange changes(call_site(), method_handle());
twisti@2615 1206
twisti@2615 1207 // Compute the dependent nmethods that have a reference to a
coleenp@3602 1208 // CallSite object. We use InstanceKlass::mark_dependent_nmethod
twisti@2615 1209 // directly instead of CodeCache::mark_for_deoptimization because we
twisti@2659 1210 // want dependents on the call site class only not all classes in
twisti@2659 1211 // the ContextStream.
twisti@2615 1212 int marked = 0;
twisti@2615 1213 {
twisti@2615 1214 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
coleenp@3602 1215 InstanceKlass* call_site_klass = InstanceKlass::cast(call_site->klass());
twisti@2615 1216 marked = call_site_klass->mark_dependent_nmethods(changes);
twisti@2615 1217 }
twisti@2615 1218 if (marked > 0) {
twisti@2615 1219 // At least one nmethod has been marked for deoptimization
twisti@2615 1220 VM_Deoptimize op;
twisti@2615 1221 VMThread::execute(&op);
twisti@2615 1222 }
twisti@2615 1223 }
twisti@2615 1224
duke@0 1225 #ifdef HOTSWAP
duke@0 1226 // Flushes compiled methods dependent on dependee in the evolutionary sense
duke@0 1227 void Universe::flush_evol_dependents_on(instanceKlassHandle ev_k_h) {
duke@0 1228 // --- Compile_lock is not held. However we are at a safepoint.
duke@0 1229 assert_locked_or_safepoint(Compile_lock);
duke@0 1230 if (CodeCache::number_of_nmethods_with_dependencies() == 0) return;
duke@0 1231
duke@0 1232 // CodeCache can only be updated by a thread_in_VM and they will all be
duke@0 1233 // stopped dring the safepoint so CodeCache will be safe to update without
duke@0 1234 // holding the CodeCache_lock.
duke@0 1235
duke@0 1236 // Compute the dependent nmethods
duke@0 1237 if (CodeCache::mark_for_evol_deoptimization(ev_k_h) > 0) {
duke@0 1238 // At least one nmethod has been marked for deoptimization
duke@0 1239
duke@0 1240 // All this already happens inside a VM_Operation, so we'll do all the work here.
duke@0 1241 // Stuff copied from VM_Deoptimize and modified slightly.
duke@0 1242
duke@0 1243 // We do not want any GCs to happen while we are in the middle of this VM operation
duke@0 1244 ResourceMark rm;
duke@0 1245 DeoptimizationMarker dm;
duke@0 1246
duke@0 1247 // Deoptimize all activations depending on marked nmethods
duke@0 1248 Deoptimization::deoptimize_dependents();
duke@0 1249
duke@0 1250 // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
duke@0 1251 CodeCache::make_marked_nmethods_not_entrant();
duke@0 1252 }
duke@0 1253 }
duke@0 1254 #endif // HOTSWAP
duke@0 1255
duke@0 1256
duke@0 1257 // Flushes compiled methods dependent on dependee
duke@0 1258 void Universe::flush_dependents_on_method(methodHandle m_h) {
duke@0 1259 // --- Compile_lock is not held. However we are at a safepoint.
duke@0 1260 assert_locked_or_safepoint(Compile_lock);
duke@0 1261
duke@0 1262 // CodeCache can only be updated by a thread_in_VM and they will all be
duke@0 1263 // stopped dring the safepoint so CodeCache will be safe to update without
duke@0 1264 // holding the CodeCache_lock.
duke@0 1265
duke@0 1266 // Compute the dependent nmethods
duke@0 1267 if (CodeCache::mark_for_deoptimization(m_h()) > 0) {
duke@0 1268 // At least one nmethod has been marked for deoptimization
duke@0 1269
duke@0 1270 // All this already happens inside a VM_Operation, so we'll do all the work here.
duke@0 1271 // Stuff copied from VM_Deoptimize and modified slightly.
duke@0 1272
duke@0 1273 // We do not want any GCs to happen while we are in the middle of this VM operation
duke@0 1274 ResourceMark rm;
duke@0 1275 DeoptimizationMarker dm;
duke@0 1276
duke@0 1277 // Deoptimize all activations depending on marked nmethods
duke@0 1278 Deoptimization::deoptimize_dependents();
duke@0 1279
duke@0 1280 // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies)
duke@0 1281 CodeCache::make_marked_nmethods_not_entrant();
duke@0 1282 }
duke@0 1283 }
duke@0 1284
tonyp@2834 1285 void Universe::print() {
tonyp@2834 1286 print_on(gclog_or_tty);
tonyp@2834 1287 }
duke@0 1288
tonyp@2834 1289 void Universe::print_on(outputStream* st, bool extended) {
duke@0 1290 st->print_cr("Heap");
tonyp@2834 1291 if (!extended) {
tonyp@2834 1292 heap()->print_on(st);
tonyp@2834 1293 } else {
tonyp@2834 1294 heap()->print_extended_on(st);
tonyp@2834 1295 }
duke@0 1296 }
duke@0 1297
duke@0 1298 void Universe::print_heap_at_SIGBREAK() {
duke@0 1299 if (PrintHeapAtSIGBREAK) {
duke@0 1300 MutexLocker hl(Heap_lock);
duke@0 1301 print_on(tty);
duke@0 1302 tty->cr();
duke@0 1303 tty->flush();
duke@0 1304 }
duke@0 1305 }
duke@0 1306
never@3136 1307 void Universe::print_heap_before_gc(outputStream* st, bool ignore_extended) {
duke@0 1308 st->print_cr("{Heap before GC invocations=%u (full %u):",
duke@0 1309 heap()->total_collections(),
duke@0 1310 heap()->total_full_collections());
never@3136 1311 if (!PrintHeapAtGCExtended || ignore_extended) {
tonyp@2834 1312 heap()->print_on(st);
tonyp@2834 1313 } else {
tonyp@2834 1314 heap()->print_extended_on(st);
tonyp@2834 1315 }
duke@0 1316 }
duke@0 1317
never@3136 1318 void Universe::print_heap_after_gc(outputStream* st, bool ignore_extended) {
duke@0 1319 st->print_cr("Heap after GC invocations=%u (full %u):",
duke@0 1320 heap()->total_collections(),
duke@0 1321 heap()->total_full_collections());
never@3136 1322 if (!PrintHeapAtGCExtended || ignore_extended) {
tonyp@2834 1323 heap()->print_on(st);
tonyp@2834 1324 } else {
tonyp@2834 1325 heap()->print_extended_on(st);
tonyp@2834 1326 }
duke@0 1327 st->print_cr("}");
duke@0 1328 }
duke@0 1329
stefank@4583 1330 void Universe::verify(VerifyOption option, const char* prefix, bool silent) {
duke@0 1331 // The use of _verify_in_progress is a temporary work around for
duke@0 1332 // 6320749. Don't bother with a creating a class to set and clear
duke@0 1333 // it since it is only used in this method and the control flow is
duke@0 1334 // straight forward.
duke@0 1335 _verify_in_progress = true;
duke@0 1336
duke@0 1337 COMPILER2_PRESENT(
duke@0 1338 assert(!DerivedPointerTable::is_active(),
duke@0 1339 "DPT should not be active during verification "
duke@0 1340 "(of thread stacks below)");
duke@0 1341 )
duke@0 1342
duke@0 1343 ResourceMark rm;
duke@0 1344 HandleMark hm; // Handles created during verification can be zapped
duke@0 1345 _verify_count++;
duke@0 1346
stefank@4583 1347 if (!silent) gclog_or_tty->print(prefix);
duke@0 1348 if (!silent) gclog_or_tty->print("[Verifying ");
duke@0 1349 if (!silent) gclog_or_tty->print("threads ");
duke@0 1350 Threads::verify();
stefank@4583 1351 if (!silent) gclog_or_tty->print("heap ");
brutisso@3276 1352 heap()->verify(silent, option);
duke@0 1353 if (!silent) gclog_or_tty->print("syms ");
duke@0 1354 SymbolTable::verify();
duke@0 1355 if (!silent) gclog_or_tty->print("strs ");
duke@0 1356 StringTable::verify();
duke@0 1357 {
duke@0 1358 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
duke@0 1359 if (!silent) gclog_or_tty->print("zone ");
duke@0 1360 CodeCache::verify();
duke@0 1361 }
duke@0 1362 if (!silent) gclog_or_tty->print("dict ");
duke@0 1363 SystemDictionary::verify();
coleenp@3602 1364 #ifndef PRODUCT
coleenp@3602 1365 if (!silent) gclog_or_tty->print("cldg ");
coleenp@3602 1366 ClassLoaderDataGraph::verify();
coleenp@3602 1367 #endif
mgerdin@3829 1368 if (!silent) gclog_or_tty->print("metaspace chunks ");
mgerdin@3829 1369 MetaspaceAux::verify_free_chunks();
duke@0 1370 if (!silent) gclog_or_tty->print("hand ");
duke@0 1371 JNIHandles::verify();
duke@0 1372 if (!silent) gclog_or_tty->print("C-heap ");
duke@0 1373 os::check_heap();
never@2222 1374 if (!silent) gclog_or_tty->print("code cache ");
never@2222 1375 CodeCache::verify_oops();
duke@0 1376 if (!silent) gclog_or_tty->print_cr("]");
duke@0 1377
duke@0 1378 _verify_in_progress = false;
duke@0 1379 }
duke@0 1380
duke@0 1381 // Oop verification (see MacroAssembler::verify_oop)
duke@0 1382
duke@0 1383 static uintptr_t _verify_oop_data[2] = {0, (uintptr_t)-1};
duke@0 1384 static uintptr_t _verify_klass_data[2] = {0, (uintptr_t)-1};
duke@0 1385
duke@0 1386
mikael@4454 1387 #ifndef PRODUCT
mikael@4454 1388
duke@0 1389 static void calculate_verify_data(uintptr_t verify_data[2],
duke@0 1390 HeapWord* low_boundary,
duke@0 1391 HeapWord* high_boundary) {
duke@0 1392 assert(low_boundary < high_boundary, "bad interval");
duke@0 1393
duke@0 1394 // decide which low-order bits we require to be clear:
duke@0 1395 size_t alignSize = MinObjAlignmentInBytes;
kvn@1491 1396 size_t min_object_size = CollectedHeap::min_fill_size();
duke@0 1397
duke@0 1398 // make an inclusive limit:
duke@0 1399 uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize;
duke@0 1400 uintptr_t min = (uintptr_t)low_boundary;
duke@0 1401 assert(min < max, "bad interval");
duke@0 1402 uintptr_t diff = max ^ min;
duke@0 1403
duke@0 1404 // throw away enough low-order bits to make the diff vanish
duke@0 1405 uintptr_t mask = (uintptr_t)(-1);
duke@0 1406 while ((mask & diff) != 0)
duke@0 1407 mask <<= 1;
duke@0 1408 uintptr_t bits = (min & mask);
duke@0 1409 assert(bits == (max & mask), "correct mask");
duke@0 1410 // check an intermediate value between min and max, just to make sure:
duke@0 1411 assert(bits == ((min + (max-min)/2) & mask), "correct mask");
duke@0 1412
duke@0 1413 // require address alignment, too:
duke@0 1414 mask |= (alignSize - 1);
duke@0 1415
duke@0 1416 if (!(verify_data[0] == 0 && verify_data[1] == (uintptr_t)-1)) {
duke@0 1417 assert(verify_data[0] == mask && verify_data[1] == bits, "mask stability");
duke@0 1418 }
duke@0 1419 verify_data[0] = mask;
duke@0 1420 verify_data[1] = bits;
duke@0 1421 }
duke@0 1422
duke@0 1423 // Oop verification (see MacroAssembler::verify_oop)
duke@0 1424
duke@0 1425 uintptr_t Universe::verify_oop_mask() {
duke@0 1426 MemRegion m = heap()->reserved_region();
duke@0 1427 calculate_verify_data(_verify_oop_data,
duke@0 1428 m.start(),
duke@0 1429 m.end());
duke@0 1430 return _verify_oop_data[0];
duke@0 1431 }
duke@0 1432
duke@0 1433
duke@0 1434
duke@0 1435 uintptr_t Universe::verify_oop_bits() {
duke@0 1436 verify_oop_mask();
duke@0 1437 return _verify_oop_data[1];
duke@0 1438 }
duke@0 1439
duke@0 1440 uintptr_t Universe::verify_mark_mask() {
duke@0 1441 return markOopDesc::lock_mask_in_place;
duke@0 1442 }
duke@0 1443
duke@0 1444 uintptr_t Universe::verify_mark_bits() {
duke@0 1445 intptr_t mask = verify_mark_mask();
duke@0 1446 intptr_t bits = (intptr_t)markOopDesc::prototype();
duke@0 1447 assert((bits & ~mask) == 0, "no stray header bits");
duke@0 1448 return bits;
duke@0 1449 }
duke@0 1450 #endif // PRODUCT
duke@0 1451
duke@0 1452
duke@0 1453 void Universe::compute_verify_oop_data() {
duke@0 1454 verify_oop_mask();
duke@0 1455 verify_oop_bits();
duke@0 1456 verify_mark_mask();
duke@0 1457 verify_mark_bits();
duke@0 1458 }
duke@0 1459
duke@0 1460
coleenp@5073 1461 void LatestMethodCache::init(Klass* k, Method* m) {
duke@0 1462 if (!UseSharedSpaces) {
duke@0 1463 _klass = k;
duke@0 1464 }
duke@0 1465 #ifndef PRODUCT
duke@0 1466 else {
duke@0 1467 // sharing initilization should have already set up _klass
duke@0 1468 assert(_klass != NULL, "just checking");
duke@0 1469 }
duke@0 1470 #endif
duke@0 1471
duke@0 1472 _method_idnum = m->method_idnum();
duke@0 1473 assert(_method_idnum >= 0, "sanity check");
duke@0 1474 }
duke@0 1475
duke@0 1476
coleenp@5073 1477 Method* LatestMethodCache::get_method() {
mullan@4807 1478 if (klass() == NULL) return NULL;
coleenp@3602 1479 InstanceKlass* ik = InstanceKlass::cast(klass());
coleenp@3602 1480 Method* m = ik->method_with_idnum(method_idnum());
duke@0 1481 assert(m != NULL, "sanity check");
duke@0 1482 return m;
duke@0 1483 }
duke@0 1484
duke@0 1485
duke@0 1486 #ifdef ASSERT
duke@0 1487 // Release dummy object(s) at bottom of heap
duke@0 1488 bool Universe::release_fullgc_alot_dummy() {
duke@0 1489 MutexLocker ml(FullGCALot_lock);
duke@0 1490 if (_fullgc_alot_dummy_array != NULL) {
duke@0 1491 if (_fullgc_alot_dummy_next >= _fullgc_alot_dummy_array->length()) {
duke@0 1492 // No more dummies to release, release entire array instead
duke@0 1493 _fullgc_alot_dummy_array = NULL;
duke@0 1494 return false;
duke@0 1495 }
duke@0 1496 if (!UseConcMarkSweepGC) {
duke@0 1497 // Release dummy at bottom of old generation
duke@0 1498 _fullgc_alot_dummy_array->obj_at_put(_fullgc_alot_dummy_next++, NULL);
duke@0 1499 }
duke@0 1500 // Release dummy at bottom of permanent generation
duke@0 1501 _fullgc_alot_dummy_array->obj_at_put(_fullgc_alot_dummy_next++, NULL);
duke@0 1502 }
duke@0 1503 return true;
duke@0 1504 }
duke@0 1505
duke@0 1506 #endif // ASSERT