Path: blob/master/src/hotspot/share/jfr/utilities/jfrAllocation.hpp
41149 views
/*1* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_JFR_UTILITIES_JFRALLOCATION_HPP25#define SHARE_JFR_UTILITIES_JFRALLOCATION_HPP2627#include "memory/allocation.hpp"28#include "utilities/exceptions.hpp"2930/*31* A subclass to the CHeapObj<mtTracing> allocator, useful for critical32* Jfr subsystems. Critical in this context means subsystems for which33* allocations are crucial to the bootstrap and initialization of Jfr.34* The default behaviour by a CHeapObj is to call vm_exit_out_of_memory()35* on allocation failure and this is problematic in combination with the36* Jfr on-demand, dynamic start at runtime, capability.37* We would not like a user dynamically starting Jfr to38* tear down the VM she is about to inspect as a side effect.39*40* This allocator uses the RETURN_NULL capabilities41* instead of calling vm_exit_out_of_memory() until Jfr is properly started.42* This allows for controlled behaviour on allocation failures during startup,43* which means we can take actions on failure, such as transactional rollback44* (deallocations and restorations).45* In addition, this allocator allows for easy hooking of memory46* allocations / deallocations for debugging purposes.47*/4849class JfrCHeapObj : public CHeapObj<mtTracing> {50private:51static void on_memory_allocation(const void* allocation, size_t size);52static char* allocate_array_noinline(size_t elements, size_t element_size);5354public:55NOINLINE void* operator new(size_t size) throw();56NOINLINE void* operator new (size_t size, const std::nothrow_t& nothrow_constant) throw();57NOINLINE void* operator new [](size_t size) throw();58NOINLINE void* operator new [](size_t size, const std::nothrow_t& nothrow_constant) throw();59void operator delete(void* p, size_t size);60void operator delete [] (void* p, size_t size);61static char* realloc_array(char* old, size_t size);62static void free(void* p, size_t size = 0);6364template <class T>65static T* new_array(size_t size) {66T* const memory = (T*)allocate_array_noinline(size, sizeof(T));67on_memory_allocation(memory, sizeof(T) * size);68return memory;69}70};7172#endif // SHARE_JFR_UTILITIES_JFRALLOCATION_HPP737475