src/share/vm/memory/universe.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 107 oop Universe::_mirrors[T_VOID+1]                      = { NULL /*, NULL...*/ };
 108 oop Universe::_main_thread_group                      = NULL;
 109 oop Universe::_system_thread_group                    = NULL;
 110 objArrayOop Universe::_the_empty_class_klass_array    = NULL;
 111 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
 112 oop Universe::_the_null_string                        = NULL;
 113 oop Universe::_the_min_jint_string                   = NULL;
 114 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
 115 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 116 LatestMethodCache* Universe::_pd_implies_cache         = NULL;
 117 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
 118 oop Universe::_out_of_memory_error_java_heap          = NULL;
 119 oop Universe::_out_of_memory_error_metaspace          = NULL;
 120 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 121 oop Universe::_out_of_memory_error_array_size         = NULL;
 122 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 123 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 124 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
 125 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 126 bool Universe::_verify_in_progress                    = false;

 127 oop Universe::_null_ptr_exception_instance            = NULL;
 128 oop Universe::_arithmetic_exception_instance          = NULL;
 129 oop Universe::_virtual_machine_error_instance         = NULL;
 130 oop Universe::_vm_exception                           = NULL;
 131 oop Universe::_allocation_context_notification_obj    = NULL;
 132 
 133 Array<int>* Universe::_the_empty_int_array            = NULL;
 134 Array<u2>* Universe::_the_empty_short_array           = NULL;
 135 Array<Klass*>* Universe::_the_empty_klass_array     = NULL;
 136 Array<Method*>* Universe::_the_empty_method_array   = NULL;
 137 
 138 // These variables are guarded by FullGCALot_lock.
 139 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
 140 debug_only(int Universe::_fullgc_alot_dummy_next      = 0;)
 141 
 142 // Heap
 143 int             Universe::_verify_count = 0;
 144 
 145 int             Universe::_base_vtable_size = 0;
 146 bool            Universe::_bootstrapping = false;


 666   Universe::_pd_implies_cache         = new LatestMethodCache();
 667   Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
 668 
 669   if (UseSharedSpaces) {
 670     // Read the data structures supporting the shared spaces (shared
 671     // system dictionary, symbol table, etc.).  After that, access to
 672     // the file (other than the mapped regions) is no longer needed, and
 673     // the file is closed. Closing the file does not affect the
 674     // currently mapped regions.
 675     MetaspaceShared::initialize_shared_spaces();
 676     StringTable::create_table();
 677   } else {
 678     SymbolTable::create_table();
 679     StringTable::create_table();
 680     ClassLoader::create_package_info_table();
 681 
 682     if (DumpSharedSpaces) {
 683       MetaspaceShared::prepare_for_dumping();
 684     }
 685   }



 686 
 687   return JNI_OK;
 688 }
 689 
 690 // Choose the heap base address and oop encoding mode
 691 // when compressed oops are used:
 692 // Unscaled  - Use 32-bits oops without encoding when
 693 //     NarrowOopHeapBaseMin + heap_size < 4Gb
 694 // ZeroBased - Use zero based compressed oops with encoding when
 695 //     NarrowOopHeapBaseMin + heap_size < 32Gb
 696 // HeapBased - Use compressed oops with heap base + encoding.
 697 
 698 // 4Gb
 699 static const uint64_t UnscaledOopHeapMax = (uint64_t(max_juint) + 1);
 700 // 32Gb
 701 // OopEncodingHeapMax == UnscaledOopHeapMax << LogMinObjAlignmentInBytes;
 702 
 703 char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_OOP_MODE mode) {
 704   assert(is_size_aligned((size_t)OopEncodingHeapMax, alignment), "Must be");
 705   assert(is_size_aligned((size_t)UnscaledOopHeapMax, alignment), "Must be");


1344                heap()->total_full_collections());
1345   if (!PrintHeapAtGCExtended || ignore_extended) {
1346     heap()->print_on(st);
1347   } else {
1348     heap()->print_extended_on(st);
1349   }
1350 }
1351 
1352 void Universe::print_heap_after_gc(outputStream* st, bool ignore_extended) {
1353   st->print_cr("Heap after GC invocations=%u (full %u):",
1354                heap()->total_collections(),
1355                heap()->total_full_collections());
1356   if (!PrintHeapAtGCExtended || ignore_extended) {
1357     heap()->print_on(st);
1358   } else {
1359     heap()->print_extended_on(st);
1360   }
1361   st->print_cr("}");
1362 }
1363 















































