stubs.cpp revision 1879
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "code/codeBlob.hpp"
#include "memory/allocation.inline.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/mutexLocker.hpp"
// Implementation of StubQueue
//
// Standard wrap-around queue implementation; the queue dimensions
// are specified by the _queue_begin & _queue_end indices. The queue
// can be in two states (transparent to the outside):
//
// a) contiguous state: all queue entries in one block (or empty)
//
// Queue: |...|XXXXXXX|...............|
// ^0 ^begin ^end ^size = limit
// |_______|
// one block
//
// b) non-contiguous state: queue entries in two blocks
//
// Queue: |XXX|.......|XXXXXXX|.......|
// ^0 ^end ^begin ^limit ^size
// |___| |_______|
// 1st block 2nd block
//
// In the non-contiguous state, the wrap-around point is
// indicated via the _buffer_limit index since the last
// queue entry may not fill up the queue completely in
// which case we need to know where the 2nd block's end
// is to do the proper wrap-around. When removing the
// last entry of the 2nd block, _buffer_limit is reset
// to _buffer_size.
//
// CAUTION: DO NOT MESS WITH THIS CODE IF YOU CANNOT PROVE
// ITS CORRECTNESS! THIS CODE IS MORE SUBTLE THAN IT LOOKS!
}
_queue_begin = 0;
_queue_end = 0;
_number_of_stubs = 0;
register_queue(this);
}
// Note: Currently StubQueues are never destroyed so nothing needs to be done here.
// If we want to implement the destructor, we need to release the BufferBlob
// allocated in the constructor (i.e., we need to keep it around or look it
// up via CodeCache::find_blob(...).
}
if (stub_contains(s, pc)) return s;
}
}
return NULL;
}
return s;
}
Stub* s = current_stub();
if (requested_size <= available_space()) {
if (is_contiguous()) {
// Queue: |...|XXXXXXX|.............|
// ^0 ^begin ^end ^size = limit
// code fits in at the end => nothing to do
return s;
} else {
// stub doesn't fit in at the queue end
// => reduce buffer limit & wrap around
_queue_end = 0;
}
}
}
if (requested_size <= available_space()) {
// Queue: |XXX|.......|XXXXXXX|.......|
// ^0 ^end ^begin ^limit ^size
s = current_stub();
return s;
}
// Not enough space left
return NULL;
}
Stub* s = current_stub();
debug_only(stub_verify(s);)
}
void StubQueue::remove_first() {
if (number_of_stubs() == 0) return;
debug_only(stub_verify(s);)
stub_finalize(s);
_queue_begin += stub_size(s);
if (_queue_begin == _queue_end) {
// buffer empty
// => reset queue indices
_queue_begin = 0;
_queue_end = 0;
} else if (_queue_begin == _buffer_limit) {
// buffer limit reached
// => reset buffer limit & wrap around
_queue_begin = 0;
}
}
void StubQueue::remove_first(int n) {
int i = MIN2(n, number_of_stubs());
while (i-- > 0) remove_first();
}
void StubQueue::remove_all(){
debug_only(verify();)
}
for (int i = 0; i < StubQueueLimit; i++) {
if (registered_stub_queues[i] == NULL) {
registered_stub_queues[i] = sq;
return;
}
}
}
for (int i = 0; i < StubQueueLimit; i++) {
if (registered_stub_queues[i] != NULL) {
f(registered_stub_queues[i]);
}
}
}
debug_only(verify();)
}
// verify only if initialized
if (_stub_buffer == NULL) return;
// verify index boundaries
// verify alignment
if (is_contiguous()) {
}
// verify contents
int n = 0;
stub_verify(s);
n++;
}
}
stub_print(s);
}
}