Path: blob/master/src/hotspot/share/memory/resourceArea.cpp
40950 views
/*1* Copyright (c) 1997, 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#include "precompiled.hpp"25#include "memory/allocation.inline.hpp"26#include "memory/resourceArea.inline.hpp"27#include "runtime/atomic.hpp"28#include "runtime/thread.inline.hpp"29#include "services/memTracker.hpp"3031void ResourceArea::bias_to(MEMFLAGS new_flags) {32if (new_flags != _flags) {33size_t size = size_in_bytes();34MemTracker::record_arena_size_change(-ssize_t(size), _flags);35MemTracker::record_arena_free(_flags);36MemTracker::record_new_arena(new_flags);37MemTracker::record_arena_size_change(ssize_t(size), new_flags);38_flags = new_flags;39}40}4142#ifdef ASSERT4344void ResourceArea::verify_has_resource_mark() {45if (_nesting <= 0) {46// Only report the first occurrence of an allocating thread that47// is missing a ResourceMark, to avoid possible recursive errors48// in error handling.49static volatile bool reported = false;50if (!Atomic::load(&reported)) {51if (!Atomic::cmpxchg(&reported, false, true)) {52fatal("memory leak: allocating without ResourceMark");53}54}55}56}5758#endif // ASSERT5960//------------------------------ResourceMark-----------------------------------61// The following routines are declared in allocation.hpp and used everywhere:6263// Allocation in thread-local resource area64extern char* resource_allocate_bytes(size_t size, AllocFailType alloc_failmode) {65return Thread::current()->resource_area()->allocate_bytes(size, alloc_failmode);66}67extern char* resource_allocate_bytes(Thread* thread, size_t size, AllocFailType alloc_failmode) {68return thread->resource_area()->allocate_bytes(size, alloc_failmode);69}7071extern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_size, AllocFailType alloc_failmode){72return (char*)Thread::current()->resource_area()->Arealloc(old, old_size, new_size, alloc_failmode);73}7475extern void resource_free_bytes( char *old, size_t size ) {76Thread::current()->resource_area()->Afree(old, size);77}787980