src/hotspot/share/code/stubs.cpp
author simonis
Mon, 04 Sep 2017 19:50:01 +0200
changeset 47688 3d1e3786d66e
parent 47216 71c04702a3d5
child 48097 8707ca0f414a
permissions -rw-r--r--
8166317: InterpreterCodeSize should be computed Reviewed-by: kvn, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents: 33105
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5403
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5403
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5403
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    26
#include "code/codeBlob.hpp"
47688
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
    27
#include "code/codeCache.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    28
#include "code/stubs.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    29
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    30
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6418
diff changeset
    31
#include "runtime/mutexLocker.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46620
diff changeset
    32
#include "utilities/align.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Implementation of StubQueue
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Standard wrap-around queue implementation; the queue dimensions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// are specified by the _queue_begin & _queue_end indices. The queue
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// can be in two states (transparent to the outside):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// a) contiguous state: all queue entries in one block (or empty)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// Queue: |...|XXXXXXX|...............|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//        ^0  ^begin  ^end            ^size = limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//            |_______|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//            one block
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// b) non-contiguous state: queue entries in two blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// Queue: |XXX|.......|XXXXXXX|.......|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//        ^0  ^end    ^begin  ^limit  ^size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
//        |___|       |_______|
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//         1st block  2nd block
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
// In the non-contiguous state, the wrap-around point is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
// indicated via the _buffer_limit index since the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// queue entry may not fill up the queue completely in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// which case we need to know where the 2nd block's end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
// is to do the proper wrap-around. When removing the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// last entry of the 2nd block, _buffer_limit is reset
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// to _buffer_size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// CAUTION: DO NOT MESS WITH THIS CODE IF YOU CANNOT PROVE
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
// ITS CORRECTNESS! THIS CODE IS MORE SUBTLE THAN IT LOOKS!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
StubQueue::StubQueue(StubInterface* stub_interface, int buffer_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                     Mutex* lock, const char* name) : _mutex(lock) {
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 42664
diff changeset
    69
  intptr_t size = align_up(buffer_size, 2*BytesPerWord);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  BufferBlob* blob = BufferBlob::create(name, size);
5403
6b0dd9c75dde 6888954: argument formatting for assert() and friends
jcoomes
parents: 1
diff changeset
    71
  if( blob == NULL) {
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31620
diff changeset
    72
    vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "CodeCache: no room for %s", name);
5403
6b0dd9c75dde 6888954: argument formatting for assert() and friends
jcoomes
parents: 1
diff changeset
    73
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  _stub_interface  = stub_interface;
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5547
diff changeset
    75
  _buffer_size     = blob->content_size();
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5547
diff changeset
    76
  _buffer_limit    = blob->content_size();
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5547
diff changeset
    77
  _stub_buffer     = blob->content_begin();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  _queue_begin     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  _queue_end       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _number_of_stubs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  register_queue(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
StubQueue::~StubQueue() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  // Note: Currently StubQueues are never destroyed so nothing needs to be done here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  //       If we want to implement the destructor, we need to release the BufferBlob
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  //       allocated in the constructor (i.e., we need to keep it around or look it
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  //       up via CodeCache::find_blob(...).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  Unimplemented();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
47688
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
    93
void StubQueue::deallocate_unused_tail() {
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
    94
  CodeBlob* blob = CodeCache::find_blob((void*)_stub_buffer);
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
    95
  CodeCache::free_unused_tail(blob, used_space());
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
    96
  // Update the limits to the new, trimmed CodeBlob size
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
    97
  _buffer_size = blob->content_size();
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
    98
  _buffer_limit = blob->content_size();
3d1e3786d66e 8166317: InterpreterCodeSize should be computed
simonis
parents: 47216
diff changeset
    99
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
Stub* StubQueue::stub_containing(address pc) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  if (contains(pc)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    for (Stub* s = first(); s != NULL; s = next(s)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      if (stub_contains(s, pc)) return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
Stub* StubQueue::request_committed(int code_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  Stub* s = request(code_size);
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 13963
diff changeset
   113
  CodeStrings strings;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 13963
diff changeset
   114
  if (s != NULL) commit(code_size, strings);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
Stub* StubQueue::request(int requested_code_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  assert(requested_code_size > 0, "requested_code_size must be > 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  if (_mutex != NULL) _mutex->lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  Stub* s = current_stub();
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 42664
diff changeset
   123
  int requested_size = align_up(stub_code_size_to_size(requested_code_size), CodeEntryAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  if (requested_size <= available_space()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    if (is_contiguous()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      // Queue: |...|XXXXXXX|.............|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      //        ^0  ^begin  ^end          ^size = limit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      assert(_buffer_limit == _buffer_size, "buffer must be fully usable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      if (_queue_end + requested_size <= _buffer_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
        // code fits in at the end => nothing to do
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 13963
diff changeset
   131
        CodeStrings strings;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 13963
diff changeset
   132
        stub_initialize(s, requested_size, strings);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        // stub doesn't fit in at the queue end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
        // => reduce buffer limit & wrap around
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
        assert(!is_empty(), "just checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
        _buffer_limit = _queue_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        _queue_end = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (requested_size <= available_space()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    assert(!is_contiguous(), "just checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    assert(_buffer_limit <= _buffer_size, "queue invariant broken");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    // Queue: |XXX|.......|XXXXXXX|.......|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    //        ^0  ^end    ^begin  ^limit  ^size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    s = current_stub();
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 13963
diff changeset
   149
    CodeStrings strings;
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 13963
diff changeset
   150
    stub_initialize(s, requested_size, strings);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    return s;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Not enough space left
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  if (_mutex != NULL) _mutex->unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 13963
diff changeset
   159
void StubQueue::commit(int committed_code_size, CodeStrings& strings) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  assert(committed_code_size > 0, "committed_code_size must be > 0");
46620
750c6edff33b 8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents: 42664
diff changeset
   161
  int committed_size = align_up(stub_code_size_to_size(committed_code_size), CodeEntryAlignment);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  Stub* s = current_stub();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  assert(committed_size <= stub_size(s), "committed size must not exceed requested size");
16368
713209c45a82 8008555: Debugging code in compiled method sometimes leaks memory
roland
parents: 13963
diff changeset
   164
  stub_initialize(s, committed_size, strings);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  _queue_end += committed_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  _number_of_stubs++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  if (_mutex != NULL) _mutex->unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  debug_only(stub_verify(s);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
void StubQueue::remove_first() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  if (number_of_stubs() == 0) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  Stub* s = first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  debug_only(stub_verify(s);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  stub_finalize(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  _queue_begin += stub_size(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  assert(_queue_begin <= _buffer_limit, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  if (_queue_begin == _queue_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    // buffer empty
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    // => reset queue indices
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    _queue_begin  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    _queue_end    = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    _buffer_limit = _buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  } else if (_queue_begin == _buffer_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    // buffer limit reached
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    // => reset buffer limit & wrap around
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    _buffer_limit = _buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    _queue_begin = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  _number_of_stubs--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
void StubQueue::remove_first(int n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  int i = MIN2(n, number_of_stubs());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  while (i-- > 0) remove_first();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
void StubQueue::remove_all(){
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  debug_only(verify();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  remove_first(number_of_stubs());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  assert(number_of_stubs() == 0, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
enum { StubQueueLimit = 10 };  // there are only a few in the world
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
static StubQueue* registered_stub_queues[StubQueueLimit];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
void StubQueue::register_queue(StubQueue* sq) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  for (int i = 0; i < StubQueueLimit; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    if (registered_stub_queues[i] == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      registered_stub_queues[i] = sq;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
void StubQueue::queues_do(void f(StubQueue* sq)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  for (int i = 0; i < StubQueueLimit; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    if (registered_stub_queues[i] != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      f(registered_stub_queues[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
void StubQueue::stubs_do(void f(Stub* s)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  debug_only(verify();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  MutexLockerEx lock(_mutex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  for (Stub* s = first(); s != NULL; s = next(s)) f(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
void StubQueue::verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // verify only if initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  if (_stub_buffer == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  MutexLockerEx lock(_mutex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  // verify index boundaries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  guarantee(0 <= _buffer_size, "buffer size must be positive");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  guarantee(0 <= _buffer_limit && _buffer_limit <= _buffer_size , "_buffer_limit out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  guarantee(0 <= _queue_begin  && _queue_begin  <  _buffer_limit, "_queue_begin out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  guarantee(0 <= _queue_end    && _queue_end    <= _buffer_limit, "_queue_end   out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // verify alignment
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  guarantee(_buffer_size  % CodeEntryAlignment == 0, "_buffer_size  not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  guarantee(_buffer_limit % CodeEntryAlignment == 0, "_buffer_limit not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  guarantee(_queue_begin  % CodeEntryAlignment == 0, "_queue_begin  not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  guarantee(_queue_end    % CodeEntryAlignment == 0, "_queue_end    not aligned");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // verify buffer limit/size relationship
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  if (is_contiguous()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    guarantee(_buffer_limit == _buffer_size, "_buffer_limit must equal _buffer_size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // verify contents
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  int n = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  for (Stub* s = first(); s != NULL; s = next(s)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    stub_verify(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    n++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  guarantee(n == number_of_stubs(), "number of stubs inconsistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  guarantee(_queue_begin != _queue_end || n == 0, "buffer indices must be the same");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
void StubQueue::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  MutexLockerEx lock(_mutex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  for (Stub* s = first(); s != NULL; s = next(s)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    stub_print(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
}
31620
53be635ad49c 8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents: 22234
diff changeset
   273