annotate src/share/vm/code/relocInfo.cpp @ 1552:c18cbe5936b8

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