1364 void Universe::verify(VerifyOption option, const char* prefix, bool silent) {
1365   // The use of _verify_in_progress is a temporary work around for
1366   // 6320749.  Don't bother with a creating a class to set and clear
1367   // it since it is only used in this method and the control flow is
1368   // straight forward.
1369   _verify_in_progress = true;
1370 
1371   COMPILER2_PRESENT(
1372     assert(!DerivedPointerTable::is_active(),
1373          "DPT should not be active during verification "
1374          "(of thread stacks below)");
1375   )
1376 
1377   ResourceMark rm;
1378   HandleMark hm;  // Handles created during verification can be zapped
1379   _verify_count++;
1380 
1381   if (!silent) gclog_or_tty->print("%s", prefix);
1382   if (!silent) gclog_or_tty->print("[Verifying ");
1383   if (!silent) gclog_or_tty->print("threads ");

1384   Threads::verify();
1385   if (!silent) gclog_or_tty->print("heap ");


1386   heap()->verify(silent, option);
1387   if (!silent) gclog_or_tty->print("syms ");


1388   SymbolTable::verify();
1389   if (!silent) gclog_or_tty->print("strs ");


1390   StringTable::verify();


1391   {
1392     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1393     if (!silent) gclog_or_tty->print("zone ");
1394     CodeCache::verify();
1395   }
1396   if (!silent) gclog_or_tty->print("dict ");


1397   SystemDictionary::verify();

1398 #ifndef PRODUCT
1399   if (!silent) gclog_or_tty->print("cldg ");

1400   ClassLoaderDataGraph::verify();

1401 #endif
1402   if (!silent) gclog_or_tty->print("metaspace chunks ");

1403   MetaspaceAux::verify_free_chunks();
1404   if (!silent) gclog_or_tty->print("hand ");


1405   JNIHandles::verify();


1406   if (!silent) gclog_or_tty->print("C-heap ");
1407   os::check_heap();
1408   if (!silent) gclog_or_tty->print("code cache ");


1409   CodeCache::verify_oops();

1410   if (!silent) gclog_or_tty->print_cr("]");
1411 
1412   _verify_in_progress = false;
1413 }
1414 
1415 // Oop verification (see MacroAssembler::verify_oop)
1416 
1417 static uintptr_t _verify_oop_data[2]   = {0, (uintptr_t)-1};
1418 static uintptr_t _verify_klass_data[2] = {0, (uintptr_t)-1};
1419 
1420 
1421 #ifndef PRODUCT
1422 
1423 static void calculate_verify_data(uintptr_t verify_data[2],
1424                                   HeapWord* low_boundary,
1425                                   HeapWord* high_boundary) {
1426   assert(low_boundary < high_boundary, "bad interval");
1427 
1428   // decide which low-order bits we require to be clear:
1429   size_t alignSize = MinObjAlignmentInBytes;


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 107 oop Universe::_mirrors[T_VOID+1]                      = { NULL /*, NULL...*/ };
 108 oop Universe::_main_thread_group                      = NULL;
 109 oop Universe::_system_thread_group                    = NULL;
 110 objArrayOop Universe::_the_empty_class_klass_array    = NULL;
 111 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
 112 oop Universe::_the_null_string                        = NULL;
 113 oop Universe::_the_min_jint_string                   = NULL;
 114 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
 115 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 116 LatestMethodCache* Universe::_pd_implies_cache         = NULL;
 117 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
 118 oop Universe::_out_of_memory_error_java_heap          = NULL;
 119 oop Universe::_out_of_memory_error_metaspace          = NULL;
 120 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 121 oop Universe::_out_of_memory_error_array_size         = NULL;
 122 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 123 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 124 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
 125 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 126 bool Universe::_verify_in_progress                    = false;
 127 long Universe::verify_flags                           = Universe::Verify_All;
 128 oop Universe::_null_ptr_exception_instance            = NULL;
 129 oop Universe::_arithmetic_exception_instance          = NULL;
 130 oop Universe::_virtual_machine_error_instance         = NULL;
 131 oop Universe::_vm_exception                           = NULL;
 132 oop Universe::_allocation_context_notification_obj    = NULL;
 133 
 134 Array<int>* Universe::_the_empty_int_array            = NULL;
 135 Array<u2>* Universe::_the_empty_short_array           = NULL;
 136 Array<Klass*>* Universe::_the_empty_klass_array     = NULL;
 137 Array<Method*>* Universe::_the_empty_method_array   = NULL;
 138 
 139 // These variables are guarded by FullGCALot_lock.
 140 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
 141 debug_only(int Universe::_fullgc_alot_dummy_next      = 0;)
 142 
 143 // Heap
 144 int             Universe::_verify_count = 0;
 145 
 146 int             Universe::_base_vtable_size = 0;
 147 bool            Universe::_bootstrapping = false;


 667   Universe::_pd_implies_cache         = new LatestMethodCache();
 668   Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
 669 
 670   if (UseSharedSpaces) {
 671     // Read the data structures supporting the shared spaces (shared
 672     // system dictionary, symbol table, etc.).  After that, access to
 673     // the file (other than the mapped regions) is no longer needed, and
 674     // the file is closed. Closing the file does not affect the
 675     // currently mapped regions.
 676     MetaspaceShared::initialize_shared_spaces();
 677     StringTable::create_table();
 678   } else {
 679     SymbolTable::create_table();
 680     StringTable::create_table();
 681     ClassLoader::create_package_info_table();
 682 
 683     if (DumpSharedSpaces) {
 684       MetaspaceShared::prepare_for_dumping();
 685     }
 686   }
 687   if (strlen(VerifySubSet) > 0) {
 688     Universe::initialize_verify_flags();
 689   }
 690 
 691   return JNI_OK;
 692 }
 693 
 694 // Choose the heap base address and oop encoding mode
 695 // when compressed oops are used:
 696 // Unscaled  - Use 32-bits oops without encoding when
 697 //     NarrowOopHeapBaseMin + heap_size < 4Gb
 698 // ZeroBased - Use zero based compressed oops with encoding when
 699 //     NarrowOopHeapBaseMin + heap_size < 32Gb
 700 // HeapBased - Use compressed oops with heap base + encoding.
 701 
 702 // 4Gb
 703 static const uint64_t UnscaledOopHeapMax = (uint64_t(max_juint) + 1);
 704 // 32Gb
 705 // OopEncodingHeapMax == UnscaledOopHeapMax << LogMinObjAlignmentInBytes;
 706 
 707 char* Universe::preferred_heap_base(size_t heap_size, size_t alignment, NARROW_OOP_MODE mode) {
 708   assert(is_size_aligned((size_t)OopEncodingHeapMax, alignment), "Must be");
 709   assert(is_size_aligned((size_t)UnscaledOopHeapMax, alignment), "Must be");


1348                heap()->total_full_collections());
1349   if (!PrintHeapAtGCExtended || ignore_extended) {
1350     heap()->print_on(st);
1351   } else {
1352     heap()->print_extended_on(st);
1353   }
1354 }
1355 
1356 void Universe::print_heap_after_gc(outputStream* st, bool ignore_extended) {
1357   st->print_cr("Heap after GC invocations=%u (full %u):",
1358                heap()->total_collections(),
1359                heap()->total_full_collections());
1360   if (!PrintHeapAtGCExtended || ignore_extended) {
1361     heap()->print_on(st);
1362   } else {
1363     heap()->print_extended_on(st);
1364   }
1365   st->print_cr("}");
1366 }
1367 
1368 void Universe::initialize_verify_flags() {
1369   verify_flags = 0;
1370   const char delimiter[] = " ,";
1371 
1372   size_t length = strlen(VerifySubSet);
1373   char* subset_list = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal);
1374   strncpy(subset_list, VerifySubSet, length + 1);
1375 
1376   char* token = strtok(subset_list, delimiter);
1377   while (token != NULL) {
1378     if (strcmp(token, "threads") == 0) {
1379       verify_flags |= Verify_Threads;
1380     } else if (strcmp(token, "heap") == 0) {
1381       verify_flags |= Verify_Heap;
1382     } else if (strcmp(token, "symbol_table") == 0) {
1383       verify_flags |= Verify_SymbolTable;
1384     } else if (strcmp(token, "string_table") == 0) {
1385       verify_flags |= Verify_StringTable;
1386     } else if (strcmp(token, "codecache") == 0) {
1387       verify_flags |= Verify_CodeCache;
1388     } else if (strcmp(token, "dictionary") == 0) {
1389       verify_flags |= Verify_SystemDictionary;
1390     } else if (strcmp(token, "classloader_data_graph") == 0) {
1391       verify_flags |= Verify_ClassLoaderDataGraph;
1392     } else if (strcmp(token, "metaspace") == 0) {
1393       verify_flags |= Verify_MetaspaceAux;
1394     } else if (strcmp(token, "jni_handles") == 0) {
1395       verify_flags |= Verify_JNIHandles;
1396     } else if (strcmp(token, "c-heap") == 0) {
1397       verify_flags |= Verify_CHeap;
1398     } else if (strcmp(token, "codecache_oops") == 0) {
1399       verify_flags |= Verify_CodeCacheOops;
1400     } else {
1401       vm_exit_during_initialization(err_msg("VerifySubSet: \'%s\' memory sub-system is unknown, please correct it", token));
1402     }
1403     token = strtok(NULL, delimiter);
1404   }
1405   FREE_C_HEAP_ARRAY(char, subset_list, mtInternal);
1406 }
1407 
1408 bool Universe::should_verify_subset(uint subset) {
1409   if (verify_flags & subset) {
1410     return true;
1411   }
1412   return false;
1413 }
1414 
1415 void Universe::verify(VerifyOption option, const char* prefix, bool silent) {
1416   // The use of _verify_in_progress is a temporary work around for
1417   // 6320749.  Don't bother with a creating a class to set and clear
1418   // it since it is only used in this method and the control flow is
1419   // straight forward.
1420   _verify_in_progress = true;
1421 
1422   COMPILER2_PRESENT(
1423     assert(!DerivedPointerTable::is_active(),
1424          "DPT should not be active during verification "
1425          "(of thread stacks below)");
1426   )
1427 
1428   ResourceMark rm;
1429   HandleMark hm;  // Handles created during verification can be zapped
1430   _verify_count++;
1431 
1432   if (!silent) gclog_or_tty->print("%s", prefix);
1433   if (!silent) gclog_or_tty->print("[Verifying ");
1434   if (should_verify_subset(Verify_Threads)) {
1435     if (!silent) gclog_or_tty->print("Threads ");
1436     Threads::verify();
1437   }
1438   if (should_verify_subset(Verify_Heap)) {
1439     if (!silent) gclog_or_tty->print("Heap ");
1440     heap()->verify(silent, option);
1441   }
1442   if (should_verify_subset(Verify_SymbolTable)) {
1443     if (!silent) gclog_or_tty->print("SymbolTable ");
1444     SymbolTable::verify();
1445   }
1446   if (should_verify_subset(Verify_StringTable)) {
1447     if (!silent) gclog_or_tty->print("StringTable ");
1448     StringTable::verify();
1449   }
1450   if (should_verify_subset(Verify_CodeCache)) {
1451   {
1452     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1453     if (!silent) gclog_or_tty->print("CodeCache ");
1454     CodeCache::verify();
1455   }
1456   }
1457   if (should_verify_subset(Verify_SystemDictionary)) {
1458     if (!silent) gclog_or_tty->print("SystemDictionary ");
1459     SystemDictionary::verify();
1460   }
1461 #ifndef PRODUCT
1462   if (should_verify_subset(Verify_ClassLoaderDataGraph)) {
1463     if (!silent) gclog_or_tty->print("ClassLoaderDataGraph ");
1464     ClassLoaderDataGraph::verify();
1465   }
1466 #endif
1467   if (should_verify_subset(Verify_MetaspaceAux)) {
1468     if (!silent) gclog_or_tty->print("MetaspaceAux ");
1469     MetaspaceAux::verify_free_chunks();
1470   }
1471   if (should_verify_subset(Verify_JNIHandles)) {
1472     if (!silent) gclog_or_tty->print("JNIHandles ");
1473     JNIHandles::verify();
1474   }
1475   if (should_verify_subset(Verify_CHeap)) {
1476     if (!silent) gclog_or_tty->print("C-heap ");
1477     os::check_heap();
1478   }
1479   if (should_verify_subset(Verify_CodeCacheOops)) {
1480     if (!silent) gclog_or_tty->print("CodeCache Oops ");
1481     CodeCache::verify_oops();
1482   }
1483   if (!silent) gclog_or_tty->print_cr("]");
1484 
1485   _verify_in_progress = false;
1486 }
1487 
1488 // Oop verification (see MacroAssembler::verify_oop)
1489 
1490 static uintptr_t _verify_oop_data[2]   = {0, (uintptr_t)-1};
1491 static uintptr_t _verify_klass_data[2] = {0, (uintptr_t)-1};
1492 
1493 
1494 #ifndef PRODUCT
1495 
1496 static void calculate_verify_data(uintptr_t verify_data[2],
1497                                   HeapWord* low_boundary,
1498                                   HeapWord* high_boundary) {
1499   assert(low_boundary < high_boundary, "bad interval");
1500 
1501   // decide which low-order bits we require to be clear:
1502   size_t alignSize = MinObjAlignmentInBytes;