Mercurial > hg > truffle
annotate src/share/vm/services/memRecorder.cpp @ 11722:ff05c78a7f64
use time passed to decide what methods to compile or inline
author | Christian Wirth <christian.wirth@oracle.com> |
---|---|
date | Thu, 19 Sep 2013 10:36:56 +0200 |
parents | 1f4355cee9a2 |
children |
rev | line source |
---|---|
6197 | 1 /* |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
7971
diff
changeset
|
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
6197 | 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 | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
7971
diff
changeset
|
72 address pc = CURRENT_PC; |
6197 | 73 record((address)this, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder), |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
7971
diff
changeset
|
74 sizeof(MemRecorder), SequenceGenerator::next(), pc); |
6197 | 75 record((address)_pointer_records, (MemPointerRecord::malloc_tag()|mtNMT|otNMTRecorder), |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
7971
diff
changeset
|
76 _pointer_records->instance_size(), SequenceGenerator::next(), pc); |
6197 | 77 } |
78 } | |
79 | |
80 MemRecorder::~MemRecorder() { | |
81 if (_pointer_records != NULL) { | |
82 if (MemTracker::is_on()) { | |
83 MemTracker::record_free((address)_pointer_records, mtNMT); | |
84 MemTracker::record_free((address)this, mtNMT); | |
85 } | |
86 delete _pointer_records; | |
87 } | |
7464
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
88 // delete all linked recorders |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
89 while (_next != NULL) { |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
90 MemRecorder* tmp = _next; |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
91 _next = _next->next(); |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
92 tmp->set_next(NULL); |
ecd24264898b
8005048: NMT: #loaded classes needs to just show the # defined classes
zgu
parents:
6882
diff
changeset
|
93 delete tmp; |
6197 | 94 } |
95 Atomic::dec(&_instance_count); | |
96 } | |
97 | |
98 // Sorting order: | |
99 // 1. memory block address | |
100 // 2. mem pointer record tags | |
101 // 3. sequence number | |
102 int MemRecorder::sort_record_fn(const void* e1, const void* e2) { | |
103 const MemPointerRecord* p1 = (const MemPointerRecord*)e1; | |
104 const MemPointerRecord* p2 = (const MemPointerRecord*)e2; | |
105 int delta = UNSIGNED_COMPARE(p1->addr(), p2->addr()); | |
106 if (delta == 0) { | |
107 int df = UNSIGNED_COMPARE((p1->flags() & MemPointerRecord::tag_masks), | |
108 (p2->flags() & MemPointerRecord::tag_masks)); | |
109 if (df == 0) { | |
110 assert(p1->seq() != p2->seq(), "dup seq"); | |
111 return p1->seq() - p2->seq(); | |
112 } else { | |
113 return df; | |
114 } | |
115 } else { | |
116 return delta; | |
117 } | |
118 } | |
119 | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
7971
diff
changeset
|
120 bool MemRecorder::record(address p, MEMFLAGS flags, size_t size, jint seq, address pc) { |
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
7971
diff
changeset
|
121 assert(seq > 0, "No sequence number"); |
6197 | 122 #ifdef ASSERT |
123 if (MemPointerRecord::is_virtual_memory_record(flags)) { | |
124 assert((flags & MemPointerRecord::tag_masks) != 0, "bad virtual memory record"); | |
125 } else { | |
126 assert((flags & MemPointerRecord::tag_masks) == MemPointerRecord::malloc_tag() || | |
127 (flags & MemPointerRecord::tag_masks) == MemPointerRecord::free_tag() || | |
128 IS_ARENA_OBJ(flags), | |
129 "bad malloc record"); | |
130 } | |
131 // a recorder should only hold records within the same generation | |
132 unsigned long cur_generation = SequenceGenerator::current_generation(); | |
133 assert(cur_generation == _generation, | |
134 "this thread did not enter sync point"); | |
135 #endif | |
136 | |
137 if (MemTracker::track_callsite()) { | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
7971
diff
changeset
|
138 SeqMemPointerRecordEx ap(p, flags, size, seq, pc); |
6197 | 139 debug_only(check_dup_seq(ap.seq());) |
140 return _pointer_records->append(&ap); | |
141 } else { | |
10986
1f4355cee9a2
8013651: NMT: reserve/release sequence id's in incorrect order due to race
zgu
parents:
7971
diff
changeset
|
142 SeqMemPointerRecord ap(p, flags, size, seq); |
6197 | 143 debug_only(check_dup_seq(ap.seq());) |
144 return _pointer_records->append(&ap); | |
145 } | |
146 } | |
147 | |
148 // iterator for alloc pointers | |
149 SequencedRecordIterator MemRecorder::pointer_itr() { | |
150 assert(_pointer_records != NULL, "just check"); | |
151 _pointer_records->sort((FN_SORT)sort_record_fn); | |
152 return SequencedRecordIterator(_pointer_records); | |
153 } | |
154 | |
155 | |
156 void MemRecorder::set_generation() { | |
157 _generation = SequenceGenerator::current_generation(); | |
158 } | |
159 | |
7971
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
160 #ifdef ASSERT |
4102b59539ce
8005012: Add WB APIs to better support NMT testing
ctornqvi
parents:
7464
diff
changeset
|
161 |
6197 | 162 void MemRecorder::check_dup_seq(jint seq) const { |
163 MemPointerArrayIteratorImpl itr(_pointer_records); | |
164 MemPointerRecord* rc = (MemPointerRecord*)itr.current(); | |
165 while (rc != NULL) { | |
166 assert(rc->seq() != seq, "dup seq"); | |
167 rc = (MemPointerRecord*)itr.next(); | |
168 } | |
169 } | |
170 | |
171 #endif |