1 /*
2 * Copyright (c) 2013, 2018, 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 #include "precompiled.hpp"
25
26 #include "logging/log.hpp"
27 #include "memory/metaspace.hpp"
28 #include "runtime/atomic.hpp"
29 #include "runtime/os.hpp"
30 #include "runtime/threadCritical.hpp"
31 #include "services/memTracker.hpp"
32 #include "services/virtualMemoryTracker.hpp"
33
34 size_t VirtualMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
35
36 void VirtualMemorySummary::initialize() {
37 assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check");
38 // Use placement operator new to initialize static data area.
39 ::new ((void*)_snapshot) VirtualMemorySnapshot();
40 }
41
42 void VirtualMemorySummary::snapshot(VirtualMemorySnapshot* s) {
43 // Snapshot current thread stacks
44 VirtualMemoryTracker::snapshot_thread_stacks();
45 as_snapshot()->copy_to(s);
46 }
47
48 SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>* VirtualMemoryTracker::_reserved_regions;
49
50 int compare_committed_region(const CommittedMemoryRegion& r1, const CommittedMemoryRegion& r2) {
51 return r1.compare(r2);
52 }
53
54 int compare_reserved_region_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2) {
55 return r1.compare(r2);
56 }
57
58 static bool is_mergeable_with(CommittedMemoryRegion* rgn, address addr, size_t size, const NativeCallStack& stack) {
59 return rgn->adjacent_to(addr, size) && rgn->call_stack()->equals(stack);
60 }
61
62 static bool is_same_as(CommittedMemoryRegion* rgn, address addr, size_t size, const NativeCallStack& stack) {
63 // It would have made sense to use rgn->equals(...), but equals returns true for overlapping regions.
64 return rgn->same_region(addr, size) && rgn->call_stack()->equals(stack);
65 }
|
1 /*
2 * Copyright (c) 2013, 2019, 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 #include "precompiled.hpp"
25
26 #include "logging/log.hpp"
27 #include "memory/metaspace.hpp"
28 #include "runtime/atomic.hpp"
29 #include "runtime/os.hpp"
30 #include "runtime/threadCritical.hpp"
31 #include "services/memTracker.hpp"
32 #include "services/threadStackTracker.hpp"
33 #include "services/virtualMemoryTracker.hpp"
34
35 size_t VirtualMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
36
37 void VirtualMemorySummary::initialize() {
38 assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check");
39 // Use placement operator new to initialize static data area.
40 ::new ((void*)_snapshot) VirtualMemorySnapshot();
41 }
42
43 void VirtualMemorySummary::snapshot(VirtualMemorySnapshot* s) {
44 // Only if thread stack is backed by virtual memory
45 if (ThreadStackTracker::track_as_vm()) {
46 // Snapshot current thread stacks
47 VirtualMemoryTracker::snapshot_thread_stacks();
48 as_snapshot()->copy_to(s);
49 }
50 }
51
52 SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>* VirtualMemoryTracker::_reserved_regions;
53
54 int compare_committed_region(const CommittedMemoryRegion& r1, const CommittedMemoryRegion& r2) {
55 return r1.compare(r2);
56 }
57
58 int compare_reserved_region_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2) {
59 return r1.compare(r2);
60 }
61
62 static bool is_mergeable_with(CommittedMemoryRegion* rgn, address addr, size_t size, const NativeCallStack& stack) {
63 return rgn->adjacent_to(addr, size) && rgn->call_stack()->equals(stack);
64 }
65
66 static bool is_same_as(CommittedMemoryRegion* rgn, address addr, size_t size, const NativeCallStack& stack) {
67 // It would have made sense to use rgn->equals(...), but equals returns true for overlapping regions.
68 return rgn->same_region(addr, size) && rgn->call_stack()->equals(stack);
69 }
|