Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/resourceArea.cpp
40950 views
1
/*
2
* Copyright (c) 1997, 2020, 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/atomic.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
size_t size = size_in_bytes();
35
MemTracker::record_arena_size_change(-ssize_t(size), _flags);
36
MemTracker::record_arena_free(_flags);
37
MemTracker::record_new_arena(new_flags);
38
MemTracker::record_arena_size_change(ssize_t(size), new_flags);
39
_flags = new_flags;
40
}
41
}
42
43
#ifdef ASSERT
44
45
void ResourceArea::verify_has_resource_mark() {
46
if (_nesting <= 0) {
47
// Only report the first occurrence of an allocating thread that
48
// is missing a ResourceMark, to avoid possible recursive errors
49
// in error handling.
50
static volatile bool reported = false;
51
if (!Atomic::load(&reported)) {
52
if (!Atomic::cmpxchg(&reported, false, true)) {
53
fatal("memory leak: allocating without ResourceMark");
54
}
55
}
56
}
57
}
58
59
#endif // ASSERT
60
61
//------------------------------ResourceMark-----------------------------------
62
// The following routines are declared in allocation.hpp and used everywhere:
63
64
// Allocation in thread-local resource area
65
extern char* resource_allocate_bytes(size_t size, AllocFailType alloc_failmode) {
66
return Thread::current()->resource_area()->allocate_bytes(size, alloc_failmode);
67
}
68
extern char* resource_allocate_bytes(Thread* thread, size_t size, AllocFailType alloc_failmode) {
69
return thread->resource_area()->allocate_bytes(size, alloc_failmode);
70
}
71
72
extern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_size, AllocFailType alloc_failmode){
73
return (char*)Thread::current()->resource_area()->Arealloc(old, old_size, new_size, alloc_failmode);
74
}
75
76
extern void resource_free_bytes( char *old, size_t size ) {
77
Thread::current()->resource_area()->Afree(old, size);
78
}
79
80