1.1 --- a/src/share/vm/memory/universe.cpp Fri Oct 12 10:49:39 2012 -0700 1.2 +++ b/src/share/vm/memory/universe.cpp Fri Oct 12 11:31:27 2012 -0700 1.3 @@ -151,7 +151,9 @@ 1.4 1.5 CollectedHeap* Universe::_collectedHeap = NULL; 1.6 1.7 -NarrowOopStruct Universe::_narrow_oop = { NULL, 0, true }; 1.8 +NarrowPtrStruct Universe::_narrow_oop = { NULL, 0, true }; 1.9 +NarrowPtrStruct Universe::_narrow_klass = { NULL, 0, true }; 1.10 +address Universe::_narrow_ptrs_base; 1.11 1.12 1.13 void Universe::basic_type_classes_do(void f(Klass*)) { 1.14 @@ -807,7 +809,7 @@ 1.15 } 1.16 if ((uint64_t)Universe::heap()->reserved_region().end() > OopEncodingHeapMax) { 1.17 // Can't reserve heap below 32Gb. 1.18 - Universe::set_narrow_oop_base(Universe::heap()->base() - os::vm_page_size()); 1.19 + // keep the Universe::narrow_oop_base() set in Universe::reserve_heap() 1.20 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes); 1.21 if (verbose) { 1.22 tty->print(", Compressed Oops with base: "PTR_FORMAT, Universe::narrow_oop_base()); 1.23 @@ -838,8 +840,16 @@ 1.24 tty->cr(); 1.25 tty->cr(); 1.26 } 1.27 + if (UseCompressedKlassPointers) { 1.28 + Universe::set_narrow_klass_base(Universe::narrow_oop_base()); 1.29 + Universe::set_narrow_klass_shift(MIN2(Universe::narrow_oop_shift(), LogKlassAlignmentInBytes)); 1.30 + } 1.31 + Universe::set_narrow_ptrs_base(Universe::narrow_oop_base()); 1.32 } 1.33 - assert(Universe::narrow_oop_base() == (Universe::heap()->base() - os::vm_page_size()) || 1.34 + // Universe::narrow_oop_base() is one page below the metaspace 1.35 + // base. The actual metaspace base depends on alignment constraints 1.36 + // so we don't know its exact location here. 1.37 + assert((intptr_t)Universe::narrow_oop_base() <= (intptr_t)(Universe::heap()->base() - os::vm_page_size() - ClassMetaspaceSize) || 1.38 Universe::narrow_oop_base() == NULL, "invalid value"); 1.39 assert(Universe::narrow_oop_shift() == LogMinObjAlignmentInBytes || 1.40 Universe::narrow_oop_shift() == 0, "invalid value"); 1.41 @@ -861,7 +871,10 @@ 1.42 ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { 1.43 // Add in the class metaspace area so the classes in the headers can 1.44 // be compressed the same as instances. 1.45 - size_t total_reserved = align_size_up(heap_size + ClassMetaspaceSize, alignment); 1.46 + // Need to round class space size up because it's below the heap and 1.47 + // the actual alignment depends on its size. 1.48 + size_t metaspace_size = align_size_up(ClassMetaspaceSize, alignment); 1.49 + size_t total_reserved = align_size_up(heap_size + metaspace_size, alignment); 1.50 char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop); 1.51 1.52 ReservedHeapSpace total_rs(total_reserved, alignment, UseLargePages, addr); 1.53 @@ -895,11 +908,23 @@ 1.54 return total_rs; 1.55 } 1.56 1.57 - // Split the reserved space into main Java heap and a space for classes 1.58 - // so that they can be compressed using the same algorithm as compressed oops 1.59 - ReservedSpace heap_rs = total_rs.first_part(heap_size); 1.60 - ReservedSpace class_rs = total_rs.last_part(heap_size, alignment); 1.61 + // Split the reserved space into main Java heap and a space for 1.62 + // classes so that they can be compressed using the same algorithm 1.63 + // as compressed oops. If compress oops and compress klass ptrs are 1.64 + // used we need the meta space first: if the alignment used for 1.65 + // compressed oops is greater than the one used for compressed klass 1.66 + // ptrs, a metadata space on top of the heap could become 1.67 + // unreachable. 1.68 + ReservedSpace class_rs = total_rs.first_part(metaspace_size); 1.69 + ReservedSpace heap_rs = total_rs.last_part(metaspace_size, alignment); 1.70 Metaspace::initialize_class_space(class_rs); 1.71 + 1.72 + if (UseCompressedOops) { 1.73 + // Universe::initialize_heap() will reset this to NULL if unscaled 1.74 + // or zero-based narrow oops are actually used. 1.75 + address base = (address)(total_rs.base() - os::vm_page_size()); 1.76 + Universe::set_narrow_oop_base(base); 1.77 + } 1.78 return heap_rs; 1.79 } 1.80