Mercurial > hg > graal-jvmci-8
comparison src/share/vm/memory/allocation.hpp @ 11173:6b0fd0964b87
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 31 Jul 2013 11:00:54 +0200 |
parents | 836a62f43af9 cf9d71d3e474 |
children | cefad50507d8 |
comparison
equal
deleted
inserted
replaced
10912:4ea54634f03e | 11173:6b0fd0964b87 |
---|---|
262 | 262 |
263 class ClassLoaderData; | 263 class ClassLoaderData; |
264 | 264 |
265 class MetaspaceObj { | 265 class MetaspaceObj { |
266 public: | 266 public: |
267 bool is_metadata() const; | |
268 bool is_metaspace_object() const; // more specific test but slower | 267 bool is_metaspace_object() const; // more specific test but slower |
269 bool is_shared() const; | 268 bool is_shared() const; |
270 void print_address_on(outputStream* st) const; // nonvirtual address printing | 269 void print_address_on(outputStream* st) const; // nonvirtual address printing |
271 | 270 |
272 #define METASPACE_OBJ_TYPES_DO(f) \ | 271 #define METASPACE_OBJ_TYPES_DO(f) \ |
338 | 337 |
339 protected: | 338 protected: |
340 Chunk* _next; // Next Chunk in list | 339 Chunk* _next; // Next Chunk in list |
341 const size_t _len; // Size of this Chunk | 340 const size_t _len; // Size of this Chunk |
342 public: | 341 public: |
343 void* operator new(size_t size, size_t length); | 342 void* operator new(size_t size, AllocFailType alloc_failmode, size_t length); |
344 void operator delete(void* p); | 343 void operator delete(void* p); |
345 Chunk(size_t length); | 344 Chunk(size_t length); |
346 | 345 |
347 enum { | 346 enum { |
348 // default sizes; make them slightly smaller than 2**k to guard against | 347 // default sizes; make them slightly smaller than 2**k to guard against |
352 // a multiple of 8. | 351 // a multiple of 8. |
353 #else | 352 #else |
354 slack = 20, // suspected sizeof(Chunk) + internal malloc headers | 353 slack = 20, // suspected sizeof(Chunk) + internal malloc headers |
355 #endif | 354 #endif |
356 | 355 |
357 init_size = 1*K - slack, // Size of first chunk | 356 tiny_size = 256 - slack, // Size of first chunk (tiny) |
357 init_size = 1*K - slack, // Size of first chunk (normal aka small) | |
358 medium_size= 10*K - slack, // Size of medium-sized chunk | 358 medium_size= 10*K - slack, // Size of medium-sized chunk |
359 size = 32*K - slack, // Default size of an Arena chunk (following the first) | 359 size = 32*K - slack, // Default size of an Arena chunk (following the first) |
360 non_pool_size = init_size + 32 // An initial size which is not one of above | 360 non_pool_size = init_size + 32 // An initial size which is not one of above |
361 }; | 361 }; |
362 | 362 |
401 debug_only(void* internal_malloc_4(size_t x);) | 401 debug_only(void* internal_malloc_4(size_t x);) |
402 NOT_PRODUCT(void inc_bytes_allocated(size_t x);) | 402 NOT_PRODUCT(void inc_bytes_allocated(size_t x);) |
403 | 403 |
404 void signal_out_of_memory(size_t request, const char* whence) const; | 404 void signal_out_of_memory(size_t request, const char* whence) const; |
405 | 405 |
406 void check_for_overflow(size_t request, const char* whence) const { | 406 bool check_for_overflow(size_t request, const char* whence, |
407 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) const { | |
407 if (UINTPTR_MAX - request < (uintptr_t)_hwm) { | 408 if (UINTPTR_MAX - request < (uintptr_t)_hwm) { |
409 if (alloc_failmode == AllocFailStrategy::RETURN_NULL) { | |
410 return false; | |
411 } | |
408 signal_out_of_memory(request, whence); | 412 signal_out_of_memory(request, whence); |
409 } | 413 } |
414 return true; | |
410 } | 415 } |
411 | 416 |
412 public: | 417 public: |
413 Arena(); | 418 Arena(); |
414 Arena(size_t init_size); | 419 Arena(size_t init_size); |
428 // Fast allocate in the arena. Common case is: pointer test + increment. | 433 // Fast allocate in the arena. Common case is: pointer test + increment. |
429 void* Amalloc(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { | 434 void* Amalloc(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
430 assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2"); | 435 assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2"); |
431 x = ARENA_ALIGN(x); | 436 x = ARENA_ALIGN(x); |
432 debug_only(if (UseMallocOnly) return malloc(x);) | 437 debug_only(if (UseMallocOnly) return malloc(x);) |
433 check_for_overflow(x, "Arena::Amalloc"); | 438 if (!check_for_overflow(x, "Arena::Amalloc", alloc_failmode)) |
439 return NULL; | |
434 NOT_PRODUCT(inc_bytes_allocated(x);) | 440 NOT_PRODUCT(inc_bytes_allocated(x);) |
435 if (_hwm + x > _max) { | 441 if (_hwm + x > _max) { |
436 return grow(x, alloc_failmode); | 442 return grow(x, alloc_failmode); |
437 } else { | 443 } else { |
438 char *old = _hwm; | 444 char *old = _hwm; |
442 } | 448 } |
443 // Further assume size is padded out to words | 449 // Further assume size is padded out to words |
444 void *Amalloc_4(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { | 450 void *Amalloc_4(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { |
445 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); | 451 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); |
446 debug_only(if (UseMallocOnly) return malloc(x);) | 452 debug_only(if (UseMallocOnly) return malloc(x);) |
447 check_for_overflow(x, "Arena::Amalloc_4"); | 453 if (!check_for_overflow(x, "Arena::Amalloc_4", alloc_failmode)) |
454 return NULL; | |
448 NOT_PRODUCT(inc_bytes_allocated(x);) | 455 NOT_PRODUCT(inc_bytes_allocated(x);) |
449 if (_hwm + x > _max) { | 456 if (_hwm + x > _max) { |
450 return grow(x, alloc_failmode); | 457 return grow(x, alloc_failmode); |
451 } else { | 458 } else { |
452 char *old = _hwm; | 459 char *old = _hwm; |
463 #if defined(SPARC) && !defined(_LP64) | 470 #if defined(SPARC) && !defined(_LP64) |
464 #define DALIGN_M1 7 | 471 #define DALIGN_M1 7 |
465 size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm; | 472 size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm; |
466 x += delta; | 473 x += delta; |
467 #endif | 474 #endif |
468 check_for_overflow(x, "Arena::Amalloc_D"); | 475 if (!check_for_overflow(x, "Arena::Amalloc_D", alloc_failmode)) |
476 return NULL; | |
469 NOT_PRODUCT(inc_bytes_allocated(x);) | 477 NOT_PRODUCT(inc_bytes_allocated(x);) |
470 if (_hwm + x > _max) { | 478 if (_hwm + x > _max) { |
471 return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes. | 479 return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes. |
472 } else { | 480 } else { |
473 char *old = _hwm; | 481 char *old = _hwm; |
633 (type*) resource_allocate_bytes((size) * sizeof(type), AllocFailStrategy::RETURN_NULL) | 641 (type*) resource_allocate_bytes((size) * sizeof(type), AllocFailStrategy::RETURN_NULL) |
634 | 642 |
635 #define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\ | 643 #define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\ |
636 (type*) resource_allocate_bytes(thread, (size) * sizeof(type)) | 644 (type*) resource_allocate_bytes(thread, (size) * sizeof(type)) |
637 | 645 |
646 #define NEW_RESOURCE_ARRAY_IN_THREAD_RETURN_NULL(thread, type, size)\ | |
647 (type*) resource_allocate_bytes(thread, (size) * sizeof(type), AllocFailStrategy::RETURN_NULL) | |
648 | |
638 #define REALLOC_RESOURCE_ARRAY(type, old, old_size, new_size)\ | 649 #define REALLOC_RESOURCE_ARRAY(type, old, old_size, new_size)\ |
639 (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type) ) | 650 (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type), (new_size) * sizeof(type)) |
651 | |
652 #define REALLOC_RESOURCE_ARRAY_RETURN_NULL(type, old, old_size, new_size)\ | |
653 (type*) resource_reallocate_bytes((char*)(old), (old_size) * sizeof(type),\ | |
654 (new_size) * sizeof(type), AllocFailStrategy::RETURN_NULL) | |
640 | 655 |
641 #define FREE_RESOURCE_ARRAY(type, old, size)\ | 656 #define FREE_RESOURCE_ARRAY(type, old, size)\ |
642 resource_free_bytes((char*)(old), (size) * sizeof(type)) | 657 resource_free_bytes((char*)(old), (size) * sizeof(type)) |
643 | 658 |
644 #define FREE_FAST(old)\ | 659 #define FREE_FAST(old)\ |
645 /* nop */ | 660 /* nop */ |
646 | 661 |
647 #define NEW_RESOURCE_OBJ(type)\ | 662 #define NEW_RESOURCE_OBJ(type)\ |
648 NEW_RESOURCE_ARRAY(type, 1) | 663 NEW_RESOURCE_ARRAY(type, 1) |
649 | 664 |
665 #define NEW_RESOURCE_OBJ_RETURN_NULL(type)\ | |
666 NEW_RESOURCE_ARRAY_RETURN_NULL(type, 1) | |
667 | |
668 #define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail)\ | |
669 (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail) | |
670 | |
671 #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\ | |
672 (type*) (AllocateHeap((size) * sizeof(type), memflags, pc)) | |
673 | |
650 #define NEW_C_HEAP_ARRAY(type, size, memflags)\ | 674 #define NEW_C_HEAP_ARRAY(type, size, memflags)\ |
651 (type*) (AllocateHeap((size) * sizeof(type), memflags)) | 675 (type*) (AllocateHeap((size) * sizeof(type), memflags)) |
652 | 676 |
677 #define NEW_C_HEAP_ARRAY2_RETURN_NULL(type, size, memflags, pc)\ | |
678 NEW_C_HEAP_ARRAY3(type, size, memflags, pc, AllocFailStrategy::RETURN_NULL) | |
679 | |
680 #define NEW_C_HEAP_ARRAY_RETURN_NULL(type, size, memflags)\ | |
681 NEW_C_HEAP_ARRAY3(type, size, memflags, (address)0, AllocFailStrategy::RETURN_NULL) | |
682 | |
653 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\ | 683 #define REALLOC_C_HEAP_ARRAY(type, old, size, memflags)\ |
654 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags)) | 684 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags)) |
655 | 685 |
686 #define REALLOC_C_HEAP_ARRAY_RETURN_NULL(type, old, size, memflags)\ | |
687 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, AllocFailStrategy::RETURN_NULL)) | |
688 | |
656 #define FREE_C_HEAP_ARRAY(type, old, memflags) \ | 689 #define FREE_C_HEAP_ARRAY(type, old, memflags) \ |
657 FreeHeap((char*)(old), memflags) | 690 FreeHeap((char*)(old), memflags) |
658 | |
659 #define NEW_C_HEAP_ARRAY2(type, size, memflags, pc)\ | |
660 (type*) (AllocateHeap((size) * sizeof(type), memflags, pc)) | |
661 | |
662 #define REALLOC_C_HEAP_ARRAY2(type, old, size, memflags, pc)\ | |
663 (type*) (ReallocateHeap((char*)old, (size) * sizeof(type), memflags, pc)) | |
664 | |
665 #define NEW_C_HEAP_ARRAY3(type, size, memflags, pc, allocfail) \ | |
666 (type*) AllocateHeap(size * sizeof(type), memflags, pc, allocfail) | |
667 | 691 |
668 // allocate type in heap without calling ctor | 692 // allocate type in heap without calling ctor |
669 #define NEW_C_HEAP_OBJ(type, memflags)\ | 693 #define NEW_C_HEAP_OBJ(type, memflags)\ |
670 NEW_C_HEAP_ARRAY(type, 1, memflags) | 694 NEW_C_HEAP_ARRAY(type, 1, memflags) |
695 | |
696 #define NEW_C_HEAP_OBJ_RETURN_NULL(type, memflags)\ | |
697 NEW_C_HEAP_ARRAY_RETURN_NULL(type, 1, memflags) | |
671 | 698 |
672 // deallocate obj of type in heap without calling dtor | 699 // deallocate obj of type in heap without calling dtor |
673 #define FREE_C_HEAP_OBJ(objname, memflags)\ | 700 #define FREE_C_HEAP_OBJ(objname, memflags)\ |
674 FreeHeap((char*)objname, memflags); | 701 FreeHeap((char*)objname, memflags); |
675 | 702 |
711 // Most OS mallocs do something similar but Solaris malloc does not revert | 738 // Most OS mallocs do something similar but Solaris malloc does not revert |
712 // to mapped memory for large allocations. By default ArrayAllocatorMallocLimit | 739 // to mapped memory for large allocations. By default ArrayAllocatorMallocLimit |
713 // is set so that we always use malloc except for Solaris where we set the | 740 // is set so that we always use malloc except for Solaris where we set the |
714 // limit to get mapped memory. | 741 // limit to get mapped memory. |
715 template <class E, MEMFLAGS F> | 742 template <class E, MEMFLAGS F> |
716 class ArrayAllocator : StackObj { | 743 class ArrayAllocator VALUE_OBJ_CLASS_SPEC { |
717 char* _addr; | 744 char* _addr; |
718 bool _use_malloc; | 745 bool _use_malloc; |
719 size_t _size; | 746 size_t _size; |
720 public: | 747 bool _free_in_destructor; |
721 ArrayAllocator() : _addr(NULL), _use_malloc(false), _size(0) { } | 748 public: |
722 ~ArrayAllocator() { free(); } | 749 ArrayAllocator(bool free_in_destructor = true) : |
750 _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { } | |
751 | |
752 ~ArrayAllocator() { | |
753 if (_free_in_destructor) { | |
754 free(); | |
755 } | |
756 } | |
757 | |
723 E* allocate(size_t length); | 758 E* allocate(size_t length); |
724 void free(); | 759 void free(); |
725 }; | 760 }; |
726 | 761 |
727 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP | 762 #endif // SHARE_VM_MEMORY_ALLOCATION_HPP |