| 1 | /* |
| 2 | * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "precompiled.hpp" |
| 26 | #include "memory/allocation.inline.hpp" |
| 27 | #include "memory/resourceArea.inline.hpp" |
| 28 | #include "runtime/mutexLocker.hpp" |
| 29 | #include "runtime/thread.inline.hpp" |
| 30 | #include "services/memTracker.hpp" |
| 31 | |
| 32 | void ResourceArea::bias_to(MEMFLAGS new_flags) { |
| 33 | if (new_flags != _flags) { |
| 34 | MemTracker::record_arena_free(_flags); |
| 35 | MemTracker::record_new_arena(new_flags); |
| 36 | _flags = new_flags; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | //------------------------------ResourceMark----------------------------------- |
| 41 | debug_only(int ResourceArea::_warned;) // to suppress multiple warnings |
| 42 | |
| 43 | // The following routines are declared in allocation.hpp and used everywhere: |
| 44 | |
| 45 | // Allocation in thread-local resource area |
| 46 | extern char* resource_allocate_bytes(size_t size, AllocFailType alloc_failmode) { |
| 47 | return Thread::current()->resource_area()->allocate_bytes(size, alloc_failmode); |
| 48 | } |
| 49 | extern char* resource_allocate_bytes(Thread* thread, size_t size, AllocFailType alloc_failmode) { |
| 50 | return thread->resource_area()->allocate_bytes(size, alloc_failmode); |
| 51 | } |
| 52 | |
| 53 | extern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_size, AllocFailType alloc_failmode){ |
| 54 | return (char*)Thread::current()->resource_area()->Arealloc(old, old_size, new_size, alloc_failmode); |
| 55 | } |
| 56 | |
| 57 | extern void resource_free_bytes( char *old, size_t size ) { |
| 58 | Thread::current()->resource_area()->Afree(old, size); |
| 59 | } |
| 60 | |
| 61 | #ifdef ASSERT |
| 62 | ResourceMark::ResourceMark(Thread *thread) { |
| 63 | assert(thread == Thread::current(), "not the current thread" ); |
| 64 | initialize(thread); |
| 65 | } |
| 66 | |
| 67 | DeoptResourceMark::DeoptResourceMark(Thread *thread) { |
| 68 | assert(thread == Thread::current(), "not the current thread" ); |
| 69 | initialize(thread); |
| 70 | } |
| 71 | #endif |
| 72 | |
| 73 | |
| 74 | //------------------------------------------------------------------------------- |
| 75 | // Non-product code |
| 76 | #ifndef PRODUCT |
| 77 | |
| 78 | void ResourceMark::free_malloced_objects() { |
| 79 | Arena::free_malloced_objects(_chunk, _hwm, _max, _area->_hwm); |
| 80 | } |
| 81 | |
| 82 | void DeoptResourceMark::free_malloced_objects() { |
| 83 | Arena::free_malloced_objects(_chunk, _hwm, _max, _area->_hwm); |
| 84 | } |
| 85 | |
| 86 | #endif |
| 87 | |