annotate src/share/vm/asm/codeBuffer.cpp @ 1978:2ca799d83d3c

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