24
25 #ifndef SHARE_MEMORY_ALLOCATION_INLINE_HPP
26 #define SHARE_MEMORY_ALLOCATION_INLINE_HPP
27
28 #include "runtime/atomic.hpp"
29 #include "runtime/globals.hpp"
30 #include "runtime/os.hpp"
31 #include "services/memTracker.hpp"
32 #include "utilities/align.hpp"
33 #include "utilities/globalDefinitions.hpp"
34
35 // Explicit C-heap memory management
36
37 #ifndef PRODUCT
38 // Increments unsigned long value for statistics (not atomic on MP, but avoids word-tearing on 32 bit).
39 inline void inc_stat_counter(volatile julong* dest, julong add_value) {
40 #ifdef _LP64
41 *dest += add_value;
42 #else
43 julong value = Atomic::load(dest);
44 Atomic::store(value + add_value, dest);
45 #endif
46 }
47 #endif
48
49 template <class E>
50 size_t MmapArrayAllocator<E>::size_for(size_t length) {
51 size_t size = length * sizeof(E);
52 int alignment = os::vm_allocation_granularity();
53 return align_up(size, alignment);
54 }
55
56 template <class E>
57 E* MmapArrayAllocator<E>::allocate_or_null(size_t length, MEMFLAGS flags) {
58 size_t size = size_for(length);
59 int alignment = os::vm_allocation_granularity();
60
61 char* addr = os::reserve_memory(size, NULL, alignment, flags);
62 if (addr == NULL) {
63 return NULL;
64 }
|
24
25 #ifndef SHARE_MEMORY_ALLOCATION_INLINE_HPP
26 #define SHARE_MEMORY_ALLOCATION_INLINE_HPP
27
28 #include "runtime/atomic.hpp"
29 #include "runtime/globals.hpp"
30 #include "runtime/os.hpp"
31 #include "services/memTracker.hpp"
32 #include "utilities/align.hpp"
33 #include "utilities/globalDefinitions.hpp"
34
35 // Explicit C-heap memory management
36
37 #ifndef PRODUCT
38 // Increments unsigned long value for statistics (not atomic on MP, but avoids word-tearing on 32 bit).
39 inline void inc_stat_counter(volatile julong* dest, julong add_value) {
40 #ifdef _LP64
41 *dest += add_value;
42 #else
43 julong value = Atomic::load(dest);
44 Atomic::store(dest, value + add_value);
45 #endif
46 }
47 #endif
48
49 template <class E>
50 size_t MmapArrayAllocator<E>::size_for(size_t length) {
51 size_t size = length * sizeof(E);
52 int alignment = os::vm_allocation_granularity();
53 return align_up(size, alignment);
54 }
55
56 template <class E>
57 E* MmapArrayAllocator<E>::allocate_or_null(size_t length, MEMFLAGS flags) {
58 size_t size = size_for(length);
59 int alignment = os::vm_allocation_granularity();
60
61 char* addr = os::reserve_memory(size, NULL, alignment, flags);
62 if (addr == NULL) {
63 return NULL;
64 }
|