author | coleenp |
Wed, 27 Mar 2013 08:19:50 -0400 | |
changeset 16588 | 7e90e795813e |
parent 13728 | 882756847a04 |
child 18446 | 635eae7b22fc |
permissions | -rw-r--r-- |
1 | 1 |
/* |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
2 |
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1217
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1217
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1217
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_CODE_RELOCINFO_HPP |
26 |
#define SHARE_VM_CODE_RELOCINFO_HPP |
|
27 |
||
28 |
#include "memory/allocation.hpp" |
|
29 |
#include "utilities/top.hpp" |
|
30 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
31 |
class NativeMovConstReg; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
32 |
|
1 | 33 |
// Types in this file: |
34 |
// relocInfo |
|
35 |
// One element of an array of halfwords encoding compressed relocations. |
|
36 |
// Also, the source of relocation types (relocInfo::oop_type, ...). |
|
37 |
// Relocation |
|
38 |
// A flyweight object representing a single relocation. |
|
39 |
// It is fully unpacked from the compressed relocation array. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
40 |
// metadata_Relocation, ... (subclasses of Relocation) |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
41 |
// The location of some type-specific operations (metadata_addr, ...). |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
42 |
// Also, the source of relocation specs (metadata_Relocation::spec, ...). |
1 | 43 |
// oop_Relocation, ... (subclasses of Relocation) |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
44 |
// oops in the code stream (strings, class loaders) |
1 | 45 |
// Also, the source of relocation specs (oop_Relocation::spec, ...). |
46 |
// RelocationHolder |
|
47 |
// A ValueObj type which acts as a union holding a Relocation object. |
|
48 |
// Represents a relocation spec passed into a CodeBuffer during assembly. |
|
49 |
// RelocIterator |
|
50 |
// A StackObj which iterates over the relocations associated with |
|
51 |
// a range of code addresses. Can be used to operate a copy of code. |
|
52 |
// PatchingRelocIterator |
|
53 |
// Specialized subtype of RelocIterator which removes breakpoints |
|
54 |
// temporarily during iteration, then restores them. |
|
55 |
// BoundRelocation |
|
56 |
// An _internal_ type shared by packers and unpackers of relocations. |
|
57 |
// It pastes together a RelocationHolder with some pointers into |
|
58 |
// code and relocInfo streams. |
|
59 |
||
60 |
||
61 |
// Notes on relocType: |
|
62 |
// |
|
63 |
// These hold enough information to read or write a value embedded in |
|
64 |
// the instructions of an CodeBlob. They're used to update: |
|
65 |
// |
|
66 |
// 1) embedded oops (isOop() == true) |
|
67 |
// 2) inline caches (isIC() == true) |
|
68 |
// 3) runtime calls (isRuntimeCall() == true) |
|
69 |
// 4) internal word ref (isInternalWord() == true) |
|
70 |
// 5) external word ref (isExternalWord() == true) |
|
71 |
// |
|
72 |
// when objects move (GC) or if code moves (compacting the code heap). |
|
73 |
// They are also used to patch the code (if a call site must change) |
|
74 |
// |
|
75 |
// A relocInfo is represented in 16 bits: |
|
76 |
// 4 bits indicating the relocation type |
|
77 |
// 12 bits indicating the offset from the previous relocInfo address |
|
78 |
// |
|
79 |
// The offsets accumulate along the relocInfo stream to encode the |
|
80 |
// address within the CodeBlob, which is named RelocIterator::addr(). |
|
81 |
// The address of a particular relocInfo always points to the first |
|
82 |
// byte of the relevant instruction (and not to any of its subfields |
|
83 |
// or embedded immediate constants). |
|
84 |
// |
|
85 |
// The offset value is scaled appropriately for the target machine. |
|
86 |
// (See relocInfo_<arch>.hpp for the offset scaling.) |
|
87 |
// |
|
88 |
// On some machines, there may also be a "format" field which may provide |
|
89 |
// additional information about the format of the instruction stream |
|
90 |
// at the corresponding code address. The format value is usually zero. |
|
91 |
// Any machine (such as Intel) whose instructions can sometimes contain |
|
92 |
// more than one relocatable constant needs format codes to distinguish |
|
93 |
// which operand goes with a given relocation. |
|
94 |
// |
|
95 |
// If the target machine needs N format bits, the offset has 12-N bits, |
|
96 |
// the format is encoded between the offset and the type, and the |
|
97 |
// relocInfo_<arch>.hpp file has manifest constants for the format codes. |
|
98 |
// |
|
99 |
// If the type is "data_prefix_tag" then the offset bits are further encoded, |
|
100 |
// and in fact represent not a code-stream offset but some inline data. |
|
101 |
// The data takes the form of a counted sequence of halfwords, which |
|
102 |
// precedes the actual relocation record. (Clients never see it directly.) |
|
103 |
// The interpetation of this extra data depends on the relocation type. |
|
104 |
// |
|
105 |
// On machines that have 32-bit immediate fields, there is usually |
|
106 |
// little need for relocation "prefix" data, because the instruction stream |
|
107 |
// is a perfectly reasonable place to store the value. On machines in |
|
108 |
// which 32-bit values must be "split" across instructions, the relocation |
|
109 |
// data is the "true" specification of the value, which is then applied |
|
110 |
// to some field of the instruction (22 or 13 bits, on SPARC). |
|
111 |
// |
|
112 |
// Whenever the location of the CodeBlob changes, any PC-relative |
|
113 |
// relocations, and any internal_word_type relocations, must be reapplied. |
|
114 |
// After the GC runs, oop_type relocations must be reapplied. |
|
115 |
// |
|
116 |
// |
|
117 |
// Here are meanings of the types: |
|
118 |
// |
|
119 |
// relocInfo::none -- a filler record |
|
120 |
// Value: none |
|
121 |
// Instruction: The corresponding code address is ignored |
|
122 |
// Data: Any data prefix and format code are ignored |
|
123 |
// (This means that any relocInfo can be disabled by setting |
|
124 |
// its type to none. See relocInfo::remove.) |
|
125 |
// |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
126 |
// relocInfo::oop_type, relocInfo::metadata_type -- a reference to an oop or meta data |
1 | 127 |
// Value: an oop, or else the address (handle) of an oop |
128 |
// Instruction types: memory (load), set (load address) |
|
129 |
// Data: [] an oop stored in 4 bytes of instruction |
|
130 |
// [n] n is the index of an oop in the CodeBlob's oop pool |
|
131 |
// [[N]n l] and l is a byte offset to be applied to the oop |
|
132 |
// [Nn Ll] both index and offset may be 32 bits if necessary |
|
133 |
// Here is a special hack, used only by the old compiler: |
|
134 |
// [[N]n 00] the value is the __address__ of the nth oop in the pool |
|
135 |
// (Note that the offset allows optimal references to class variables.) |
|
136 |
// |
|
137 |
// relocInfo::internal_word_type -- an address within the same CodeBlob |
|
138 |
// relocInfo::section_word_type -- same, but can refer to another section |
|
139 |
// Value: an address in the CodeBlob's code or constants section |
|
140 |
// Instruction types: memory (load), set (load address) |
|
141 |
// Data: [] stored in 4 bytes of instruction |
|
142 |
// [[L]l] a relative offset (see [About Offsets] below) |
|
143 |
// In the case of section_word_type, the offset is relative to a section |
|
144 |
// base address, and the section number (e.g., SECT_INSTS) is encoded |
|
145 |
// into the low two bits of the offset L. |
|
146 |
// |
|
147 |
// relocInfo::external_word_type -- a fixed address in the runtime system |
|
148 |
// Value: an address |
|
149 |
// Instruction types: memory (load), set (load address) |
|
150 |
// Data: [] stored in 4 bytes of instruction |
|
151 |
// [n] the index of a "well-known" stub (usual case on RISC) |
|
152 |
// [Ll] a 32-bit address |
|
153 |
// |
|
154 |
// relocInfo::runtime_call_type -- a fixed subroutine in the runtime system |
|
155 |
// Value: an address |
|
156 |
// Instruction types: PC-relative call (or a PC-relative branch) |
|
157 |
// Data: [] stored in 4 bytes of instruction |
|
158 |
// |
|
159 |
// relocInfo::static_call_type -- a static call |
|
160 |
// Value: an CodeBlob, a stub, or a fixup routine |
|
161 |
// Instruction types: a call |
|
162 |
// Data: [] |
|
163 |
// The identity of the callee is extracted from debugging information. |
|
164 |
// //%note reloc_3 |
|
165 |
// |
|
166 |
// relocInfo::virtual_call_type -- a virtual call site (which includes an inline |
|
167 |
// cache) |
|
168 |
// Value: an CodeBlob, a stub, the interpreter, or a fixup routine |
|
169 |
// Instruction types: a call, plus some associated set-oop instructions |
|
170 |
// Data: [] the associated set-oops are adjacent to the call |
|
171 |
// [n] n is a relative offset to the first set-oop |
|
172 |
// [[N]n l] and l is a limit within which the set-oops occur |
|
173 |
// [Nn Ll] both n and l may be 32 bits if necessary |
|
174 |
// The identity of the callee is extracted from debugging information. |
|
175 |
// |
|
176 |
// relocInfo::opt_virtual_call_type -- a virtual call site that is statically bound |
|
177 |
// |
|
178 |
// Same info as a static_call_type. We use a special type, so the handling of |
|
179 |
// virtuals and statics are separated. |
|
180 |
// |
|
181 |
// |
|
182 |
// The offset n points to the first set-oop. (See [About Offsets] below.) |
|
183 |
// In turn, the set-oop instruction specifies or contains an oop cell devoted |
|
184 |
// exclusively to the IC call, which can be patched along with the call. |
|
185 |
// |
|
186 |
// The locations of any other set-oops are found by searching the relocation |
|
187 |
// information starting at the first set-oop, and continuing until all |
|
188 |
// relocations up through l have been inspected. The value l is another |
|
189 |
// relative offset. (Both n and l are relative to the call's first byte.) |
|
190 |
// |
|
191 |
// The limit l of the search is exclusive. However, if it points within |
|
192 |
// the call (e.g., offset zero), it is adjusted to point after the call and |
|
193 |
// any associated machine-specific delay slot. |
|
194 |
// |
|
195 |
// Since the offsets could be as wide as 32-bits, these conventions |
|
196 |
// put no restrictions whatever upon code reorganization. |
|
197 |
// |
|
198 |
// The compiler is responsible for ensuring that transition from a clean |
|
199 |
// state to a monomorphic compiled state is MP-safe. This implies that |
|
200 |
// the system must respond well to intermediate states where a random |
|
201 |
// subset of the set-oops has been correctly from the clean state |
|
202 |
// upon entry to the VEP of the compiled method. In the case of a |
|
203 |
// machine (Intel) with a single set-oop instruction, the 32-bit |
|
204 |
// immediate field must not straddle a unit of memory coherence. |
|
205 |
// //%note reloc_3 |
|
206 |
// |
|
207 |
// relocInfo::breakpoint_type -- a conditional breakpoint in the code |
|
208 |
// Value: none |
|
209 |
// Instruction types: any whatsoever |
|
210 |
// Data: [b [T]t i...] |
|
211 |
// The b is a bit-packed word representing the breakpoint's attributes. |
|
212 |
// The t is a target address which the breakpoint calls (when it is enabled). |
|
213 |
// The i... is a place to store one or two instruction words overwritten |
|
214 |
// by a trap, so that the breakpoint may be subsequently removed. |
|
215 |
// |
|
216 |
// relocInfo::static_stub_type -- an extra stub for each static_call_type |
|
217 |
// Value: none |
|
218 |
// Instruction types: a virtual call: { set_oop; jump; } |
|
219 |
// Data: [[N]n] the offset of the associated static_call reloc |
|
220 |
// This stub becomes the target of a static call which must be upgraded |
|
221 |
// to a virtual call (because the callee is interpreted). |
|
222 |
// See [About Offsets] below. |
|
223 |
// //%note reloc_2 |
|
224 |
// |
|
225 |
// For example: |
|
226 |
// |
|
227 |
// INSTRUCTIONS RELOC: TYPE PREFIX DATA |
|
228 |
// ------------ ---- ----------- |
|
229 |
// sethi %hi(myObject), R oop_type [n(myObject)] |
|
230 |
// ld [R+%lo(myObject)+fldOffset], R2 oop_type [n(myObject) fldOffset] |
|
231 |
// add R2, 1, R2 |
|
232 |
// st R2, [R+%lo(myObject)+fldOffset] oop_type [n(myObject) fldOffset] |
|
233 |
//%note reloc_1 |
|
234 |
// |
|
235 |
// This uses 4 instruction words, 8 relocation halfwords, |
|
236 |
// and an entry (which is sharable) in the CodeBlob's oop pool, |
|
237 |
// for a total of 36 bytes. |
|
238 |
// |
|
239 |
// Note that the compiler is responsible for ensuring the "fldOffset" when |
|
240 |
// added to "%lo(myObject)" does not overflow the immediate fields of the |
|
241 |
// memory instructions. |
|
242 |
// |
|
243 |
// |
|
244 |
// [About Offsets] Relative offsets are supplied to this module as |
|
245 |
// positive byte offsets, but they may be internally stored scaled |
|
246 |
// and/or negated, depending on what is most compact for the target |
|
247 |
// system. Since the object pointed to by the offset typically |
|
248 |
// precedes the relocation address, it is profitable to store |
|
249 |
// these negative offsets as positive numbers, but this decision |
|
250 |
// is internal to the relocation information abstractions. |
|
251 |
// |
|
252 |
||
253 |
class Relocation; |
|
254 |
class CodeBuffer; |
|
255 |
class CodeSection; |
|
256 |
class RelocIterator; |
|
257 |
||
258 |
class relocInfo VALUE_OBJ_CLASS_SPEC { |
|
259 |
friend class RelocIterator; |
|
260 |
public: |
|
261 |
enum relocType { |
|
262 |
none = 0, // Used when no relocation should be generated |
|
263 |
oop_type = 1, // embedded oop |
|
264 |
virtual_call_type = 2, // a standard inline cache call for a virtual send |
|
265 |
opt_virtual_call_type = 3, // a virtual call that has been statically bound (i.e., no IC cache) |
|
266 |
static_call_type = 4, // a static send |
|
267 |
static_stub_type = 5, // stub-entry for static send (takes care of interpreter case) |
|
268 |
runtime_call_type = 6, // call to fixed external routine |
|
269 |
external_word_type = 7, // reference to fixed external address |
|
270 |
internal_word_type = 8, // reference within the current code blob |
|
271 |
section_word_type = 9, // internal, but a cross-section reference |
|
272 |
poll_type = 10, // polling instruction for safepoints |
|
273 |
poll_return_type = 11, // polling instruction for safepoints at return |
|
274 |
breakpoint_type = 12, // an initialization barrier or safepoint |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
275 |
metadata_type = 13, // metadata that used to be oops |
1 | 276 |
yet_unused_type_2 = 14, // Still unused |
277 |
data_prefix_tag = 15, // tag for a prefix (carries data arguments) |
|
278 |
type_mask = 15 // A mask which selects only the above values |
|
279 |
}; |
|
280 |
||
281 |
protected: |
|
282 |
unsigned short _value; |
|
283 |
||
284 |
enum RawBitsToken { RAW_BITS }; |
|
285 |
relocInfo(relocType type, RawBitsToken ignore, int bits) |
|
286 |
: _value((type << nontype_width) + bits) { } |
|
287 |
||
288 |
relocInfo(relocType type, RawBitsToken ignore, int off, int f) |
|
289 |
: _value((type << nontype_width) + (off / (unsigned)offset_unit) + (f << offset_width)) { } |
|
290 |
||
291 |
public: |
|
292 |
// constructor |
|
293 |
relocInfo(relocType type, int offset, int format = 0) |
|
294 |
#ifndef ASSERT |
|
295 |
{ |
|
296 |
(*this) = relocInfo(type, RAW_BITS, offset, format); |
|
297 |
} |
|
298 |
#else |
|
299 |
// Put a bunch of assertions out-of-line. |
|
300 |
; |
|
301 |
#endif |
|
302 |
||
303 |
#define APPLY_TO_RELOCATIONS(visitor) \ |
|
304 |
visitor(oop) \ |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
305 |
visitor(metadata) \ |
1 | 306 |
visitor(virtual_call) \ |
307 |
visitor(opt_virtual_call) \ |
|
308 |
visitor(static_call) \ |
|
309 |
visitor(static_stub) \ |
|
310 |
visitor(runtime_call) \ |
|
311 |
visitor(external_word) \ |
|
312 |
visitor(internal_word) \ |
|
313 |
visitor(poll) \ |
|
314 |
visitor(poll_return) \ |
|
315 |
visitor(breakpoint) \ |
|
316 |
visitor(section_word) \ |
|
317 |
||
318 |
||
319 |
public: |
|
320 |
enum { |
|
321 |
value_width = sizeof(unsigned short) * BitsPerByte, |
|
322 |
type_width = 4, // == log2(type_mask+1) |
|
323 |
nontype_width = value_width - type_width, |
|
324 |
datalen_width = nontype_width-1, |
|
325 |
datalen_tag = 1 << datalen_width, // or-ed into _value |
|
326 |
datalen_limit = 1 << datalen_width, |
|
327 |
datalen_mask = (1 << datalen_width)-1 |
|
328 |
}; |
|
329 |
||
330 |
// accessors |
|
331 |
public: |
|
332 |
relocType type() const { return (relocType)((unsigned)_value >> nontype_width); } |
|
333 |
int format() const { return format_mask==0? 0: format_mask & |
|
334 |
((unsigned)_value >> offset_width); } |
|
335 |
int addr_offset() const { assert(!is_prefix(), "must have offset"); |
|
336 |
return (_value & offset_mask)*offset_unit; } |
|
337 |
||
338 |
protected: |
|
339 |
const short* data() const { assert(is_datalen(), "must have data"); |
|
340 |
return (const short*)(this + 1); } |
|
341 |
int datalen() const { assert(is_datalen(), "must have data"); |
|
342 |
return (_value & datalen_mask); } |
|
343 |
int immediate() const { assert(is_immediate(), "must have immed"); |
|
344 |
return (_value & datalen_mask); } |
|
345 |
public: |
|
346 |
static int addr_unit() { return offset_unit; } |
|
347 |
static int offset_limit() { return (1 << offset_width) * offset_unit; } |
|
348 |
||
349 |
void set_type(relocType type); |
|
350 |
void set_format(int format); |
|
351 |
||
352 |
void remove() { set_type(none); } |
|
353 |
||
354 |
protected: |
|
355 |
bool is_none() const { return type() == none; } |
|
356 |
bool is_prefix() const { return type() == data_prefix_tag; } |
|
357 |
bool is_datalen() const { assert(is_prefix(), "must be prefix"); |
|
358 |
return (_value & datalen_tag) != 0; } |
|
359 |
bool is_immediate() const { assert(is_prefix(), "must be prefix"); |
|
360 |
return (_value & datalen_tag) == 0; } |
|
361 |
||
362 |
public: |
|
363 |
// Occasionally records of type relocInfo::none will appear in the stream. |
|
364 |
// We do not bother to filter these out, but clients should ignore them. |
|
365 |
// These records serve as "filler" in three ways: |
|
366 |
// - to skip large spans of unrelocated code (this is rare) |
|
367 |
// - to pad out the relocInfo array to the required oop alignment |
|
368 |
// - to disable old relocation information which is no longer applicable |
|
369 |
||
370 |
inline friend relocInfo filler_relocInfo(); |
|
371 |
||
372 |
// Every non-prefix relocation may be preceded by at most one prefix, |
|
373 |
// which supplies 1 or more halfwords of associated data. Conventionally, |
|
374 |
// an int is represented by 0, 1, or 2 halfwords, depending on how |
|
375 |
// many bits are required to represent the value. (In addition, |
|
376 |
// if the sole halfword is a 10-bit unsigned number, it is made |
|
377 |
// "immediate" in the prefix header word itself. This optimization |
|
378 |
// is invisible outside this module.) |
|
379 |
||
380 |
inline friend relocInfo prefix_relocInfo(int datalen = 0); |
|
381 |
||
382 |
protected: |
|
383 |
// an immediate relocInfo optimizes a prefix with one 10-bit unsigned value |
|
384 |
static relocInfo immediate_relocInfo(int data0) { |
|
385 |
assert(fits_into_immediate(data0), "data0 in limits"); |
|
386 |
return relocInfo(relocInfo::data_prefix_tag, RAW_BITS, data0); |
|
387 |
} |
|
388 |
static bool fits_into_immediate(int data0) { |
|
389 |
return (data0 >= 0 && data0 < datalen_limit); |
|
390 |
} |
|
391 |
||
392 |
public: |
|
393 |
// Support routines for compilers. |
|
394 |
||
395 |
// This routine takes an infant relocInfo (unprefixed) and |
|
396 |
// edits in its prefix, if any. It also updates dest.locs_end. |
|
397 |
void initialize(CodeSection* dest, Relocation* reloc); |
|
398 |
||
399 |
// This routine updates a prefix and returns the limit pointer. |
|
400 |
// It tries to compress the prefix from 32 to 16 bits, and if |
|
401 |
// successful returns a reduced "prefix_limit" pointer. |
|
402 |
relocInfo* finish_prefix(short* prefix_limit); |
|
403 |
||
404 |
// bit-packers for the data array: |
|
405 |
||
406 |
// As it happens, the bytes within the shorts are ordered natively, |
|
407 |
// but the shorts within the word are ordered big-endian. |
|
408 |
// This is an arbitrary choice, made this way mainly to ease debugging. |
|
409 |
static int data0_from_int(jint x) { return x >> value_width; } |
|
410 |
static int data1_from_int(jint x) { return (short)x; } |
|
411 |
static jint jint_from_data(short* data) { |
|
412 |
return (data[0] << value_width) + (unsigned short)data[1]; |
|
413 |
} |
|
414 |
||
415 |
static jint short_data_at(int n, short* data, int datalen) { |
|
416 |
return datalen > n ? data[n] : 0; |
|
417 |
} |
|
418 |
||
419 |
static jint jint_data_at(int n, short* data, int datalen) { |
|
420 |
return datalen > n+1 ? jint_from_data(&data[n]) : short_data_at(n, data, datalen); |
|
421 |
} |
|
422 |
||
423 |
// Update methods for relocation information |
|
424 |
// (since code is dynamically patched, we also need to dynamically update the relocation info) |
|
425 |
// Both methods takes old_type, so it is able to performe sanity checks on the information removed. |
|
426 |
static void change_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type, relocType new_type); |
|
427 |
static void remove_reloc_info_for_address(RelocIterator *itr, address pc, relocType old_type); |
|
428 |
||
429 |
// Machine dependent stuff |
|
7397 | 430 |
#ifdef TARGET_ARCH_x86 |
431 |
# include "relocInfo_x86.hpp" |
|
432 |
#endif |
|
433 |
#ifdef TARGET_ARCH_sparc |
|
434 |
# include "relocInfo_sparc.hpp" |
|
435 |
#endif |
|
436 |
#ifdef TARGET_ARCH_zero |
|
437 |
# include "relocInfo_zero.hpp" |
|
438 |
#endif |
|
8107
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
439 |
#ifdef TARGET_ARCH_arm |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
440 |
# include "relocInfo_arm.hpp" |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
441 |
#endif |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
442 |
#ifdef TARGET_ARCH_ppc |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
443 |
# include "relocInfo_ppc.hpp" |
78e5bd944384
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
7397
diff
changeset
|
444 |
#endif |
7397 | 445 |
|
1 | 446 |
|
447 |
protected: |
|
448 |
// Derived constant, based on format_width which is PD: |
|
449 |
enum { |
|
450 |
offset_width = nontype_width - format_width, |
|
451 |
offset_mask = (1<<offset_width) - 1, |
|
452 |
format_mask = (1<<format_width) - 1 |
|
453 |
}; |
|
454 |
public: |
|
455 |
enum { |
|
456 |
// Conservatively large estimate of maximum length (in shorts) |
|
457 |
// of any relocation record (probably breakpoints are largest). |
|
458 |
// Extended format is length prefix, data words, and tag/offset suffix. |
|
459 |
length_limit = 1 + 1 + (3*BytesPerWord/BytesPerShort) + 1, |
|
460 |
have_format = format_width > 0 |
|
461 |
}; |
|
462 |
}; |
|
463 |
||
464 |
#define FORWARD_DECLARE_EACH_CLASS(name) \ |
|
465 |
class name##_Relocation; |
|
466 |
APPLY_TO_RELOCATIONS(FORWARD_DECLARE_EACH_CLASS) |
|
467 |
#undef FORWARD_DECLARE_EACH_CLASS |
|
468 |
||
469 |
||
470 |
||
471 |
inline relocInfo filler_relocInfo() { |
|
472 |
return relocInfo(relocInfo::none, relocInfo::offset_limit() - relocInfo::offset_unit); |
|
473 |
} |
|
474 |
||
475 |
inline relocInfo prefix_relocInfo(int datalen) { |
|
476 |
assert(relocInfo::fits_into_immediate(datalen), "datalen in limits"); |
|
477 |
return relocInfo(relocInfo::data_prefix_tag, relocInfo::RAW_BITS, relocInfo::datalen_tag | datalen); |
|
478 |
} |
|
479 |
||
480 |
||
481 |
// Holder for flyweight relocation objects. |
|
482 |
// Although the flyweight subclasses are of varying sizes, |
|
483 |
// the holder is "one size fits all". |
|
484 |
class RelocationHolder VALUE_OBJ_CLASS_SPEC { |
|
485 |
friend class Relocation; |
|
486 |
friend class CodeSection; |
|
487 |
||
488 |
private: |
|
489 |
// this preallocated memory must accommodate all subclasses of Relocation |
|
490 |
// (this number is assertion-checked in Relocation::operator new) |
|
491 |
enum { _relocbuf_size = 5 }; |
|
492 |
void* _relocbuf[ _relocbuf_size ]; |
|
493 |
||
494 |
public: |
|
495 |
Relocation* reloc() const { return (Relocation*) &_relocbuf[0]; } |
|
496 |
inline relocInfo::relocType type() const; |
|
497 |
||
498 |
// Add a constant offset to a relocation. Helper for class Address. |
|
499 |
RelocationHolder plus(int offset) const; |
|
500 |
||
501 |
inline RelocationHolder(); // initializes type to none |
|
502 |
||
503 |
inline RelocationHolder(Relocation* r); // make a copy |
|
504 |
||
505 |
static const RelocationHolder none; |
|
506 |
}; |
|
507 |
||
508 |
// A RelocIterator iterates through the relocation information of a CodeBlob. |
|
509 |
// It is a variable BoundRelocation which is able to take on successive |
|
510 |
// values as it is advanced through a code stream. |
|
511 |
// Usage: |
|
512 |
// RelocIterator iter(nm); |
|
513 |
// while (iter.next()) { |
|
514 |
// iter.reloc()->some_operation(); |
|
515 |
// } |
|
516 |
// or: |
|
517 |
// RelocIterator iter(nm); |
|
518 |
// while (iter.next()) { |
|
519 |
// switch (iter.type()) { |
|
520 |
// case relocInfo::oop_type : |
|
521 |
// case relocInfo::ic_type : |
|
522 |
// case relocInfo::prim_type : |
|
523 |
// case relocInfo::uncommon_type : |
|
524 |
// case relocInfo::runtime_call_type : |
|
525 |
// case relocInfo::internal_word_type: |
|
526 |
// case relocInfo::external_word_type: |
|
527 |
// ... |
|
528 |
// } |
|
529 |
// } |
|
530 |
||
531 |
class RelocIterator : public StackObj { |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
532 |
enum { SECT_LIMIT = 3 }; // must be equal to CodeBuffer::SECT_LIMIT, checked in ctor |
1 | 533 |
friend class Relocation; |
534 |
friend class relocInfo; // for change_reloc_info_for_address only |
|
535 |
typedef relocInfo::relocType relocType; |
|
536 |
||
537 |
private: |
|
538 |
address _limit; // stop producing relocations after this _addr |
|
539 |
relocInfo* _current; // the current relocation information |
|
540 |
relocInfo* _end; // end marker; we're done iterating when _current == _end |
|
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
541 |
nmethod* _code; // compiled method containing _addr |
1 | 542 |
address _addr; // instruction to which the relocation applies |
543 |
short _databuf; // spare buffer for compressed data |
|
544 |
short* _data; // pointer to the relocation's data |
|
545 |
short _datalen; // number of halfwords in _data |
|
546 |
char _format; // position within the instruction |
|
547 |
||
548 |
// Base addresses needed to compute targets of section_word_type relocs. |
|
549 |
address _section_start[SECT_LIMIT]; |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
550 |
address _section_end [SECT_LIMIT]; |
1 | 551 |
|
552 |
void set_has_current(bool b) { |
|
553 |
_datalen = !b ? -1 : 0; |
|
554 |
debug_only(_data = NULL); |
|
555 |
} |
|
556 |
void set_current(relocInfo& ri) { |
|
557 |
_current = &ri; |
|
558 |
set_has_current(true); |
|
559 |
} |
|
560 |
||
561 |
RelocationHolder _rh; // where the current relocation is allocated |
|
562 |
||
563 |
relocInfo* current() const { assert(has_current(), "must have current"); |
|
564 |
return _current; } |
|
565 |
||
566 |
void set_limits(address begin, address limit); |
|
567 |
||
568 |
void advance_over_prefix(); // helper method |
|
569 |
||
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
570 |
void initialize_misc(); |
1 | 571 |
|
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
572 |
void initialize(nmethod* nm, address begin, address limit); |
1 | 573 |
|
574 |
friend class PatchingRelocIterator; |
|
575 |
// make an uninitialized one, for PatchingRelocIterator: |
|
576 |
RelocIterator() { initialize_misc(); } |
|
577 |
||
578 |
public: |
|
579 |
// constructor |
|
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
580 |
RelocIterator(nmethod* nm, address begin = NULL, address limit = NULL); |
1 | 581 |
RelocIterator(CodeSection* cb, address begin = NULL, address limit = NULL); |
582 |
||
583 |
// get next reloc info, return !eos |
|
584 |
bool next() { |
|
585 |
_current++; |
|
586 |
assert(_current <= _end, "must not overrun relocInfo"); |
|
587 |
if (_current == _end) { |
|
588 |
set_has_current(false); |
|
589 |
return false; |
|
590 |
} |
|
591 |
set_has_current(true); |
|
592 |
||
593 |
if (_current->is_prefix()) { |
|
594 |
advance_over_prefix(); |
|
595 |
assert(!current()->is_prefix(), "only one prefix at a time"); |
|
596 |
} |
|
597 |
||
598 |
_addr += _current->addr_offset(); |
|
599 |
||
600 |
if (_limit != NULL && _addr >= _limit) { |
|
601 |
set_has_current(false); |
|
602 |
return false; |
|
603 |
} |
|
604 |
||
605 |
if (relocInfo::have_format) _format = current()->format(); |
|
606 |
return true; |
|
607 |
} |
|
608 |
||
609 |
// accessors |
|
610 |
address limit() const { return _limit; } |
|
611 |
void set_limit(address x); |
|
612 |
relocType type() const { return current()->type(); } |
|
613 |
int format() const { return (relocInfo::have_format) ? current()->format() : 0; } |
|
614 |
address addr() const { return _addr; } |
|
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
615 |
nmethod* code() const { return _code; } |
1 | 616 |
short* data() const { return _data; } |
617 |
int datalen() const { return _datalen; } |
|
618 |
bool has_current() const { return _datalen >= 0; } |
|
619 |
||
620 |
void set_addr(address addr) { _addr = addr; } |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
621 |
bool addr_in_const() const; |
1 | 622 |
|
623 |
address section_start(int n) const { |
|
6432
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
624 |
assert(_section_start[n], "must be initialized"); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
625 |
return _section_start[n]; |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
626 |
} |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
627 |
address section_end(int n) const { |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
628 |
assert(_section_end[n], "must be initialized"); |
d36e09b60939
6961697: move nmethod constants section before instruction section
twisti
parents:
5702
diff
changeset
|
629 |
return _section_end[n]; |
1 | 630 |
} |
631 |
||
632 |
// The address points to the affected displacement part of the instruction. |
|
633 |
// For RISC, this is just the whole instruction. |
|
634 |
// For Intel, this is an unaligned 32-bit word. |
|
635 |
||
636 |
// type-specific relocation accessors: oop_Relocation* oop_reloc(), etc. |
|
637 |
#define EACH_TYPE(name) \ |
|
638 |
inline name##_Relocation* name##_reloc(); |
|
639 |
APPLY_TO_RELOCATIONS(EACH_TYPE) |
|
640 |
#undef EACH_TYPE |
|
641 |
// generic relocation accessor; switches on type to call the above |
|
642 |
Relocation* reloc(); |
|
643 |
||
644 |
// CodeBlob's have relocation indexes for faster random access: |
|
645 |
static int locs_and_index_size(int code_size, int locs_size); |
|
646 |
// Store an index into [dest_start+dest_count..dest_end). |
|
647 |
// At dest_start[0..dest_count] is the actual relocation information. |
|
648 |
// Everything else up to dest_end is free space for the index. |
|
649 |
static void create_index(relocInfo* dest_begin, int dest_count, relocInfo* dest_end); |
|
650 |
||
651 |
#ifndef PRODUCT |
|
652 |
public: |
|
653 |
void print(); |
|
654 |
void print_current(); |
|
655 |
#endif |
|
656 |
}; |
|
657 |
||
658 |
||
659 |
// A Relocation is a flyweight object allocated within a RelocationHolder. |
|
660 |
// It represents the relocation data of relocation record. |
|
661 |
// So, the RelocIterator unpacks relocInfos into Relocations. |
|
662 |
||
663 |
class Relocation VALUE_OBJ_CLASS_SPEC { |
|
664 |
friend class RelocationHolder; |
|
665 |
friend class RelocIterator; |
|
666 |
||
667 |
private: |
|
668 |
static void guarantee_size(); |
|
669 |
||
670 |
// When a relocation has been created by a RelocIterator, |
|
671 |
// this field is non-null. It allows the relocation to know |
|
672 |
// its context, such as the address to which it applies. |
|
673 |
RelocIterator* _binding; |
|
674 |
||
675 |
protected: |
|
676 |
RelocIterator* binding() const { |
|
677 |
assert(_binding != NULL, "must be bound"); |
|
678 |
return _binding; |
|
679 |
} |
|
680 |
void set_binding(RelocIterator* b) { |
|
681 |
assert(_binding == NULL, "must be unbound"); |
|
682 |
_binding = b; |
|
683 |
assert(_binding != NULL, "must now be bound"); |
|
684 |
} |
|
685 |
||
686 |
Relocation() { |
|
687 |
_binding = NULL; |
|
688 |
} |
|
689 |
||
690 |
static RelocationHolder newHolder() { |
|
691 |
return RelocationHolder(); |
|
692 |
} |
|
693 |
||
694 |
public: |
|
695 |
void* operator new(size_t size, const RelocationHolder& holder) { |
|
696 |
if (size > sizeof(holder._relocbuf)) guarantee_size(); |
|
697 |
assert((void* const *)holder.reloc() == &holder._relocbuf[0], "ptrs must agree"); |
|
698 |
return holder.reloc(); |
|
699 |
} |
|
700 |
||
701 |
// make a generic relocation for a given type (if possible) |
|
702 |
static RelocationHolder spec_simple(relocInfo::relocType rtype); |
|
703 |
||
704 |
// here is the type-specific hook which writes relocation data: |
|
705 |
virtual void pack_data_to(CodeSection* dest) { } |
|
706 |
||
707 |
// here is the type-specific hook which reads (unpacks) relocation data: |
|
708 |
virtual void unpack_data() { |
|
709 |
assert(datalen()==0 || type()==relocInfo::none, "no data here"); |
|
710 |
} |
|
711 |
||
9111
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
712 |
static bool is_reloc_index(intptr_t index) { |
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
713 |
return 0 < index && index < os::vm_page_size(); |
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
714 |
} |
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
715 |
|
1 | 716 |
protected: |
717 |
// Helper functions for pack_data_to() and unpack_data(). |
|
718 |
||
719 |
// Most of the compression logic is confined here. |
|
720 |
// (The "immediate data" mechanism of relocInfo works independently |
|
721 |
// of this stuff, and acts to further compress most 1-word data prefixes.) |
|
722 |
||
723 |
// A variable-width int is encoded as a short if it will fit in 16 bits. |
|
724 |
// The decoder looks at datalen to decide whether to unpack short or jint. |
|
725 |
// Most relocation records are quite simple, containing at most two ints. |
|
726 |
||
727 |
static bool is_short(jint x) { return x == (short)x; } |
|
728 |
static short* add_short(short* p, int x) { *p++ = x; return p; } |
|
729 |
static short* add_jint (short* p, jint x) { |
|
730 |
*p++ = relocInfo::data0_from_int(x); *p++ = relocInfo::data1_from_int(x); |
|
731 |
return p; |
|
732 |
} |
|
733 |
static short* add_var_int(short* p, jint x) { // add a variable-width int |
|
734 |
if (is_short(x)) p = add_short(p, x); |
|
735 |
else p = add_jint (p, x); |
|
736 |
return p; |
|
737 |
} |
|
738 |
||
739 |
static short* pack_1_int_to(short* p, jint x0) { |
|
740 |
// Format is one of: [] [x] [Xx] |
|
741 |
if (x0 != 0) p = add_var_int(p, x0); |
|
742 |
return p; |
|
743 |
} |
|
744 |
int unpack_1_int() { |
|
745 |
assert(datalen() <= 2, "too much data"); |
|
746 |
return relocInfo::jint_data_at(0, data(), datalen()); |
|
747 |
} |
|
748 |
||
749 |
// With two ints, the short form is used only if both ints are short. |
|
750 |
short* pack_2_ints_to(short* p, jint x0, jint x1) { |
|
751 |
// Format is one of: [] [x y?] [Xx Y?y] |
|
752 |
if (x0 == 0 && x1 == 0) { |
|
753 |
// no halfwords needed to store zeroes |
|
754 |
} else if (is_short(x0) && is_short(x1)) { |
|
755 |
// 1-2 halfwords needed to store shorts |
|
756 |
p = add_short(p, x0); if (x1!=0) p = add_short(p, x1); |
|
757 |
} else { |
|
758 |
// 3-4 halfwords needed to store jints |
|
759 |
p = add_jint(p, x0); p = add_var_int(p, x1); |
|
760 |
} |
|
761 |
return p; |
|
762 |
} |
|
763 |
void unpack_2_ints(jint& x0, jint& x1) { |
|
764 |
int dlen = datalen(); |
|
765 |
short* dp = data(); |
|
766 |
if (dlen <= 2) { |
|
767 |
x0 = relocInfo::short_data_at(0, dp, dlen); |
|
768 |
x1 = relocInfo::short_data_at(1, dp, dlen); |
|
769 |
} else { |
|
770 |
assert(dlen <= 4, "too much data"); |
|
771 |
x0 = relocInfo::jint_data_at(0, dp, dlen); |
|
772 |
x1 = relocInfo::jint_data_at(2, dp, dlen); |
|
773 |
} |
|
774 |
} |
|
775 |
||
776 |
protected: |
|
777 |
// platform-dependent utilities for decoding and patching instructions |
|
8724
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
778 |
void pd_set_data_value (address x, intptr_t off, bool verify_only = false); // a set or mem-ref |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
779 |
void pd_verify_data_value (address x, intptr_t off) { pd_set_data_value(x, off, true); } |
1 | 780 |
address pd_call_destination (address orig_addr = NULL); |
781 |
void pd_set_call_destination (address x); |
|
782 |
void pd_swap_in_breakpoint (address x, short* instrs, int instrlen); |
|
783 |
void pd_swap_out_breakpoint (address x, short* instrs, int instrlen); |
|
784 |
static int pd_breakpoint_size (); |
|
785 |
||
786 |
// this extracts the address of an address in the code stream instead of the reloc data |
|
787 |
address* pd_address_in_code (); |
|
788 |
||
789 |
// this extracts an address from the code stream instead of the reloc data |
|
790 |
address pd_get_address_from_code (); |
|
791 |
||
792 |
// these convert from byte offsets, to scaled offsets, to addresses |
|
793 |
static jint scaled_offset(address x, address base) { |
|
794 |
int byte_offset = x - base; |
|
795 |
int offset = -byte_offset / relocInfo::addr_unit(); |
|
796 |
assert(address_from_scaled_offset(offset, base) == x, "just checkin'"); |
|
797 |
return offset; |
|
798 |
} |
|
799 |
static jint scaled_offset_null_special(address x, address base) { |
|
800 |
// Some relocations treat offset=0 as meaning NULL. |
|
801 |
// Handle this extra convention carefully. |
|
802 |
if (x == NULL) return 0; |
|
803 |
assert(x != base, "offset must not be zero"); |
|
804 |
return scaled_offset(x, base); |
|
805 |
} |
|
806 |
static address address_from_scaled_offset(jint offset, address base) { |
|
807 |
int byte_offset = -( offset * relocInfo::addr_unit() ); |
|
808 |
return base + byte_offset; |
|
809 |
} |
|
810 |
||
811 |
// these convert between indexes and addresses in the runtime system |
|
812 |
static int32_t runtime_address_to_index(address runtime_address); |
|
813 |
static address index_to_runtime_address(int32_t index); |
|
814 |
||
815 |
// helpers for mapping between old and new addresses after a move or resize |
|
816 |
address old_addr_for(address newa, const CodeBuffer* src, CodeBuffer* dest); |
|
817 |
address new_addr_for(address olda, const CodeBuffer* src, CodeBuffer* dest); |
|
818 |
void normalize_address(address& addr, const CodeSection* dest, bool allow_other_sections = false); |
|
819 |
||
820 |
public: |
|
821 |
// accessors which only make sense for a bound Relocation |
|
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
822 |
address addr() const { return binding()->addr(); } |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
823 |
nmethod* code() const { return binding()->code(); } |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
824 |
bool addr_in_const() const { return binding()->addr_in_const(); } |
1 | 825 |
protected: |
826 |
short* data() const { return binding()->data(); } |
|
827 |
int datalen() const { return binding()->datalen(); } |
|
828 |
int format() const { return binding()->format(); } |
|
829 |
||
830 |
public: |
|
831 |
virtual relocInfo::relocType type() { return relocInfo::none; } |
|
832 |
||
833 |
// is it a call instruction? |
|
834 |
virtual bool is_call() { return false; } |
|
835 |
||
836 |
// is it a data movement instruction? |
|
837 |
virtual bool is_data() { return false; } |
|
838 |
||
839 |
// some relocations can compute their own values |
|
840 |
virtual address value(); |
|
841 |
||
842 |
// all relocations are able to reassert their values |
|
843 |
virtual void set_value(address x); |
|
844 |
||
845 |
virtual void clear_inline_cache() { } |
|
846 |
||
847 |
// This method assumes that all virtual/static (inline) caches are cleared (since for static_call_type and |
|
848 |
// ic_call_type is not always posisition dependent (depending on the state of the cache)). However, this is |
|
849 |
// probably a reasonable assumption, since empty caches simplifies code reloacation. |
|
850 |
virtual void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { } |
|
851 |
||
852 |
void print(); |
|
853 |
}; |
|
854 |
||
855 |
||
856 |
// certain inlines must be deferred until class Relocation is defined: |
|
857 |
||
858 |
inline RelocationHolder::RelocationHolder() { |
|
859 |
// initialize the vtbl, just to keep things type-safe |
|
860 |
new(*this) Relocation(); |
|
861 |
} |
|
862 |
||
863 |
||
864 |
inline RelocationHolder::RelocationHolder(Relocation* r) { |
|
865 |
// wordwise copy from r (ok if it copies garbage after r) |
|
866 |
for (int i = 0; i < _relocbuf_size; i++) { |
|
867 |
_relocbuf[i] = ((void**)r)[i]; |
|
868 |
} |
|
869 |
} |
|
870 |
||
871 |
||
872 |
relocInfo::relocType RelocationHolder::type() const { |
|
873 |
return reloc()->type(); |
|
874 |
} |
|
875 |
||
876 |
// A DataRelocation always points at a memory or load-constant instruction.. |
|
877 |
// It is absolute on most machines, and the constant is split on RISCs. |
|
878 |
// The specific subtypes are oop, external_word, and internal_word. |
|
879 |
// By convention, the "value" does not include a separately reckoned "offset". |
|
880 |
class DataRelocation : public Relocation { |
|
881 |
public: |
|
882 |
bool is_data() { return true; } |
|
883 |
||
884 |
// both target and offset must be computed somehow from relocation data |
|
885 |
virtual int offset() { return 0; } |
|
886 |
address value() = 0; |
|
887 |
void set_value(address x) { set_value(x, offset()); } |
|
888 |
void set_value(address x, intptr_t o) { |
|
889 |
if (addr_in_const()) |
|
890 |
*(address*)addr() = x; |
|
891 |
else |
|
892 |
pd_set_data_value(x, o); |
|
893 |
} |
|
8724
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
894 |
void verify_value(address x) { |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
895 |
if (addr_in_const()) |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
896 |
assert(*(address*)addr() == x, "must agree"); |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
897 |
else |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
898 |
pd_verify_data_value(x, offset()); |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
899 |
} |
1 | 900 |
|
901 |
// The "o" (displacement) argument is relevant only to split relocations |
|
902 |
// on RISC machines. In some CPUs (SPARC), the set-hi and set-lo ins'ns |
|
903 |
// can encode more than 32 bits between them. This allows compilers to |
|
904 |
// share set-hi instructions between addresses that differ by a small |
|
905 |
// offset (e.g., different static variables in the same class). |
|
906 |
// On such machines, the "x" argument to set_value on all set-lo |
|
907 |
// instructions must be the same as the "x" argument for the |
|
908 |
// corresponding set-hi instructions. The "o" arguments for the |
|
909 |
// set-hi instructions are ignored, and must not affect the high-half |
|
910 |
// immediate constant. The "o" arguments for the set-lo instructions are |
|
911 |
// added into the low-half immediate constant, and must not overflow it. |
|
912 |
}; |
|
913 |
||
914 |
// A CallRelocation always points at a call instruction. |
|
915 |
// It is PC-relative on most machines. |
|
916 |
class CallRelocation : public Relocation { |
|
917 |
public: |
|
918 |
bool is_call() { return true; } |
|
919 |
||
920 |
address destination() { return pd_call_destination(); } |
|
921 |
void set_destination(address x); // pd_set_call_destination |
|
922 |
||
923 |
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest); |
|
924 |
address value() { return destination(); } |
|
925 |
void set_value(address x) { set_destination(x); } |
|
926 |
}; |
|
927 |
||
928 |
class oop_Relocation : public DataRelocation { |
|
929 |
relocInfo::relocType type() { return relocInfo::oop_type; } |
|
930 |
||
931 |
public: |
|
932 |
// encode in one of these formats: [] [n] [n l] [Nn l] [Nn Ll] |
|
933 |
// an oop in the CodeBlob's oop pool |
|
934 |
static RelocationHolder spec(int oop_index, int offset = 0) { |
|
935 |
assert(oop_index > 0, "must be a pool-resident oop"); |
|
936 |
RelocationHolder rh = newHolder(); |
|
937 |
new(rh) oop_Relocation(oop_index, offset); |
|
938 |
return rh; |
|
939 |
} |
|
940 |
// an oop in the instruction stream |
|
941 |
static RelocationHolder spec_for_immediate() { |
|
942 |
const int oop_index = 0; |
|
943 |
const int offset = 0; // if you want an offset, use the oop pool |
|
944 |
RelocationHolder rh = newHolder(); |
|
945 |
new(rh) oop_Relocation(oop_index, offset); |
|
946 |
return rh; |
|
947 |
} |
|
948 |
||
949 |
private: |
|
950 |
jint _oop_index; // if > 0, index into CodeBlob::oop_at |
|
951 |
jint _offset; // byte offset to apply to the oop itself |
|
952 |
||
953 |
oop_Relocation(int oop_index, int offset) { |
|
954 |
_oop_index = oop_index; _offset = offset; |
|
955 |
} |
|
956 |
||
957 |
friend class RelocIterator; |
|
958 |
oop_Relocation() { } |
|
959 |
||
960 |
public: |
|
961 |
int oop_index() { return _oop_index; } |
|
962 |
int offset() { return _offset; } |
|
963 |
||
964 |
// data is packed in "2_ints" format: [i o] or [Ii Oo] |
|
965 |
void pack_data_to(CodeSection* dest); |
|
966 |
void unpack_data(); |
|
967 |
||
968 |
void fix_oop_relocation(); // reasserts oop value |
|
969 |
||
8724
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
970 |
void verify_oop_relocation(); |
693c6b883b54
7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents:
8107
diff
changeset
|
971 |
|
1 | 972 |
address value() { return (address) *oop_addr(); } |
973 |
||
974 |
bool oop_is_immediate() { return oop_index() == 0; } |
|
975 |
||
976 |
oop* oop_addr(); // addr or &pool[jint_data] |
|
977 |
oop oop_value(); // *oop_addr |
|
978 |
// Note: oop_value transparently converts Universe::non_oop_word to NULL. |
|
979 |
}; |
|
980 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
981 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
982 |
// copy of oop_Relocation for now but may delete stuff in both/either |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
983 |
class metadata_Relocation : public DataRelocation { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
984 |
relocInfo::relocType type() { return relocInfo::metadata_type; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
985 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
986 |
public: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
987 |
// encode in one of these formats: [] [n] [n l] [Nn l] [Nn Ll] |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
988 |
// an metadata in the CodeBlob's metadata pool |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
989 |
static RelocationHolder spec(int metadata_index, int offset = 0) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
990 |
assert(metadata_index > 0, "must be a pool-resident metadata"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
991 |
RelocationHolder rh = newHolder(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
992 |
new(rh) metadata_Relocation(metadata_index, offset); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
993 |
return rh; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
994 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
995 |
// an metadata in the instruction stream |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
996 |
static RelocationHolder spec_for_immediate() { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
997 |
const int metadata_index = 0; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
998 |
const int offset = 0; // if you want an offset, use the metadata pool |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
999 |
RelocationHolder rh = newHolder(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1000 |
new(rh) metadata_Relocation(metadata_index, offset); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1001 |
return rh; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1002 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1003 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1004 |
private: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1005 |
jint _metadata_index; // if > 0, index into nmethod::metadata_at |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1006 |
jint _offset; // byte offset to apply to the metadata itself |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1007 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1008 |
metadata_Relocation(int metadata_index, int offset) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1009 |
_metadata_index = metadata_index; _offset = offset; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1010 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1011 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1012 |
friend class RelocIterator; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1013 |
metadata_Relocation() { } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1014 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1015 |
// Fixes a Metadata pointer in the code. Most platforms embeds the |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1016 |
// Metadata pointer in the code at compile time so this is empty |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1017 |
// for them. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1018 |
void pd_fix_value(address x); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1019 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1020 |
public: |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1021 |
int metadata_index() { return _metadata_index; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1022 |
int offset() { return _offset; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1023 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1024 |
// data is packed in "2_ints" format: [i o] or [Ii Oo] |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1025 |
void pack_data_to(CodeSection* dest); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1026 |
void unpack_data(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1027 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1028 |
void fix_metadata_relocation(); // reasserts metadata value |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1029 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1030 |
void verify_metadata_relocation(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1031 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1032 |
address value() { return (address) *metadata_addr(); } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1033 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1034 |
bool metadata_is_immediate() { return metadata_index() == 0; } |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1035 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1036 |
Metadata** metadata_addr(); // addr or &pool[jint_data] |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1037 |
Metadata* metadata_value(); // *metadata_addr |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1038 |
// Note: metadata_value transparently converts Universe::non_metadata_word to NULL. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1039 |
}; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1040 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1041 |
|
1 | 1042 |
class virtual_call_Relocation : public CallRelocation { |
1043 |
relocInfo::relocType type() { return relocInfo::virtual_call_type; } |
|
1044 |
||
1045 |
public: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1046 |
// "cached_value" points to the first associated set-oop. |
1 | 1047 |
// The oop_limit helps find the last associated set-oop. |
1048 |
// (See comments at the top of this file.) |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1049 |
static RelocationHolder spec(address cached_value) { |
1 | 1050 |
RelocationHolder rh = newHolder(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1051 |
new(rh) virtual_call_Relocation(cached_value); |
1 | 1052 |
return rh; |
1053 |
} |
|
1054 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1055 |
virtual_call_Relocation(address cached_value) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1056 |
_cached_value = cached_value; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1057 |
assert(cached_value != NULL, "first oop address must be specified"); |
1 | 1058 |
} |
1059 |
||
1060 |
private: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1061 |
address _cached_value; // location of set-value instruction |
1 | 1062 |
|
1063 |
friend class RelocIterator; |
|
1064 |
virtual_call_Relocation() { } |
|
1065 |
||
1066 |
||
1067 |
public: |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
9124
diff
changeset
|
1068 |
address cached_value(); |
1 | 1069 |
|
1070 |
// data is packed as scaled offsets in "2_ints" format: [f l] or [Ff Ll] |
|
1071 |
// oop_limit is set to 0 if the limit falls somewhere within the call. |
|
1072 |
// When unpacking, a zero oop_limit is taken to refer to the end of the call. |
|
1073 |
// (This has the effect of bringing in the call's delay slot on SPARC.) |
|
1074 |
void pack_data_to(CodeSection* dest); |
|
1075 |
void unpack_data(); |
|
1076 |
||
1077 |
void clear_inline_cache(); |
|
1078 |
}; |
|
1079 |
||
1080 |
||
1081 |
class opt_virtual_call_Relocation : public CallRelocation { |
|
1082 |
relocInfo::relocType type() { return relocInfo::opt_virtual_call_type; } |
|
1083 |
||
1084 |
public: |
|
1085 |
static RelocationHolder spec() { |
|
1086 |
RelocationHolder rh = newHolder(); |
|
1087 |
new(rh) opt_virtual_call_Relocation(); |
|
1088 |
return rh; |
|
1089 |
} |
|
1090 |
||
1091 |
private: |
|
1092 |
friend class RelocIterator; |
|
1093 |
opt_virtual_call_Relocation() { } |
|
1094 |
||
1095 |
public: |
|
1096 |
void clear_inline_cache(); |
|
1097 |
||
1098 |
// find the matching static_stub |
|
1099 |
address static_stub(); |
|
1100 |
}; |
|
1101 |
||
1102 |
||
1103 |
class static_call_Relocation : public CallRelocation { |
|
1104 |
relocInfo::relocType type() { return relocInfo::static_call_type; } |
|
1105 |
||
1106 |
public: |
|
1107 |
static RelocationHolder spec() { |
|
1108 |
RelocationHolder rh = newHolder(); |
|
1109 |
new(rh) static_call_Relocation(); |
|
1110 |
return rh; |
|
1111 |
} |
|
1112 |
||
1113 |
private: |
|
1114 |
friend class RelocIterator; |
|
1115 |
static_call_Relocation() { } |
|
1116 |
||
1117 |
public: |
|
1118 |
void clear_inline_cache(); |
|
1119 |
||
1120 |
// find the matching static_stub |
|
1121 |
address static_stub(); |
|
1122 |
}; |
|
1123 |
||
1124 |
class static_stub_Relocation : public Relocation { |
|
1125 |
relocInfo::relocType type() { return relocInfo::static_stub_type; } |
|
1126 |
||
1127 |
public: |
|
1128 |
static RelocationHolder spec(address static_call) { |
|
1129 |
RelocationHolder rh = newHolder(); |
|
1130 |
new(rh) static_stub_Relocation(static_call); |
|
1131 |
return rh; |
|
1132 |
} |
|
1133 |
||
1134 |
private: |
|
1135 |
address _static_call; // location of corresponding static_call |
|
1136 |
||
1137 |
static_stub_Relocation(address static_call) { |
|
1138 |
_static_call = static_call; |
|
1139 |
} |
|
1140 |
||
1141 |
friend class RelocIterator; |
|
1142 |
static_stub_Relocation() { } |
|
1143 |
||
1144 |
public: |
|
1145 |
void clear_inline_cache(); |
|
1146 |
||
1147 |
address static_call() { return _static_call; } |
|
1148 |
||
1149 |
// data is packed as a scaled offset in "1_int" format: [c] or [Cc] |
|
1150 |
void pack_data_to(CodeSection* dest); |
|
1151 |
void unpack_data(); |
|
1152 |
}; |
|
1153 |
||
1154 |
class runtime_call_Relocation : public CallRelocation { |
|
1155 |
relocInfo::relocType type() { return relocInfo::runtime_call_type; } |
|
1156 |
||
1157 |
public: |
|
1158 |
static RelocationHolder spec() { |
|
1159 |
RelocationHolder rh = newHolder(); |
|
1160 |
new(rh) runtime_call_Relocation(); |
|
1161 |
return rh; |
|
1162 |
} |
|
1163 |
||
1164 |
private: |
|
1165 |
friend class RelocIterator; |
|
1166 |
runtime_call_Relocation() { } |
|
1167 |
||
1168 |
public: |
|
1169 |
}; |
|
1170 |
||
1171 |
class external_word_Relocation : public DataRelocation { |
|
1172 |
relocInfo::relocType type() { return relocInfo::external_word_type; } |
|
1173 |
||
1174 |
public: |
|
1175 |
static RelocationHolder spec(address target) { |
|
1176 |
assert(target != NULL, "must not be null"); |
|
1177 |
RelocationHolder rh = newHolder(); |
|
1178 |
new(rh) external_word_Relocation(target); |
|
1179 |
return rh; |
|
1180 |
} |
|
1181 |
||
1182 |
// Use this one where all 32/64 bits of the target live in the code stream. |
|
1183 |
// The target must be an intptr_t, and must be absolute (not relative). |
|
1184 |
static RelocationHolder spec_for_immediate() { |
|
1185 |
RelocationHolder rh = newHolder(); |
|
1186 |
new(rh) external_word_Relocation(NULL); |
|
1187 |
return rh; |
|
1188 |
} |
|
1189 |
||
9111
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
1190 |
// Some address looking values aren't safe to treat as relocations |
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
1191 |
// and should just be treated as constants. |
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
1192 |
static bool can_be_relocated(address target) { |
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
1193 |
return target != NULL && !is_reloc_index((intptr_t)target); |
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
1194 |
} |
c100c09c66f2
6777083: assert(target != __null,"must not be null")
never
parents:
8724
diff
changeset
|
1195 |
|
1 | 1196 |
private: |
1197 |
address _target; // address in runtime |
|
1198 |
||
1199 |
external_word_Relocation(address target) { |
|
1200 |
_target = target; |
|
1201 |
} |
|
1202 |
||
1203 |
friend class RelocIterator; |
|
1204 |
external_word_Relocation() { } |
|
1205 |
||
1206 |
public: |
|
1207 |
// data is packed as a well-known address in "1_int" format: [a] or [Aa] |
|
1208 |
// The function runtime_address_to_index is used to turn full addresses |
|
1209 |
// to short indexes, if they are pre-registered by the stub mechanism. |
|
1210 |
// If the "a" value is 0 (i.e., _target is NULL), the address is stored |
|
1211 |
// in the code stream. See external_word_Relocation::target(). |
|
1212 |
void pack_data_to(CodeSection* dest); |
|
1213 |
void unpack_data(); |
|
1214 |
||
1215 |
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest); |
|
1216 |
address target(); // if _target==NULL, fetch addr from code stream |
|
1217 |
address value() { return target(); } |
|
1218 |
}; |
|
1219 |
||
1220 |
class internal_word_Relocation : public DataRelocation { |
|
1221 |
relocInfo::relocType type() { return relocInfo::internal_word_type; } |
|
1222 |
||
1223 |
public: |
|
1224 |
static RelocationHolder spec(address target) { |
|
1225 |
assert(target != NULL, "must not be null"); |
|
1226 |
RelocationHolder rh = newHolder(); |
|
1227 |
new(rh) internal_word_Relocation(target); |
|
1228 |
return rh; |
|
1229 |
} |
|
1230 |
||
1231 |
// use this one where all the bits of the target can fit in the code stream: |
|
1232 |
static RelocationHolder spec_for_immediate() { |
|
1233 |
RelocationHolder rh = newHolder(); |
|
1234 |
new(rh) internal_word_Relocation(NULL); |
|
1235 |
return rh; |
|
1236 |
} |
|
1237 |
||
1238 |
internal_word_Relocation(address target) { |
|
1239 |
_target = target; |
|
1240 |
_section = -1; // self-relative |
|
1241 |
} |
|
1242 |
||
1243 |
protected: |
|
1244 |
address _target; // address in CodeBlob |
|
1245 |
int _section; // section providing base address, if any |
|
1246 |
||
1247 |
friend class RelocIterator; |
|
1248 |
internal_word_Relocation() { } |
|
1249 |
||
1250 |
// bit-width of LSB field in packed offset, if section >= 0 |
|
1251 |
enum { section_width = 2 }; // must equal CodeBuffer::sect_bits |
|
1252 |
||
1253 |
public: |
|
1254 |
// data is packed as a scaled offset in "1_int" format: [o] or [Oo] |
|
1255 |
// If the "o" value is 0 (i.e., _target is NULL), the offset is stored |
|
1256 |
// in the code stream. See internal_word_Relocation::target(). |
|
1257 |
// If _section is not -1, it is appended to the low bits of the offset. |
|
1258 |
void pack_data_to(CodeSection* dest); |
|
1259 |
void unpack_data(); |
|
1260 |
||
1261 |
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest); |
|
1262 |
address target(); // if _target==NULL, fetch addr from code stream |
|
1263 |
int section() { return _section; } |
|
1264 |
address value() { return target(); } |
|
1265 |
}; |
|
1266 |
||
1267 |
class section_word_Relocation : public internal_word_Relocation { |
|
1268 |
relocInfo::relocType type() { return relocInfo::section_word_type; } |
|
1269 |
||
1270 |
public: |
|
1271 |
static RelocationHolder spec(address target, int section) { |
|
1272 |
RelocationHolder rh = newHolder(); |
|
1273 |
new(rh) section_word_Relocation(target, section); |
|
1274 |
return rh; |
|
1275 |
} |
|
1276 |
||
1277 |
section_word_Relocation(address target, int section) { |
|
1278 |
assert(target != NULL, "must not be null"); |
|
1279 |
assert(section >= 0, "must be a valid section"); |
|
1280 |
_target = target; |
|
1281 |
_section = section; |
|
1282 |
} |
|
1283 |
||
1284 |
//void pack_data_to -- inherited |
|
1285 |
void unpack_data(); |
|
1286 |
||
1287 |
private: |
|
1288 |
friend class RelocIterator; |
|
1289 |
section_word_Relocation() { } |
|
1290 |
}; |
|
1291 |
||
1292 |
||
1293 |
class poll_Relocation : public Relocation { |
|
1294 |
bool is_data() { return true; } |
|
1295 |
relocInfo::relocType type() { return relocInfo::poll_type; } |
|
1066 | 1296 |
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest); |
1 | 1297 |
}; |
1298 |
||
1299 |
class poll_return_Relocation : public Relocation { |
|
1300 |
bool is_data() { return true; } |
|
1301 |
relocInfo::relocType type() { return relocInfo::poll_return_type; } |
|
1066 | 1302 |
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest); |
1 | 1303 |
}; |
1304 |
||
1305 |
||
1306 |
class breakpoint_Relocation : public Relocation { |
|
1307 |
relocInfo::relocType type() { return relocInfo::breakpoint_type; } |
|
1308 |
||
1309 |
enum { |
|
1310 |
// attributes which affect the interpretation of the data: |
|
1311 |
removable_attr = 0x0010, // buffer [i...] allows for undoing the trap |
|
1312 |
internal_attr = 0x0020, // the target is an internal addr (local stub) |
|
1313 |
settable_attr = 0x0040, // the target is settable |
|
1314 |
||
1315 |
// states which can change over time: |
|
1316 |
enabled_state = 0x0100, // breakpoint must be active in running code |
|
1317 |
active_state = 0x0200, // breakpoint instruction actually in code |
|
1318 |
||
1319 |
kind_mask = 0x000F, // mask for extracting kind |
|
1320 |
high_bit = 0x4000 // extra bit which is always set |
|
1321 |
}; |
|
1322 |
||
1323 |
public: |
|
1324 |
enum { |
|
1325 |
// kinds: |
|
1326 |
initialization = 1, |
|
1327 |
safepoint = 2 |
|
1328 |
}; |
|
1329 |
||
1330 |
// If target is NULL, 32 bits are reserved for a later set_target(). |
|
1331 |
static RelocationHolder spec(int kind, address target = NULL, bool internal_target = false) { |
|
1332 |
RelocationHolder rh = newHolder(); |
|
1333 |
new(rh) breakpoint_Relocation(kind, target, internal_target); |
|
1334 |
return rh; |
|
1335 |
} |
|
1336 |
||
1337 |
private: |
|
1338 |
// We require every bits value to NOT to fit into relocInfo::datalen_width, |
|
1339 |
// because we are going to actually store state in the reloc, and so |
|
1340 |
// cannot allow it to be compressed (and hence copied by the iterator). |
|
1341 |
||
1342 |
short _bits; // bit-encoded kind, attrs, & state |
|
1343 |
address _target; |
|
1344 |
||
1345 |
breakpoint_Relocation(int kind, address target, bool internal_target); |
|
1346 |
||
1347 |
friend class RelocIterator; |
|
1348 |
breakpoint_Relocation() { } |
|
1349 |
||
1350 |
short bits() const { return _bits; } |
|
1351 |
short& live_bits() const { return data()[0]; } |
|
1352 |
short* instrs() const { return data() + datalen() - instrlen(); } |
|
1353 |
int instrlen() const { return removable() ? pd_breakpoint_size() : 0; } |
|
1354 |
||
1355 |
void set_bits(short x) { |
|
1356 |
assert(live_bits() == _bits, "must be the only mutator of reloc info"); |
|
1357 |
live_bits() = _bits = x; |
|
1358 |
} |
|
1359 |
||
1360 |
public: |
|
1361 |
address target() const; |
|
1362 |
void set_target(address x); |
|
1363 |
||
1364 |
int kind() const { return bits() & kind_mask; } |
|
1365 |
bool enabled() const { return (bits() & enabled_state) != 0; } |
|
1366 |
bool active() const { return (bits() & active_state) != 0; } |
|
1367 |
bool internal() const { return (bits() & internal_attr) != 0; } |
|
1368 |
bool removable() const { return (bits() & removable_attr) != 0; } |
|
1369 |
bool settable() const { return (bits() & settable_attr) != 0; } |
|
1370 |
||
1371 |
void set_enabled(bool b); // to activate, you must also say set_active |
|
1372 |
void set_active(bool b); // actually inserts bpt (must be enabled 1st) |
|
1373 |
||
1374 |
// data is packed as 16 bits, followed by the target (1 or 2 words), followed |
|
1375 |
// if necessary by empty storage for saving away original instruction bytes. |
|
1376 |
void pack_data_to(CodeSection* dest); |
|
1377 |
void unpack_data(); |
|
1378 |
||
1379 |
// during certain operations, breakpoints must be out of the way: |
|
1380 |
void fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { |
|
1381 |
assert(!active(), "cannot perform relocation on enabled breakpoints"); |
|
1382 |
} |
|
1383 |
}; |
|
1384 |
||
1385 |
||
1386 |
// We know all the xxx_Relocation classes, so now we can define these: |
|
1387 |
#define EACH_CASE(name) \ |
|
1388 |
inline name##_Relocation* RelocIterator::name##_reloc() { \ |
|
1389 |
assert(type() == relocInfo::name##_type, "type must agree"); \ |
|
1390 |
/* The purpose of the placed "new" is to re-use the same */ \ |
|
1391 |
/* stack storage for each new iteration. */ \ |
|
1392 |
name##_Relocation* r = new(_rh) name##_Relocation(); \ |
|
1393 |
r->set_binding(this); \ |
|
1394 |
r->name##_Relocation::unpack_data(); \ |
|
1395 |
return r; \ |
|
1396 |
} |
|
1397 |
APPLY_TO_RELOCATIONS(EACH_CASE); |
|
1398 |
#undef EACH_CASE |
|
1399 |
||
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
1400 |
inline RelocIterator::RelocIterator(nmethod* nm, address begin, address limit) { |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
1401 |
initialize(nm, begin, limit); |
1 | 1402 |
} |
1403 |
||
1404 |
// if you are going to patch code, you should use this subclass of |
|
1405 |
// RelocIterator |
|
1406 |
class PatchingRelocIterator : public RelocIterator { |
|
1407 |
private: |
|
1408 |
RelocIterator _init_state; |
|
1409 |
||
1410 |
void prepass(); // deactivates all breakpoints |
|
1411 |
void postpass(); // reactivates all enabled breakpoints |
|
1412 |
||
1413 |
// do not copy these puppies; it would have unpredictable side effects |
|
1414 |
// these are private and have no bodies defined because they should not be called |
|
1415 |
PatchingRelocIterator(const RelocIterator&); |
|
1416 |
void operator=(const RelocIterator&); |
|
1417 |
||
1418 |
public: |
|
5686
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
1419 |
PatchingRelocIterator(nmethod* nm, address begin = NULL, address limit = NULL) |
5435e77aa3df
6951083: oops and relocations should part of nmethod not CodeBlob
twisti
parents:
1217
diff
changeset
|
1420 |
: RelocIterator(nm, begin, limit) { prepass(); } |
1 | 1421 |
|
1422 |
~PatchingRelocIterator() { postpass(); } |
|
1423 |
}; |
|
7397 | 1424 |
|
1425 |
#endif // SHARE_VM_CODE_RELOCINFO_HPP |