Mercurial > hg > graal-compiler
annotate src/share/vm/services/memRecorder.cpp @ 9097:a0ab945fb95f
build output during buildvms command is sent to console (instead of log files) if -c option is given
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 12 Apr 2013 22:13:26 +0200 |
parents | 4102b59539ce |
children | 1f4355cee9a2 |
rev | line source |
---|---|
6197 | 1 /* |
2 * Copyright (c) 2012, 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 | |
27 #include "runtime/atomic.hpp" | |
28 #include "services/memBaseline.hpp" | |
29 #include "services/memRecorder.hpp" | |
30 #include "services/memPtr.hpp" | |
31 #include "services/memTracker.hpp" | |
32 | |
33 MemPointer* SequencedRecordIterator::next_record() { | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
34 MemPointerRecord* itr_cur = (MemPointerRecord*)_itr.current(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
35 if (itr_cur == NULL) { |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
36 return itr_cur; |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
37 } |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
38 |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
39 MemPointerRecord* itr_next = (MemPointerRecord*)_itr.next(); |
6197 | 40 |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
41 // don't collapse virtual memory records |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
42 while (itr_next != NULL && !itr_cur->is_vm_pointer() && |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
43 !itr_next->is_vm_pointer() && |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
44 same_kind(itr_cur, itr_next)) { |
6197 | 45 itr_cur = itr_next; |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6231
diff
changeset
|
46 itr_next = (MemPointerRecord*)_itr.next(); |
6197 | 47 } |
48 | |
49 return itr_cur; | |
50 } | |
51 | |
52 | |
6231 | 53 volatile jint MemRecorder::_instance_count = 0; |
6197 | 54 |
55 MemRecorder::MemRecorder() { | |
56 assert(MemTracker::is_on(), "Native memory tracking is off"); | |
6231 | 57 Atomic::inc(&_instance_count); |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
58 set_generation(); |
6197 | 59 |
60 if (MemTracker::track_callsite()) { | |
61 _pointer_records = new (std::nothrow)FixedSizeMemPointerArray<SeqMemPointerRecordEx, | |
62 DEFAULT_RECORDER_PTR_ARRAY_SIZE>(); | |
63 } else { | |
64 _pointer_records = new (std::nothrow)FixedSizeMemPointerArray<SeqMemPointerRecord, | |
65 DEFAULT_RECORDER_PTR_ARRAY_SIZE>(); | |
66 } | |
67 _next = NULL; | |
68 | |
69 | |
70 if (_pointer_records != NULL) { | |
71 // recode itself | |
72 record((address)this, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder), | |
73 sizeof(MemRecorder), CALLER_PC); | |
74 record((address)_pointer_records, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder), | |
75 _pointer_records->instance_size(),CURRENT_PC); | |
76 } | |
77 } | |
78 | |
79 MemRecorder::~MemRecorder() { | |
80 if (_pointer_records != NULL) { | |
81 if (MemTracker::is_on()) { | |
82 MemTracker::record_free((address)_pointer_records, mtNMT); | |
83 MemTracker::record_free((address)this, mtNMT); | |
84 } | |
85 delete _pointer_records; | |
86 } | |
7464
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
87 // delete all linked recorders |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
88 while (_next != NULL) { |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
89 MemRecorder* tmp = _next; |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
90 _next = _next->next(); |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
91 tmp->set_next(NULL); |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
92 delete tmp; |
6197 | 93 } |
94 Atomic::dec(&_instance_count); | |
95 } | |
96 | |
97 // Sorting order: | |
98 // 1. memory block address | |
99 // 2. mem pointer record tags | |
100 // 3. sequence number | |
101 int MemRecorder::sort_record_fn(const void* e1, const void* e2) { | |
102 const MemPointerRecord* p1 = (const MemPointerRecord*)e1; | |
103 const MemPointerRecord* p2 = (const MemPointerRecord*)e2; | |
104 int delta = UNSIGNED_COMPARE(p1->addr(), p2->addr()); | |
105 if (delta == 0) { | |
106 int df = UNSIGNED_COMPARE((p1->flags() & MemPointerRecord::tag_masks), | |
107 (p2->flags() & MemPointerRecord::tag_masks)); | |
108 if (df == 0) { | |
109 assert(p1->seq() != p2->seq(), "dup seq"); | |
110 return p1->seq() - p2->seq(); | |
111 } else { | |
112 return df; | |
113 } | |
114 } else { | |
115 return delta; | |
116 } | |
117 } | |
118 | |
119 bool MemRecorder::record(address p, MEMFLAGS flags, size_t size, address pc) { | |
120 #ifdef ASSERT | |
121 if (MemPointerRecord::is_virtual_memory_record(flags)) { | |
122 assert((flags & MemPointerRecord::tag_masks) != 0, "bad virtual memory record"); | |
123 } else { | |
124 assert((flags & MemPointerRecord::tag_masks) == MemPointerRecord::malloc_tag() || | |
125 (flags & MemPointerRecord::tag_masks) == MemPointerRecord::free_tag() || | |
126 IS_ARENA_OBJ(flags), | |
127 "bad malloc record"); | |
128 } | |
129 // a recorder should only hold records within the same generation | |
130 unsigned long cur_generation = SequenceGenerator::current_generation(); | |
131 assert(cur_generation == _generation, | |
132 "this thread did not enter sync point"); | |
133 #endif | |
134 | |
135 if (MemTracker::track_callsite()) { | |
136 SeqMemPointerRecordEx ap(p, flags, size, pc); | |
137 debug_only(check_dup_seq(ap.seq());) | |
138 return _pointer_records->append(&ap); | |
139 } else { | |
140 SeqMemPointerRecord ap(p, flags, size); | |
141 debug_only(check_dup_seq(ap.seq());) | |
142 return _pointer_records->append(&ap); | |
143 } | |
144 } | |
145 | |
146 // iterator for alloc pointers | |
147 SequencedRecordIterator MemRecorder::pointer_itr() { | |
148 assert(_pointer_records != NULL, "just check"); | |
149 _pointer_records->sort((FN_SORT)sort_record_fn); | |
150 return SequencedRecordIterator(_pointer_records); | |
151 } | |
152 | |
153 | |
154 void MemRecorder::set_generation() { | |
155 _generation = SequenceGenerator::current_generation(); | |
156 } | |
157 | |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
158 #ifdef ASSERT |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
159 |
6197 | 160 void MemRecorder::check_dup_seq(jint seq) const { |
161 MemPointerArrayIteratorImpl itr(_pointer_records); | |
162 MemPointerRecord* rc = (MemPointerRecord*)itr.current(); | |
163 while (rc != NULL) { | |
164 assert(rc->seq() != seq, "dup seq"); | |
165 rc = (MemPointerRecord*)itr.next(); | |
166 } | |
167 } | |
168 | |
169 #endif |