hotspot/src/share/vm/code/stubs.cpp
author ant
Fri, 04 Dec 2009 15:07:15 +0300
changeset 4369 18b883ed2b58
parent 1 489c9b5090e2
child 5403 6b0dd9c75dde
permissions -rw-r--r--
6903354: deadlock involving Component.show & SunToolkit.getImageFromHash Reviewed-by: art, bae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_stubs.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Implementation of StubQueue
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Standard wrap-around queue implementation; the queue dimensions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// are specified by the _queue_begin & _queue_end indices. The queue
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// can be in two states (transparent to the outside):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// a) contiguous state: all queue entries in one block (or empty)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Queue: |...|XXXXXXX|...............|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//        ^0  ^begin  ^end            ^size = limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//            |_______|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//            one block
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// b) non-contiguous state: queue entries in two blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// Queue: |XXX|.......|XXXXXXX|.......|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//        ^0  ^end    ^begin  ^limit  ^size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//        |___|       |_______|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//         1st block  2nd block
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// In the non-contiguous state, the wrap-around point is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// indicated via the _buffer_limit index since the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// queue entry may not fill up the queue completely in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// which case we need to know where the 2nd block's end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// is to do the proper wrap-around. When removing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// last entry of the 2nd block, _buffer_limit is reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// to _buffer_size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// CAUTION: DO NOT MESS WITH THIS CODE IF YOU CANNOT PROVE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// ITS CORRECTNESS! THIS CODE IS MORE SUBTLE THAN IT LOOKS!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
StubQueue::StubQueue(StubInterface* stub_interface, int buffer_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
                     Mutex* lock, const char* name) : _mutex(lock) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  intptr_t size = round_to(buffer_size, 2*BytesPerWord);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  BufferBlob* blob = BufferBlob::create(name, size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  if( blob == NULL ) vm_exit_out_of_memory1(size, "CodeCache: no room for %s", name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  _stub_interface  = stub_interface;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  _buffer_size     = blob->instructions_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  _buffer_limit    = blob->instructions_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  _stub_buffer     = blob->instructions_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _queue_begin     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _queue_end       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _number_of_stubs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  register_queue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
StubQueue::~StubQueue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // Note: Currently StubQueues are never destroyed so nothing needs to be done here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  //       If we want to implement the destructor, we need to release the BufferBlob
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  //       allocated in the constructor (i.e., we need to keep it around or look it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  //       up via CodeCache::find_blob(...).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  Unimplemented();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
Stub* StubQueue::stub_containing(address pc) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  if (contains(pc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    for (Stub* s = first(); s != NULL; s = next(s)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      if (stub_contains(s, pc)) return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
Stub* StubQueue::request_committed(int code_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  Stub* s = request(code_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  if (s != NULL) commit(code_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
Stub* StubQueue::request(int requested_code_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  assert(requested_code_size > 0, "requested_code_size must be > 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  if (_mutex != NULL) _mutex->lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  Stub* s = current_stub();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  int requested_size = round_to(stub_code_size_to_size(requested_code_size), CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  if (requested_size <= available_space()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    if (is_contiguous()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      // Queue: |...|XXXXXXX|.............|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      //        ^0  ^begin  ^end          ^size = limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
      assert(_buffer_limit == _buffer_size, "buffer must be fully usable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      if (_queue_end + requested_size <= _buffer_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
        // code fits in at the end => nothing to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
        stub_initialize(s, requested_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
        return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
        // stub doesn't fit in at the queue end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        // => reduce buffer limit & wrap around
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        assert(!is_empty(), "just checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
        _buffer_limit = _queue_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
        _queue_end = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (requested_size <= available_space()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    assert(!is_contiguous(), "just checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    assert(_buffer_limit <= _buffer_size, "queue invariant broken");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    // Queue: |XXX|.......|XXXXXXX|.......|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    //        ^0  ^end    ^begin  ^limit  ^size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    s = current_stub();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    stub_initialize(s, requested_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // Not enough space left
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  if (_mutex != NULL) _mutex->unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
void StubQueue::commit(int committed_code_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  assert(committed_code_size > 0, "committed_code_size must be > 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  int committed_size = round_to(stub_code_size_to_size(committed_code_size), CodeEntryAlignment);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  Stub* s = current_stub();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  assert(committed_size <= stub_size(s), "committed size must not exceed requested size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  stub_initialize(s, committed_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  _queue_end += committed_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  _number_of_stubs++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  if (_mutex != NULL) _mutex->unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  debug_only(stub_verify(s);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
void StubQueue::remove_first() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  if (number_of_stubs() == 0) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  Stub* s = first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  debug_only(stub_verify(s);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  stub_finalize(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  _queue_begin += stub_size(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  assert(_queue_begin <= _buffer_limit, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  if (_queue_begin == _queue_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    // buffer empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    // => reset queue indices
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    _queue_begin  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    _queue_end    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    _buffer_limit = _buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  } else if (_queue_begin == _buffer_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    // buffer limit reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
    // => reset buffer limit & wrap around
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    _buffer_limit = _buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    _queue_begin = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  _number_of_stubs--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
void StubQueue::remove_first(int n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  int i = MIN2(n, number_of_stubs());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  while (i-- > 0) remove_first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
void StubQueue::remove_all(){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  debug_only(verify();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  remove_first(number_of_stubs());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  assert(number_of_stubs() == 0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
enum { StubQueueLimit = 10 };  // there are only a few in the world
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
static StubQueue* registered_stub_queues[StubQueueLimit];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
void StubQueue::register_queue(StubQueue* sq) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  for (int i = 0; i < StubQueueLimit; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    if (registered_stub_queues[i] == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
      registered_stub_queues[i] = sq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
void StubQueue::queues_do(void f(StubQueue* sq)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  for (int i = 0; i < StubQueueLimit; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    if (registered_stub_queues[i] != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
      f(registered_stub_queues[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
void StubQueue::stubs_do(void f(Stub* s)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  debug_only(verify();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  MutexLockerEx lock(_mutex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  for (Stub* s = first(); s != NULL; s = next(s)) f(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
void StubQueue::verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // verify only if initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  if (_stub_buffer == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  MutexLockerEx lock(_mutex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // verify index boundaries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  guarantee(0 <= _buffer_size, "buffer size must be positive");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  guarantee(0 <= _buffer_limit && _buffer_limit <= _buffer_size , "_buffer_limit out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  guarantee(0 <= _queue_begin  && _queue_begin  <  _buffer_limit, "_queue_begin out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  guarantee(0 <= _queue_end    && _queue_end    <= _buffer_limit, "_queue_end   out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // verify alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  guarantee(_buffer_size  % CodeEntryAlignment == 0, "_buffer_size  not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  guarantee(_buffer_limit % CodeEntryAlignment == 0, "_buffer_limit not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  guarantee(_queue_begin  % CodeEntryAlignment == 0, "_queue_begin  not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  guarantee(_queue_end    % CodeEntryAlignment == 0, "_queue_end    not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  // verify buffer limit/size relationship
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  if (is_contiguous()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    guarantee(_buffer_limit == _buffer_size, "_buffer_limit must equal _buffer_size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // verify contents
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  int n = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  for (Stub* s = first(); s != NULL; s = next(s)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    stub_verify(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    n++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  guarantee(n == number_of_stubs(), "number of stubs inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  guarantee(_queue_begin != _queue_end || n == 0, "buffer indices must be the same");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
void StubQueue::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  MutexLockerEx lock(_mutex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  for (Stub* s = first(); s != NULL; s = next(s)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    stub_print(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
}