src/share/vm/memory/universe.cpp

changeset 4523
10d5f25a7c67
parent 4465
203f64878aab
child 4544
3c9bc17b9403
     1.1 --- a/src/share/vm/memory/universe.cpp	Sun Feb 03 17:12:31 2013 -0500
     1.2 +++ b/src/share/vm/memory/universe.cpp	Mon Feb 04 08:26:02 2013 -0500
     1.3 @@ -144,6 +144,7 @@
     1.4  NarrowPtrStruct Universe::_narrow_klass = { NULL, 0, true };
     1.5  address Universe::_narrow_ptrs_base;
     1.6  
     1.7 +size_t          Universe::_class_metaspace_size;
     1.8  
     1.9  void Universe::basic_type_classes_do(void f(Klass*)) {
    1.10    f(boolArrayKlassObj());
    1.11 @@ -689,8 +690,15 @@
    1.12      // Return specified base for the first request.
    1.13      if (!FLAG_IS_DEFAULT(HeapBaseMinAddress) && (mode == UnscaledNarrowOop)) {
    1.14        base = HeapBaseMinAddress;
    1.15 -    } else if (total_size <= OopEncodingHeapMax && (mode != HeapBasedNarrowOop)) {
    1.16 -      if (total_size <= NarrowOopHeapMax && (mode == UnscaledNarrowOop) &&
    1.17 +
    1.18 +    // If the total size and the metaspace size are small enough to allow
    1.19 +    // UnscaledNarrowOop then just use UnscaledNarrowOop.
    1.20 +    } else if ((total_size <= OopEncodingHeapMax) && (mode != HeapBasedNarrowOop) &&
    1.21 +        (!UseCompressedKlassPointers ||
    1.22 +          (((OopEncodingHeapMax - heap_size) + Universe::class_metaspace_size()) <= KlassEncodingMetaspaceMax))) {
    1.23 +      // We don't need to check the metaspace size here because it is always smaller
    1.24 +      // than total_size.
    1.25 +      if ((total_size <= NarrowOopHeapMax) && (mode == UnscaledNarrowOop) &&
    1.26            (Universe::narrow_oop_shift() == 0)) {
    1.27          // Use 32-bits oops without encoding and
    1.28          // place heap's top on the 4Gb boundary
    1.29 @@ -706,14 +714,24 @@
    1.30            base = (OopEncodingHeapMax - heap_size);
    1.31          }
    1.32        }
    1.33 +
    1.34 +    // See if ZeroBaseNarrowOop encoding will work for a heap based at
    1.35 +    // (KlassEncodingMetaspaceMax - class_metaspace_size()).
    1.36 +    } else if (UseCompressedKlassPointers && (mode != HeapBasedNarrowOop) &&
    1.37 +        (Universe::class_metaspace_size() + HeapBaseMinAddress <= KlassEncodingMetaspaceMax) &&
    1.38 +        (KlassEncodingMetaspaceMax + heap_size - Universe::class_metaspace_size() <= OopEncodingHeapMax)) {
    1.39 +      base = (KlassEncodingMetaspaceMax - Universe::class_metaspace_size());
    1.40      } else {
    1.41 -      // Can't reserve below 32Gb.
    1.42 +      // UnscaledNarrowOop encoding didn't work, and no base was found for ZeroBasedOops or
    1.43 +      // HeapBasedNarrowOop encoding was requested.  So, can't reserve below 32Gb.
    1.44        Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
    1.45      }
    1.46 +
    1.47      // Set narrow_oop_base and narrow_oop_use_implicit_null_checks
    1.48      // used in ReservedHeapSpace() constructors.
    1.49      // The final values will be set in initialize_heap() below.
    1.50 -    if (base != 0 && (base + heap_size) <= OopEncodingHeapMax) {
    1.51 +    if ((base != 0) && ((base + heap_size) <= OopEncodingHeapMax) &&
    1.52 +        (!UseCompressedKlassPointers || (base + Universe::class_metaspace_size()) <= KlassEncodingMetaspaceMax)) {
    1.53        // Use zero based compressed oops
    1.54        Universe::set_narrow_oop_base(NULL);
    1.55        // Don't need guard page for implicit checks in indexed
    1.56 @@ -796,7 +814,9 @@
    1.57        tty->print("heap address: " PTR_FORMAT ", size: " SIZE_FORMAT " MB",
    1.58                   Universe::heap()->base(), Universe::heap()->reserved_region().byte_size()/M);
    1.59      }
    1.60 -    if ((uint64_t)Universe::heap()->reserved_region().end() > OopEncodingHeapMax) {
    1.61 +    if (((uint64_t)Universe::heap()->reserved_region().end() > OopEncodingHeapMax) ||
    1.62 +        (UseCompressedKlassPointers &&
    1.63 +        ((uint64_t)Universe::heap()->base() + Universe::class_metaspace_size() > KlassEncodingMetaspaceMax))) {
    1.64        // Can't reserve heap below 32Gb.
    1.65        // keep the Universe::narrow_oop_base() set in Universe::reserve_heap()
    1.66        Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
    1.67 @@ -862,8 +882,8 @@
    1.68    // be compressed the same as instances.
    1.69    // Need to round class space size up because it's below the heap and
    1.70    // the actual alignment depends on its size.
    1.71 -  size_t metaspace_size = align_size_up(ClassMetaspaceSize, alignment);
    1.72 -  size_t total_reserved = align_size_up(heap_size + metaspace_size, alignment);
    1.73 +  Universe::set_class_metaspace_size(align_size_up(ClassMetaspaceSize, alignment));
    1.74 +  size_t total_reserved = align_size_up(heap_size + Universe::class_metaspace_size(), alignment);
    1.75    char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop);
    1.76  
    1.77    ReservedHeapSpace total_rs(total_reserved, alignment, UseLargePages, addr);
    1.78 @@ -904,8 +924,8 @@
    1.79    // compressed oops is greater than the one used for compressed klass
    1.80    // ptrs, a metadata space on top of the heap could become
    1.81    // unreachable.
    1.82 -  ReservedSpace class_rs = total_rs.first_part(metaspace_size);
    1.83 -  ReservedSpace heap_rs = total_rs.last_part(metaspace_size, alignment);
    1.84 +  ReservedSpace class_rs = total_rs.first_part(Universe::class_metaspace_size());
    1.85 +  ReservedSpace heap_rs = total_rs.last_part(Universe::class_metaspace_size(), alignment);
    1.86    Metaspace::initialize_class_space(class_rs);
    1.87  
    1.88    if (UseCompressedOops) {

mercurial