< prev index next >

src/share/vm/utilities/globalDefinitions.hpp

Print this page




 310 inline address       set_address_bits(address x, int m)       { return address(intptr_t(x) | m); }
 311 inline address       clear_address_bits(address x, int m)     { return address(intptr_t(x) & ~m); }
 312 
 313 //  Utility functions to "portably" make cast to/from function pointers.
 314 
 315 inline address_word  mask_address_bits(address x, int m)      { return address_word(x) & m; }
 316 inline address_word  castable_address(address x)              { return address_word(x) ; }
 317 inline address_word  castable_address(void* x)                { return address_word(x) ; }
 318 
 319 // Pointer subtraction.
 320 // The idea here is to avoid ptrdiff_t, which is signed and so doesn't have
 321 // the range we might need to find differences from one end of the heap
 322 // to the other.
 323 // A typical use might be:
 324 //     if (pointer_delta(end(), top()) >= size) {
 325 //       // enough room for an object of size
 326 //       ...
 327 // and then additions like
 328 //       ... top() + size ...
 329 // are safe because we know that top() is at least size below end().
 330 inline size_t pointer_delta(const void* left,
 331                             const void* right,
 332                             size_t element_size) {
 333   return (((uintptr_t) left) - ((uintptr_t) right)) / element_size;
 334 }

 335 // A version specialized for HeapWord*'s.
 336 inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) {
 337   return pointer_delta(left, right, sizeof(HeapWord));
 338 }
 339 // A version specialized for MetaWord*'s.
 340 inline size_t pointer_delta(const MetaWord* left, const MetaWord* right) {
 341   return pointer_delta(left, right, sizeof(MetaWord));
 342 }
 343 
 344 //
 345 // ANSI C++ does not allow casting from one pointer type to a function pointer
 346 // directly without at best a warning. This macro accomplishes it silently
 347 // In every case that is present at this point the value be cast is a pointer
 348 // to a C linkage function. In some case the type used for the cast reflects
 349 // that linkage and a picky compiler would not complain. In other cases because
 350 // there is no convenient place to place a typedef with extern C linkage (i.e
 351 // a platform dependent header file) it doesn't. At this point no compiler seems
 352 // picky enough to catch these instances (which are few). It is possible that
 353 // using templates could fix these for all cases. This use of templates is likely
 354 // so far from the middle of the road that it is likely to be problematic in


 497 }
 498 
 499 inline intptr_t align_size_up(intptr_t size, intptr_t alignment) {
 500   return align_size_up_(size, alignment);
 501 }
 502 
 503 #define align_size_down_(size, alignment) ((size) & ~((alignment) - 1))
 504 
 505 inline intptr_t align_size_down(intptr_t size, intptr_t alignment) {
 506   return align_size_down_(size, alignment);
 507 }
 508 
 509 #define is_size_aligned_(size, alignment) ((size) == (align_size_up_(size, alignment)))
 510 
 511 inline void* align_ptr_up(const void* ptr, size_t alignment) {
 512   return (void*)align_size_up((intptr_t)ptr, (intptr_t)alignment);
 513 }
 514 
 515 inline void* align_ptr_down(void* ptr, size_t alignment) {
 516   return (void*)align_size_down((intptr_t)ptr, (intptr_t)alignment);




 517 }
 518 
 519 // Align metaspace objects by rounding up to natural word boundary
 520 
 521 inline intptr_t align_metadata_size(intptr_t size) {
 522   return align_size_up(size, 1);
 523 }
 524 
 525 // Align objects in the Java Heap by rounding up their size, in HeapWord units.
 526 // Since the size is given in words this is somewhat of a nop, but
 527 // distinguishes it from align_object_size.
 528 inline intptr_t align_object_size(intptr_t size) {
 529   return align_size_up(size, MinObjAlignment);
 530 }
 531 
 532 inline bool is_object_aligned(intptr_t addr) {
 533   return addr == align_object_size(addr);
 534 }
 535 
 536 // Pad out certain offsets to jlong alignment, in HeapWord units.




 310 inline address       set_address_bits(address x, int m)       { return address(intptr_t(x) | m); }
 311 inline address       clear_address_bits(address x, int m)     { return address(intptr_t(x) & ~m); }
 312 
 313 //  Utility functions to "portably" make cast to/from function pointers.
 314 
 315 inline address_word  mask_address_bits(address x, int m)      { return address_word(x) & m; }
 316 inline address_word  castable_address(address x)              { return address_word(x) ; }
 317 inline address_word  castable_address(void* x)                { return address_word(x) ; }
 318 
 319 // Pointer subtraction.
 320 // The idea here is to avoid ptrdiff_t, which is signed and so doesn't have
 321 // the range we might need to find differences from one end of the heap
 322 // to the other.
 323 // A typical use might be:
 324 //     if (pointer_delta(end(), top()) >= size) {
 325 //       // enough room for an object of size
 326 //       ...
 327 // and then additions like
 328 //       ... top() + size ...
 329 // are safe because we know that top() is at least size below end().
 330 inline size_t pointer_delta(const volatile void* left,
 331                             const volatile void* right,
 332                             size_t element_size) {
 333   return (((uintptr_t) left) - ((uintptr_t) right)) / element_size;
 334 }
 335 
 336 // A version specialized for HeapWord*'s.
 337 inline size_t pointer_delta(const HeapWord* left, const HeapWord* right) {
 338   return pointer_delta(left, right, sizeof(HeapWord));
 339 }
 340 // A version specialized for MetaWord*'s.
 341 inline size_t pointer_delta(const MetaWord* left, const MetaWord* right) {
 342   return pointer_delta(left, right, sizeof(MetaWord));
 343 }
 344 
 345 //
 346 // ANSI C++ does not allow casting from one pointer type to a function pointer
 347 // directly without at best a warning. This macro accomplishes it silently
 348 // In every case that is present at this point the value be cast is a pointer
 349 // to a C linkage function. In some case the type used for the cast reflects
 350 // that linkage and a picky compiler would not complain. In other cases because
 351 // there is no convenient place to place a typedef with extern C linkage (i.e
 352 // a platform dependent header file) it doesn't. At this point no compiler seems
 353 // picky enough to catch these instances (which are few). It is possible that
 354 // using templates could fix these for all cases. This use of templates is likely
 355 // so far from the middle of the road that it is likely to be problematic in


 498 }
 499 
 500 inline intptr_t align_size_up(intptr_t size, intptr_t alignment) {
 501   return align_size_up_(size, alignment);
 502 }
 503 
 504 #define align_size_down_(size, alignment) ((size) & ~((alignment) - 1))
 505 
 506 inline intptr_t align_size_down(intptr_t size, intptr_t alignment) {
 507   return align_size_down_(size, alignment);
 508 }
 509 
 510 #define is_size_aligned_(size, alignment) ((size) == (align_size_up_(size, alignment)))
 511 
 512 inline void* align_ptr_up(const void* ptr, size_t alignment) {
 513   return (void*)align_size_up((intptr_t)ptr, (intptr_t)alignment);
 514 }
 515 
 516 inline void* align_ptr_down(void* ptr, size_t alignment) {
 517   return (void*)align_size_down((intptr_t)ptr, (intptr_t)alignment);
 518 }
 519 
 520 inline volatile void* align_ptr_down(volatile void* ptr, size_t alignment) {
 521   return (volatile void*)align_size_down((intptr_t)ptr, (intptr_t)alignment);
 522 }
 523 
 524 // Align metaspace objects by rounding up to natural word boundary
 525 
 526 inline intptr_t align_metadata_size(intptr_t size) {
 527   return align_size_up(size, 1);
 528 }
 529 
 530 // Align objects in the Java Heap by rounding up their size, in HeapWord units.
 531 // Since the size is given in words this is somewhat of a nop, but
 532 // distinguishes it from align_object_size.
 533 inline intptr_t align_object_size(intptr_t size) {
 534   return align_size_up(size, MinObjAlignment);
 535 }
 536 
 537 inline bool is_object_aligned(intptr_t addr) {
 538   return addr == align_object_size(addr);
 539 }
 540 
 541 // Pad out certain offsets to jlong alignment, in HeapWord units.


< prev index next >