hotspot/src/share/vm/code/relocInfo.cpp
author david
Fri, 09 Oct 2015 09:42:33 +0200
changeset 33148 68fa8b6c4340
parent 24952 953481cd953d
child 33198 b37ad9fbf681
permissions -rw-r--r--
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files 8042894: runtime: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files Reviewed-by: goetz, brutisso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 22872
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    25
#include "precompiled.hpp"
14626
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 13728
diff changeset
    26
#include "code/codeCache.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    27
#include "code/compiledIC.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    28
#include "code/nmethod.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    29
#include "code/relocInfo.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    30
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    31
#include "runtime/stubCodeGenerator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6432
diff changeset
    32
#include "utilities/copy.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
const RelocationHolder RelocationHolder::none; // its type is relocInfo::none
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Implementation of relocInfo
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
relocInfo::relocInfo(relocType t, int off, int f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  assert(t != data_prefix_tag, "cannot build a prefix this way");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  assert((t & type_mask) == t, "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  assert((f & format_mask) == f, "wrong format");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  assert(off >= 0 && off < offset_limit(), "offset out off bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  assert((off & (offset_unit-1)) == 0, "misaligned offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  (*this) = relocInfo(t, RAW_BITS, off, f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
void relocInfo::initialize(CodeSection* dest, Relocation* reloc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  relocInfo* data = this+1;  // here's where the data might go
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  dest->set_locs_end(data);  // sync end: the next call may read dest.locs_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  reloc->pack_data_to(dest); // maybe write data into locs, advancing locs_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  relocInfo* data_limit = dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  if (data_limit > data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    relocInfo suffix = (*this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    data_limit = this->finish_prefix((short*) data_limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    // Finish up with the suffix.  (Hack note: pack_data_to might edit this.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    *data_limit = suffix;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    dest->set_locs_end(data_limit+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
relocInfo* relocInfo::finish_prefix(short* prefix_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  assert(sizeof(relocInfo) == sizeof(short), "change this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  short* p = (short*)(this+1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  assert(prefix_limit >= p, "must be a valid span of data");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  int plen = prefix_limit - p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  if (plen == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    debug_only(_value = 0xFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    return this;                         // no data: remove self completely
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  if (plen == 1 && fits_into_immediate(p[0])) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    (*this) = immediate_relocInfo(p[0]); // move data inside self
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    return this+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // cannot compact, so just update the count and return the limit pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  (*this) = prefix_relocInfo(plen);   // write new datalen
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  assert(data() + datalen() == prefix_limit, "pointers must line up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  return (relocInfo*)prefix_limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
void relocInfo::set_type(relocType t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  int old_offset = addr_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  int old_format = format();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  (*this) = relocInfo(t, old_offset, old_format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  assert(type()==(int)t, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  assert(addr_offset()==old_offset, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  assert(format()==old_format, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
void relocInfo::set_format(int f) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  int old_offset = addr_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  assert((f & format_mask) == f, "wrong format");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  _value = (_value & ~(format_mask << offset_width)) | (f << offset_width);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  assert(addr_offset()==old_offset, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
void relocInfo::change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  bool found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  while (itr->next() && !found) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    if (itr->addr() == pc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      assert(itr->type()==old_type, "wrong relocInfo type found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      itr->current()->set_type(new_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      found=true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  assert(found, "no relocInfo found for pc");
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
void relocInfo::remove_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  change_reloc_info_for_address(itr, pc, old_type, none);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// ----------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// Implementation of RelocIterator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   123
void RelocIterator::initialize(nmethod* nm, address begin, address limit) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  initialize_misc();
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
  if (nm == NULL && begin != NULL) {
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   127
    // allow nmethod to be deduced from beginning address
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   128
    CodeBlob* cb = CodeCache::find_blob(begin);
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   129
    nm = cb->as_nmethod_or_null();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   131
  assert(nm != NULL, "must be able to deduce nmethod from other arguments");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   133
  _code    = nm;
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   134
  _current = nm->relocation_begin() - 1;
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   135
  _end     = nm->relocation_end();
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   136
  _addr    = nm->content_begin();
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   137
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   138
  // Initialize code sections.
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   139
  _section_start[CodeBuffer::SECT_CONSTS] = nm->consts_begin();
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   140
  _section_start[CodeBuffer::SECT_INSTS ] = nm->insts_begin() ;
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   141
  _section_start[CodeBuffer::SECT_STUBS ] = nm->stub_begin()  ;
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   142
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   143
  _section_end  [CodeBuffer::SECT_CONSTS] = nm->consts_end()  ;
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   144
  _section_end  [CodeBuffer::SECT_INSTS ] = nm->insts_end()   ;
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   145
  _section_end  [CodeBuffer::SECT_STUBS ] = nm->stub_end()    ;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  assert(!has_current(), "just checking");
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5702
diff changeset
   148
  assert(begin == NULL || begin >= nm->code_begin(), "in bounds");
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5702
diff changeset
   149
  assert(limit == NULL || limit <= nm->code_end(),   "in bounds");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  set_limits(begin, limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
RelocIterator::RelocIterator(CodeSection* cs, address begin, address limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  initialize_misc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  _current = cs->locs_start()-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  _end     = cs->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  _addr    = cs->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  _code    = NULL; // Not cb->blob();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  CodeBuffer* cb = cs->outer();
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   163
  assert((int) SECT_LIMIT == CodeBuffer::SECT_LIMIT, "my copy must be equal");
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   164
  for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) {
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   165
    CodeSection* cs = cb->code_section(n);
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   166
    _section_start[n] = cs->start();
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   167
    _section_end  [n] = cs->end();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  assert(!has_current(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  assert(begin == NULL || begin >= cs->start(), "in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  assert(limit == NULL || limit <= cs->end(),   "in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  set_limits(begin, limit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
enum { indexCardSize = 128 };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
struct RelocIndexEntry {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  jint addr_offset;          // offset from header_end of an addr()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  jint reloc_offset;         // offset from header_end of a relocInfo (prefix)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   185
bool RelocIterator::addr_in_const() const {
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   186
  const int n = CodeBuffer::SECT_CONSTS;
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   187
  return section_start(n) <= addr() && addr() < section_end(n);
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   188
}
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   189
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   190
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
static inline int num_cards(int code_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  return (code_size-1) / indexCardSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
int RelocIterator::locs_and_index_size(int code_size, int locs_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  if (!UseRelocIndex)  return locs_size;   // no index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  code_size = round_to(code_size, oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  locs_size = round_to(locs_size, oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  int index_size = num_cards(code_size) * sizeof(RelocIndexEntry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // format of indexed relocs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  //   relocation_begin:   relocInfo ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  //   index:              (addr,reloc#) ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  //                       indexSize           :relocation_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  return locs_size + index_size + BytesPerInt;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
void RelocIterator::create_index(relocInfo* dest_begin, int dest_count, relocInfo* dest_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  address relocation_begin = (address)dest_begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  address relocation_end   = (address)dest_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  int     total_size       = relocation_end - relocation_begin;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  int     locs_size        = dest_count * sizeof(relocInfo);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  if (!UseRelocIndex) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    Copy::fill_to_bytes(relocation_begin + locs_size, total_size-locs_size, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  int     index_size       = total_size - locs_size - BytesPerInt;      // find out how much space is left
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  int     ncards           = index_size / sizeof(RelocIndexEntry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  assert(total_size == locs_size + index_size + BytesPerInt, "checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  assert(index_size >= 0 && index_size % sizeof(RelocIndexEntry) == 0, "checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  jint*   index_size_addr  = (jint*)relocation_end - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  assert(sizeof(jint) == BytesPerInt, "change this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  *index_size_addr = index_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  if (index_size != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    assert(index_size > 0, "checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    RelocIndexEntry* index = (RelocIndexEntry *)(relocation_begin + locs_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    assert(index == (RelocIndexEntry*)index_size_addr - ncards, "checkin'");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    // walk over the relocations, and fill in index entries as we go
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    RelocIterator iter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    const address    initial_addr    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    relocInfo* const initial_current = dest_begin - 1;  // biased by -1 like elsewhere
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    iter._code    = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    iter._addr    = initial_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    iter._limit   = (address)(intptr_t)(ncards * indexCardSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    iter._current = initial_current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    iter._end     = dest_begin + dest_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    address next_card_addr = (address)indexCardSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    int addr_offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    int reloc_offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      // Checkpoint the iterator before advancing it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      addr_offset  = iter._addr    - initial_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      reloc_offset = iter._current - initial_current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      if (!iter.next())  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      while (iter.addr() >= next_card_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
        index[i].addr_offset  = addr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
        index[i].reloc_offset = reloc_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
        i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        next_card_addr += indexCardSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    while (i < ncards) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      index[i].addr_offset  = addr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
      index[i].reloc_offset = reloc_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
void RelocIterator::set_limits(address begin, address limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  int index_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  if (UseRelocIndex && _code != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    index_size = ((jint*)_end)[-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    _end = (relocInfo*)( (address)_end - index_size - BytesPerInt );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  _limit = limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  // the limit affects this next stuff:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  if (begin != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    // In ASSERT mode we do not actually use the index, but simply
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    // check that its contents would have led us to the right answer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    address addrCheck = _addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    relocInfo* infoCheck = _current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    if (index_size > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      // skip ahead
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      RelocIndexEntry* index       = (RelocIndexEntry*)_end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
      RelocIndexEntry* index_limit = (RelocIndexEntry*)((address)index + index_size);
6418
6671edbd230e 6978355: renaming for 6961697
twisti
parents: 5702
diff changeset
   290
      assert(_addr == _code->code_begin(), "_addr must be unadjusted");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      int card = (begin - _addr) / indexCardSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      if (card > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
        if (index+card-1 < index_limit)  index += card-1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
        else                             index = index_limit - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
        addrCheck = _addr    + index->addr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
        infoCheck = _current + index->reloc_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
        // Advance the iterator immediately to the last valid state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
        // for the previous card.  Calling "next" will then advance
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
        // it to the first item on the required card.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
        _addr    += index->addr_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
        _current += index->reloc_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    relocInfo* backup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    address    backup_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      backup      = _current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      backup_addr = _addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      if (backup == infoCheck) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
        assert(backup_addr == addrCheck, "must match"); addrCheck = NULL; infoCheck = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
        assert(addrCheck == NULL || backup_addr <= addrCheck, "must not pass addrCheck");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      if (!next() || addr() >= begin) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    assert(addrCheck == NULL || addrCheck == backup_addr, "must have matched addrCheck");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    assert(infoCheck == NULL || infoCheck == backup,      "must have matched infoCheck");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    // At this point, either we are at the first matching record,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    // or else there is no such record, and !has_current().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    // In either case, revert to the immediatly preceding state.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
    _current = backup;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    _addr    = backup_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    set_has_current(false);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
void RelocIterator::set_limit(address limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  address code_end = (address)code() + code()->size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  assert(limit == NULL || limit <= code_end, "in bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  _limit = limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
// All the strange bit-encodings are in here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
// The idea is to encode relocation data which are small integers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
// very efficiently (a single extra halfword).  Larger chunks of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
// relocation data need a halfword header to hold their size.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
void RelocIterator::advance_over_prefix() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  if (_current->is_datalen()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    _data    = (short*) _current->data();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    _datalen =          _current->datalen();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    _current += _datalen + 1;   // skip the embedded data & header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    _databuf = _current->immediate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    _data = &_databuf;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    _datalen = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    _current++;                 // skip the header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  // The client will see the following relocInfo, whatever that is.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  // It is the reloc to which the preceding data applies.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
6432
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   360
void RelocIterator::initialize_misc() {
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   361
  set_has_current(false);
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   362
  for (int i = (int) CodeBuffer::SECT_FIRST; i < (int) CodeBuffer::SECT_LIMIT; i++) {
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   363
    _section_start[i] = NULL;  // these will be lazily computed, if needed
d36e09b60939 6961697: move nmethod constants section before instruction section
twisti
parents: 6418
diff changeset
   364
    _section_end  [i] = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
Relocation* RelocIterator::reloc() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  // (take the "switch" out-of-line)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  relocInfo::relocType t = type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  if (false) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  #define EACH_TYPE(name)                             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  else if (t == relocInfo::name##_type) {             \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    return name##_reloc();                            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  APPLY_TO_RELOCATIONS(EACH_TYPE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  #undef EACH_TYPE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  assert(t == relocInfo::none, "must be padding");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  return new(_rh) Relocation();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
//////// Methods for flyweight Relocation types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
RelocationHolder RelocationHolder::plus(int offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  if (offset != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    switch (type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    case relocInfo::none:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
    case relocInfo::oop_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
        oop_Relocation* r = (oop_Relocation*)reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
        return oop_Relocation::spec(r->oop_index(), r->offset() + offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   397
    case relocInfo::metadata_type:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   398
      {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   399
        metadata_Relocation* r = (metadata_Relocation*)reloc();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   400
        return metadata_Relocation::spec(r->metadata_index(), r->offset() + offset);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   401
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  return (*this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
void Relocation::guarantee_size() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  guarantee(false, "Make _relocbuf bigger!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    // some relocations can compute their own values
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
address Relocation::value() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
void Relocation::set_value(address x) {
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
RelocationHolder Relocation::spec_simple(relocInfo::relocType rtype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  if (rtype == relocInfo::none)  return RelocationHolder::none;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  relocInfo ri = relocInfo(rtype, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  RelocIterator itr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  itr.set_current(ri);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  itr.reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  return itr._rh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
int32_t Relocation::runtime_address_to_index(address runtime_address) {
9111
c100c09c66f2 6777083: assert(target != __null,"must not be null")
never
parents: 8724
diff changeset
   436
  assert(!is_reloc_index((intptr_t)runtime_address), "must not look like an index");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  if (runtime_address == NULL)  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  StubCodeDesc* p = StubCodeDesc::desc_for(runtime_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  if (p != NULL && p->begin() == runtime_address) {
9111
c100c09c66f2 6777083: assert(target != __null,"must not be null")
never
parents: 8724
diff changeset
   442
    assert(is_reloc_index(p->index()), "there must not be too many stubs");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    return (int32_t)p->index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    // Known "miscellaneous" non-stub pointers:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    // os::get_polling_page(), SafepointSynchronize::address_of_state()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
    if (PrintRelocations) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
   448
      tty->print_cr("random unregistered address in relocInfo: " INTPTR_FORMAT, p2i(runtime_address));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    return (int32_t) (intptr_t)runtime_address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    // didn't fit return non-index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
#endif /* _LP64 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  }
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
address Relocation::index_to_runtime_address(int32_t index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  if (index == 0)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
9111
c100c09c66f2 6777083: assert(target != __null,"must not be null")
never
parents: 8724
diff changeset
   463
  if (is_reloc_index(index)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    StubCodeDesc* p = StubCodeDesc::desc_for_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    assert(p != NULL, "there must be a stub for this index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    return p->begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    // this only works on 32bit machines
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    return (address) ((intptr_t) index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    fatal("Relocation::index_to_runtime_address, int32_t not pointer sized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
#endif /* _LP64 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
address Relocation::old_addr_for(address newa,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
                                 const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  int sect = dest->section_index_of(newa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  address ostart = src->code_section(sect)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  address nstart = dest->code_section(sect)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  return ostart + (newa - nstart);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
address Relocation::new_addr_for(address olda,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
                                 const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  debug_only(const CodeBuffer* src0 = src);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  int sect = CodeBuffer::SECT_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  // Look for olda in the source buffer, and all previous incarnations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  // if the source buffer has been expanded.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  for (; src != NULL; src = src->before_expand()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    sect = src->section_index_of(olda);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    if (sect != CodeBuffer::SECT_NONE)  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  guarantee(sect != CodeBuffer::SECT_NONE, "lost track of this address");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  address ostart = src->code_section(sect)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  address nstart = dest->code_section(sect)->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  return nstart + (olda - ostart);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
void Relocation::normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  address addr0 = addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  if (addr0 == NULL || dest->allocates2(addr0))  return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  CodeBuffer* cb = dest->outer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  addr = new_addr_for(addr0, cb, cb);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  assert(allow_other_sections || dest->contains2(addr),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
         "addr must be in required section");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
void CallRelocation::set_destination(address x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  pd_set_call_destination(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
void CallRelocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  // Usually a self-relative reference to an external routine.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  // On some platforms, the reference is absolute (not self-relative).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  // The enhanced use of pd_call_destination sorts this all out.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  address orig_addr = old_addr_for(addr(), src, dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  address callee    = pd_call_destination(orig_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  // Reassert the callee address, this time in the new copy of the code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
  pd_set_call_destination(callee);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
//// pack/unpack methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
void oop_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  short* p = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  p = pack_2_ints_to(p, _oop_index, _offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
void oop_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  unpack_2_ints(_oop_index, _offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   541
void metadata_Relocation::pack_data_to(CodeSection* dest) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   542
  short* p = (short*) dest->locs_end();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   543
  p = pack_2_ints_to(p, _metadata_index, _offset);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   544
  dest->set_locs_end((relocInfo*) p);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   545
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   546
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   547
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   548
void metadata_Relocation::unpack_data() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   549
  unpack_2_ints(_metadata_index, _offset);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   550
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   551
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
void virtual_call_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  short*  p     = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  address point =          dest->locs_point();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   557
  normalize_address(_cached_value, dest);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   558
  jint x0 = scaled_offset_null_special(_cached_value, point);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   559
  p = pack_1_int_to(p, x0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
void virtual_call_Relocation::unpack_data() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   565
  jint x0 = unpack_1_int();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  address point = addr();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   567
  _cached_value = x0==0? NULL: address_from_scaled_offset(x0, point);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
void static_stub_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  short* p = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  CodeSection* insts = dest->outer()->insts();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  normalize_address(_static_call, insts);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  p = pack_1_int_to(p, scaled_offset(_static_call, insts->start()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
void static_stub_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  address base = binding()->section_start(CodeBuffer::SECT_INSTS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  _static_call = address_from_scaled_offset(unpack_1_int(), base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
22813
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   584
void trampoline_stub_Relocation::pack_data_to(CodeSection* dest ) {
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   585
  short* p = (short*) dest->locs_end();
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   586
  CodeSection* insts = dest->outer()->insts();
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   587
  normalize_address(_owner, insts);
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   588
  p = pack_1_int_to(p, scaled_offset(_owner, insts->start()));
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   589
  dest->set_locs_end((relocInfo*) p);
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   590
}
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   591
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   592
void trampoline_stub_Relocation::unpack_data() {
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   593
  address base = binding()->section_start(CodeBuffer::SECT_INSTS);
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   594
  _owner = address_from_scaled_offset(unpack_1_int(), base);
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   595
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
void external_word_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  short* p = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  int32_t index = runtime_address_to_index(_target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  p = pack_1_int_to(p, index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
#else
9111
c100c09c66f2 6777083: assert(target != __null,"must not be null")
never
parents: 8724
diff changeset
   603
  if (is_reloc_index(index)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    p = pack_2_ints_to(p, index, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    jlong t = (jlong) _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    int32_t lo = low(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    int32_t hi = high(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
    p = pack_2_ints_to(p, lo, hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    DEBUG_ONLY(jlong t1 = jlong_from(hi, lo));
9111
c100c09c66f2 6777083: assert(target != __null,"must not be null")
never
parents: 8724
diff changeset
   611
    assert(!is_reloc_index(t1) && (address) t1 == _target, "not symmetric");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
#endif /* _LP64 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
void external_word_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  _target = index_to_runtime_address(unpack_1_int());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
  int32_t lo, hi;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  unpack_2_ints(lo, hi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  jlong t = jlong_from(hi, lo);;
9111
c100c09c66f2 6777083: assert(target != __null,"must not be null")
never
parents: 8724
diff changeset
   625
  if (is_reloc_index(t)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    _target = index_to_runtime_address(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    _target = (address) t;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
#endif /* _LP64 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
void internal_word_Relocation::pack_data_to(CodeSection* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
  short* p = (short*) dest->locs_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
  normalize_address(_target, dest, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  // Check whether my target address is valid within this section.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  // If not, strengthen the relocation type to point to another section.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
  int sindex = _section;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  if (sindex == CodeBuffer::SECT_NONE && _target != NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
      && (!dest->allocates(_target) || _target == dest->locs_point())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
    sindex = dest->outer()->section_index_of(_target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    guarantee(sindex != CodeBuffer::SECT_NONE, "must belong somewhere");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    relocInfo* base = dest->locs_end() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    assert(base->type() == this->type(), "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
    // Change the written type, to be section_word_type instead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    base->set_type(relocInfo::section_word_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  // Note: An internal_word relocation cannot refer to its own instruction,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  // because we reserve "0" to mean that the pointer itself is embedded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  // in the code stream.  We use a section_word relocation for such cases.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  if (sindex == CodeBuffer::SECT_NONE) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    assert(type() == relocInfo::internal_word_type, "must be base class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    guarantee(_target == NULL || dest->allocates2(_target), "must be within the given code section");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    jint x0 = scaled_offset_null_special(_target, dest->locs_point());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
    assert(!(x0 == 0 && _target != NULL), "correct encoding of null target");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    p = pack_1_int_to(p, x0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    assert(_target != NULL, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    CodeSection* sect = dest->outer()->code_section(sindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    guarantee(sect->allocates2(_target), "must be in correct section");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    address base = sect->start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    jint offset = scaled_offset(_target, base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    assert((uint)sindex < (uint)CodeBuffer::SECT_LIMIT, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
    assert(CodeBuffer::SECT_LIMIT <= (1 << section_width), "section_width++");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    p = pack_1_int_to(p, (offset << section_width) | sindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  dest->set_locs_end((relocInfo*) p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
void internal_word_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  jint x0 = unpack_1_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
  _target = x0==0? NULL: address_from_scaled_offset(x0, addr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  _section = CodeBuffer::SECT_NONE;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
void section_word_Relocation::unpack_data() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  jint    x      = unpack_1_int();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  jint    offset = (x >> section_width);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  int     sindex = (x & ((1<<section_width)-1));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  address base   = binding()->section_start(sindex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  _section = sindex;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  _target  = address_from_scaled_offset(offset, base);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
//// miscellaneous methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
oop* oop_Relocation::oop_addr() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  int n = _oop_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  if (n == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
    // oop is stored in the code stream
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    return (oop*) pd_address_in_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  } else {
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
   700
    // oop is stored in table at nmethod::oops_begin
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
    return code()->oop_addr_at(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
oop oop_Relocation::oop_value() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  oop v = *oop_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
  // clean inline caches store a special pseudo-null
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
  if (v == (oop)Universe::non_oop_word())  v = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
  return v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
void oop_Relocation::fix_oop_relocation() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  if (!oop_is_immediate()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
    // get the oop from the pool, and re-insert it into the instruction:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
    set_value(value());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
8724
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8107
diff changeset
   722
void oop_Relocation::verify_oop_relocation() {
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8107
diff changeset
   723
  if (!oop_is_immediate()) {
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8107
diff changeset
   724
    // get the oop from the pool, and re-insert it into the instruction:
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8107
diff changeset
   725
    verify_value(value());
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8107
diff changeset
   726
  }
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8107
diff changeset
   727
}
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 8107
diff changeset
   728
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   729
// meta data versions
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   730
Metadata** metadata_Relocation::metadata_addr() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   731
  int n = _metadata_index;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   732
  if (n == 0) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   733
    // metadata is stored in the code stream
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   734
    return (Metadata**) pd_address_in_code();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
    } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   736
    // metadata is stored in table at nmethod::metadatas_begin
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   737
    return code()->metadata_addr_at(n);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   742
Metadata* metadata_Relocation::metadata_value() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   743
  Metadata* v = *metadata_addr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   744
  // clean inline caches store a special pseudo-null
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   745
  if (v == (Metadata*)Universe::non_oop_word())  v = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   746
  return v;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   749
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   750
void metadata_Relocation::fix_metadata_relocation() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   751
  if (!metadata_is_immediate()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   752
    // get the metadata from the pool, and re-insert it into the instruction:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   753
    pd_fix_value(value());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   754
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   758
void metadata_Relocation::verify_metadata_relocation() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   759
  if (!metadata_is_immediate()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   760
    // get the metadata from the pool, and re-insert it into the instruction:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   761
    verify_value(value());
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   762
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   765
address virtual_call_Relocation::cached_value() {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   766
  assert(_cached_value != NULL && _cached_value < addr(), "must precede ic_call");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   767
  return _cached_value;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
void virtual_call_Relocation::clear_inline_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  // No stubs for ICs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  // Clean IC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
  CompiledIC* icache = CompiledIC_at(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
  icache->set_to_clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
void opt_virtual_call_Relocation::clear_inline_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  // No stubs for ICs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  // Clean IC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  CompiledIC* icache = CompiledIC_at(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
  icache->set_to_clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
address opt_virtual_call_Relocation::static_stub() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  // search for the static stub who points back to this static call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  address static_call_addr = addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  RelocIterator iter(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
  while (iter.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
    if (iter.type() == relocInfo::static_stub_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
      if (iter.static_stub_reloc()->static_call() == static_call_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
        return iter.addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
void static_call_Relocation::clear_inline_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
  // Safe call site info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
  CompiledStaticCall* handler = compiledStaticCall_at(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
  handler->set_to_clean();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
address static_call_Relocation::static_stub() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
  // search for the static stub who points back to this static call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  address static_call_addr = addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  RelocIterator iter(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
  while (iter.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
    if (iter.type() == relocInfo::static_stub_type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
      if (iter.static_stub_reloc()->static_call() == static_call_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
        return iter.addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
22813
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   825
// Finds the trampoline address for a call. If no trampoline stub is
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   826
// found NULL is returned which can be handled by the caller.
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   827
address trampoline_stub_Relocation::get_trampoline_for(address call, nmethod* code) {
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   828
  // There are no relocations available when the code gets relocated
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   829
  // because of CodeBuffer expansion.
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   830
  if (code->relocation_size() == 0)
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   831
    return NULL;
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   832
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   833
  RelocIterator iter(code, call);
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   834
  while (iter.next()) {
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   835
    if (iter.type() == relocInfo::trampoline_stub_type) {
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   836
      if (iter.trampoline_stub_reloc()->owner() == call) {
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   837
        return iter.addr();
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   838
      }
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   839
    }
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   840
  }
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   841
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   842
  return NULL;
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
   843
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
void static_stub_Relocation::clear_inline_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  // Call stub is only used when calling the interpreted code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  // It does not really need to be cleared, except that we want to clean out the methodoop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  CompiledStaticCall::set_stub_to_clean(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
void external_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  address target = _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
  if (target == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
    // An absolute embedded reference to an external location,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    // which means there is nothing to fix here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
  // Probably this reference is absolute, not relative, so the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  // following is probably a no-op.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  assert(src->section_index_of(target) == CodeBuffer::SECT_NONE, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
  set_value(target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
address external_word_Relocation::target() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  address target = _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  if (target == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
    target = pd_get_address_from_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  return target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
void internal_word_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  address target = _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  if (target == NULL) {
24952
953481cd953d 8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents: 24424
diff changeset
   878
    target = new_addr_for(this->target(), src, dest);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
  set_value(target);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
address internal_word_Relocation::target() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
  address target = _target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  if (target == NULL) {
24952
953481cd953d 8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents: 24424
diff changeset
   887
    if (addr_in_const()) {
953481cd953d 8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents: 24424
diff changeset
   888
      target = *(address*)addr();
953481cd953d 8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents: 24424
diff changeset
   889
    } else {
953481cd953d 8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents: 24424
diff changeset
   890
      target = pd_get_address_from_code();
953481cd953d 8044538: assert(which != imm_operand) failed: instruction is not a movq reg, imm64
thartmann
parents: 24424
diff changeset
   891
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  return target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
//---------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
// Non-product code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
static const char* reloc_type_string(relocInfo::relocType t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  switch (t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  #define EACH_CASE(name) \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  case relocInfo::name##_type: \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
    return #name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  APPLY_TO_RELOCATIONS(EACH_CASE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  #undef EACH_CASE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  case relocInfo::none:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
    return "none";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
  case relocInfo::data_prefix_tag:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
    return "prefix";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
    return "UNKNOWN RELOC TYPE";
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
void RelocIterator::print_current() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  if (!has_current()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
    tty->print_cr("(no relocs)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  }
7427
d7b79a367474 6985015: C1 needs to support compressed oops
iveresov
parents: 7397
diff changeset
   925
  tty->print("relocInfo@" INTPTR_FORMAT " [type=%d(%s) addr=" INTPTR_FORMAT " offset=%d",
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
   926
             p2i(_current), type(), reloc_type_string((relocInfo::relocType) type()), p2i(_addr), _current->addr_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
  if (current()->format() != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
    tty->print(" format=%d", current()->format());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
  if (datalen() == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
    tty->print(" data=%d", data()[0]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  } else if (datalen() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
    tty->print(" data={");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
    for (int i = 0; i < datalen(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
      tty->print("%04x", data()[i] & 0xFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
    tty->print("}");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  tty->print("]");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
  switch (type()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
  case relocInfo::oop_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
      oop_Relocation* r = oop_reloc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
      oop* oop_addr  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
      oop  raw_oop   = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
      oop  oop_value = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
      if (code() != NULL || r->oop_is_immediate()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
        oop_addr  = r->oop_addr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
        raw_oop   = *oop_addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
        oop_value = r->oop_value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
      tty->print(" | [oop_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]",
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
   952
                 p2i(oop_addr), p2i(raw_oop), r->offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
      // Do not print the oop by default--we want this routine to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
      // work even during GC or other inconvenient times.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
      if (WizardMode && oop_value != NULL) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
   956
        tty->print("oop_value=" INTPTR_FORMAT ": ", p2i(oop_value));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
        oop_value->print_value_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   961
  case relocInfo::metadata_type:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   962
    {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   963
      metadata_Relocation* r = metadata_reloc();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   964
      Metadata** metadata_addr  = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   965
      Metadata*    raw_metadata   = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   966
      Metadata*    metadata_value = NULL;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   967
      if (code() != NULL || r->metadata_is_immediate()) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   968
        metadata_addr  = r->metadata_addr();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   969
        raw_metadata   = *metadata_addr;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   970
        metadata_value = r->metadata_value();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   971
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   972
      tty->print(" | [metadata_addr=" INTPTR_FORMAT " *=" INTPTR_FORMAT " offset=%d]",
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
   973
                 p2i(metadata_addr), p2i(raw_metadata), r->offset());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   974
      if (metadata_value != NULL) {
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
   975
        tty->print("metadata_value=" INTPTR_FORMAT ": ", p2i(metadata_value));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   976
        metadata_value->print_value_on(tty);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   977
      }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   978
      break;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   979
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
  case relocInfo::external_word_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
  case relocInfo::internal_word_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
  case relocInfo::section_word_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
      DataRelocation* r = (DataRelocation*) reloc();
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
   985
      tty->print(" | [target=" INTPTR_FORMAT "]", p2i(r->value())); //value==target
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
  case relocInfo::static_call_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
  case relocInfo::runtime_call_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
      CallRelocation* r = (CallRelocation*) reloc();
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
   992
      tty->print(" | [destination=" INTPTR_FORMAT "]", p2i(r->destination()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  case relocInfo::virtual_call_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
      virtual_call_Relocation* r = (virtual_call_Relocation*) reloc();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 9124
diff changeset
   998
      tty->print(" | [destination=" INTPTR_FORMAT " cached_value=" INTPTR_FORMAT "]",
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
   999
                 p2i(r->destination()), p2i(r->cached_value()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
  case relocInfo::static_stub_type:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
      static_stub_Relocation* r = (static_stub_Relocation*) reloc();
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
  1005
      tty->print(" | [static_call=" INTPTR_FORMAT "]", p2i(r->static_call()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
    }
22813
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
  1008
  case relocInfo::trampoline_stub_type:
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
  1009
    {
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
  1010
      trampoline_stub_Relocation* r = (trampoline_stub_Relocation*) reloc();
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
  1011
      tty->print(" | [trampoline owner=" INTPTR_FORMAT "]", p2i(r->owner()));
22813
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
  1012
      break;
422557569a6b 8016696: PPC64 (part 4): add relocation for trampoline stubs
goetz
parents: 18446
diff changeset
  1013
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
  tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
void RelocIterator::print() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  RelocIterator save_this = (*this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
  relocInfo* scan = _current;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
  if (!has_current())  scan += 1;  // nothing to scan here!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
  bool skip_next = has_current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
  bool got_next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
  while (true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
    got_next = (skip_next || next());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
    skip_next = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 24952
diff changeset
  1030
    tty->print("         @" INTPTR_FORMAT ": ", p2i(scan));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
    relocInfo* newscan = _current+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
    if (!has_current())  newscan -= 1;  // nothing to scan here!
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
    while (scan < newscan) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
      tty->print("%04x", *(short*)scan & 0xFFFF);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
      scan++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
    if (!got_next)  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
    print_current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  (*this) = save_this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
// For the debugger:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
extern "C"
5686
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
  1048
void print_blob_locs(nmethod* nm) {
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
  1049
  nm->print();
5435e77aa3df 6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents: 1
diff changeset
  1050
  RelocIterator iter(nm);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  iter.print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
extern "C"
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
void print_buf_locs(CodeBuffer* cb) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
  FlagSetting fs(PrintRelocations, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
  cb->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
#endif // !PRODUCT