@@ -108,19 +108,27 @@ class JfrMemorySpace : public JfrCHeapObj {
108
108
};
109
109
110
110
// allocations are even multiples of the mspace min size
111
- inline u8 align_allocation_size (u8 requested_size, size_t min_elem_size) {
111
+ inline size_t align_allocation_size (size_t requested_size, size_t min_elem_size) {
112
112
assert ((int )min_elem_size % os::vm_page_size () == 0 , " invariant" );
113
+ if (requested_size > static_cast <size_t >(min_intx)) {
114
+ assert (false , err_msg (" requested size: " SIZE_FORMAT " is too large" , requested_size));
115
+ return 0 ;
116
+ }
113
117
u8 alloc_size_bytes = min_elem_size;
114
118
while (requested_size > alloc_size_bytes) {
115
119
alloc_size_bytes <<= 1 ;
116
120
}
117
121
assert ((int )alloc_size_bytes % os::vm_page_size () == 0 , " invariant" );
118
- return alloc_size_bytes;
122
+ assert (alloc_size_bytes <= static_cast <size_t >(min_intx), " invariant" );
123
+ return static_cast <size_t >(alloc_size_bytes);
119
124
}
120
125
121
126
template <typename T, template <typename > class RetrievalType , typename Callback>
122
127
T* JfrMemorySpace<T, RetrievalType, Callback>::allocate(size_t size) {
123
- const u8 aligned_size_bytes = align_allocation_size (size, _min_elem_size);
128
+ const size_t aligned_size_bytes = align_allocation_size (size, _min_elem_size);
129
+ if (size != 0 && aligned_size_bytes == 0 ) {
130
+ return NULL ;
131
+ }
124
132
void * const allocation = JfrCHeapObj::new_array<u1>(aligned_size_bytes + sizeof (T));
125
133
if (allocation == NULL ) {
126
134
return NULL ;
0 commit comments