annotate src/share/vm/runtime/handles.cpp @ 61:5a76ab815e34

6667833: Remove CacheTimeMillis Summary: Remove -XX:+CacheTimeMillis option and associated functionality Reviewed-by: acorn, never
author sbohne
date Wed, 19 Mar 2008 09:58:01 -0400
parents
children c18cbe5936b8
rev   line source
duke@0 1 /*
duke@0 2 * Copyright 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
duke@0 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@0 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@0 21 * have any questions.
duke@0 22 *
duke@0 23 */
duke@0 24
duke@0 25 # include "incls/_precompiled.incl"
duke@0 26 # include "incls/_handles.cpp.incl"
duke@0 27
duke@0 28 #ifdef ASSERT
duke@0 29 oop* HandleArea::allocate_handle(oop obj) {
duke@0 30 assert(_handle_mark_nesting > 1, "memory leak: allocating handle outside HandleMark");
duke@0 31 assert(_no_handle_mark_nesting == 0, "allocating handle inside NoHandleMark");
duke@0 32 assert(SharedSkipVerify || obj->is_oop(), "sanity check");
duke@0 33 return real_allocate_handle(obj);
duke@0 34 }
duke@0 35
duke@0 36 Handle::Handle(Thread* thread, oop obj) {
duke@0 37 assert(thread == Thread::current(), "sanity check");
duke@0 38 if (obj == NULL) {
duke@0 39 _handle = NULL;
duke@0 40 } else {
duke@0 41 _handle = thread->handle_area()->allocate_handle(obj);
duke@0 42 }
duke@0 43 }
duke@0 44
duke@0 45 #endif
duke@0 46
duke@0 47 static uintx chunk_oops_do(OopClosure* f, Chunk* chunk, char* chunk_top) {
duke@0 48 oop* bottom = (oop*) chunk->bottom();
duke@0 49 oop* top = (oop*) chunk_top;
duke@0 50 uintx handles_visited = top - bottom;
duke@0 51 assert(top >= bottom && top <= (oop*) chunk->top(), "just checking");
duke@0 52 // during GC phase 3, a handle may be a forward pointer that
duke@0 53 // is not yet valid, so loosen the assertion
duke@0 54 while (bottom < top) {
duke@0 55 // assert((*bottom)->is_oop(), "handle should point to oop");
duke@0 56 assert(Universe::heap()->is_in(*bottom), "handle should be valid heap address");
duke@0 57 f->do_oop(bottom++);
duke@0 58 }
duke@0 59 return handles_visited;
duke@0 60 }
duke@0 61
duke@0 62 // Used for debugging handle allocation.
duke@0 63 NOT_PRODUCT(jint _nof_handlemarks = 0;)
duke@0 64
duke@0 65 void HandleArea::oops_do(OopClosure* f) {
duke@0 66 uintx handles_visited = 0;
duke@0 67 // First handle the current chunk. It is filled to the high water mark.
duke@0 68 handles_visited += chunk_oops_do(f, _chunk, _hwm);
duke@0 69 // Then handle all previous chunks. They are completely filled.
duke@0 70 Chunk* k = _first;
duke@0 71 while(k != _chunk) {
duke@0 72 handles_visited += chunk_oops_do(f, k, k->top());
duke@0 73 k = k->next();
duke@0 74 }
duke@0 75
duke@0 76 // The thread local handle areas should not get very large
duke@0 77 if (TraceHandleAllocation && handles_visited > TotalHandleAllocationLimit) {
duke@0 78 #ifdef ASSERT
duke@0 79 warning("%d: Visited in HandleMark : %d",
duke@0 80 _nof_handlemarks, handles_visited);
duke@0 81 #else
duke@0 82 warning("Visited in HandleMark : %d", handles_visited);
duke@0 83 #endif
duke@0 84 }
duke@0 85 if (_prev != NULL) _prev->oops_do(f);
duke@0 86 }
duke@0 87
duke@0 88 void HandleMark::initialize(Thread* thread) {
duke@0 89 _thread = thread;
duke@0 90 // Save area
duke@0 91 _area = thread->handle_area();
duke@0 92 // Save current top
duke@0 93 _chunk = _area->_chunk;
duke@0 94 _hwm = _area->_hwm;
duke@0 95 _max = _area->_max;
duke@0 96 NOT_PRODUCT(_size_in_bytes = _area->_size_in_bytes;)
duke@0 97 debug_only(_area->_handle_mark_nesting++);
duke@0 98 assert(_area->_handle_mark_nesting > 0, "must stack allocate HandleMarks");
duke@0 99 debug_only(Atomic::inc(&_nof_handlemarks);)
duke@0 100
duke@0 101 // Link this in the thread
duke@0 102 set_previous_handle_mark(thread->last_handle_mark());
duke@0 103 thread->set_last_handle_mark(this);
duke@0 104 }
duke@0 105
duke@0 106
duke@0 107 HandleMark::~HandleMark() {
duke@0 108 HandleArea* area = _area; // help compilers with poor alias analysis
duke@0 109 assert(area == _thread->handle_area(), "sanity check");
duke@0 110 assert(area->_handle_mark_nesting > 0, "must stack allocate HandleMarks" );
duke@0 111 debug_only(area->_handle_mark_nesting--);
duke@0 112
duke@0 113 // Debug code to trace the number of handles allocated per mark/
duke@0 114 #ifdef ASSERT
duke@0 115 if (TraceHandleAllocation) {
duke@0 116 size_t handles = 0;
duke@0 117 Chunk *c = _chunk->next();
duke@0 118 if (c == NULL) {
duke@0 119 handles = area->_hwm - _hwm; // no new chunk allocated
duke@0 120 } else {
duke@0 121 handles = _max - _hwm; // add rest in first chunk
duke@0 122 while(c != NULL) {
duke@0 123 handles += c->length();
duke@0 124 c = c->next();
duke@0 125 }
duke@0 126 handles -= area->_max - area->_hwm; // adjust for last trunk not full
duke@0 127 }
duke@0 128 handles /= sizeof(void *); // Adjust for size of a handle
duke@0 129 if (handles > HandleAllocationLimit) {
duke@0 130 // Note: _nof_handlemarks is only set in debug mode
duke@0 131 warning("%d: Allocated in HandleMark : %d", _nof_handlemarks, handles);
duke@0 132 }
duke@0 133 }
duke@0 134 #endif
duke@0 135
duke@0 136 // Delete later chunks
duke@0 137 if( _chunk->next() ) {
duke@0 138 _chunk->next_chop();
duke@0 139 }
duke@0 140 // Roll back arena to saved top markers
duke@0 141 area->_chunk = _chunk;
duke@0 142 area->_hwm = _hwm;
duke@0 143 area->_max = _max;
duke@0 144 NOT_PRODUCT(area->set_size_in_bytes(_size_in_bytes);)
duke@0 145 #ifdef ASSERT
duke@0 146 // clear out first chunk (to detect allocation bugs)
duke@0 147 if (ZapVMHandleArea) {
duke@0 148 memset(_hwm, badHandleValue, _max - _hwm);
duke@0 149 }
duke@0 150 Atomic::dec(&_nof_handlemarks);
duke@0 151 #endif
duke@0 152
duke@0 153 // Unlink this from the thread
duke@0 154 _thread->set_last_handle_mark(previous_handle_mark());
duke@0 155 }
duke@0 156
duke@0 157 #ifdef ASSERT
duke@0 158
duke@0 159 NoHandleMark::NoHandleMark() {
duke@0 160 HandleArea* area = Thread::current()->handle_area();
duke@0 161 area->_no_handle_mark_nesting++;
duke@0 162 assert(area->_no_handle_mark_nesting > 0, "must stack allocate NoHandleMark" );
duke@0 163 }
duke@0 164
duke@0 165
duke@0 166 NoHandleMark::~NoHandleMark() {
duke@0 167 HandleArea* area = Thread::current()->handle_area();
duke@0 168 assert(area->_no_handle_mark_nesting > 0, "must stack allocate NoHandleMark" );
duke@0 169 area->_no_handle_mark_nesting--;
duke@0 170 }
duke@0 171
duke@0 172
duke@0 173 ResetNoHandleMark::ResetNoHandleMark() {
duke@0 174 HandleArea* area = Thread::current()->handle_area();
duke@0 175 _no_handle_mark_nesting = area->_no_handle_mark_nesting;
duke@0 176 area->_no_handle_mark_nesting = 0;
duke@0 177 }
duke@0 178
duke@0 179
duke@0 180 ResetNoHandleMark::~ResetNoHandleMark() {
duke@0 181 HandleArea* area = Thread::current()->handle_area();
duke@0 182 area->_no_handle_mark_nesting = _no_handle_mark_nesting;
duke@0 183 }
duke@0 184
duke@0 185 #endif