hotspot/src/share/vm/code/relocInfo.cpp
author twisti
Thu, 20 May 2010 06:34:23 -0700
changeset 5686 5435e77aa3df
parent 1 489c9b5090e2
child 5702 201c5cde25bb
permissions -rw-r--r--
6951083: oops and relocations should part of nmethod not CodeBlob Summary: This moves the oops from Codeblob to nmethod. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
     2
 * Copyright 1997-2010 Sun Microsystems, Inc.  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
 *
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/_relocInfo.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
const RelocationHolder RelocationHolder::none; // its type is relocInfo::none
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Implementation of relocInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
relocInfo::relocInfo(relocType t, int off, int f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  assert(t != data_prefix_tag, "cannot build a prefix this way");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  assert((t & type_mask) == t, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert((f & format_mask) == f, "wrong format");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  assert(off >= 0 && off < offset_limit(), "offset out off bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  assert((off & (offset_unit-1)) == 0, "misaligned offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  (*this) = relocInfo(t, RAW_BITS, off, f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
void relocInfo::initialize(CodeSection* dest, Relocation* reloc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  relocInfo* data = this+1;  // here's where the data might go
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  dest->set_locs_end(data);  // sync end: the next call may read dest.locs_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  reloc->pack_data_to(dest); // maybe write data into locs, advancing locs_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  relocInfo* data_limit = dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  if (data_limit > data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    relocInfo suffix = (*this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    data_limit = this->finish_prefix((short*) data_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    // Finish up with the suffix.  (Hack note: pack_data_to might edit this.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    *data_limit = suffix;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    dest->set_locs_end(data_limit+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
relocInfo* relocInfo::finish_prefix(short* prefix_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  assert(sizeof(relocInfo) == sizeof(short), "change this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  short* p = (short*)(this+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  assert(prefix_limit >= p, "must be a valid span of data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  int plen = prefix_limit - p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  if (plen == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    debug_only(_value = 0xFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    return this;                         // no data: remove self completely
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  if (plen == 1 && fits_into_immediate(p[0])) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    (*this) = immediate_relocInfo(p[0]); // move data inside self
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    return this+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // cannot compact, so just update the count and return the limit pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  (*this) = prefix_relocInfo(plen);   // write new datalen
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  assert(data() + datalen() == prefix_limit, "pointers must line up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  return (relocInfo*)prefix_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
void relocInfo::set_type(relocType t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  int old_offset = addr_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  int old_format = format();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  (*this) = relocInfo(t, old_offset, old_format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  assert(type()==(int)t, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  assert(addr_offset()==old_offset, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  assert(format()==old_format, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
void relocInfo::set_format(int f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  int old_offset = addr_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  assert((f & format_mask) == f, "wrong format");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _value = (_value & ~(format_mask << offset_width)) | (f << offset_width);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  assert(addr_offset()==old_offset, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
void relocInfo::change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  bool found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  while (itr->next() && !found) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    if (itr->addr() == pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      assert(itr->type()==old_type, "wrong relocInfo type found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      itr->current()->set_type(new_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      found=true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  assert(found, "no relocInfo found for pc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
void relocInfo::remove_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  change_reloc_info_for_address(itr, pc, old_type, none);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// ----------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// Implementation of RelocIterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   118
void RelocIterator::initialize(nmethod* nm, address begin, address limit) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  initialize_misc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   121
  if (nm == NULL && begin != NULL) {
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   122
    // allow nmethod to be deduced from beginning address
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   123
    CodeBlob* cb = CodeCache::find_blob(begin);
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   124
    nm = cb->as_nmethod_or_null();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   126
  assert(nm != NULL, "must be able to deduce nmethod from other arguments");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   128
  _code    = nm;
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   129
  _current = nm->relocation_begin() - 1;
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   130
  _end     = nm->relocation_end();
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   131
  _addr    = (address) nm->instructions_begin();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert(!has_current(), "just checking");
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   134
  address code_end = nm->instructions_end();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   136
  assert(begin == NULL || begin >= nm->instructions_begin(), "in bounds");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
 // FIX THIS  assert(limit == NULL || limit <= code_end,     "in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  set_limits(begin, limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
RelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  initialize_misc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  _current = cs->locs_start()-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  _end     = cs->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  _addr    = cs->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  _code    = NULL; // Not cb->blob();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  CodeBuffer* cb = cs->outer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  assert((int)SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  for (int n = 0; n < (int)SECT_LIMIT; n++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    _section_start[n] = cb->code_section(n)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  assert(!has_current(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  assert(begin == NULL || begin >= cs->start(), "in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  assert(limit == NULL || limit <= cs->end(),   "in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  set_limits(begin, limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
enum { indexCardSize = 128 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
struct RelocIndexEntry {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  jint addr_offset;          // offset from header_end of an addr()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  jint reloc_offset;         // offset from header_end of a relocInfo (prefix)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
static inline int num_cards(int code_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  return (code_size-1) / indexCardSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
int RelocIterator::locs_and_index_size(int code_size, int locs_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  if (!UseRelocIndex)  return locs_size;   // no index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  code_size = round_to(code_size, oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  locs_size = round_to(locs_size, oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  int index_size = num_cards(code_size) * sizeof(RelocIndexEntry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // format of indexed relocs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  //   relocation_begin:   relocInfo ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  //   index:              (addr,reloc#) ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  //                       indexSize           :relocation_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  return locs_size + index_size + BytesPerInt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
void RelocIterator::create_index(relocInfo* dest_begin, int dest_count, relocInfo* dest_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  address relocation_begin = (address)dest_begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  address relocation_end   = (address)dest_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  int     total_size       = relocation_end - relocation_begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  int     locs_size        = dest_count * sizeof(relocInfo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  if (!UseRelocIndex) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    Copy::fill_to_bytes(relocation_begin + locs_size, total_size-locs_size, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  int     index_size       = total_size - locs_size - BytesPerInt;      // find out how much space is left
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  int     ncards           = index_size / sizeof(RelocIndexEntry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  assert(total_size == locs_size + index_size + BytesPerInt, "checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  assert(index_size >= 0 && index_size % sizeof(RelocIndexEntry) == 0, "checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  jint*   index_size_addr  = (jint*)relocation_end - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  assert(sizeof(jint) == BytesPerInt, "change this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  *index_size_addr = index_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  if (index_size != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    assert(index_size > 0, "checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    RelocIndexEntry* index = (RelocIndexEntry *)(relocation_begin + locs_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    assert(index == (RelocIndexEntry*)index_size_addr - ncards, "checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    // walk over the relocations, and fill in index entries as we go
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    RelocIterator iter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    const address    initial_addr    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    relocInfo* const initial_current = dest_begin - 1;  // biased by -1 like elsewhere
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    iter._code    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    iter._addr    = initial_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    iter._limit   = (address)(intptr_t)(ncards * indexCardSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    iter._current = initial_current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    iter._end     = dest_begin + dest_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    address next_card_addr = (address)indexCardSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    int addr_offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    int reloc_offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      // Checkpoint the iterator before advancing it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
      addr_offset  = iter._addr    - initial_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
      reloc_offset = iter._current - initial_current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      if (!iter.next())  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      while (iter.addr() >= next_card_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
        index[i].addr_offset  = addr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        index[i].reloc_offset = reloc_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
        next_card_addr += indexCardSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    while (i < ncards) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      index[i].addr_offset  = addr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      index[i].reloc_offset = reloc_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
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 RelocIterator::set_limits(address begin, address limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  int index_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  if (UseRelocIndex && _code != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    index_size = ((jint*)_end)[-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    _end = (relocInfo*)( (address)_end - index_size - BytesPerInt );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  _limit = limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  // the limit affects this next stuff:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if (begin != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    // In ASSERT mode we do not actually use the index, but simply
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    // check that its contents would have led us to the right answer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    address addrCheck = _addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    relocInfo* infoCheck = _current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    if (index_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      // skip ahead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      RelocIndexEntry* index       = (RelocIndexEntry*)_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      RelocIndexEntry* index_limit = (RelocIndexEntry*)((address)index + index_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      assert(_addr == _code->instructions_begin(), "_addr must be unadjusted");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      int card = (begin - _addr) / indexCardSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      if (card > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
        if (index+card-1 < index_limit)  index += card-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
        else                             index = index_limit - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
        addrCheck = _addr    + index->addr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
        infoCheck = _current + index->reloc_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
        // Advance the iterator immediately to the last valid state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
        // for the previous card.  Calling "next" will then advance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
        // it to the first item on the required card.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
        _addr    += index->addr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
        _current += index->reloc_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    relocInfo* backup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    address    backup_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      backup      = _current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      backup_addr = _addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      if (backup == infoCheck) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
        assert(backup_addr == addrCheck, "must match"); addrCheck = NULL; infoCheck = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
        assert(addrCheck == NULL || backup_addr <= addrCheck, "must not pass addrCheck");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
      if (!next() || addr() >= begin) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    assert(addrCheck == NULL || addrCheck == backup_addr, "must have matched addrCheck");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
    assert(infoCheck == NULL || infoCheck == backup,      "must have matched infoCheck");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
    // At this point, either we are at the first matching record,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    // or else there is no such record, and !has_current().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    // In either case, revert to the immediatly preceding state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    _current = backup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    _addr    = backup_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    set_has_current(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
void RelocIterator::set_limit(address limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  address code_end = (address)code() + code()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  assert(limit == NULL || limit <= code_end, "in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  _limit = limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
void PatchingRelocIterator:: prepass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  // turn breakpoints off during patching
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  _init_state = (*this);        // save cursor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  while (next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    if (type() == relocInfo::breakpoint_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      breakpoint_reloc()->set_active(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  (RelocIterator&)(*this) = _init_state;        // reset cursor for client
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
void PatchingRelocIterator:: postpass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  // turn breakpoints back on after patching
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  (RelocIterator&)(*this) = _init_state;        // reset cursor again
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  while (next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    if (type() == relocInfo::breakpoint_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
      breakpoint_Relocation* bpt = breakpoint_reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
      bpt->set_active(bpt->enabled());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
// All the strange bit-encodings are in here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
// The idea is to encode relocation data which are small integers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
// very efficiently (a single extra halfword).  Larger chunks of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
// relocation data need a halfword header to hold their size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
void RelocIterator::advance_over_prefix() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  if (_current->is_datalen()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    _data    = (short*) _current->data();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    _datalen =          _current->datalen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    _current += _datalen + 1;   // skip the embedded data & header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    _databuf = _current->immediate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    _data = &_databuf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    _datalen = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    _current++;                 // skip the header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  // The client will see the following relocInfo, whatever that is.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  // It is the reloc to which the preceding data applies.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
address RelocIterator::compute_section_start(int n) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
// This routine not only computes a section start, but also
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
// memoizes it for later.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
#define CACHE ((RelocIterator*)this)->_section_start[n]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  CodeBlob* cb = code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  guarantee(cb != NULL, "must have a code blob");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  if (n == CodeBuffer::SECT_INSTS)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
    return CACHE = cb->instructions_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  assert(cb->is_nmethod(), "only nmethods have these sections");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  nmethod* nm = (nmethod*) cb;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  address res = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  switch (n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  case CodeBuffer::SECT_STUBS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    res = nm->stub_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  case CodeBuffer::SECT_CONSTS:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    res = nm->consts_begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  assert(nm->contains(res) || res == nm->instructions_end(), "tame pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  CACHE = res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
#undef CACHE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
Relocation* RelocIterator::reloc() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  // (take the "switch" out-of-line)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  relocInfo::relocType t = type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  if (false) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  #define EACH_TYPE(name)                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  else if (t == relocInfo::name##_type) {             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    return name##_reloc();                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  APPLY_TO_RELOCATIONS(EACH_TYPE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  #undef EACH_TYPE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  assert(t == relocInfo::none, "must be padding");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  return new(_rh) Relocation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
//////// Methods for flyweight Relocation types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
RelocationHolder RelocationHolder::plus(int offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  if (offset != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
    switch (type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    case relocInfo::none:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
    case relocInfo::oop_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
        oop_Relocation* r = (oop_Relocation*)reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
        return oop_Relocation::spec(r->oop_index(), r->offset() + offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  return (*this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
void Relocation::guarantee_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  guarantee(false, "Make _relocbuf bigger!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    // some relocations can compute their own values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
address Relocation::value() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
void Relocation::set_value(address x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
RelocationHolder Relocation::spec_simple(relocInfo::relocType rtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  if (rtype == relocInfo::none)  return RelocationHolder::none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  relocInfo ri = relocInfo(rtype, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  RelocIterator itr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  itr.set_current(ri);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  itr.reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  return itr._rh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
static inline bool is_index(intptr_t index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  return 0 < index && index < os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
int32_t Relocation::runtime_address_to_index(address runtime_address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  assert(!is_index((intptr_t)runtime_address), "must not look like an index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  if (runtime_address == NULL)  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  StubCodeDesc* p = StubCodeDesc::desc_for(runtime_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  if (p != NULL && p->begin() == runtime_address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    assert(is_index(p->index()), "there must not be too many stubs");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    return (int32_t)p->index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    // Known "miscellaneous" non-stub pointers:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    // os::get_polling_page(), SafepointSynchronize::address_of_state()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    if (PrintRelocations) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
      tty->print_cr("random unregistered address in relocInfo: " INTPTR_FORMAT, runtime_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    return (int32_t) (intptr_t)runtime_address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    // didn't fit return non-index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
#endif /* _LP64 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
address Relocation::index_to_runtime_address(int32_t index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  if (index == 0)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  if (is_index(index)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    StubCodeDesc* p = StubCodeDesc::desc_for_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    assert(p != NULL, "there must be a stub for this index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
    return p->begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    // this only works on 32bit machines
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    return (address) ((intptr_t) index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    fatal("Relocation::index_to_runtime_address, int32_t not pointer sized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
#endif /* _LP64 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
address Relocation::old_addr_for(address newa,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
                                 const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  int sect = dest->section_index_of(newa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  address ostart = src->code_section(sect)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  address nstart = dest->code_section(sect)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  return ostart + (newa - nstart);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
address Relocation::new_addr_for(address olda,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
                                 const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  debug_only(const CodeBuffer* src0 = src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  int sect = CodeBuffer::SECT_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  // Look for olda in the source buffer, and all previous incarnations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  // if the source buffer has been expanded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  for (; src != NULL; src = src->before_expand()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    sect = src->section_index_of(olda);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    if (sect != CodeBuffer::SECT_NONE)  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  address ostart = src->code_section(sect)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  address nstart = dest->code_section(sect)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  return nstart + (olda - ostart);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
void Relocation::normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  address addr0 = addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  if (addr0 == NULL || dest->allocates2(addr0))  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  CodeBuffer* cb = dest->outer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  addr = new_addr_for(addr0, cb, cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  assert(allow_other_sections || dest->contains2(addr),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
         "addr must be in required section");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
void CallRelocation::set_destination(address x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  pd_set_call_destination(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
void CallRelocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // Usually a self-relative reference to an external routine.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  // On some platforms, the reference is absolute (not self-relative).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  // The enhanced use of pd_call_destination sorts this all out.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  address orig_addr = old_addr_for(addr(), src, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  address callee    = pd_call_destination(orig_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  // Reassert the callee address, this time in the new copy of the code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  pd_set_call_destination(callee);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
//// pack/unpack methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
void oop_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  short* p = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  p = pack_2_ints_to(p, _oop_index, _offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
void oop_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  unpack_2_ints(_oop_index, _offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
void virtual_call_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  short*  p     = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  address point =          dest->locs_point();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  // Try to make a pointer NULL first.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  if (_oop_limit >= point &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
      _oop_limit <= point + NativeCall::instruction_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    _oop_limit = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  // If the _oop_limit is NULL, it "defaults" to the end of the call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  // See ic_call_Relocation::oop_limit() below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  normalize_address(_first_oop, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  normalize_address(_oop_limit, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  jint x0 = scaled_offset_null_special(_first_oop, point);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  jint x1 = scaled_offset_null_special(_oop_limit, point);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  p = pack_2_ints_to(p, x0, x1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
void virtual_call_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  jint x0, x1; unpack_2_ints(x0, x1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  address point = addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  _first_oop = x0==0? NULL: address_from_scaled_offset(x0, point);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  _oop_limit = x1==0? NULL: address_from_scaled_offset(x1, point);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
void static_stub_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  short* p = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  CodeSection* insts = dest->outer()->insts();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  normalize_address(_static_call, insts);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  p = pack_1_int_to(p, scaled_offset(_static_call, insts->start()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
void static_stub_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  address base = binding()->section_start(CodeBuffer::SECT_INSTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  _static_call = address_from_scaled_offset(unpack_1_int(), base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
void external_word_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  short* p = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  int32_t index = runtime_address_to_index(_target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  p = pack_1_int_to(p, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  if (is_index(index)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    p = pack_2_ints_to(p, index, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    jlong t = (jlong) _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    int32_t lo = low(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
    int32_t hi = high(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    p = pack_2_ints_to(p, lo, hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
    DEBUG_ONLY(jlong t1 = jlong_from(hi, lo));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
    assert(!is_index(t1) && (address) t1 == _target, "not symmetric");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
#endif /* _LP64 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
void external_word_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  _target = index_to_runtime_address(unpack_1_int());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  int32_t lo, hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  unpack_2_ints(lo, hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  jlong t = jlong_from(hi, lo);;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  if (is_index(t)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    _target = index_to_runtime_address(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
    _target = (address) t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
#endif /* _LP64 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
void internal_word_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
  short* p = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  normalize_address(_target, dest, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  // Check whether my target address is valid within this section.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  // If not, strengthen the relocation type to point to another section.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  int sindex = _section;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  if (sindex == CodeBuffer::SECT_NONE && _target != NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
      && (!dest->allocates(_target) || _target == dest->locs_point())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    sindex = dest->outer()->section_index_of(_target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    relocInfo* base = dest->locs_end() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    assert(base->type() == this->type(), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    // Change the written type, to be section_word_type instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    base->set_type(relocInfo::section_word_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  // Note: An internal_word relocation cannot refer to its own instruction,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  // because we reserve "0" to mean that the pointer itself is embedded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  // in the code stream.  We use a section_word relocation for such cases.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  if (sindex == CodeBuffer::SECT_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    assert(type() == relocInfo::internal_word_type, "must be base class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
    guarantee(_target == NULL || dest->allocates2(_target), "must be within the given code section");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    jint x0 = scaled_offset_null_special(_target, dest->locs_point());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    assert(!(x0 == 0 && _target != NULL), "correct encoding of null target");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    p = pack_1_int_to(p, x0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    assert(_target != NULL, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    CodeSection* sect = dest->outer()->code_section(sindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    guarantee(sect->allocates2(_target), "must be in correct section");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    address base = sect->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
    jint offset = scaled_offset(_target, base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
    assert((uint)sindex < (uint)CodeBuffer::SECT_LIMIT, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    assert(CodeBuffer::SECT_LIMIT <= (1 << section_width), "section_width++");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
    p = pack_1_int_to(p, (offset << section_width) | sindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
void internal_word_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  jint x0 = unpack_1_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  _target = x0==0? NULL: address_from_scaled_offset(x0, addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  _section = CodeBuffer::SECT_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
void section_word_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  jint    x      = unpack_1_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  jint    offset = (x >> section_width);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  int     sindex = (x & ((1<<section_width)-1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  address base   = binding()->section_start(sindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  _section = sindex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
  _target  = address_from_scaled_offset(offset, base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
void breakpoint_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  short* p = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  address point = dest->locs_point();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  *p++ = _bits;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  assert(_target != NULL, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  if (internal())  normalize_address(_target, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  jint target_bits =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
    (jint)( internal() ? scaled_offset           (_target, point)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
                       : runtime_address_to_index(_target) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  if (settable()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
    // save space for set_target later
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
    p = add_jint(p, target_bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
    p = add_var_int(p, target_bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  for (int i = 0; i < instrlen(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
    // put placeholder words until bytes can be saved
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
    p = add_short(p, (short)0x7777);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
void breakpoint_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
  _bits = live_bits();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  int targetlen = datalen() - 1 - instrlen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  jint target_bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  if (targetlen == 0)       target_bits = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
  else if (targetlen == 1)  target_bits = *(data()+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  else if (targetlen == 2)  target_bits = relocInfo::jint_from_data(data()+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  else                      { ShouldNotReachHere(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
  _target = internal() ? address_from_scaled_offset(target_bits, addr())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
                       : index_to_runtime_address  (target_bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
//// miscellaneous methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
oop* oop_Relocation::oop_addr() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  int n = _oop_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  if (n == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
    // oop is stored in the code stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
    return (oop*) pd_address_in_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
  } else {
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   758
    // oop is stored in table at nmethod::oops_begin
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
    return code()->oop_addr_at(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
oop oop_Relocation::oop_value() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
  oop v = *oop_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  // clean inline caches store a special pseudo-null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
  if (v == (oop)Universe::non_oop_word())  v = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  return v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
void oop_Relocation::fix_oop_relocation() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  if (!oop_is_immediate()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    // get the oop from the pool, and re-insert it into the instruction:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    set_value(value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   780
RelocIterator virtual_call_Relocation::parse_ic(nmethod* &nm, address &ic_call, address &first_oop,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
                                                oop* &oop_addr, bool *is_optimized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  assert(ic_call != NULL, "ic_call address must be set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  assert(ic_call != NULL || first_oop != NULL, "must supply a non-null input");
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   784
  if (nm == NULL) {
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   785
    CodeBlob* code;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    if (ic_call != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
      code = CodeCache::find_blob(ic_call);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
    } else if (first_oop != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
      code = CodeCache::find_blob(first_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
    }
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   791
    nm = code->as_nmethod_or_null();
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   792
    assert(nm != NULL, "address to parse must be in nmethod");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  }
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   794
  assert(ic_call   == NULL || nm->contains(ic_call),   "must be in nmethod");
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   795
  assert(first_oop == NULL || nm->contains(first_oop), "must be in nmethod");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
  address oop_limit = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  if (ic_call != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    // search for the ic_call at the given address
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   801
    RelocIterator iter(nm, ic_call, ic_call+1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
    bool ret = iter.next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
    assert(ret == true, "relocInfo must exist at this address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
    assert(iter.addr() == ic_call, "must find ic_call");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
    if (iter.type() == relocInfo::virtual_call_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
      virtual_call_Relocation* r = iter.virtual_call_reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
      first_oop = r->first_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
      oop_limit = r->oop_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
      *is_optimized = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
      assert(iter.type() == relocInfo::opt_virtual_call_type, "must be a virtual call");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
      *is_optimized = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
      oop_addr = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
      first_oop = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
      return iter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  // search for the first_oop, to get its oop_addr
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   820
  RelocIterator all_oops(nm, first_oop);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  RelocIterator iter = all_oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  iter.set_limit(first_oop+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
  bool found_oop = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
  while (iter.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    if (iter.type() == relocInfo::oop_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
      assert(iter.addr() == first_oop, "must find first_oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
      oop_addr = iter.oop_reloc()->oop_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
      found_oop = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  assert(found_oop, "must find first_oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  bool did_reset = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
  while (ic_call == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
    // search forward for the ic_call matching the given first_oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
    while (iter.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
      if (iter.type() == relocInfo::virtual_call_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
        virtual_call_Relocation* r = iter.virtual_call_reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
        if (r->first_oop() == first_oop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
          ic_call   = r->addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
          oop_limit = r->oop_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    guarantee(!did_reset, "cannot find ic_call");
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   848
    iter = RelocIterator(nm); // search the whole nmethod
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
    did_reset = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  assert(oop_limit != NULL && first_oop != NULL && ic_call != NULL, "");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  all_oops.set_limit(oop_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  return all_oops;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
address virtual_call_Relocation::first_oop() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  assert(_first_oop != NULL && _first_oop < addr(), "must precede ic_call");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  return _first_oop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
address virtual_call_Relocation::oop_limit() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  if (_oop_limit == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
    return addr() + NativeCall::instruction_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
    return _oop_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
void virtual_call_Relocation::clear_inline_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  // No stubs for ICs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  // Clean IC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  CompiledIC* icache = CompiledIC_at(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  icache->set_to_clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
void opt_virtual_call_Relocation::clear_inline_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  // No stubs for ICs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  // Clean IC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  CompiledIC* icache = CompiledIC_at(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  icache->set_to_clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
address opt_virtual_call_Relocation::static_stub() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  // search for the static stub who points back to this static call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  address static_call_addr = addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  RelocIterator iter(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  while (iter.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
    if (iter.type() == relocInfo::static_stub_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
      if (iter.static_stub_reloc()->static_call() == static_call_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
        return iter.addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
void static_call_Relocation::clear_inline_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  // Safe call site info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  CompiledStaticCall* handler = compiledStaticCall_at(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  handler->set_to_clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
address static_call_Relocation::static_stub() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  // search for the static stub who points back to this static call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
  address static_call_addr = addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
  RelocIterator iter(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
  while (iter.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
    if (iter.type() == relocInfo::static_stub_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
      if (iter.static_stub_reloc()->static_call() == static_call_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
        return iter.addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
void static_stub_Relocation::clear_inline_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  // Call stub is only used when calling the interpreted code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
  // It does not really need to be cleared, except that we want to clean out the methodoop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  CompiledStaticCall::set_stub_to_clean(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
  address target = _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  if (target == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
    // An absolute embedded reference to an external location,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
    // which means there is nothing to fix here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  // Probably this reference is absolute, not relative, so the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  // following is probably a no-op.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
  assert(src->section_index_of(target) == CodeBuffer::SECT_NONE, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
  set_value(target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
address external_word_Relocation::target() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
  address target = _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
  if (target == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
    target = pd_get_address_from_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
  return target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  address target = _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  if (target == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
    if (addr_in_const()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
      target = new_addr_for(*(address*)addr(), src, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
      target = new_addr_for(pd_get_address_from_code(), src, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  set_value(target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
address internal_word_Relocation::target() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
  address target = _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  if (target == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    target = pd_get_address_from_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
  return target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
breakpoint_Relocation::breakpoint_Relocation(int kind, address target, bool internal) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  bool active    = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  bool enabled   = (kind == initialization);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  bool removable = (kind != safepoint);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  bool settable  = (target == NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
  int bits = kind;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
  if (enabled)    bits |= enabled_state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
  if (internal)   bits |= internal_attr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  if (removable)  bits |= removable_attr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
  if (settable)   bits |= settable_attr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  _bits = bits | high_bit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  _target = target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  assert(this->kind()      == kind,      "kind encoded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  assert(this->enabled()   == enabled,   "enabled encoded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  assert(this->active()    == active,    "active encoded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  assert(this->internal()  == internal,  "internal encoded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  assert(this->removable() == removable, "removable encoded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  assert(this->settable()  == settable,  "settable encoded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
address breakpoint_Relocation::target() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
  return _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
void breakpoint_Relocation::set_target(address x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
  assert(settable(), "must be settable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
  jint target_bits =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
    (jint)(internal() ? scaled_offset           (x, addr())
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
                      : runtime_address_to_index(x));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  short* p = &live_bits() + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
  p = add_jint(p, target_bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
  assert(p == instrs(), "new target must fit");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
  _target = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
void breakpoint_Relocation::set_enabled(bool b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  if (enabled() == b) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
  if (b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
    set_bits(bits() | enabled_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
    set_active(false);          // remove the actual breakpoint insn, if any
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    set_bits(bits() & ~enabled_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
void breakpoint_Relocation::set_active(bool b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
  assert(!b || enabled(), "cannot activate a disabled breakpoint");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  if (active() == b) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
  // %%% should probably seize a lock here (might not be the right lock)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  //MutexLockerEx ml_patch(Patching_lock, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
  //if (active() == b)  return;         // recheck state after locking
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
  if (b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
    set_bits(bits() | active_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
    if (instrlen() == 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
      fatal("breakpoints in original code must be undoable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
    pd_swap_in_breakpoint (addr(), instrs(), instrlen());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
    set_bits(bits() & ~active_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
    pd_swap_out_breakpoint(addr(), instrs(), instrlen());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
//---------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
// Non-product code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
static const char* reloc_type_string(relocInfo::relocType t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
  switch (t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
  #define EACH_CASE(name) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  case relocInfo::name##_type: \
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
    return #name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
  APPLY_TO_RELOCATIONS(EACH_CASE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
  #undef EACH_CASE
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
  case relocInfo::none:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
    return "none";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
  case relocInfo::data_prefix_tag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
    return "prefix";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
    return "UNKNOWN RELOC TYPE";
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
void RelocIterator::print_current() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  if (!has_current()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    tty->print_cr("(no relocs)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
  tty->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
             _current, type(), reloc_type_string((relocInfo::relocType) type()), _addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
  if (current()->format() != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
    tty->print(" format=%d", current()->format());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
  if (datalen() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
    tty->print(" data=%d", data()[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
  } else if (datalen() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
    tty->print(" data={");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
    for (int i = 0; i < datalen(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
      tty->print("%04x", data()[i] & 0xFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
    tty->print("}");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  tty->print("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
  switch (type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
  case relocInfo::oop_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
      oop_Relocation* r = oop_reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
      oop* oop_addr  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
      oop  raw_oop   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
      oop  oop_value = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
      if (code() != NULL || r->oop_is_immediate()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
        oop_addr  = r->oop_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
        raw_oop   = *oop_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
        oop_value = r->oop_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
      tty->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
                 oop_addr, (address)raw_oop, r->offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
      // Do not print the oop by default--we want this routine to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
      // work even during GC or other inconvenient times.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
      if (WizardMode && oop_value != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
        tty->print("oop_value=" INTPTR_FORMAT ": ", (address)oop_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
        oop_value->print_value_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
  case relocInfo::external_word_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
  case relocInfo::internal_word_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
  case relocInfo::section_word_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
      DataRelocation* r = (DataRelocation*) reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
      tty->print(" | [target=" INTPTR_FORMAT "]", r->value()); //value==target
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
  case relocInfo::static_call_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
  case relocInfo::runtime_call_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
      CallRelocation* r = (CallRelocation*) reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
      tty->print(" | [destination=" INTPTR_FORMAT "]", r->destination());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
  case relocInfo::virtual_call_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
      virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
      tty->print(" | [destination=" INTPTR_FORMAT " first_oop=" INTPTR_FORMAT " oop_limit=" INTPTR_FORMAT "]",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
                 r->destination(), r->first_oop(), r->oop_limit());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
  case relocInfo::static_stub_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
      static_stub_Relocation* r = (static_stub_Relocation*) reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
      tty->print(" | [static_call=" INTPTR_FORMAT "]", r->static_call());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
void RelocIterator::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
  RelocIterator save_this = (*this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
  relocInfo* scan = _current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
  if (!has_current())  scan += 1;  // nothing to scan here!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
  bool skip_next = has_current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
  bool got_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
  while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
    got_next = (skip_next || next());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
    skip_next = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
    tty->print("         @" INTPTR_FORMAT ": ", scan);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
    relocInfo* newscan = _current+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
    if (!has_current())  newscan -= 1;  // nothing to scan here!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
    while (scan < newscan) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
      tty->print("%04x", *(short*)scan & 0xFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
      scan++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
    if (!got_next)  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
    print_current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
  (*this) = save_this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
// For the debugger:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
extern "C"
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
  1181
void print_blob_locs(nmethod* nm) {
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
  1182
  nm->print();
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
  1183
  RelocIterator iter(nm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  iter.print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
extern "C"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
void print_buf_locs(CodeBuffer* cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  FlagSetting fs(PrintRelocations, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
  cb->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
#endif // !PRODUCT