262 p2i(p), p2i(bottom()), p2i(end())); 263 if (p >= top()) { 264 return top(); 265 } else { 266 HeapWord* last = bottom() + BrooksPointer::word_size(); 267 HeapWord* cur = last; 268 while (cur <= p) { 269 last = cur; 270 cur += oop(cur)->size() + BrooksPointer::word_size(); 271 } 272 assert(oop(last)->is_oop(), 273 PTR_FORMAT" should be an object start", p2i(last)); 274 return last; 275 } 276 } 277 278 void ShenandoahHeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) { 279 uintx region_size; 280 if (FLAG_IS_DEFAULT(ShenandoahHeapRegionSize)) { 281 if (ShenandoahMinRegionSize > initial_heap_size / MIN_NUM_REGIONS) { 282 vm_exit_during_initialization("Invalid -XX:ShenandoahMinRegionSize option"); 283 } 284 if (ShenandoahMinRegionSize < MIN_REGION_SIZE) { 285 vm_exit_during_initialization("Invalid -XX:ShenandoahMinRegionSize option"); 286 } 287 if (ShenandoahMinRegionSize < MinTLABSize) { 288 vm_exit_during_initialization("Invalid -XX:ShenandoahMinRegionSize option"); 289 } 290 if (ShenandoahMaxRegionSize < MIN_REGION_SIZE) { 291 vm_exit_during_initialization("Invalid -XX:ShenandoahMaxRegionSize option"); 292 } 293 if (ShenandoahMinRegionSize > ShenandoahMaxRegionSize) { 294 vm_exit_during_initialization("Invalid -XX:ShenandoahMinRegionSize or -XX:ShenandoahMaxRegionSize"); 295 } 296 size_t average_heap_size = (initial_heap_size + max_heap_size) / 2; 297 region_size = MAX2(average_heap_size / ShenandoahTargetNumRegions, 298 ShenandoahMinRegionSize); 299 300 // Now make sure that we don't go over or under our limits. 301 region_size = MAX2(ShenandoahMinRegionSize, region_size); 302 region_size = MIN2(ShenandoahMaxRegionSize, region_size); 303 304 } else { 305 if (ShenandoahHeapRegionSize > initial_heap_size / MIN_NUM_REGIONS) { 306 vm_exit_during_initialization("Invalid -XX:ShenandoahHeapRegionSize option"); 307 } 308 if (ShenandoahHeapRegionSize < MIN_REGION_SIZE) { 309 vm_exit_during_initialization("Invalid -XX:ShenandoahHeapRegionSize option"); 310 } 311 region_size = ShenandoahHeapRegionSize; 312 } 313 314 // Make sure region size is at least one large page, if enabled. 315 // Otherwise, mem-protecting one region may falsely protect the adjacent 316 // regions too. 317 if (UseLargePages) { 318 region_size = MAX2(region_size, os::large_page_size()); 319 } 320 321 int region_size_log = log2_long((jlong) region_size); 322 // Recalculate the region size to make sure it's a power of 323 // 2. This means that region_size is the largest power of 2 that's 324 // <= what we've calculated so far. 325 region_size = ((uintx)1 << region_size_log); 326 327 // Now, set up the globals. 328 guarantee(RegionSizeShift == 0, "we should only set it once"); 329 RegionSizeShift = region_size_log; | 262 p2i(p), p2i(bottom()), p2i(end())); 263 if (p >= top()) { 264 return top(); 265 } else { 266 HeapWord* last = bottom() + BrooksPointer::word_size(); 267 HeapWord* cur = last; 268 while (cur <= p) { 269 last = cur; 270 cur += oop(cur)->size() + BrooksPointer::word_size(); 271 } 272 assert(oop(last)->is_oop(), 273 PTR_FORMAT" should be an object start", p2i(last)); 274 return last; 275 } 276 } 277 278 void ShenandoahHeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) { 279 uintx region_size; 280 if (FLAG_IS_DEFAULT(ShenandoahHeapRegionSize)) { 281 if (ShenandoahMinRegionSize > initial_heap_size / MIN_NUM_REGIONS) { 282 err_msg message("Initial heap size (" SIZE_FORMAT "K) is too low to afford the minimum number " 283 "of regions (" SIZE_FORMAT ") of minimum region size (" SIZE_FORMAT "K).", 284 initial_heap_size/K, MIN_NUM_REGIONS, ShenandoahMinRegionSize/K); 285 vm_exit_during_initialization("Invalid -XX:ShenandoahMinRegionSize option", message); 286 } 287 if (ShenandoahMinRegionSize < MIN_REGION_SIZE) { 288 err_msg message("" SIZE_FORMAT "K should not be lower than minimum region size (" SIZE_FORMAT "K).", 289 ShenandoahMinRegionSize/K, MIN_REGION_SIZE/K); 290 vm_exit_during_initialization("Invalid -XX:ShenandoahMinRegionSize option", message); 291 } 292 if (ShenandoahMinRegionSize < MinTLABSize) { 293 err_msg message("" SIZE_FORMAT "K should not be lower than TLAB size size (" SIZE_FORMAT "K).", 294 ShenandoahMinRegionSize/K, MinTLABSize/K); 295 vm_exit_during_initialization("Invalid -XX:ShenandoahMinRegionSize option", message); 296 } 297 if (ShenandoahMaxRegionSize < MIN_REGION_SIZE) { 298 err_msg message("" SIZE_FORMAT "K should not be lower than min region size (" SIZE_FORMAT "K).", 299 ShenandoahMaxRegionSize/K, MIN_REGION_SIZE/K); 300 vm_exit_during_initialization("Invalid -XX:ShenandoahMaxRegionSize option", message); 301 } 302 if (ShenandoahMinRegionSize > ShenandoahMaxRegionSize) { 303 err_msg message("Minimum (" SIZE_FORMAT "K) should be larger than maximum (" SIZE_FORMAT "K).", 304 ShenandoahMinRegionSize/K, ShenandoahMaxRegionSize/K); 305 vm_exit_during_initialization("Invalid -XX:ShenandoahMinRegionSize or -XX:ShenandoahMaxRegionSize", message); 306 } 307 size_t average_heap_size = (initial_heap_size + max_heap_size) / 2; 308 region_size = MAX2(average_heap_size / ShenandoahTargetNumRegions, 309 ShenandoahMinRegionSize); 310 311 // Now make sure that we don't go over or under our limits. 312 region_size = MAX2(ShenandoahMinRegionSize, region_size); 313 region_size = MIN2(ShenandoahMaxRegionSize, region_size); 314 315 } else { 316 if (ShenandoahHeapRegionSize > initial_heap_size / MIN_NUM_REGIONS) { 317 err_msg message("Initial heap size (" SIZE_FORMAT "K) is too low to afford the minimum number " 318 "of regions (" SIZE_FORMAT ") of requested size (" SIZE_FORMAT "K).", 319 initial_heap_size/K, MIN_NUM_REGIONS, ShenandoahHeapRegionSize/K); 320 vm_exit_during_initialization("Invalid -XX:ShenandoahHeapRegionSize option", message); 321 } 322 if (ShenandoahHeapRegionSize < MIN_REGION_SIZE) { 323 err_msg message("" SIZE_FORMAT " should not be lower than min region size (" SIZE_FORMAT "K).", 324 ShenandoahHeapRegionSize/K, MIN_REGION_SIZE/K); 325 vm_exit_during_initialization("Invalid -XX:ShenandoahHeapRegionSize option", message); 326 } 327 region_size = ShenandoahHeapRegionSize; 328 } 329 330 // Make sure region size is at least one large page, if enabled. 331 // Otherwise, mem-protecting one region may falsely protect the adjacent 332 // regions too. 333 if (UseLargePages) { 334 region_size = MAX2(region_size, os::large_page_size()); 335 } 336 337 int region_size_log = log2_long((jlong) region_size); 338 // Recalculate the region size to make sure it's a power of 339 // 2. This means that region_size is the largest power of 2 that's 340 // <= what we've calculated so far. 341 region_size = ((uintx)1 << region_size_log); 342 343 // Now, set up the globals. 344 guarantee(RegionSizeShift == 0, "we should only set it once"); 345 RegionSizeShift = region_size_log; |