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 "oops/constantPool.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "runtime/atomic.hpp"
30 #include "runtime/handles.inline.hpp"
31 #include "runtime/thread.inline.hpp"
32
33 #ifdef ASSERT
34 oop* HandleArea::allocate_handle(oop obj) {
35 assert(_handle_mark_nesting > 1, "memory leak: allocating handle outside HandleMark");
36 assert(_no_handle_mark_nesting == 0, "allocating handle inside NoHandleMark");
37 assert(oopDesc::is_oop(obj), "not an oop: " INTPTR_FORMAT, p2i(obj));
38 return real_allocate_handle(obj);
39 }
40 #endif
41
42 // Copy constructors and destructors for metadata handles
43 // These do too much to inline.
44 #define DEF_METADATA_HANDLE_FN_NOINLINE(name, type) \
45 name##Handle::name##Handle(const name##Handle &h) { \
46 _value = h._value; \
47 if (_value != NULL) { \
48 assert(_value->is_valid(), "obj is valid"); \
76 } \
77 return *this; \
78 } \
79 inline void name##Handle::remove() { \
80 if (_value != NULL) { \
81 int i = _thread->metadata_handles()->find_from_end((Metadata*)_value); \
82 assert(i!=-1, "not in metadata_handles list"); \
83 _thread->metadata_handles()->remove_at(i); \
84 } \
85 } \
86 name##Handle::~name##Handle () { remove(); } \
87
88 DEF_METADATA_HANDLE_FN_NOINLINE(method, Method)
89 DEF_METADATA_HANDLE_FN_NOINLINE(constantPool, ConstantPool)
90
91
92 static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) {
93 oop* bottom = (oop*) chunk->bottom();
94 oop* top = (oop*) chunk_top;
95 uintx handles_visited = top - bottom;
96 assert(top >= bottom && top <= (oop*) chunk->top(), "just checking");
97 // during GC phase 3, a handle may be a forward pointer that
98 // is not yet valid, so loosen the assertion
99 while (bottom < top) {
100 // This test can be moved up but for now check every oop.
101
102 assert(oopDesc::is_oop(*bottom), "handle should point to oop");
103 if (Universe::heap()->is_in_reserved_or_null(*bottom)) {
104 f->do_oop(bottom);
105 }
106 bottom++;
107 }
108 return handles_visited;
109 }
110
111 // Used for debugging handle allocation.
112 NOT_PRODUCT(jint _nof_handlemarks = 0;)
113
114 void HandleArea::oops_do(OopClosure* f) {
115 uintx handles_visited = 0;
116 // First handle the current chunk. It is filled to the high water mark.
117 handles_visited += chunk_oops_do(f, _chunk, _hwm);
118 // Then handle all previous chunks. They are completely filled.
119 Chunk* k = _first;
120 while(k != _chunk) {
121 handles_visited += chunk_oops_do(f, k, k->top());
122 k = k->next();
123 }
124
|
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 "oops/constantPool.hpp"
28 #include "oops/oop.inline.hpp"
29 #include "oops/valueKlass.hpp"
30 #include "runtime/atomic.hpp"
31 #include "runtime/handles.inline.hpp"
32 #include "runtime/thread.inline.hpp"
33
34 #ifdef ASSERT
35 oop* HandleArea::allocate_handle(oop obj) {
36 assert(_handle_mark_nesting > 1, "memory leak: allocating handle outside HandleMark");
37 assert(_no_handle_mark_nesting == 0, "allocating handle inside NoHandleMark");
38 assert(oopDesc::is_oop(obj), "not an oop: " INTPTR_FORMAT, p2i(obj));
39 return real_allocate_handle(obj);
40 }
41 #endif
42
43 // Copy constructors and destructors for metadata handles
44 // These do too much to inline.
45 #define DEF_METADATA_HANDLE_FN_NOINLINE(name, type) \
46 name##Handle::name##Handle(const name##Handle &h) { \
47 _value = h._value; \
48 if (_value != NULL) { \
49 assert(_value->is_valid(), "obj is valid"); \
77 } \
78 return *this; \
79 } \
80 inline void name##Handle::remove() { \
81 if (_value != NULL) { \
82 int i = _thread->metadata_handles()->find_from_end((Metadata*)_value); \
83 assert(i!=-1, "not in metadata_handles list"); \
84 _thread->metadata_handles()->remove_at(i); \
85 } \
86 } \
87 name##Handle::~name##Handle () { remove(); } \
88
89 DEF_METADATA_HANDLE_FN_NOINLINE(method, Method)
90 DEF_METADATA_HANDLE_FN_NOINLINE(constantPool, ConstantPool)
91
92
93 static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) {
94 oop* bottom = (oop*) chunk->bottom();
95 oop* top = (oop*) chunk_top;
96 uintx handles_visited = top - bottom;
97 BufferedValuesDealiaser* dealiaser = NULL;
98 assert(top >= bottom && top <= (oop*) chunk->top(), "just checking");
99 // during GC phase 3, a handle may be a forward pointer that
100 // is not yet valid, so loosen the assertion
101 while (bottom < top) {
102 // This test can be moved up but for now check every oop.
103
104 assert(oopDesc::is_oop(*bottom), "handle should point to oop");
105 if (Universe::heap()->is_in_reserved_or_null(*bottom)) {
106 f->do_oop(bottom);
107 } else {
108 if (VTBuffer::is_in_vt_buffer(*bottom)) {
109 if(dealiaser == NULL) {
110 dealiaser = Thread::current()->buffered_values_dealiaser();
111 }
112 dealiaser->oops_do(f, *bottom);
113 }
114 }
115 bottom++;
116 }
117 return handles_visited;
118 }
119
120 // Used for debugging handle allocation.
121 NOT_PRODUCT(jint _nof_handlemarks = 0;)
122
123 void HandleArea::oops_do(OopClosure* f) {
124 uintx handles_visited = 0;
125 // First handle the current chunk. It is filled to the high water mark.
126 handles_visited += chunk_oops_do(f, _chunk, _hwm);
127 // Then handle all previous chunks. They are completely filled.
128 Chunk* k = _first;
129 while(k != _chunk) {
130 handles_visited += chunk_oops_do(f, k, k->top());
131 k = k->next();
132 }
133
|