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