Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/utilities/jfrAllocation.hpp
38920 views
/*1* Copyright (c) 2014, 2018, 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_VM_JFR_UTILITIES_JFRALLOCATION_HPP25#define SHARE_VM_JFR_UTILITIES_JFRALLOCATION_HPP2627#include "memory/allocation.hpp"28#include "services/memTracker.hpp"29#include "utilities/exceptions.hpp"3031/*32* A subclass to the CHeapObj<mtTracing> allocator, useful for critical33* Jfr subsystems. Critical in this context means subsystems for which34* allocations are crucial to the bootstrap and initialization of Jfr.35* The default behaviour by a CHeapObj is to call vm_exit_out_of_memory()36* on allocation failure and this is problematic in combination with the37* Jfr on-demand, dynamic start at runtime, capability.38* We would not like a user dynamically starting Jfr to39* tear down the VM she is about to inspect as a side effect.40*41* This allocator uses the RETURN_NULL capabilities42* instead of calling vm_exit_out_of_memory() until Jfr is properly started.43* This allows for controlled behaviour on allocation failures during startup,44* which means we can take actions on failure, such as transactional rollback45* (deallocations and restorations).46* In addition, this allocator allows for easy hooking of memory47* allocations / deallocations for debugging purposes.48*/4950class JfrCHeapObj : public CHeapObj<mtTracing> {51private:52static void on_memory_allocation(const void* allocation, size_t size);53static char* allocate_array_noinline(size_t elements, size_t element_size);5455public:56NOINLINE void* operator new(size_t size) throw();57NOINLINE void* operator new (size_t size, const std::nothrow_t& nothrow_constant) throw();58NOINLINE void* operator new [](size_t size) throw();59NOINLINE void* operator new [](size_t size, const std::nothrow_t& nothrow_constant) throw();60void operator delete(void* p, size_t size);61void operator delete [] (void* p, size_t size);62static char* realloc_array(char* old, size_t size);63static void free(void* p, size_t size = 0);6465template <class T>66static T* new_array(size_t size) {67T* const memory = (T*)allocate_array_noinline(size, sizeof(T));68on_memory_allocation(memory, sizeof(T) * size);69return memory;70}71};7273#endif // SHARE_VM_JFR_UTILITIES_JFRALLOCATION_HPP747576