Mercurial > hg > truffle
annotate src/share/vm/asm/codeBuffer.cpp @ 3456:782e2bb60c41
7052494: Eclipse test fails on JDK 7 b142
Summary: Keep 'ne' test in Counted loop when we can't guarantee during compilation that init < limit.
Reviewed-by: never
author | kvn |
---|---|
date | Mon, 20 Jun 2011 16:45:35 -0700 |
parents | 79d8657be916 |
children | 06f017f7daa7 754110e02bd5 |
rev | line source |
---|---|
0 | 1 /* |
1748 | 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
579
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:
579
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "asm/codeBuffer.hpp" | |
27 #include "compiler/disassembler.hpp" | |
28 #include "utilities/copy.hpp" | |
0 | 29 |
30 // The structure of a CodeSection: | |
31 // | |
32 // _start -> +----------------+ | |
33 // | machine code...| | |
34 // _end -> |----------------| | |
35 // | | | |
36 // | (empty) | | |
37 // | | | |
38 // | | | |
39 // +----------------+ | |
40 // _limit -> | | | |
41 // | |
42 // _locs_start -> +----------------+ | |
43 // |reloc records...| | |
44 // |----------------| | |
45 // _locs_end -> | | | |
46 // | | | |
47 // | (empty) | | |
48 // | | | |
49 // | | | |
50 // +----------------+ | |
51 // _locs_limit -> | | | |
52 // The _end (resp. _limit) pointer refers to the first | |
53 // unused (resp. unallocated) byte. | |
54 | |
55 // The structure of the CodeBuffer while code is being accumulated: | |
56 // | |
57 // _total_start -> \ | |
58 // _insts._start -> +----------------+ | |
59 // | | | |
60 // | Code | | |
61 // | | | |
62 // _stubs._start -> |----------------| | |
63 // | | | |
64 // | Stubs | (also handlers for deopt/exception) | |
65 // | | | |
66 // _consts._start -> |----------------| | |
67 // | | | |
68 // | Constants | | |
69 // | | | |
70 // +----------------+ | |
71 // + _total_size -> | | | |
72 // | |
73 // When the code and relocations are copied to the code cache, | |
74 // the empty parts of each section are removed, and everything | |
75 // is copied into contiguous locations. | |
76 | |
77 typedef CodeBuffer::csize_t csize_t; // file-local definition | |
78 | |
1748 | 79 // External buffer, in a predefined CodeBlob. |
0 | 80 // Important: The code_start must be taken exactly, and not realigned. |
1748 | 81 CodeBuffer::CodeBuffer(CodeBlob* blob) { |
0 | 82 initialize_misc("static buffer"); |
1748 | 83 initialize(blob->content_begin(), blob->content_size()); |
0 | 84 assert(verify_section_allocation(), "initial use of buffer OK"); |
85 } | |
86 | |
87 void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) { | |
88 // Compute maximal alignment. | |
89 int align = _insts.alignment(); | |
90 // Always allow for empty slop around each section. | |
91 int slop = (int) CodeSection::end_slop(); | |
92 | |
93 assert(blob() == NULL, "only once"); | |
94 set_blob(BufferBlob::create(_name, code_size + (align+slop) * (SECT_LIMIT+1))); | |
95 if (blob() == NULL) { | |
96 // The assembler constructor will throw a fatal on an empty CodeBuffer. | |
97 return; // caller must test this | |
98 } | |
99 | |
100 // Set up various pointers into the blob. | |
101 initialize(_total_start, _total_size); | |
102 | |
1748 | 103 assert((uintptr_t)insts_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned"); |
0 | 104 |
105 pd_initialize(); | |
106 | |
107 if (locs_size != 0) { | |
108 _insts.initialize_locs(locs_size / sizeof(relocInfo)); | |
109 } | |
110 | |
111 assert(verify_section_allocation(), "initial use of blob is OK"); | |
112 } | |
113 | |
114 | |
115 CodeBuffer::~CodeBuffer() { | |
116 // If we allocate our code buffer from the CodeCache | |
117 // via a BufferBlob, and it's not permanent, then | |
118 // free the BufferBlob. | |
119 // The rest of the memory will be freed when the ResourceObj | |
120 // is released. | |
121 assert(verify_section_allocation(), "final storage configuration still OK"); | |
122 for (CodeBuffer* cb = this; cb != NULL; cb = cb->before_expand()) { | |
123 // Previous incarnations of this buffer are held live, so that internal | |
124 // addresses constructed before expansions will not be confused. | |
125 cb->free_blob(); | |
126 } | |
561
5bfdb08ea692
6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents:
196
diff
changeset
|
127 |
5bfdb08ea692
6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents:
196
diff
changeset
|
128 // free any overflow storage |
5bfdb08ea692
6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents:
196
diff
changeset
|
129 delete _overflow_arena; |
5bfdb08ea692
6782260: Memory leak in CodeBuffer::create_patch_overflow
never
parents:
196
diff
changeset
|
130 |
0 | 131 #ifdef ASSERT |
1685 | 132 // Save allocation type to execute assert in ~ResourceObj() |
133 // which is called after this destructor. | |
2015
79d8657be916
6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents:
1972
diff
changeset
|
134 assert(_default_oop_recorder.allocated_on_stack(), "should be embedded object"); |
1685 | 135 ResourceObj::allocation_type at = _default_oop_recorder.get_allocation_type(); |
0 | 136 Copy::fill_to_bytes(this, sizeof(*this), badResourceValue); |
1685 | 137 ResourceObj::set_allocation_type((address)(&_default_oop_recorder), at); |
0 | 138 #endif |
139 } | |
140 | |
141 void CodeBuffer::initialize_oop_recorder(OopRecorder* r) { | |
142 assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once"); | |
143 DEBUG_ONLY(_default_oop_recorder.oop_size()); // force unused OR to be frozen | |
144 _oop_recorder = r; | |
145 } | |
146 | |
147 void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) { | |
148 assert(cs != &_insts, "insts is the memory provider, not the consumer"); | |
149 csize_t slop = CodeSection::end_slop(); // margin between sections | |
150 int align = cs->alignment(); | |
151 assert(is_power_of_2(align), "sanity"); | |
152 address start = _insts._start; | |
153 address limit = _insts._limit; | |
154 address middle = limit - size; | |
155 middle -= (intptr_t)middle & (align-1); // align the division point downward | |
156 guarantee(middle - slop > start, "need enough space to divide up"); | |
157 _insts._limit = middle - slop; // subtract desired space, plus slop | |
158 cs->initialize(middle, limit - middle); | |
159 assert(cs->start() == middle, "sanity"); | |
160 assert(cs->limit() == limit, "sanity"); | |
161 // give it some relocations to start with, if the main section has them | |
162 if (_insts.has_locs()) cs->initialize_locs(1); | |
163 } | |
164 | |
165 void CodeBuffer::freeze_section(CodeSection* cs) { | |
166 CodeSection* next_cs = (cs == consts())? NULL: code_section(cs->index()+1); | |
167 csize_t frozen_size = cs->size(); | |
168 if (next_cs != NULL) { | |
169 frozen_size = next_cs->align_at_start(frozen_size); | |
170 } | |
171 address old_limit = cs->limit(); | |
172 address new_limit = cs->start() + frozen_size; | |
173 relocInfo* old_locs_limit = cs->locs_limit(); | |
174 relocInfo* new_locs_limit = cs->locs_end(); | |
175 // Patch the limits. | |
176 cs->_limit = new_limit; | |
177 cs->_locs_limit = new_locs_limit; | |
178 cs->_frozen = true; | |
179 if (!next_cs->is_allocated() && !next_cs->is_frozen()) { | |
180 // Give remaining buffer space to the following section. | |
181 next_cs->initialize(new_limit, old_limit - new_limit); | |
182 next_cs->initialize_shared_locs(new_locs_limit, | |
183 old_locs_limit - new_locs_limit); | |
184 } | |
185 } | |
186 | |
187 void CodeBuffer::set_blob(BufferBlob* blob) { | |
188 _blob = blob; | |
189 if (blob != NULL) { | |
1748 | 190 address start = blob->content_begin(); |
191 address end = blob->content_end(); | |
0 | 192 // Round up the starting address. |
193 int align = _insts.alignment(); | |
194 start += (-(intptr_t)start) & (align-1); | |
195 _total_start = start; | |
196 _total_size = end - start; | |
197 } else { | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
198 #ifdef ASSERT |
0 | 199 // Clean out dangling pointers. |
200 _total_start = badAddress; | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
201 _consts._start = _consts._end = badAddress; |
0 | 202 _insts._start = _insts._end = badAddress; |
203 _stubs._start = _stubs._end = badAddress; | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
204 #endif //ASSERT |
0 | 205 } |
206 } | |
207 | |
208 void CodeBuffer::free_blob() { | |
209 if (_blob != NULL) { | |
210 BufferBlob::free(_blob); | |
211 set_blob(NULL); | |
212 } | |
213 } | |
214 | |
215 const char* CodeBuffer::code_section_name(int n) { | |
216 #ifdef PRODUCT | |
217 return NULL; | |
218 #else //PRODUCT | |
219 switch (n) { | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
220 case SECT_CONSTS: return "consts"; |
0 | 221 case SECT_INSTS: return "insts"; |
222 case SECT_STUBS: return "stubs"; | |
223 default: return NULL; | |
224 } | |
225 #endif //PRODUCT | |
226 } | |
227 | |
228 int CodeBuffer::section_index_of(address addr) const { | |
229 for (int n = 0; n < (int)SECT_LIMIT; n++) { | |
230 const CodeSection* cs = code_section(n); | |
231 if (cs->allocates(addr)) return n; | |
232 } | |
233 return SECT_NONE; | |
234 } | |
235 | |
236 int CodeBuffer::locator(address addr) const { | |
237 for (int n = 0; n < (int)SECT_LIMIT; n++) { | |
238 const CodeSection* cs = code_section(n); | |
239 if (cs->allocates(addr)) { | |
240 return locator(addr - cs->start(), n); | |
241 } | |
242 } | |
243 return -1; | |
244 } | |
245 | |
246 address CodeBuffer::locator_address(int locator) const { | |
247 if (locator < 0) return NULL; | |
248 address start = code_section(locator_sect(locator))->start(); | |
249 return start + locator_pos(locator); | |
250 } | |
251 | |
252 address CodeBuffer::decode_begin() { | |
253 address begin = _insts.start(); | |
254 if (_decode_begin != NULL && _decode_begin > begin) | |
255 begin = _decode_begin; | |
256 return begin; | |
257 } | |
258 | |
259 | |
260 GrowableArray<int>* CodeBuffer::create_patch_overflow() { | |
261 if (_overflow_arena == NULL) { | |
262 _overflow_arena = new Arena(); | |
263 } | |
264 return new (_overflow_arena) GrowableArray<int>(_overflow_arena, 8, 0, 0); | |
265 } | |
266 | |
267 | |
268 // Helper function for managing labels and their target addresses. | |
269 // Returns a sensible address, and if it is not the label's final | |
270 // address, notes the dependency (at 'branch_pc') on the label. | |
271 address CodeSection::target(Label& L, address branch_pc) { | |
272 if (L.is_bound()) { | |
273 int loc = L.loc(); | |
274 if (index() == CodeBuffer::locator_sect(loc)) { | |
275 return start() + CodeBuffer::locator_pos(loc); | |
276 } else { | |
277 return outer()->locator_address(loc); | |
278 } | |
279 } else { | |
280 assert(allocates2(branch_pc), "sanity"); | |
281 address base = start(); | |
282 int patch_loc = CodeBuffer::locator(branch_pc - base, index()); | |
283 L.add_patch_at(outer(), patch_loc); | |
284 | |
285 // Need to return a pc, doesn't matter what it is since it will be | |
286 // replaced during resolution later. | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
287 // Don't return NULL or badAddress, since branches shouldn't overflow. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
288 // Don't return base either because that could overflow displacements |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
289 // for shorter branches. It will get checked when bound. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
290 return branch_pc; |
0 | 291 } |
292 } | |
293 | |
294 void CodeSection::relocate(address at, RelocationHolder const& spec, int format) { | |
295 Relocation* reloc = spec.reloc(); | |
296 relocInfo::relocType rtype = (relocInfo::relocType) reloc->type(); | |
297 if (rtype == relocInfo::none) return; | |
298 | |
299 // The assertion below has been adjusted, to also work for | |
300 // relocation for fixup. Sometimes we want to put relocation | |
301 // information for the next instruction, since it will be patched | |
302 // with a call. | |
303 assert(start() <= at && at <= end()+1, | |
304 "cannot relocate data outside code boundaries"); | |
305 | |
306 if (!has_locs()) { | |
307 // no space for relocation information provided => code cannot be | |
308 // relocated. Make sure that relocate is only called with rtypes | |
309 // that can be ignored for this kind of code. | |
310 assert(rtype == relocInfo::none || | |
311 rtype == relocInfo::runtime_call_type || | |
312 rtype == relocInfo::internal_word_type|| | |
313 rtype == relocInfo::section_word_type || | |
314 rtype == relocInfo::external_word_type, | |
315 "code needs relocation information"); | |
316 // leave behind an indication that we attempted a relocation | |
317 DEBUG_ONLY(_locs_start = _locs_limit = (relocInfo*)badAddress); | |
318 return; | |
319 } | |
320 | |
321 // Advance the point, noting the offset we'll have to record. | |
322 csize_t offset = at - locs_point(); | |
323 set_locs_point(at); | |
324 | |
325 // Test for a couple of overflow conditions; maybe expand the buffer. | |
326 relocInfo* end = locs_end(); | |
327 relocInfo* req = end + relocInfo::length_limit; | |
328 // Check for (potential) overflow | |
329 if (req >= locs_limit() || offset >= relocInfo::offset_limit()) { | |
330 req += (uint)offset / (uint)relocInfo::offset_limit(); | |
331 if (req >= locs_limit()) { | |
332 // Allocate or reallocate. | |
333 expand_locs(locs_count() + (req - end)); | |
334 // reload pointer | |
335 end = locs_end(); | |
336 } | |
337 } | |
338 | |
339 // If the offset is giant, emit filler relocs, of type 'none', but | |
340 // each carrying the largest possible offset, to advance the locs_point. | |
341 while (offset >= relocInfo::offset_limit()) { | |
342 assert(end < locs_limit(), "adjust previous paragraph of code"); | |
343 *end++ = filler_relocInfo(); | |
344 offset -= filler_relocInfo().addr_offset(); | |
345 } | |
346 | |
347 // If it's a simple reloc with no data, we'll just write (rtype | offset). | |
348 (*end) = relocInfo(rtype, offset, format); | |
349 | |
350 // If it has data, insert the prefix, as (data_prefix_tag | data1), data2. | |
351 end->initialize(this, reloc); | |
352 } | |
353 | |
354 void CodeSection::initialize_locs(int locs_capacity) { | |
355 assert(_locs_start == NULL, "only one locs init step, please"); | |
356 // Apply a priori lower limits to relocation size: | |
357 csize_t min_locs = MAX2(size() / 16, (csize_t)4); | |
358 if (locs_capacity < min_locs) locs_capacity = min_locs; | |
359 relocInfo* locs_start = NEW_RESOURCE_ARRAY(relocInfo, locs_capacity); | |
360 _locs_start = locs_start; | |
361 _locs_end = locs_start; | |
362 _locs_limit = locs_start + locs_capacity; | |
363 _locs_own = true; | |
364 } | |
365 | |
366 void CodeSection::initialize_shared_locs(relocInfo* buf, int length) { | |
367 assert(_locs_start == NULL, "do this before locs are allocated"); | |
368 // Internal invariant: locs buf must be fully aligned. | |
369 // See copy_relocations_to() below. | |
370 while ((uintptr_t)buf % HeapWordSize != 0 && length > 0) { | |
371 ++buf; --length; | |
372 } | |
373 if (length > 0) { | |
374 _locs_start = buf; | |
375 _locs_end = buf; | |
376 _locs_limit = buf + length; | |
377 _locs_own = false; | |
378 } | |
379 } | |
380 | |
381 void CodeSection::initialize_locs_from(const CodeSection* source_cs) { | |
382 int lcount = source_cs->locs_count(); | |
383 if (lcount != 0) { | |
384 initialize_shared_locs(source_cs->locs_start(), lcount); | |
385 _locs_end = _locs_limit = _locs_start + lcount; | |
386 assert(is_allocated(), "must have copied code already"); | |
387 set_locs_point(start() + source_cs->locs_point_off()); | |
388 } | |
389 assert(this->locs_count() == source_cs->locs_count(), "sanity"); | |
390 } | |
391 | |
392 void CodeSection::expand_locs(int new_capacity) { | |
393 if (_locs_start == NULL) { | |
394 initialize_locs(new_capacity); | |
395 return; | |
396 } else { | |
397 int old_count = locs_count(); | |
398 int old_capacity = locs_capacity(); | |
399 if (new_capacity < old_capacity * 2) | |
400 new_capacity = old_capacity * 2; | |
401 relocInfo* locs_start; | |
402 if (_locs_own) { | |
403 locs_start = REALLOC_RESOURCE_ARRAY(relocInfo, _locs_start, old_capacity, new_capacity); | |
404 } else { | |
405 locs_start = NEW_RESOURCE_ARRAY(relocInfo, new_capacity); | |
1603
d93949c5bdcc
6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents:
1552
diff
changeset
|
406 Copy::conjoint_jbytes(_locs_start, locs_start, old_capacity * sizeof(relocInfo)); |
0 | 407 _locs_own = true; |
408 } | |
409 _locs_start = locs_start; | |
410 _locs_end = locs_start + old_count; | |
411 _locs_limit = locs_start + new_capacity; | |
412 } | |
413 } | |
414 | |
415 | |
416 /// Support for emitting the code to its final location. | |
417 /// The pattern is the same for all functions. | |
418 /// We iterate over all the sections, padding each to alignment. | |
419 | |
1748 | 420 csize_t CodeBuffer::total_content_size() const { |
421 csize_t size_so_far = 0; | |
0 | 422 for (int n = 0; n < (int)SECT_LIMIT; n++) { |
423 const CodeSection* cs = code_section(n); | |
424 if (cs->is_empty()) continue; // skip trivial section | |
1748 | 425 size_so_far = cs->align_at_start(size_so_far); |
426 size_so_far += cs->size(); | |
0 | 427 } |
1748 | 428 return size_so_far; |
0 | 429 } |
430 | |
431 void CodeBuffer::compute_final_layout(CodeBuffer* dest) const { | |
432 address buf = dest->_total_start; | |
433 csize_t buf_offset = 0; | |
1748 | 434 assert(dest->_total_size >= total_content_size(), "must be big enough"); |
0 | 435 |
436 { | |
437 // not sure why this is here, but why not... | |
438 int alignSize = MAX2((intx) sizeof(jdouble), CodeEntryAlignment); | |
439 assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment"); | |
440 } | |
441 | |
442 const CodeSection* prev_cs = NULL; | |
443 CodeSection* prev_dest_cs = NULL; | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
444 |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
445 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
0 | 446 // figure compact layout of each section |
447 const CodeSection* cs = code_section(n); | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
448 csize_t csize = cs->size(); |
0 | 449 |
450 CodeSection* dest_cs = dest->code_section(n); | |
451 if (!cs->is_empty()) { | |
452 // Compute initial padding; assign it to the previous non-empty guy. | |
453 // Cf. figure_expanded_capacities. | |
454 csize_t padding = cs->align_at_start(buf_offset) - buf_offset; | |
455 if (padding != 0) { | |
456 buf_offset += padding; | |
457 assert(prev_dest_cs != NULL, "sanity"); | |
458 prev_dest_cs->_limit += padding; | |
459 } | |
460 #ifdef ASSERT | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
461 if (prev_cs != NULL && prev_cs->is_frozen() && n < (SECT_LIMIT - 1)) { |
0 | 462 // Make sure the ends still match up. |
463 // This is important because a branch in a frozen section | |
464 // might target code in a following section, via a Label, | |
465 // and without a relocation record. See Label::patch_instructions. | |
466 address dest_start = buf+buf_offset; | |
467 csize_t start2start = cs->start() - prev_cs->start(); | |
468 csize_t dest_start2start = dest_start - prev_dest_cs->start(); | |
469 assert(start2start == dest_start2start, "cannot stretch frozen sect"); | |
470 } | |
471 #endif //ASSERT | |
472 prev_dest_cs = dest_cs; | |
473 prev_cs = cs; | |
474 } | |
475 | |
476 debug_only(dest_cs->_start = NULL); // defeat double-initialization assert | |
477 dest_cs->initialize(buf+buf_offset, csize); | |
478 dest_cs->set_end(buf+buf_offset+csize); | |
479 assert(dest_cs->is_allocated(), "must always be allocated"); | |
480 assert(cs->is_empty() == dest_cs->is_empty(), "sanity"); | |
481 | |
482 buf_offset += csize; | |
483 } | |
484 | |
485 // Done calculating sections; did it come out to the right end? | |
1748 | 486 assert(buf_offset == total_content_size(), "sanity"); |
0 | 487 assert(dest->verify_section_allocation(), "final configuration works"); |
488 } | |
489 | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
490 csize_t CodeBuffer::total_offset_of(CodeSection* cs) const { |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
491 csize_t size_so_far = 0; |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
492 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
493 const CodeSection* cur_cs = code_section(n); |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
494 if (!cur_cs->is_empty()) { |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
495 size_so_far = cur_cs->align_at_start(size_so_far); |
0 | 496 } |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
497 if (cur_cs->index() == cs->index()) { |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
498 return size_so_far; |
0 | 499 } |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
500 size_so_far += cur_cs->size(); |
0 | 501 } |
502 ShouldNotReachHere(); | |
503 return -1; | |
504 } | |
505 | |
506 csize_t CodeBuffer::total_relocation_size() const { | |
507 csize_t lsize = copy_relocations_to(NULL); // dry run only | |
1748 | 508 csize_t csize = total_content_size(); |
0 | 509 csize_t total = RelocIterator::locs_and_index_size(csize, lsize); |
510 return (csize_t) align_size_up(total, HeapWordSize); | |
511 } | |
512 | |
513 csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const { | |
514 address buf = NULL; | |
515 csize_t buf_offset = 0; | |
516 csize_t buf_limit = 0; | |
517 if (dest != NULL) { | |
518 buf = (address)dest->relocation_begin(); | |
519 buf_limit = (address)dest->relocation_end() - buf; | |
520 assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned"); | |
521 assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized"); | |
522 } | |
523 // if dest == NULL, this is just the sizing pass | |
524 | |
525 csize_t code_end_so_far = 0; | |
526 csize_t code_point_so_far = 0; | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
527 for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) { |
0 | 528 // pull relocs out of each section |
529 const CodeSection* cs = code_section(n); | |
530 assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity"); | |
531 if (cs->is_empty()) continue; // skip trivial section | |
532 relocInfo* lstart = cs->locs_start(); | |
533 relocInfo* lend = cs->locs_end(); | |
534 csize_t lsize = (csize_t)( (address)lend - (address)lstart ); | |
535 csize_t csize = cs->size(); | |
536 code_end_so_far = cs->align_at_start(code_end_so_far); | |
537 | |
538 if (lsize > 0) { | |
539 // Figure out how to advance the combined relocation point | |
540 // first to the beginning of this section. | |
541 // We'll insert one or more filler relocs to span that gap. | |
542 // (Don't bother to improve this by editing the first reloc's offset.) | |
543 csize_t new_code_point = code_end_so_far; | |
544 for (csize_t jump; | |
545 code_point_so_far < new_code_point; | |
546 code_point_so_far += jump) { | |
547 jump = new_code_point - code_point_so_far; | |
548 relocInfo filler = filler_relocInfo(); | |
549 if (jump >= filler.addr_offset()) { | |
550 jump = filler.addr_offset(); | |
551 } else { // else shrink the filler to fit | |
552 filler = relocInfo(relocInfo::none, jump); | |
553 } | |
554 if (buf != NULL) { | |
555 assert(buf_offset + (csize_t)sizeof(filler) <= buf_limit, "filler in bounds"); | |
556 *(relocInfo*)(buf+buf_offset) = filler; | |
557 } | |
558 buf_offset += sizeof(filler); | |
559 } | |
560 | |
561 // Update code point and end to skip past this section: | |
562 csize_t last_code_point = code_end_so_far + cs->locs_point_off(); | |
563 assert(code_point_so_far <= last_code_point, "sanity"); | |
564 code_point_so_far = last_code_point; // advance past this guy's relocs | |
565 } | |
566 code_end_so_far += csize; // advance past this guy's instructions too | |
567 | |
568 // Done with filler; emit the real relocations: | |
569 if (buf != NULL && lsize != 0) { | |
570 assert(buf_offset + lsize <= buf_limit, "target in bounds"); | |
571 assert((uintptr_t)lstart % HeapWordSize == 0, "sane start"); | |
572 if (buf_offset % HeapWordSize == 0) { | |
573 // Use wordwise copies if possible: | |
574 Copy::disjoint_words((HeapWord*)lstart, | |
575 (HeapWord*)(buf+buf_offset), | |
576 (lsize + HeapWordSize-1) / HeapWordSize); | |
577 } else { | |
1603
d93949c5bdcc
6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents:
1552
diff
changeset
|
578 Copy::conjoint_jbytes(lstart, buf+buf_offset, lsize); |
0 | 579 } |
580 } | |
581 buf_offset += lsize; | |
582 } | |
583 | |
584 // Align end of relocation info in target. | |
585 while (buf_offset % HeapWordSize != 0) { | |
586 if (buf != NULL) { | |
587 relocInfo padding = relocInfo(relocInfo::none, 0); | |
588 assert(buf_offset + (csize_t)sizeof(padding) <= buf_limit, "padding in bounds"); | |
589 *(relocInfo*)(buf+buf_offset) = padding; | |
590 } | |
591 buf_offset += sizeof(relocInfo); | |
592 } | |
593 | |
1748 | 594 assert(code_end_so_far == total_content_size(), "sanity"); |
0 | 595 |
596 // Account for index: | |
597 if (buf != NULL) { | |
598 RelocIterator::create_index(dest->relocation_begin(), | |
599 buf_offset / sizeof(relocInfo), | |
600 dest->relocation_end()); | |
601 } | |
602 | |
603 return buf_offset; | |
604 } | |
605 | |
606 void CodeBuffer::copy_code_to(CodeBlob* dest_blob) { | |
607 #ifndef PRODUCT | |
608 if (PrintNMethods && (WizardMode || Verbose)) { | |
609 tty->print("done with CodeBuffer:"); | |
610 ((CodeBuffer*)this)->print(); | |
611 } | |
612 #endif //PRODUCT | |
613 | |
1748 | 614 CodeBuffer dest(dest_blob); |
615 assert(dest_blob->content_size() >= total_content_size(), "good sizing"); | |
0 | 616 this->compute_final_layout(&dest); |
617 relocate_code_to(&dest); | |
618 | |
619 // transfer comments from buffer to blob | |
620 dest_blob->set_comments(_comments); | |
621 | |
622 // Done moving code bytes; were they the right size? | |
1748 | 623 assert(round_to(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity"); |
0 | 624 |
625 // Flush generated code | |
1748 | 626 ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size()); |
0 | 627 } |
628 | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
629 // Move all my code into another code buffer. Consult applicable |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
630 // relocs to repair embedded addresses. The layout in the destination |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
631 // CodeBuffer is different to the source CodeBuffer: the destination |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
632 // CodeBuffer gets the final layout (consts, insts, stubs in order of |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
633 // ascending address). |
0 | 634 void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { |
635 DEBUG_ONLY(address dest_end = dest->_total_start + dest->_total_size); | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
636 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
0 | 637 // pull code out of each section |
638 const CodeSection* cs = code_section(n); | |
639 if (cs->is_empty()) continue; // skip trivial section | |
640 CodeSection* dest_cs = dest->code_section(n); | |
641 assert(cs->size() == dest_cs->size(), "sanity"); | |
642 csize_t usize = dest_cs->size(); | |
643 csize_t wsize = align_size_up(usize, HeapWordSize); | |
644 assert(dest_cs->start() + wsize <= dest_end, "no overflow"); | |
645 // Copy the code as aligned machine words. | |
646 // This may also include an uninitialized partial word at the end. | |
647 Copy::disjoint_words((HeapWord*)cs->start(), | |
648 (HeapWord*)dest_cs->start(), | |
649 wsize / HeapWordSize); | |
650 | |
651 if (dest->blob() == NULL) { | |
652 // Destination is a final resting place, not just another buffer. | |
653 // Normalize uninitialized bytes in the final padding. | |
654 Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(), | |
655 Assembler::code_fill_byte()); | |
656 } | |
657 | |
658 assert(cs->locs_start() != (relocInfo*)badAddress, | |
659 "this section carries no reloc storage, but reloc was attempted"); | |
660 | |
661 // Make the new code copy use the old copy's relocations: | |
662 dest_cs->initialize_locs_from(cs); | |
663 | |
664 { // Repair the pc relative information in the code after the move | |
665 RelocIterator iter(dest_cs); | |
666 while (iter.next()) { | |
667 iter.reloc()->fix_relocation_after_move(this, dest); | |
668 } | |
669 } | |
670 } | |
671 } | |
672 | |
673 csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs, | |
674 csize_t amount, | |
675 csize_t* new_capacity) { | |
676 csize_t new_total_cap = 0; | |
677 | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
678 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
0 | 679 const CodeSection* sect = code_section(n); |
680 | |
681 if (!sect->is_empty()) { | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
682 // Compute initial padding; assign it to the previous section, |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
683 // even if it's empty (e.g. consts section can be empty). |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
684 // Cf. compute_final_layout |
0 | 685 csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap; |
686 if (padding != 0) { | |
687 new_total_cap += padding; | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
688 assert(n - 1 >= SECT_FIRST, "sanity"); |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
689 new_capacity[n - 1] += padding; |
0 | 690 } |
691 } | |
692 | |
693 csize_t exp = sect->size(); // 100% increase | |
694 if ((uint)exp < 4*K) exp = 4*K; // minimum initial increase | |
695 if (sect == which_cs) { | |
696 if (exp < amount) exp = amount; | |
697 if (StressCodeBuffers) exp = amount; // expand only slightly | |
698 } else if (n == SECT_INSTS) { | |
699 // scale down inst increases to a more modest 25% | |
700 exp = 4*K + ((exp - 4*K) >> 2); | |
701 if (StressCodeBuffers) exp = amount / 2; // expand only slightly | |
702 } else if (sect->is_empty()) { | |
703 // do not grow an empty secondary section | |
704 exp = 0; | |
705 } | |
706 // Allow for inter-section slop: | |
707 exp += CodeSection::end_slop(); | |
708 csize_t new_cap = sect->size() + exp; | |
709 if (new_cap < sect->capacity()) { | |
710 // No need to expand after all. | |
711 new_cap = sect->capacity(); | |
712 } | |
713 new_capacity[n] = new_cap; | |
714 new_total_cap += new_cap; | |
715 } | |
716 | |
717 return new_total_cap; | |
718 } | |
719 | |
720 void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) { | |
721 #ifndef PRODUCT | |
722 if (PrintNMethods && (WizardMode || Verbose)) { | |
723 tty->print("expanding CodeBuffer:"); | |
724 this->print(); | |
725 } | |
726 | |
727 if (StressCodeBuffers && blob() != NULL) { | |
728 static int expand_count = 0; | |
729 if (expand_count >= 0) expand_count += 1; | |
730 if (expand_count > 100 && is_power_of_2(expand_count)) { | |
731 tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count); | |
732 // simulate an occasional allocation failure: | |
733 free_blob(); | |
734 } | |
735 } | |
736 #endif //PRODUCT | |
737 | |
738 // Resizing must be allowed | |
739 { | |
740 if (blob() == NULL) return; // caller must check for blob == NULL | |
741 for (int n = 0; n < (int)SECT_LIMIT; n++) { | |
742 guarantee(!code_section(n)->is_frozen(), "resizing not allowed when frozen"); | |
743 } | |
744 } | |
745 | |
746 // Figure new capacity for each section. | |
747 csize_t new_capacity[SECT_LIMIT]; | |
748 csize_t new_total_cap | |
749 = figure_expanded_capacities(which_cs, amount, new_capacity); | |
750 | |
751 // Create a new (temporary) code buffer to hold all the new data | |
752 CodeBuffer cb(name(), new_total_cap, 0); | |
753 if (cb.blob() == NULL) { | |
754 // Failed to allocate in code cache. | |
755 free_blob(); | |
756 return; | |
757 } | |
758 | |
759 // Create an old code buffer to remember which addresses used to go where. | |
760 // This will be useful when we do final assembly into the code cache, | |
761 // because we will need to know how to warp any internal address that | |
762 // has been created at any time in this CodeBuffer's past. | |
763 CodeBuffer* bxp = new CodeBuffer(_total_start, _total_size); | |
764 bxp->take_over_code_from(this); // remember the old undersized blob | |
765 DEBUG_ONLY(this->_blob = NULL); // silence a later assert | |
766 bxp->_before_expand = this->_before_expand; | |
767 this->_before_expand = bxp; | |
768 | |
769 // Give each section its required (expanded) capacity. | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
770 for (int n = (int)SECT_LIMIT-1; n >= SECT_FIRST; n--) { |
0 | 771 CodeSection* cb_sect = cb.code_section(n); |
772 CodeSection* this_sect = code_section(n); | |
773 if (new_capacity[n] == 0) continue; // already nulled out | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
774 if (n != SECT_INSTS) { |
0 | 775 cb.initialize_section_size(cb_sect, new_capacity[n]); |
776 } | |
777 assert(cb_sect->capacity() >= new_capacity[n], "big enough"); | |
778 address cb_start = cb_sect->start(); | |
779 cb_sect->set_end(cb_start + this_sect->size()); | |
780 if (this_sect->mark() == NULL) { | |
781 cb_sect->clear_mark(); | |
782 } else { | |
783 cb_sect->set_mark(cb_start + this_sect->mark_off()); | |
784 } | |
785 } | |
786 | |
787 // Move all the code and relocations to the new blob: | |
788 relocate_code_to(&cb); | |
789 | |
790 // Copy the temporary code buffer into the current code buffer. | |
791 // Basically, do {*this = cb}, except for some control information. | |
792 this->take_over_code_from(&cb); | |
793 cb.set_blob(NULL); | |
794 | |
795 // Zap the old code buffer contents, to avoid mistakenly using them. | |
796 debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size, | |
797 badCodeHeapFreeVal)); | |
798 | |
799 _decode_begin = NULL; // sanity | |
800 | |
801 // Make certain that the new sections are all snugly inside the new blob. | |
802 assert(verify_section_allocation(), "expanded allocation is ship-shape"); | |
803 | |
804 #ifndef PRODUCT | |
805 if (PrintNMethods && (WizardMode || Verbose)) { | |
806 tty->print("expanded CodeBuffer:"); | |
807 this->print(); | |
808 } | |
809 #endif //PRODUCT | |
810 } | |
811 | |
812 void CodeBuffer::take_over_code_from(CodeBuffer* cb) { | |
813 // Must already have disposed of the old blob somehow. | |
814 assert(blob() == NULL, "must be empty"); | |
815 #ifdef ASSERT | |
816 | |
817 #endif | |
818 // Take the new blob away from cb. | |
819 set_blob(cb->blob()); | |
820 // Take over all the section pointers. | |
821 for (int n = 0; n < (int)SECT_LIMIT; n++) { | |
822 CodeSection* cb_sect = cb->code_section(n); | |
823 CodeSection* this_sect = code_section(n); | |
824 this_sect->take_over_code_from(cb_sect); | |
825 } | |
826 _overflow_arena = cb->_overflow_arena; | |
827 // Make sure the old cb won't try to use it or free it. | |
828 DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress); | |
829 } | |
830 | |
831 #ifdef ASSERT | |
832 bool CodeBuffer::verify_section_allocation() { | |
833 address tstart = _total_start; | |
834 if (tstart == badAddress) return true; // smashed by set_blob(NULL) | |
835 address tend = tstart + _total_size; | |
836 if (_blob != NULL) { | |
1748 | 837 assert(tstart >= _blob->content_begin(), "sanity"); |
838 assert(tend <= _blob->content_end(), "sanity"); | |
0 | 839 } |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
840 // Verify disjointness. |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
841 for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
0 | 842 CodeSection* sect = code_section(n); |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
843 if (!sect->is_allocated() || sect->is_empty()) continue; |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
844 assert((intptr_t)sect->start() % sect->alignment() == 0 |
0 | 845 || sect->is_empty() || _blob == NULL, |
846 "start is aligned"); | |
1762
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
847 for (int m = (int) SECT_FIRST; m < (int) SECT_LIMIT; m++) { |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
848 CodeSection* other = code_section(m); |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
849 if (!other->is_allocated() || other == sect) continue; |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
850 assert(!other->contains(sect->start() ), "sanity"); |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
851 // limit is an exclusive address and can be the start of another |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
852 // section. |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
853 assert(!other->contains(sect->limit() - 1), "sanity"); |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
854 } |
0878d7bae69f
6961697: move nmethod constants section before instruction section
twisti
parents:
1748
diff
changeset
|
855 assert(sect->end() <= tend, "sanity"); |
0 | 856 } |
857 return true; | |
858 } | |
859 #endif //ASSERT | |
860 | |
861 #ifndef PRODUCT | |
862 | |
863 void CodeSection::dump() { | |
864 address ptr = start(); | |
865 for (csize_t step; ptr < end(); ptr += step) { | |
866 step = end() - ptr; | |
867 if (step > jintSize * 4) step = jintSize * 4; | |
868 tty->print(PTR_FORMAT ": ", ptr); | |
869 while (step > 0) { | |
870 tty->print(" " PTR32_FORMAT, *(jint*)ptr); | |
871 ptr += jintSize; | |
872 } | |
873 tty->cr(); | |
874 } | |
875 } | |
876 | |
877 | |
878 void CodeSection::decode() { | |
879 Disassembler::decode(start(), end()); | |
880 } | |
881 | |
882 | |
883 void CodeBuffer::block_comment(intptr_t offset, const char * comment) { | |
884 _comments.add_comment(offset, comment); | |
885 } | |
886 | |
887 | |
888 class CodeComment: public CHeapObj { | |
889 private: | |
890 friend class CodeComments; | |
891 intptr_t _offset; | |
892 const char * _comment; | |
893 CodeComment* _next; | |
894 | |
895 ~CodeComment() { | |
896 assert(_next == NULL, "wrong interface for freeing list"); | |
897 os::free((void*)_comment); | |
898 } | |
899 | |
900 public: | |
901 CodeComment(intptr_t offset, const char * comment) { | |
902 _offset = offset; | |
903 _comment = os::strdup(comment); | |
904 _next = NULL; | |
905 } | |
906 | |
907 intptr_t offset() const { return _offset; } | |
908 const char * comment() const { return _comment; } | |
909 CodeComment* next() { return _next; } | |
910 | |
911 void set_next(CodeComment* next) { _next = next; } | |
912 | |
913 CodeComment* find(intptr_t offset) { | |
914 CodeComment* a = this; | |
915 while (a != NULL && a->_offset != offset) { | |
916 a = a->_next; | |
917 } | |
918 return a; | |
919 } | |
920 }; | |
921 | |
922 | |
923 void CodeComments::add_comment(intptr_t offset, const char * comment) { | |
924 CodeComment* c = new CodeComment(offset, comment); | |
925 CodeComment* insert = NULL; | |
926 if (_comments != NULL) { | |
927 CodeComment* c = _comments->find(offset); | |
928 insert = c; | |
929 while (c && c->offset() == offset) { | |
930 insert = c; | |
931 c = c->next(); | |
932 } | |
933 } | |
934 if (insert) { | |
935 // insert after comments with same offset | |
936 c->set_next(insert->next()); | |
937 insert->set_next(c); | |
938 } else { | |
939 c->set_next(_comments); | |
940 _comments = c; | |
941 } | |
942 } | |
943 | |
944 | |
945 void CodeComments::assign(CodeComments& other) { | |
946 assert(_comments == NULL, "don't overwrite old value"); | |
947 _comments = other._comments; | |
948 } | |
949 | |
950 | |
951 void CodeComments::print_block_comment(outputStream* stream, intptr_t offset) { | |
952 if (_comments != NULL) { | |
953 CodeComment* c = _comments->find(offset); | |
954 while (c && c->offset() == offset) { | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
955 stream->bol(); |
0 | 956 stream->print(" ;; "); |
957 stream->print_cr(c->comment()); | |
958 c = c->next(); | |
959 } | |
960 } | |
961 } | |
962 | |
963 | |
964 void CodeComments::free() { | |
965 CodeComment* n = _comments; | |
966 while (n) { | |
967 // unlink the node from the list saving a pointer to the next | |
968 CodeComment* p = n->_next; | |
969 n->_next = NULL; | |
970 delete n; | |
971 n = p; | |
972 } | |
973 _comments = NULL; | |
974 } | |
975 | |
976 | |
977 | |
978 void CodeBuffer::decode() { | |
1748 | 979 Disassembler::decode(decode_begin(), insts_end()); |
980 _decode_begin = insts_end(); | |
0 | 981 } |
982 | |
983 | |
984 void CodeBuffer::skip_decode() { | |
1748 | 985 _decode_begin = insts_end(); |
0 | 986 } |
987 | |
988 | |
989 void CodeBuffer::decode_all() { | |
990 for (int n = 0; n < (int)SECT_LIMIT; n++) { | |
991 // dump contents of each section | |
992 CodeSection* cs = code_section(n); | |
993 tty->print_cr("! %s:", code_section_name(n)); | |
994 if (cs != consts()) | |
995 cs->decode(); | |
996 else | |
997 cs->dump(); | |
998 } | |
999 } | |
1000 | |
1001 | |
1002 void CodeSection::print(const char* name) { | |
1003 csize_t locs_size = locs_end() - locs_start(); | |
1004 tty->print_cr(" %7s.code = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d)%s", | |
1005 name, start(), end(), limit(), size(), capacity(), | |
1006 is_frozen()? " [frozen]": ""); | |
1007 tty->print_cr(" %7s.locs = " PTR_FORMAT " : " PTR_FORMAT " : " PTR_FORMAT " (%d of %d) point=%d", | |
1008 name, locs_start(), locs_end(), locs_limit(), locs_size, locs_capacity(), locs_point_off()); | |
1009 if (PrintRelocations) { | |
1010 RelocIterator iter(this); | |
1011 iter.print(); | |
1012 } | |
1013 } | |
1014 | |
1015 void CodeBuffer::print() { | |
1016 if (this == NULL) { | |
1017 tty->print_cr("NULL CodeBuffer pointer"); | |
1018 return; | |
1019 } | |
1020 | |
1021 tty->print_cr("CodeBuffer:"); | |
1022 for (int n = 0; n < (int)SECT_LIMIT; n++) { | |
1023 // print each section | |
1024 CodeSection* cs = code_section(n); | |
1025 cs->print(code_section_name(n)); | |
1026 } | |
1027 } | |
1028 | |
1029 #endif // PRODUCT |