File: | jdk/src/hotspot/share/asm/codeBuffer.cpp |
Warning: | line 474, column 7 Value stored to 'prev_cs' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | * |
5 | * This code is free software; you can redistribute it and/or modify it |
6 | * under the terms of the GNU General Public License version 2 only, as |
7 | * published by the Free Software Foundation. |
8 | * |
9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 | * version 2 for more details (a copy is included in the LICENSE file that |
13 | * accompanied this code). |
14 | * |
15 | * You should have received a copy of the GNU General Public License version |
16 | * 2 along with this work; if not, write to the Free Software Foundation, |
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | * |
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 | * or visit www.oracle.com if you need additional information or have any |
21 | * questions. |
22 | * |
23 | */ |
24 | |
25 | #include "precompiled.hpp" |
26 | #include "asm/codeBuffer.hpp" |
27 | #include "code/oopRecorder.inline.hpp" |
28 | #include "compiler/disassembler.hpp" |
29 | #include "logging/log.hpp" |
30 | #include "oops/klass.inline.hpp" |
31 | #include "oops/methodData.hpp" |
32 | #include "oops/oop.inline.hpp" |
33 | #include "runtime/icache.hpp" |
34 | #include "runtime/safepointVerifiers.hpp" |
35 | #include "utilities/align.hpp" |
36 | #include "utilities/copy.hpp" |
37 | #include "utilities/powerOfTwo.hpp" |
38 | #include "utilities/xmlstream.hpp" |
39 | |
40 | // The structure of a CodeSection: |
41 | // |
42 | // _start -> +----------------+ |
43 | // | machine code...| |
44 | // _end -> |----------------| |
45 | // | | |
46 | // | (empty) | |
47 | // | | |
48 | // | | |
49 | // +----------------+ |
50 | // _limit -> | | |
51 | // |
52 | // _locs_start -> +----------------+ |
53 | // |reloc records...| |
54 | // |----------------| |
55 | // _locs_end -> | | |
56 | // | | |
57 | // | (empty) | |
58 | // | | |
59 | // | | |
60 | // +----------------+ |
61 | // _locs_limit -> | | |
62 | // The _end (resp. _limit) pointer refers to the first |
63 | // unused (resp. unallocated) byte. |
64 | |
65 | // The structure of the CodeBuffer while code is being accumulated: |
66 | // |
67 | // _total_start -> \ |
68 | // _insts._start -> +----------------+ |
69 | // | | |
70 | // | Code | |
71 | // | | |
72 | // _stubs._start -> |----------------| |
73 | // | | |
74 | // | Stubs | (also handlers for deopt/exception) |
75 | // | | |
76 | // _consts._start -> |----------------| |
77 | // | | |
78 | // | Constants | |
79 | // | | |
80 | // +----------------+ |
81 | // + _total_size -> | | |
82 | // |
83 | // When the code and relocations are copied to the code cache, |
84 | // the empty parts of each section are removed, and everything |
85 | // is copied into contiguous locations. |
86 | |
87 | typedef CodeBuffer::csize_t csize_t; // file-local definition |
88 | |
89 | // External buffer, in a predefined CodeBlob. |
90 | // Important: The code_start must be taken exactly, and not realigned. |
91 | CodeBuffer::CodeBuffer(CodeBlob* blob) DEBUG_ONLY(: Scrubber(this, sizeof(*this))): Scrubber(this, sizeof(*this)) { |
92 | // Provide code buffer with meaningful name |
93 | initialize_misc(blob->name()); |
94 | initialize(blob->content_begin(), blob->content_size()); |
95 | debug_only(verify_section_allocation();)verify_section_allocation(); |
96 | } |
97 | |
98 | void CodeBuffer::initialize(csize_t code_size, csize_t locs_size) { |
99 | // Compute maximal alignment. |
100 | int align = _insts.alignment(); |
101 | // Always allow for empty slop around each section. |
102 | int slop = (int) CodeSection::end_slop(); |
103 | |
104 | assert(blob() == NULL, "only once")do { if (!(blob() == __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 104, "assert(" "blob() == __null" ") failed", "only once"); ::breakpoint(); } } while (0); |
105 | set_blob(BufferBlob::create(_name, code_size + (align+slop) * (SECT_LIMIT+1))); |
106 | if (blob() == NULL__null) { |
107 | // The assembler constructor will throw a fatal on an empty CodeBuffer. |
108 | return; // caller must test this |
109 | } |
110 | |
111 | // Set up various pointers into the blob. |
112 | initialize(_total_start, _total_size); |
113 | |
114 | assert((uintptr_t)insts_begin() % CodeEntryAlignment == 0, "instruction start not code entry aligned")do { if (!((uintptr_t)insts_begin() % CodeEntryAlignment == 0 )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 114, "assert(" "(uintptr_t)insts_begin() % CodeEntryAlignment == 0" ") failed", "instruction start not code entry aligned"); ::breakpoint (); } } while (0); |
115 | |
116 | pd_initialize(); |
117 | |
118 | if (locs_size != 0) { |
119 | _insts.initialize_locs(locs_size / sizeof(relocInfo)); |
120 | } |
121 | |
122 | debug_only(verify_section_allocation();)verify_section_allocation(); |
123 | } |
124 | |
125 | |
126 | CodeBuffer::~CodeBuffer() { |
127 | verify_section_allocation(); |
128 | |
129 | // If we allocated our code buffer from the CodeCache via a BufferBlob, and |
130 | // it's not permanent, then free the BufferBlob. The rest of the memory |
131 | // will be freed when the ResourceObj is released. |
132 | for (CodeBuffer* cb = this; cb != NULL__null; cb = cb->before_expand()) { |
133 | // Previous incarnations of this buffer are held live, so that internal |
134 | // addresses constructed before expansions will not be confused. |
135 | cb->free_blob(); |
136 | } |
137 | |
138 | // free any overflow storage |
139 | delete _overflow_arena; |
140 | |
141 | NOT_PRODUCT(clear_strings())clear_strings(); |
142 | |
143 | assert(_default_oop_recorder.allocated_on_stack_or_embedded(), "should be embedded object")do { if (!(_default_oop_recorder.allocated_on_stack_or_embedded ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 143, "assert(" "_default_oop_recorder.allocated_on_stack_or_embedded()" ") failed", "should be embedded object"); ::breakpoint(); } } while (0); |
144 | } |
145 | |
146 | void CodeBuffer::initialize_oop_recorder(OopRecorder* r) { |
147 | assert(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused(), "do this once")do { if (!(_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 147, "assert(" "_oop_recorder == &_default_oop_recorder && _default_oop_recorder.is_unused()" ") failed", "do this once"); ::breakpoint(); } } while (0); |
148 | DEBUG_ONLY(_default_oop_recorder.freeze())_default_oop_recorder.freeze(); // force unused OR to be frozen |
149 | _oop_recorder = r; |
150 | } |
151 | |
152 | void CodeBuffer::initialize_section_size(CodeSection* cs, csize_t size) { |
153 | assert(cs != &_insts, "insts is the memory provider, not the consumer")do { if (!(cs != &_insts)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 153, "assert(" "cs != &_insts" ") failed", "insts is the memory provider, not the consumer" ); ::breakpoint(); } } while (0); |
154 | csize_t slop = CodeSection::end_slop(); // margin between sections |
155 | int align = cs->alignment(); |
156 | assert(is_power_of_2(align), "sanity")do { if (!(is_power_of_2(align))) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 156, "assert(" "is_power_of_2(align)" ") failed", "sanity") ; ::breakpoint(); } } while (0); |
157 | address start = _insts._start; |
158 | address limit = _insts._limit; |
159 | address middle = limit - size; |
160 | middle -= (intptr_t)middle & (align-1); // align the division point downward |
161 | guarantee(middle - slop > start, "need enough space to divide up")do { if (!(middle - slop > start)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 161, "guarantee(" "middle - slop > start" ") failed", "need enough space to divide up" ); ::breakpoint(); } } while (0); |
162 | _insts._limit = middle - slop; // subtract desired space, plus slop |
163 | cs->initialize(middle, limit - middle); |
164 | assert(cs->start() == middle, "sanity")do { if (!(cs->start() == middle)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 164, "assert(" "cs->start() == middle" ") failed", "sanity" ); ::breakpoint(); } } while (0); |
165 | assert(cs->limit() == limit, "sanity")do { if (!(cs->limit() == limit)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 165, "assert(" "cs->limit() == limit" ") failed", "sanity" ); ::breakpoint(); } } while (0); |
166 | // give it some relocations to start with, if the main section has them |
167 | if (_insts.has_locs()) cs->initialize_locs(1); |
168 | } |
169 | |
170 | void CodeBuffer::set_blob(BufferBlob* blob) { |
171 | _blob = blob; |
172 | if (blob != NULL__null) { |
173 | address start = blob->content_begin(); |
174 | address end = blob->content_end(); |
175 | // Round up the starting address. |
176 | int align = _insts.alignment(); |
177 | start += (-(intptr_t)start) & (align-1); |
178 | _total_start = start; |
179 | _total_size = end - start; |
180 | } else { |
181 | #ifdef ASSERT1 |
182 | // Clean out dangling pointers. |
183 | _total_start = badAddress((address)::badAddressVal); |
184 | _consts._start = _consts._end = badAddress((address)::badAddressVal); |
185 | _insts._start = _insts._end = badAddress((address)::badAddressVal); |
186 | _stubs._start = _stubs._end = badAddress((address)::badAddressVal); |
187 | #endif //ASSERT |
188 | } |
189 | } |
190 | |
191 | void CodeBuffer::free_blob() { |
192 | if (_blob != NULL__null) { |
193 | BufferBlob::free(_blob); |
194 | set_blob(NULL__null); |
195 | } |
196 | } |
197 | |
198 | const char* CodeBuffer::code_section_name(int n) { |
199 | #ifdef PRODUCT |
200 | return NULL__null; |
201 | #else //PRODUCT |
202 | switch (n) { |
203 | case SECT_CONSTS: return "consts"; |
204 | case SECT_INSTS: return "insts"; |
205 | case SECT_STUBS: return "stubs"; |
206 | default: return NULL__null; |
207 | } |
208 | #endif //PRODUCT |
209 | } |
210 | |
211 | int CodeBuffer::section_index_of(address addr) const { |
212 | for (int n = 0; n < (int)SECT_LIMIT; n++) { |
213 | const CodeSection* cs = code_section(n); |
214 | if (cs->allocates(addr)) return n; |
215 | } |
216 | return SECT_NONE; |
217 | } |
218 | |
219 | int CodeBuffer::locator(address addr) const { |
220 | for (int n = 0; n < (int)SECT_LIMIT; n++) { |
221 | const CodeSection* cs = code_section(n); |
222 | if (cs->allocates(addr)) { |
223 | return locator(addr - cs->start(), n); |
224 | } |
225 | } |
226 | return -1; |
227 | } |
228 | |
229 | |
230 | bool CodeBuffer::is_backward_branch(Label& L) { |
231 | return L.is_bound() && insts_end() <= locator_address(L.loc()); |
232 | } |
233 | |
234 | #ifndef PRODUCT |
235 | address CodeBuffer::decode_begin() { |
236 | address begin = _insts.start(); |
237 | if (_decode_begin != NULL__null && _decode_begin > begin) |
238 | begin = _decode_begin; |
239 | return begin; |
240 | } |
241 | #endif // !PRODUCT |
242 | |
243 | GrowableArray<int>* CodeBuffer::create_patch_overflow() { |
244 | if (_overflow_arena == NULL__null) { |
245 | _overflow_arena = new (mtCode) Arena(mtCode); |
246 | } |
247 | return new (_overflow_arena) GrowableArray<int>(_overflow_arena, 8, 0, 0); |
248 | } |
249 | |
250 | |
251 | // Helper function for managing labels and their target addresses. |
252 | // Returns a sensible address, and if it is not the label's final |
253 | // address, notes the dependency (at 'branch_pc') on the label. |
254 | address CodeSection::target(Label& L, address branch_pc) { |
255 | if (L.is_bound()) { |
256 | int loc = L.loc(); |
257 | if (index() == CodeBuffer::locator_sect(loc)) { |
258 | return start() + CodeBuffer::locator_pos(loc); |
259 | } else { |
260 | return outer()->locator_address(loc); |
261 | } |
262 | } else { |
263 | assert(allocates2(branch_pc), "sanity")do { if (!(allocates2(branch_pc))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 263, "assert(" "allocates2(branch_pc)" ") failed", "sanity" ); ::breakpoint(); } } while (0); |
264 | address base = start(); |
265 | int patch_loc = CodeBuffer::locator(branch_pc - base, index()); |
266 | L.add_patch_at(outer(), patch_loc); |
267 | |
268 | // Need to return a pc, doesn't matter what it is since it will be |
269 | // replaced during resolution later. |
270 | // Don't return NULL or badAddress, since branches shouldn't overflow. |
271 | // Don't return base either because that could overflow displacements |
272 | // for shorter branches. It will get checked when bound. |
273 | return branch_pc; |
274 | } |
275 | } |
276 | |
277 | void CodeSection::relocate(address at, relocInfo::relocType rtype, int format, jint method_index) { |
278 | RelocationHolder rh; |
279 | switch (rtype) { |
280 | case relocInfo::none: return; |
281 | case relocInfo::opt_virtual_call_type: { |
282 | rh = opt_virtual_call_Relocation::spec(method_index); |
283 | break; |
284 | } |
285 | case relocInfo::static_call_type: { |
286 | rh = static_call_Relocation::spec(method_index); |
287 | break; |
288 | } |
289 | case relocInfo::virtual_call_type: { |
290 | assert(method_index == 0, "resolved method overriding is not supported")do { if (!(method_index == 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 290, "assert(" "method_index == 0" ") failed", "resolved method overriding is not supported" ); ::breakpoint(); } } while (0); |
291 | rh = Relocation::spec_simple(rtype); |
292 | break; |
293 | } |
294 | default: { |
295 | rh = Relocation::spec_simple(rtype); |
296 | break; |
297 | } |
298 | } |
299 | relocate(at, rh, format); |
300 | } |
301 | |
302 | void CodeSection::relocate(address at, RelocationHolder const& spec, int format) { |
303 | // Do not relocate in scratch buffers. |
304 | if (scratch_emit()) { return; } |
305 | Relocation* reloc = spec.reloc(); |
306 | relocInfo::relocType rtype = (relocInfo::relocType) reloc->type(); |
307 | if (rtype == relocInfo::none) return; |
308 | |
309 | // The assertion below has been adjusted, to also work for |
310 | // relocation for fixup. Sometimes we want to put relocation |
311 | // information for the next instruction, since it will be patched |
312 | // with a call. |
313 | assert(start() <= at && at <= end()+1,do { if (!(start() <= at && at <= end()+1)) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 314, "assert(" "start() <= at && at <= end()+1" ") failed", "cannot relocate data outside code boundaries"); ::breakpoint(); } } while (0) |
314 | "cannot relocate data outside code boundaries")do { if (!(start() <= at && at <= end()+1)) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 314, "assert(" "start() <= at && at <= end()+1" ") failed", "cannot relocate data outside code boundaries"); ::breakpoint(); } } while (0); |
315 | |
316 | if (!has_locs()) { |
317 | // no space for relocation information provided => code cannot be |
318 | // relocated. Make sure that relocate is only called with rtypes |
319 | // that can be ignored for this kind of code. |
320 | assert(rtype == relocInfo::none ||do { if (!(rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo ::section_word_type || rtype == relocInfo::external_word_type )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 325, "assert(" "rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo::section_word_type || rtype == relocInfo::external_word_type" ") failed", "code needs relocation information"); ::breakpoint (); } } while (0) |
321 | rtype == relocInfo::runtime_call_type ||do { if (!(rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo ::section_word_type || rtype == relocInfo::external_word_type )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 325, "assert(" "rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo::section_word_type || rtype == relocInfo::external_word_type" ") failed", "code needs relocation information"); ::breakpoint (); } } while (0) |
322 | rtype == relocInfo::internal_word_type||do { if (!(rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo ::section_word_type || rtype == relocInfo::external_word_type )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 325, "assert(" "rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo::section_word_type || rtype == relocInfo::external_word_type" ") failed", "code needs relocation information"); ::breakpoint (); } } while (0) |
323 | rtype == relocInfo::section_word_type ||do { if (!(rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo ::section_word_type || rtype == relocInfo::external_word_type )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 325, "assert(" "rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo::section_word_type || rtype == relocInfo::external_word_type" ") failed", "code needs relocation information"); ::breakpoint (); } } while (0) |
324 | rtype == relocInfo::external_word_type,do { if (!(rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo ::section_word_type || rtype == relocInfo::external_word_type )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 325, "assert(" "rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo::section_word_type || rtype == relocInfo::external_word_type" ") failed", "code needs relocation information"); ::breakpoint (); } } while (0) |
325 | "code needs relocation information")do { if (!(rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo ::section_word_type || rtype == relocInfo::external_word_type )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 325, "assert(" "rtype == relocInfo::none || rtype == relocInfo::runtime_call_type || rtype == relocInfo::internal_word_type|| rtype == relocInfo::section_word_type || rtype == relocInfo::external_word_type" ") failed", "code needs relocation information"); ::breakpoint (); } } while (0); |
326 | // leave behind an indication that we attempted a relocation |
327 | DEBUG_ONLY(_locs_start = _locs_limit = (relocInfo*)badAddress)_locs_start = _locs_limit = (relocInfo*)((address)::badAddressVal ); |
328 | return; |
329 | } |
330 | |
331 | // Advance the point, noting the offset we'll have to record. |
332 | csize_t offset = at - locs_point(); |
333 | set_locs_point(at); |
334 | |
335 | // Test for a couple of overflow conditions; maybe expand the buffer. |
336 | relocInfo* end = locs_end(); |
337 | relocInfo* req = end + relocInfo::length_limit; |
338 | // Check for (potential) overflow |
339 | if (req >= locs_limit() || offset >= relocInfo::offset_limit()) { |
340 | req += (uint)offset / (uint)relocInfo::offset_limit(); |
341 | if (req >= locs_limit()) { |
342 | // Allocate or reallocate. |
343 | expand_locs(locs_count() + (req - end)); |
344 | // reload pointer |
345 | end = locs_end(); |
346 | } |
347 | } |
348 | |
349 | // If the offset is giant, emit filler relocs, of type 'none', but |
350 | // each carrying the largest possible offset, to advance the locs_point. |
351 | while (offset >= relocInfo::offset_limit()) { |
352 | assert(end < locs_limit(), "adjust previous paragraph of code")do { if (!(end < locs_limit())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 352, "assert(" "end < locs_limit()" ") failed", "adjust previous paragraph of code" ); ::breakpoint(); } } while (0); |
353 | *end++ = filler_relocInfo(); |
354 | offset -= filler_relocInfo().addr_offset(); |
355 | } |
356 | |
357 | // If it's a simple reloc with no data, we'll just write (rtype | offset). |
358 | (*end) = relocInfo(rtype, offset, format); |
359 | |
360 | // If it has data, insert the prefix, as (data_prefix_tag | data1), data2. |
361 | end->initialize(this, reloc); |
362 | } |
363 | |
364 | void CodeSection::initialize_locs(int locs_capacity) { |
365 | assert(_locs_start == NULL, "only one locs init step, please")do { if (!(_locs_start == __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 365, "assert(" "_locs_start == __null" ") failed", "only one locs init step, please" ); ::breakpoint(); } } while (0); |
366 | // Apply a priori lower limits to relocation size: |
367 | csize_t min_locs = MAX2(size() / 16, (csize_t)4); |
368 | if (locs_capacity < min_locs) locs_capacity = min_locs; |
369 | relocInfo* locs_start = NEW_RESOURCE_ARRAY(relocInfo, locs_capacity)(relocInfo*) resource_allocate_bytes((locs_capacity) * sizeof (relocInfo)); |
370 | _locs_start = locs_start; |
371 | _locs_end = locs_start; |
372 | _locs_limit = locs_start + locs_capacity; |
373 | _locs_own = true; |
374 | } |
375 | |
376 | void CodeSection::initialize_shared_locs(relocInfo* buf, int length) { |
377 | assert(_locs_start == NULL, "do this before locs are allocated")do { if (!(_locs_start == __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 377, "assert(" "_locs_start == __null" ") failed", "do this before locs are allocated" ); ::breakpoint(); } } while (0); |
378 | // Internal invariant: locs buf must be fully aligned. |
379 | // See copy_relocations_to() below. |
380 | while ((uintptr_t)buf % HeapWordSize != 0 && length > 0) { |
381 | ++buf; --length; |
382 | } |
383 | if (length > 0) { |
384 | _locs_start = buf; |
385 | _locs_end = buf; |
386 | _locs_limit = buf + length; |
387 | _locs_own = false; |
388 | } |
389 | } |
390 | |
391 | void CodeSection::initialize_locs_from(const CodeSection* source_cs) { |
392 | int lcount = source_cs->locs_count(); |
393 | if (lcount != 0) { |
394 | initialize_shared_locs(source_cs->locs_start(), lcount); |
395 | _locs_end = _locs_limit = _locs_start + lcount; |
396 | assert(is_allocated(), "must have copied code already")do { if (!(is_allocated())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 396, "assert(" "is_allocated()" ") failed", "must have copied code already" ); ::breakpoint(); } } while (0); |
397 | set_locs_point(start() + source_cs->locs_point_off()); |
398 | } |
399 | assert(this->locs_count() == source_cs->locs_count(), "sanity")do { if (!(this->locs_count() == source_cs->locs_count( ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 399, "assert(" "this->locs_count() == source_cs->locs_count()" ") failed", "sanity"); ::breakpoint(); } } while (0); |
400 | } |
401 | |
402 | void CodeSection::expand_locs(int new_capacity) { |
403 | if (_locs_start == NULL__null) { |
404 | initialize_locs(new_capacity); |
405 | return; |
406 | } else { |
407 | int old_count = locs_count(); |
408 | int old_capacity = locs_capacity(); |
409 | if (new_capacity < old_capacity * 2) |
410 | new_capacity = old_capacity * 2; |
411 | relocInfo* locs_start; |
412 | if (_locs_own) { |
413 | locs_start = REALLOC_RESOURCE_ARRAY(relocInfo, _locs_start, old_capacity, new_capacity)(relocInfo*) resource_reallocate_bytes((char*)(_locs_start), ( old_capacity) * sizeof(relocInfo), (new_capacity) * sizeof(relocInfo )); |
414 | } else { |
415 | locs_start = NEW_RESOURCE_ARRAY(relocInfo, new_capacity)(relocInfo*) resource_allocate_bytes((new_capacity) * sizeof( relocInfo)); |
416 | Copy::conjoint_jbytes(_locs_start, locs_start, old_capacity * sizeof(relocInfo)); |
417 | _locs_own = true; |
418 | } |
419 | _locs_start = locs_start; |
420 | _locs_end = locs_start + old_count; |
421 | _locs_limit = locs_start + new_capacity; |
422 | } |
423 | } |
424 | |
425 | |
426 | /// Support for emitting the code to its final location. |
427 | /// The pattern is the same for all functions. |
428 | /// We iterate over all the sections, padding each to alignment. |
429 | |
430 | csize_t CodeBuffer::total_content_size() const { |
431 | csize_t size_so_far = 0; |
432 | for (int n = 0; n < (int)SECT_LIMIT; n++) { |
433 | const CodeSection* cs = code_section(n); |
434 | if (cs->is_empty()) continue; // skip trivial section |
435 | size_so_far = cs->align_at_start(size_so_far); |
436 | size_so_far += cs->size(); |
437 | } |
438 | return size_so_far; |
439 | } |
440 | |
441 | void CodeBuffer::compute_final_layout(CodeBuffer* dest) const { |
442 | address buf = dest->_total_start; |
443 | csize_t buf_offset = 0; |
444 | assert(dest->_total_size >= total_content_size(), "must be big enough")do { if (!(dest->_total_size >= total_content_size())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 444, "assert(" "dest->_total_size >= total_content_size()" ") failed", "must be big enough"); ::breakpoint(); } } while (0); |
445 | |
446 | { |
447 | // not sure why this is here, but why not... |
448 | int alignSize = MAX2((intx) sizeof(jdouble), CodeEntryAlignment); |
449 | assert( (dest->_total_start - _insts.start()) % alignSize == 0, "copy must preserve alignment")do { if (!((dest->_total_start - _insts.start()) % alignSize == 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 449, "assert(" "(dest->_total_start - _insts.start()) % alignSize == 0" ") failed", "copy must preserve alignment"); ::breakpoint(); } } while (0); |
450 | } |
451 | |
452 | const CodeSection* prev_cs = NULL__null; |
453 | CodeSection* prev_dest_cs = NULL__null; |
454 | |
455 | for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
456 | // figure compact layout of each section |
457 | const CodeSection* cs = code_section(n); |
458 | csize_t csize = cs->size(); |
459 | |
460 | CodeSection* dest_cs = dest->code_section(n); |
461 | if (!cs->is_empty()) { |
462 | // Compute initial padding; assign it to the previous non-empty guy. |
463 | // Cf. figure_expanded_capacities. |
464 | csize_t padding = cs->align_at_start(buf_offset) - buf_offset; |
465 | if (prev_dest_cs != NULL__null) { |
466 | if (padding != 0) { |
467 | buf_offset += padding; |
468 | prev_dest_cs->_limit += padding; |
469 | } |
470 | } else { |
471 | guarantee(padding == 0, "In first iteration no padding should be needed.")do { if (!(padding == 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 471, "guarantee(" "padding == 0" ") failed", "In first iteration no padding should be needed." ); ::breakpoint(); } } while (0); |
472 | } |
473 | prev_dest_cs = dest_cs; |
474 | prev_cs = cs; |
Value stored to 'prev_cs' is never read | |
475 | } |
476 | |
477 | debug_only(dest_cs->_start = NULL)dest_cs->_start = __null; // defeat double-initialization assert |
478 | dest_cs->initialize(buf+buf_offset, csize); |
479 | dest_cs->set_end(buf+buf_offset+csize); |
480 | assert(dest_cs->is_allocated(), "must always be allocated")do { if (!(dest_cs->is_allocated())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 480, "assert(" "dest_cs->is_allocated()" ") failed", "must always be allocated" ); ::breakpoint(); } } while (0); |
481 | assert(cs->is_empty() == dest_cs->is_empty(), "sanity")do { if (!(cs->is_empty() == dest_cs->is_empty())) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 481, "assert(" "cs->is_empty() == dest_cs->is_empty()" ") failed", "sanity"); ::breakpoint(); } } while (0); |
482 | |
483 | buf_offset += csize; |
484 | } |
485 | |
486 | // Done calculating sections; did it come out to the right end? |
487 | assert(buf_offset == total_content_size(), "sanity")do { if (!(buf_offset == total_content_size())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 487, "assert(" "buf_offset == total_content_size()" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
488 | debug_only(dest->verify_section_allocation();)dest->verify_section_allocation(); |
489 | } |
490 | |
491 | // Append an oop reference that keeps the class alive. |
492 | static void append_oop_references(GrowableArray<oop>* oops, Klass* k) { |
493 | oop cl = k->klass_holder(); |
494 | if (cl != NULL__null && !oops->contains(cl)) { |
495 | oops->append(cl); |
496 | } |
497 | } |
498 | |
499 | void CodeBuffer::finalize_oop_references(const methodHandle& mh) { |
500 | NoSafepointVerifier nsv; |
501 | |
502 | GrowableArray<oop> oops; |
503 | |
504 | // Make sure that immediate metadata records something in the OopRecorder |
505 | for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
506 | // pull code out of each section |
507 | CodeSection* cs = code_section(n); |
508 | if (cs->is_empty()) continue; // skip trivial section |
509 | RelocIterator iter(cs); |
510 | while (iter.next()) { |
511 | if (iter.type() == relocInfo::metadata_type) { |
512 | metadata_Relocation* md = iter.metadata_reloc(); |
513 | if (md->metadata_is_immediate()) { |
514 | Metadata* m = md->metadata_value(); |
515 | if (oop_recorder()->is_real(m)) { |
516 | if (m->is_methodData()) { |
517 | m = ((MethodData*)m)->method(); |
518 | } |
519 | if (m->is_method()) { |
520 | m = ((Method*)m)->method_holder(); |
521 | } |
522 | if (m->is_klass()) { |
523 | append_oop_references(&oops, (Klass*)m); |
524 | } else { |
525 | // XXX This will currently occur for MDO which don't |
526 | // have a backpointer. This has to be fixed later. |
527 | m->print(); |
528 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 528); ::breakpoint(); } while (0); |
529 | } |
530 | } |
531 | } |
532 | } |
533 | } |
534 | } |
535 | |
536 | if (!oop_recorder()->is_unused()) { |
537 | for (int i = 0; i < oop_recorder()->metadata_count(); i++) { |
538 | Metadata* m = oop_recorder()->metadata_at(i); |
539 | if (oop_recorder()->is_real(m)) { |
540 | if (m->is_methodData()) { |
541 | m = ((MethodData*)m)->method(); |
542 | } |
543 | if (m->is_method()) { |
544 | m = ((Method*)m)->method_holder(); |
545 | } |
546 | if (m->is_klass()) { |
547 | append_oop_references(&oops, (Klass*)m); |
548 | } else { |
549 | m->print(); |
550 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 550); ::breakpoint(); } while (0); |
551 | } |
552 | } |
553 | } |
554 | |
555 | } |
556 | |
557 | // Add the class loader of Method* for the nmethod itself |
558 | append_oop_references(&oops, mh->method_holder()); |
559 | |
560 | // Add any oops that we've found |
561 | Thread* thread = Thread::current(); |
562 | for (int i = 0; i < oops.length(); i++) { |
563 | oop_recorder()->find_index((jobject)thread->handle_area()->allocate_handle(oops.at(i))); |
564 | } |
565 | } |
566 | |
567 | |
568 | |
569 | csize_t CodeBuffer::total_offset_of(const CodeSection* cs) const { |
570 | csize_t size_so_far = 0; |
571 | for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
572 | const CodeSection* cur_cs = code_section(n); |
573 | if (!cur_cs->is_empty()) { |
574 | size_so_far = cur_cs->align_at_start(size_so_far); |
575 | } |
576 | if (cur_cs->index() == cs->index()) { |
577 | return size_so_far; |
578 | } |
579 | size_so_far += cur_cs->size(); |
580 | } |
581 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 581); ::breakpoint(); } while (0); |
582 | return -1; |
583 | } |
584 | |
585 | csize_t CodeBuffer::total_relocation_size() const { |
586 | csize_t total = copy_relocations_to(NULL__null); // dry run only |
587 | return (csize_t) align_up(total, HeapWordSize); |
588 | } |
589 | |
590 | csize_t CodeBuffer::copy_relocations_to(address buf, csize_t buf_limit, bool only_inst) const { |
591 | csize_t buf_offset = 0; |
592 | csize_t code_end_so_far = 0; |
593 | csize_t code_point_so_far = 0; |
594 | |
595 | assert((uintptr_t)buf % HeapWordSize == 0, "buf must be fully aligned")do { if (!((uintptr_t)buf % HeapWordSize == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 595, "assert(" "(uintptr_t)buf % HeapWordSize == 0" ") failed" , "buf must be fully aligned"); ::breakpoint(); } } while (0); |
596 | assert(buf_limit % HeapWordSize == 0, "buf must be evenly sized")do { if (!(buf_limit % HeapWordSize == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 596, "assert(" "buf_limit % HeapWordSize == 0" ") failed", "buf must be evenly sized" ); ::breakpoint(); } } while (0); |
597 | |
598 | for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) { |
599 | if (only_inst && (n != (int)SECT_INSTS)) { |
600 | // Need only relocation info for code. |
601 | continue; |
602 | } |
603 | // pull relocs out of each section |
604 | const CodeSection* cs = code_section(n); |
605 | assert(!(cs->is_empty() && cs->locs_count() > 0), "sanity")do { if (!(!(cs->is_empty() && cs->locs_count() > 0))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 605, "assert(" "!(cs->is_empty() && cs->locs_count() > 0)" ") failed", "sanity"); ::breakpoint(); } } while (0); |
606 | if (cs->is_empty()) continue; // skip trivial section |
607 | relocInfo* lstart = cs->locs_start(); |
608 | relocInfo* lend = cs->locs_end(); |
609 | csize_t lsize = (csize_t)( (address)lend - (address)lstart ); |
610 | csize_t csize = cs->size(); |
611 | code_end_so_far = cs->align_at_start(code_end_so_far); |
612 | |
613 | if (lsize > 0) { |
614 | // Figure out how to advance the combined relocation point |
615 | // first to the beginning of this section. |
616 | // We'll insert one or more filler relocs to span that gap. |
617 | // (Don't bother to improve this by editing the first reloc's offset.) |
618 | csize_t new_code_point = code_end_so_far; |
619 | for (csize_t jump; |
620 | code_point_so_far < new_code_point; |
621 | code_point_so_far += jump) { |
622 | jump = new_code_point - code_point_so_far; |
623 | relocInfo filler = filler_relocInfo(); |
624 | if (jump >= filler.addr_offset()) { |
625 | jump = filler.addr_offset(); |
626 | } else { // else shrink the filler to fit |
627 | filler = relocInfo(relocInfo::none, jump); |
628 | } |
629 | if (buf != NULL__null) { |
630 | assert(buf_offset + (csize_t)sizeof(filler) <= buf_limit, "filler in bounds")do { if (!(buf_offset + (csize_t)sizeof(filler) <= buf_limit )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 630, "assert(" "buf_offset + (csize_t)sizeof(filler) <= buf_limit" ") failed", "filler in bounds"); ::breakpoint(); } } while ( 0); |
631 | *(relocInfo*)(buf+buf_offset) = filler; |
632 | } |
633 | buf_offset += sizeof(filler); |
634 | } |
635 | |
636 | // Update code point and end to skip past this section: |
637 | csize_t last_code_point = code_end_so_far + cs->locs_point_off(); |
638 | assert(code_point_so_far <= last_code_point, "sanity")do { if (!(code_point_so_far <= last_code_point)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 638, "assert(" "code_point_so_far <= last_code_point" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
639 | code_point_so_far = last_code_point; // advance past this guy's relocs |
640 | } |
641 | code_end_so_far += csize; // advance past this guy's instructions too |
642 | |
643 | // Done with filler; emit the real relocations: |
644 | if (buf != NULL__null && lsize != 0) { |
645 | assert(buf_offset + lsize <= buf_limit, "target in bounds")do { if (!(buf_offset + lsize <= buf_limit)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 645, "assert(" "buf_offset + lsize <= buf_limit" ") failed" , "target in bounds"); ::breakpoint(); } } while (0); |
646 | assert((uintptr_t)lstart % HeapWordSize == 0, "sane start")do { if (!((uintptr_t)lstart % HeapWordSize == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 646, "assert(" "(uintptr_t)lstart % HeapWordSize == 0" ") failed" , "sane start"); ::breakpoint(); } } while (0); |
647 | if (buf_offset % HeapWordSize == 0) { |
648 | // Use wordwise copies if possible: |
649 | Copy::disjoint_words((HeapWord*)lstart, |
650 | (HeapWord*)(buf+buf_offset), |
651 | (lsize + HeapWordSize-1) / HeapWordSize); |
652 | } else { |
653 | Copy::conjoint_jbytes(lstart, buf+buf_offset, lsize); |
654 | } |
655 | } |
656 | buf_offset += lsize; |
657 | } |
658 | |
659 | // Align end of relocation info in target. |
660 | while (buf_offset % HeapWordSize != 0) { |
661 | if (buf != NULL__null) { |
662 | relocInfo padding = relocInfo(relocInfo::none, 0); |
663 | assert(buf_offset + (csize_t)sizeof(padding) <= buf_limit, "padding in bounds")do { if (!(buf_offset + (csize_t)sizeof(padding) <= buf_limit )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 663, "assert(" "buf_offset + (csize_t)sizeof(padding) <= buf_limit" ") failed", "padding in bounds"); ::breakpoint(); } } while ( 0); |
664 | *(relocInfo*)(buf+buf_offset) = padding; |
665 | } |
666 | buf_offset += sizeof(relocInfo); |
667 | } |
668 | |
669 | assert(only_inst || code_end_so_far == total_content_size(), "sanity")do { if (!(only_inst || code_end_so_far == total_content_size ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 669, "assert(" "only_inst || code_end_so_far == total_content_size()" ") failed", "sanity"); ::breakpoint(); } } while (0); |
670 | |
671 | return buf_offset; |
672 | } |
673 | |
674 | csize_t CodeBuffer::copy_relocations_to(CodeBlob* dest) const { |
675 | address buf = NULL__null; |
676 | csize_t buf_offset = 0; |
677 | csize_t buf_limit = 0; |
678 | |
679 | if (dest != NULL__null) { |
680 | buf = (address)dest->relocation_begin(); |
681 | buf_limit = (address)dest->relocation_end() - buf; |
682 | } |
683 | // if dest == NULL, this is just the sizing pass |
684 | // |
685 | buf_offset = copy_relocations_to(buf, buf_limit, false); |
686 | |
687 | return buf_offset; |
688 | } |
689 | |
690 | void CodeBuffer::copy_code_to(CodeBlob* dest_blob) { |
691 | #ifndef PRODUCT |
692 | if (PrintNMethods && (WizardMode || Verbose)) { |
693 | tty->print("done with CodeBuffer:"); |
694 | ((CodeBuffer*)this)->print(); |
695 | } |
696 | #endif //PRODUCT |
697 | |
698 | CodeBuffer dest(dest_blob); |
699 | assert(dest_blob->content_size() >= total_content_size(), "good sizing")do { if (!(dest_blob->content_size() >= total_content_size ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 699, "assert(" "dest_blob->content_size() >= total_content_size()" ") failed", "good sizing"); ::breakpoint(); } } while (0); |
700 | this->compute_final_layout(&dest); |
701 | |
702 | // Set beginning of constant table before relocating. |
703 | dest_blob->set_ctable_begin(dest.consts()->start()); |
704 | |
705 | relocate_code_to(&dest); |
706 | |
707 | // Share assembly remarks and debug strings with the blob. |
708 | NOT_PRODUCT(dest_blob->use_remarks(_asm_remarks))dest_blob->use_remarks(_asm_remarks); |
709 | NOT_PRODUCT(dest_blob->use_strings(_dbg_strings))dest_blob->use_strings(_dbg_strings); |
710 | |
711 | // Done moving code bytes; were they the right size? |
712 | assert((int)align_up(dest.total_content_size(), oopSize) == dest_blob->content_size(), "sanity")do { if (!((int)align_up(dest.total_content_size(), oopSize) == dest_blob->content_size())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 712, "assert(" "(int)align_up(dest.total_content_size(), oopSize) == dest_blob->content_size()" ") failed", "sanity"); ::breakpoint(); } } while (0); |
713 | |
714 | // Flush generated code |
715 | ICache::invalidate_range(dest_blob->code_begin(), dest_blob->code_size()); |
716 | } |
717 | |
718 | // Move all my code into another code buffer. Consult applicable |
719 | // relocs to repair embedded addresses. The layout in the destination |
720 | // CodeBuffer is different to the source CodeBuffer: the destination |
721 | // CodeBuffer gets the final layout (consts, insts, stubs in order of |
722 | // ascending address). |
723 | void CodeBuffer::relocate_code_to(CodeBuffer* dest) const { |
724 | address dest_end = dest->_total_start + dest->_total_size; |
725 | address dest_filled = NULL__null; |
726 | for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
727 | // pull code out of each section |
728 | const CodeSection* cs = code_section(n); |
729 | if (cs->is_empty()) continue; // skip trivial section |
730 | CodeSection* dest_cs = dest->code_section(n); |
731 | assert(cs->size() == dest_cs->size(), "sanity")do { if (!(cs->size() == dest_cs->size())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 731, "assert(" "cs->size() == dest_cs->size()" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
732 | csize_t usize = dest_cs->size(); |
733 | csize_t wsize = align_up(usize, HeapWordSize); |
734 | assert(dest_cs->start() + wsize <= dest_end, "no overflow")do { if (!(dest_cs->start() + wsize <= dest_end)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 734, "assert(" "dest_cs->start() + wsize <= dest_end" ") failed", "no overflow"); ::breakpoint(); } } while (0); |
735 | // Copy the code as aligned machine words. |
736 | // This may also include an uninitialized partial word at the end. |
737 | Copy::disjoint_words((HeapWord*)cs->start(), |
738 | (HeapWord*)dest_cs->start(), |
739 | wsize / HeapWordSize); |
740 | |
741 | if (dest->blob() == NULL__null) { |
742 | // Destination is a final resting place, not just another buffer. |
743 | // Normalize uninitialized bytes in the final padding. |
744 | Copy::fill_to_bytes(dest_cs->end(), dest_cs->remaining(), |
745 | Assembler::code_fill_byte()); |
746 | } |
747 | // Keep track of the highest filled address |
748 | dest_filled = MAX2(dest_filled, dest_cs->end() + dest_cs->remaining()); |
749 | |
750 | assert(cs->locs_start() != (relocInfo*)badAddress,do { if (!(cs->locs_start() != (relocInfo*)((address)::badAddressVal ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 751, "assert(" "cs->locs_start() != (relocInfo*)((address)::badAddressVal)" ") failed", "this section carries no reloc storage, but reloc was attempted" ); ::breakpoint(); } } while (0) |
751 | "this section carries no reloc storage, but reloc was attempted")do { if (!(cs->locs_start() != (relocInfo*)((address)::badAddressVal ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 751, "assert(" "cs->locs_start() != (relocInfo*)((address)::badAddressVal)" ") failed", "this section carries no reloc storage, but reloc was attempted" ); ::breakpoint(); } } while (0); |
752 | |
753 | // Make the new code copy use the old copy's relocations: |
754 | dest_cs->initialize_locs_from(cs); |
755 | } |
756 | |
757 | // Do relocation after all sections are copied. |
758 | // This is necessary if the code uses constants in stubs, which are |
759 | // relocated when the corresponding instruction in the code (e.g., a |
760 | // call) is relocated. Stubs are placed behind the main code |
761 | // section, so that section has to be copied before relocating. |
762 | for (int n = (int) SECT_FIRST; n < (int)SECT_LIMIT; n++) { |
763 | // pull code out of each section |
764 | const CodeSection* cs = code_section(n); |
765 | if (cs->is_empty()) continue; // skip trivial section |
766 | CodeSection* dest_cs = dest->code_section(n); |
767 | { // Repair the pc relative information in the code after the move |
768 | RelocIterator iter(dest_cs); |
769 | while (iter.next()) { |
770 | iter.reloc()->fix_relocation_after_move(this, dest); |
771 | } |
772 | } |
773 | } |
774 | |
775 | if (dest->blob() == NULL__null && dest_filled != NULL__null) { |
776 | // Destination is a final resting place, not just another buffer. |
777 | // Normalize uninitialized bytes in the final padding. |
778 | Copy::fill_to_bytes(dest_filled, dest_end - dest_filled, |
779 | Assembler::code_fill_byte()); |
780 | |
781 | } |
782 | } |
783 | |
784 | csize_t CodeBuffer::figure_expanded_capacities(CodeSection* which_cs, |
785 | csize_t amount, |
786 | csize_t* new_capacity) { |
787 | csize_t new_total_cap = 0; |
788 | |
789 | for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
790 | const CodeSection* sect = code_section(n); |
791 | |
792 | if (!sect->is_empty()) { |
793 | // Compute initial padding; assign it to the previous section, |
794 | // even if it's empty (e.g. consts section can be empty). |
795 | // Cf. compute_final_layout |
796 | csize_t padding = sect->align_at_start(new_total_cap) - new_total_cap; |
797 | if (padding != 0) { |
798 | new_total_cap += padding; |
799 | assert(n - 1 >= SECT_FIRST, "sanity")do { if (!(n - 1 >= SECT_FIRST)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 799, "assert(" "n - 1 >= SECT_FIRST" ") failed", "sanity" ); ::breakpoint(); } } while (0); |
800 | new_capacity[n - 1] += padding; |
801 | } |
802 | } |
803 | |
804 | csize_t exp = sect->size(); // 100% increase |
805 | if ((uint)exp < 4*K) exp = 4*K; // minimum initial increase |
806 | if (sect == which_cs) { |
807 | if (exp < amount) exp = amount; |
808 | if (StressCodeBuffers) exp = amount; // expand only slightly |
809 | } else if (n == SECT_INSTS) { |
810 | // scale down inst increases to a more modest 25% |
811 | exp = 4*K + ((exp - 4*K) >> 2); |
812 | if (StressCodeBuffers) exp = amount / 2; // expand only slightly |
813 | } else if (sect->is_empty()) { |
814 | // do not grow an empty secondary section |
815 | exp = 0; |
816 | } |
817 | // Allow for inter-section slop: |
818 | exp += CodeSection::end_slop(); |
819 | csize_t new_cap = sect->size() + exp; |
820 | if (new_cap < sect->capacity()) { |
821 | // No need to expand after all. |
822 | new_cap = sect->capacity(); |
823 | } |
824 | new_capacity[n] = new_cap; |
825 | new_total_cap += new_cap; |
826 | } |
827 | |
828 | return new_total_cap; |
829 | } |
830 | |
831 | void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) { |
832 | #ifndef PRODUCT |
833 | if (PrintNMethods && (WizardMode || Verbose)) { |
834 | tty->print("expanding CodeBuffer:"); |
835 | this->print(); |
836 | } |
837 | |
838 | if (StressCodeBuffers && blob() != NULL__null) { |
839 | static int expand_count = 0; |
840 | if (expand_count >= 0) expand_count += 1; |
841 | if (expand_count > 100 && is_power_of_2(expand_count)) { |
842 | tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count); |
843 | // simulate an occasional allocation failure: |
844 | free_blob(); |
845 | } |
846 | } |
847 | #endif //PRODUCT |
848 | |
849 | // Resizing must be allowed |
850 | { |
851 | if (blob() == NULL__null) return; // caller must check for blob == NULL |
852 | } |
853 | |
854 | // Figure new capacity for each section. |
855 | csize_t new_capacity[SECT_LIMIT]; |
856 | memset(new_capacity, 0, sizeof(csize_t) * SECT_LIMIT); |
857 | csize_t new_total_cap |
858 | = figure_expanded_capacities(which_cs, amount, new_capacity); |
859 | |
860 | // Create a new (temporary) code buffer to hold all the new data |
861 | CodeBuffer cb(name(), new_total_cap, 0); |
862 | if (cb.blob() == NULL__null) { |
863 | // Failed to allocate in code cache. |
864 | free_blob(); |
865 | return; |
866 | } |
867 | |
868 | // Create an old code buffer to remember which addresses used to go where. |
869 | // This will be useful when we do final assembly into the code cache, |
870 | // because we will need to know how to warp any internal address that |
871 | // has been created at any time in this CodeBuffer's past. |
872 | CodeBuffer* bxp = new CodeBuffer(_total_start, _total_size); |
873 | bxp->take_over_code_from(this); // remember the old undersized blob |
874 | DEBUG_ONLY(this->_blob = NULL)this->_blob = __null; // silence a later assert |
875 | bxp->_before_expand = this->_before_expand; |
876 | this->_before_expand = bxp; |
877 | |
878 | // Give each section its required (expanded) capacity. |
879 | for (int n = (int)SECT_LIMIT-1; n >= SECT_FIRST; n--) { |
880 | CodeSection* cb_sect = cb.code_section(n); |
881 | CodeSection* this_sect = code_section(n); |
882 | if (new_capacity[n] == 0) continue; // already nulled out |
883 | if (n != SECT_INSTS) { |
884 | cb.initialize_section_size(cb_sect, new_capacity[n]); |
885 | } |
886 | assert(cb_sect->capacity() >= new_capacity[n], "big enough")do { if (!(cb_sect->capacity() >= new_capacity[n])) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 886, "assert(" "cb_sect->capacity() >= new_capacity[n]" ") failed", "big enough"); ::breakpoint(); } } while (0); |
887 | address cb_start = cb_sect->start(); |
888 | cb_sect->set_end(cb_start + this_sect->size()); |
889 | if (this_sect->mark() == NULL__null) { |
890 | cb_sect->clear_mark(); |
891 | } else { |
892 | cb_sect->set_mark(cb_start + this_sect->mark_off()); |
893 | } |
894 | } |
895 | |
896 | // Needs to be initialized when calling fix_relocation_after_move. |
897 | cb.blob()->set_ctable_begin(cb.consts()->start()); |
898 | |
899 | // Move all the code and relocations to the new blob: |
900 | relocate_code_to(&cb); |
901 | |
902 | // Copy the temporary code buffer into the current code buffer. |
903 | // Basically, do {*this = cb}, except for some control information. |
904 | this->take_over_code_from(&cb); |
905 | cb.set_blob(NULL__null); |
906 | |
907 | // Zap the old code buffer contents, to avoid mistakenly using them. |
908 | debug_only(Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size,Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size , badCodeHeapFreeVal); |
909 | badCodeHeapFreeVal);)Copy::fill_to_bytes(bxp->_total_start, bxp->_total_size , badCodeHeapFreeVal); |
910 | |
911 | // Make certain that the new sections are all snugly inside the new blob. |
912 | debug_only(verify_section_allocation();)verify_section_allocation(); |
913 | |
914 | #ifndef PRODUCT |
915 | _decode_begin = NULL__null; // sanity |
916 | if (PrintNMethods && (WizardMode || Verbose)) { |
917 | tty->print("expanded CodeBuffer:"); |
918 | this->print(); |
919 | } |
920 | #endif //PRODUCT |
921 | } |
922 | |
923 | void CodeBuffer::take_over_code_from(CodeBuffer* cb) { |
924 | // Must already have disposed of the old blob somehow. |
925 | assert(blob() == NULL, "must be empty")do { if (!(blob() == __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 925, "assert(" "blob() == __null" ") failed", "must be empty" ); ::breakpoint(); } } while (0); |
926 | // Take the new blob away from cb. |
927 | set_blob(cb->blob()); |
928 | // Take over all the section pointers. |
929 | for (int n = 0; n < (int)SECT_LIMIT; n++) { |
930 | CodeSection* cb_sect = cb->code_section(n); |
931 | CodeSection* this_sect = code_section(n); |
932 | this_sect->take_over_code_from(cb_sect); |
933 | } |
934 | _overflow_arena = cb->_overflow_arena; |
935 | // Make sure the old cb won't try to use it or free it. |
936 | DEBUG_ONLY(cb->_blob = (BufferBlob*)badAddress)cb->_blob = (BufferBlob*)((address)::badAddressVal); |
937 | } |
938 | |
939 | void CodeBuffer::verify_section_allocation() { |
940 | address tstart = _total_start; |
941 | if (tstart == badAddress((address)::badAddressVal)) return; // smashed by set_blob(NULL) |
942 | address tend = tstart + _total_size; |
943 | if (_blob != NULL__null) { |
944 | guarantee(tstart >= _blob->content_begin(), "sanity")do { if (!(tstart >= _blob->content_begin())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 944, "guarantee(" "tstart >= _blob->content_begin()" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
945 | guarantee(tend <= _blob->content_end(), "sanity")do { if (!(tend <= _blob->content_end())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 945, "guarantee(" "tend <= _blob->content_end()" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
946 | } |
947 | // Verify disjointness. |
948 | for (int n = (int) SECT_FIRST; n < (int) SECT_LIMIT; n++) { |
949 | CodeSection* sect = code_section(n); |
950 | if (!sect->is_allocated() || sect->is_empty()) { |
951 | continue; |
952 | } |
953 | guarantee(_blob == nullptr || is_aligned(sect->start(), sect->alignment()),do { if (!(_blob == nullptr || is_aligned(sect->start(), sect ->alignment()))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 954, "guarantee(" "_blob == nullptr || is_aligned(sect->start(), sect->alignment())" ") failed", "start is aligned"); ::breakpoint(); } } while ( 0) |
954 | "start is aligned")do { if (!(_blob == nullptr || is_aligned(sect->start(), sect ->alignment()))) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 954, "guarantee(" "_blob == nullptr || is_aligned(sect->start(), sect->alignment())" ") failed", "start is aligned"); ::breakpoint(); } } while ( 0); |
955 | for (int m = n + 1; m < (int) SECT_LIMIT; m++) { |
956 | CodeSection* other = code_section(m); |
957 | if (!other->is_allocated() || other == sect) { |
958 | continue; |
959 | } |
960 | guarantee(other->disjoint(sect), "sanity")do { if (!(other->disjoint(sect))) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 960, "guarantee(" "other->disjoint(sect)" ") failed", "sanity" ); ::breakpoint(); } } while (0); |
961 | } |
962 | guarantee(sect->end() <= tend, "sanity")do { if (!(sect->end() <= tend)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 962, "guarantee(" "sect->end() <= tend" ") failed", "sanity" ); ::breakpoint(); } } while (0); |
963 | guarantee(sect->end() <= sect->limit(), "sanity")do { if (!(sect->end() <= sect->limit())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 963, "guarantee(" "sect->end() <= sect->limit()" ") failed" , "sanity"); ::breakpoint(); } } while (0); |
964 | } |
965 | } |
966 | |
967 | void CodeBuffer::log_section_sizes(const char* name) { |
968 | if (xtty != NULL__null) { |
969 | ttyLocker ttyl; |
970 | // log info about buffer usage |
971 | xtty->print_cr("<blob name='%s' size='%d'>", name, _total_size); |
972 | for (int n = (int) CodeBuffer::SECT_FIRST; n < (int) CodeBuffer::SECT_LIMIT; n++) { |
973 | CodeSection* sect = code_section(n); |
974 | if (!sect->is_allocated() || sect->is_empty()) continue; |
975 | xtty->print_cr("<sect index='%d' size='" SIZE_FORMAT"%" "l" "u" "' free='" SIZE_FORMAT"%" "l" "u" "'/>", |
976 | n, sect->limit() - sect->start(), sect->limit() - sect->end()); |
977 | } |
978 | xtty->print_cr("</blob>"); |
979 | } |
980 | } |
981 | |
982 | #ifndef PRODUCT |
983 | void CodeBuffer::block_comment(ptrdiff_t offset, const char* comment) { |
984 | if (_collect_comments) { |
985 | const char* str = _asm_remarks.insert(offset, comment); |
986 | postcond(str != comment)do { if (!(str != comment)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 986, "assert(" "str != comment" ") failed", "postcond"); :: breakpoint(); } } while (0); |
987 | } |
988 | } |
989 | |
990 | const char* CodeBuffer::code_string(const char* str) { |
991 | const char* tmp = _dbg_strings.insert(str); |
992 | postcond(tmp != str)do { if (!(tmp != str)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 992, "assert(" "tmp != str" ") failed", "postcond"); ::breakpoint (); } } while (0); |
993 | return tmp; |
994 | } |
995 | |
996 | void CodeBuffer::decode() { |
997 | ttyLocker ttyl; |
998 | Disassembler::decode(decode_begin(), insts_end(), tty NOT_PRODUCT(COMMA &asm_remarks()), &asm_remarks()); |
999 | _decode_begin = insts_end(); |
1000 | } |
1001 | |
1002 | void CodeSection::print(const char* name) { |
1003 | csize_t locs_size = locs_end() - locs_start(); |
1004 | tty->print_cr(" %7s.code = " PTR_FORMAT"0x%016" "l" "x" " : " PTR_FORMAT"0x%016" "l" "x" " : " PTR_FORMAT"0x%016" "l" "x" " (%d of %d)", |
1005 | name, p2i(start()), p2i(end()), p2i(limit()), size(), capacity()); |
1006 | tty->print_cr(" %7s.locs = " PTR_FORMAT"0x%016" "l" "x" " : " PTR_FORMAT"0x%016" "l" "x" " : " PTR_FORMAT"0x%016" "l" "x" " (%d of %d) point=%d", |
1007 | name, p2i(locs_start()), p2i(locs_end()), p2i(locs_limit()), locs_size, locs_capacity(), locs_point_off()); |
1008 | if (PrintRelocations) { |
1009 | RelocIterator iter(this); |
1010 | iter.print(); |
1011 | } |
1012 | } |
1013 | |
1014 | void CodeBuffer::print() { |
1015 | if (this == NULL__null) { |
1016 | tty->print_cr("NULL CodeBuffer pointer"); |
1017 | return; |
1018 | } |
1019 | |
1020 | tty->print_cr("CodeBuffer:"); |
1021 | for (int n = 0; n < (int)SECT_LIMIT; n++) { |
1022 | // print each section |
1023 | CodeSection* cs = code_section(n); |
1024 | cs->print(code_section_name(n)); |
1025 | } |
1026 | } |
1027 | |
1028 | // ----- CHeapString ----------------------------------------------------------- |
1029 | |
1030 | class CHeapString : public CHeapObj<mtCode> { |
1031 | public: |
1032 | CHeapString(const char* str) : _string(os::strdup(str)) {} |
1033 | ~CHeapString() { |
1034 | os::free((void*)_string); |
1035 | _string = nullptr; |
1036 | } |
1037 | const char* string() const { return _string; } |
1038 | |
1039 | private: |
1040 | const char* _string; |
1041 | }; |
1042 | |
1043 | // ----- AsmRemarkCollection --------------------------------------------------- |
1044 | |
1045 | class AsmRemarkCollection : public CHeapObj<mtCode> { |
1046 | public: |
1047 | AsmRemarkCollection() : _ref_cnt(1), _remarks(nullptr), _next(nullptr) {} |
1048 | ~AsmRemarkCollection() { |
1049 | assert(is_empty(), "Must 'clear()' before deleting!")do { if (!(is_empty())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1049, "assert(" "is_empty()" ") failed", "Must 'clear()' before deleting!" ); ::breakpoint(); } } while (0); |
1050 | assert(_ref_cnt == 0, "No uses must remain when deleting!")do { if (!(_ref_cnt == 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1050, "assert(" "_ref_cnt == 0" ") failed", "No uses must remain when deleting!" ); ::breakpoint(); } } while (0); |
1051 | } |
1052 | AsmRemarkCollection* reuse() { |
1053 | precond(_ref_cnt > 0)do { if (!(_ref_cnt > 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1053, "assert(" "_ref_cnt > 0" ") failed", "precond"); :: breakpoint(); } } while (0); |
1054 | return _ref_cnt++, this; |
1055 | } |
1056 | |
1057 | const char* insert(uint offset, const char* remark); |
1058 | const char* lookup(uint offset) const; |
1059 | const char* next(uint offset) const; |
1060 | |
1061 | bool is_empty() const { return _remarks == nullptr; } |
1062 | uint clear(); |
1063 | |
1064 | private: |
1065 | struct Cell : CHeapString { |
1066 | Cell(const char* remark, uint offset) : |
1067 | CHeapString(remark), offset(offset), prev(nullptr), next(nullptr) {} |
1068 | void push_back(Cell* cell) { |
1069 | Cell* head = this; |
1070 | Cell* tail = prev; |
1071 | tail->next = cell; |
1072 | cell->next = head; |
1073 | cell->prev = tail; |
1074 | prev = cell; |
1075 | } |
1076 | uint offset; |
1077 | Cell* prev; |
1078 | Cell* next; |
1079 | }; |
1080 | uint _ref_cnt; |
1081 | Cell* _remarks; |
1082 | // Using a 'mutable' iteration pointer to allow 'const' on lookup/next (that |
1083 | // does not change the state of the list per se), supportig a simplistic |
1084 | // iteration scheme. |
1085 | mutable Cell* _next; |
1086 | }; |
1087 | |
1088 | // ----- DbgStringCollection --------------------------------------------------- |
1089 | |
1090 | class DbgStringCollection : public CHeapObj<mtCode> { |
1091 | public: |
1092 | DbgStringCollection() : _ref_cnt(1), _strings(nullptr) {} |
1093 | ~DbgStringCollection() { |
1094 | assert(is_empty(), "Must 'clear()' before deleting!")do { if (!(is_empty())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1094, "assert(" "is_empty()" ") failed", "Must 'clear()' before deleting!" ); ::breakpoint(); } } while (0); |
1095 | assert(_ref_cnt == 0, "No uses must remain when deleting!")do { if (!(_ref_cnt == 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1095, "assert(" "_ref_cnt == 0" ") failed", "No uses must remain when deleting!" ); ::breakpoint(); } } while (0); |
1096 | } |
1097 | DbgStringCollection* reuse() { |
1098 | precond(_ref_cnt > 0)do { if (!(_ref_cnt > 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1098, "assert(" "_ref_cnt > 0" ") failed", "precond"); :: breakpoint(); } } while (0); |
1099 | return _ref_cnt++, this; |
1100 | } |
1101 | |
1102 | const char* insert(const char* str); |
1103 | const char* lookup(const char* str) const; |
1104 | |
1105 | bool is_empty() const { return _strings == nullptr; } |
1106 | uint clear(); |
1107 | |
1108 | private: |
1109 | struct Cell : CHeapString { |
1110 | Cell(const char* dbgstr) : |
1111 | CHeapString(dbgstr), prev(nullptr), next(nullptr) {} |
1112 | void push_back(Cell* cell) { |
1113 | Cell* head = this; |
1114 | Cell* tail = prev; |
1115 | tail->next = cell; |
1116 | cell->next = head; |
1117 | cell->prev = tail; |
1118 | prev = cell; |
1119 | } |
1120 | Cell* prev; |
1121 | Cell* next; |
1122 | }; |
1123 | uint _ref_cnt; |
1124 | Cell* _strings; |
1125 | }; |
1126 | |
1127 | // ----- AsmRemarks ------------------------------------------------------------ |
1128 | // |
1129 | // Acting as interface to reference counted mapping [offset -> remark], where |
1130 | // offset is a byte offset into an instruction stream (CodeBuffer, CodeBlob or |
1131 | // other memory buffer) and remark is a string (comment). |
1132 | // |
1133 | AsmRemarks::AsmRemarks() : _remarks(new AsmRemarkCollection()) { |
1134 | assert(_remarks != nullptr, "Allocation failure!")do { if (!(_remarks != nullptr)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1134, "assert(" "_remarks != nullptr" ") failed", "Allocation failure!" ); ::breakpoint(); } } while (0); |
1135 | } |
1136 | |
1137 | AsmRemarks::~AsmRemarks() { |
1138 | assert(_remarks == nullptr, "Must 'clear()' before deleting!")do { if (!(_remarks == nullptr)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1138, "assert(" "_remarks == nullptr" ") failed", "Must 'clear()' before deleting!" ); ::breakpoint(); } } while (0); |
1139 | } |
1140 | |
1141 | const char* AsmRemarks::insert(uint offset, const char* remstr) { |
1142 | precond(remstr != nullptr)do { if (!(remstr != nullptr)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1142, "assert(" "remstr != nullptr" ") failed", "precond"); ::breakpoint(); } } while (0); |
1143 | return _remarks->insert(offset, remstr); |
1144 | } |
1145 | |
1146 | bool AsmRemarks::is_empty() const { |
1147 | return _remarks->is_empty(); |
1148 | } |
1149 | |
1150 | void AsmRemarks::share(const AsmRemarks &src) { |
1151 | precond(is_empty())do { if (!(is_empty())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1151, "assert(" "is_empty()" ") failed", "precond"); ::breakpoint (); } } while (0); |
1152 | clear(); |
1153 | _remarks = src._remarks->reuse(); |
1154 | } |
1155 | |
1156 | void AsmRemarks::clear() { |
1157 | if (_remarks->clear() == 0) { |
1158 | delete _remarks; |
1159 | } |
1160 | _remarks = nullptr; |
1161 | } |
1162 | |
1163 | uint AsmRemarks::print(uint offset, outputStream* strm) const { |
1164 | uint count = 0; |
1165 | const char* prefix = " ;; "; |
1166 | const char* remstr = _remarks->lookup(offset); |
1167 | while (remstr != nullptr) { |
1168 | strm->bol(); |
1169 | strm->print("%s", prefix); |
1170 | // Don't interpret as format strings since it could contain '%'. |
1171 | strm->print_raw(remstr); |
1172 | // Advance to next line iff string didn't contain a cr() at the end. |
1173 | strm->bol(); |
1174 | remstr = _remarks->next(offset); |
1175 | count++; |
1176 | } |
1177 | return count; |
1178 | } |
1179 | |
1180 | // ----- DbgStrings ------------------------------------------------------------ |
1181 | // |
1182 | // Acting as interface to reference counted collection of (debug) strings used |
1183 | // in the code generated, and thus requiring a fixed address. |
1184 | // |
1185 | DbgStrings::DbgStrings() : _strings(new DbgStringCollection()) { |
1186 | assert(_strings != nullptr, "Allocation failure!")do { if (!(_strings != nullptr)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1186, "assert(" "_strings != nullptr" ") failed", "Allocation failure!" ); ::breakpoint(); } } while (0); |
1187 | } |
1188 | |
1189 | DbgStrings::~DbgStrings() { |
1190 | assert(_strings == nullptr, "Must 'clear()' before deleting!")do { if (!(_strings == nullptr)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1190, "assert(" "_strings == nullptr" ") failed", "Must 'clear()' before deleting!" ); ::breakpoint(); } } while (0); |
1191 | } |
1192 | |
1193 | const char* DbgStrings::insert(const char* dbgstr) { |
1194 | const char* str = _strings->lookup(dbgstr); |
1195 | return str != nullptr ? str : _strings->insert(dbgstr); |
1196 | } |
1197 | |
1198 | bool DbgStrings::is_empty() const { |
1199 | return _strings->is_empty(); |
1200 | } |
1201 | |
1202 | void DbgStrings::share(const DbgStrings &src) { |
1203 | precond(is_empty())do { if (!(is_empty())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1203, "assert(" "is_empty()" ") failed", "precond"); ::breakpoint (); } } while (0); |
1204 | _strings = src._strings->reuse(); |
1205 | } |
1206 | |
1207 | void DbgStrings::clear() { |
1208 | if (_strings->clear() == 0) { |
1209 | delete _strings; |
1210 | } |
1211 | _strings = nullptr; |
1212 | } |
1213 | |
1214 | // ----- AsmRemarkCollection --------------------------------------------------- |
1215 | |
1216 | const char* AsmRemarkCollection::insert(uint offset, const char* remstr) { |
1217 | precond(remstr != nullptr)do { if (!(remstr != nullptr)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1217, "assert(" "remstr != nullptr" ") failed", "precond"); ::breakpoint(); } } while (0); |
1218 | Cell* cell = new Cell { remstr, offset }; |
1219 | if (is_empty()) { |
1220 | cell->prev = cell; |
1221 | cell->next = cell; |
1222 | _remarks = cell; |
1223 | } else { |
1224 | _remarks->push_back(cell); |
1225 | } |
1226 | return cell->string(); |
1227 | } |
1228 | |
1229 | const char* AsmRemarkCollection::lookup(uint offset) const { |
1230 | _next = _remarks; |
1231 | return next(offset); |
1232 | } |
1233 | |
1234 | const char* AsmRemarkCollection::next(uint offset) const { |
1235 | if (_next != nullptr) { |
1236 | Cell* i = _next; |
1237 | do { |
1238 | if (i->offset == offset) { |
1239 | _next = i->next == _remarks ? nullptr : i->next; |
1240 | return i->string(); |
1241 | } |
1242 | i = i->next; |
1243 | } while (i != _remarks); |
1244 | _next = nullptr; |
1245 | } |
1246 | return nullptr; |
1247 | } |
1248 | |
1249 | uint AsmRemarkCollection::clear() { |
1250 | precond(_ref_cnt > 0)do { if (!(_ref_cnt > 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1250, "assert(" "_ref_cnt > 0" ") failed", "precond"); :: breakpoint(); } } while (0); |
1251 | if (--_ref_cnt > 0) { |
1252 | return _ref_cnt; |
1253 | } |
1254 | if (!is_empty()) { |
1255 | uint count = 0; |
1256 | Cell* i = _remarks; |
1257 | do { |
1258 | Cell* next = i->next; |
1259 | delete i; |
1260 | i = next; |
1261 | count++; |
1262 | } while (i != _remarks); |
1263 | |
1264 | log_debug(codestrings)(!(LogImpl<(LogTag::_codestrings), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_codestrings), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>("Clear %u asm-remark%s.", count, count == 1 ? "" : "s"); |
1265 | _remarks = nullptr; |
1266 | } |
1267 | return 0; // i.e. _ref_cnt == 0 |
1268 | } |
1269 | |
1270 | // ----- DbgStringCollection --------------------------------------------------- |
1271 | |
1272 | const char* DbgStringCollection::insert(const char* dbgstr) { |
1273 | precond(dbgstr != nullptr)do { if (!(dbgstr != nullptr)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1273, "assert(" "dbgstr != nullptr" ") failed", "precond"); ::breakpoint(); } } while (0); |
1274 | Cell* cell = new Cell { dbgstr }; |
1275 | |
1276 | if (is_empty()) { |
1277 | cell->prev = cell; |
1278 | cell->next = cell; |
1279 | _strings = cell; |
1280 | } else { |
1281 | _strings->push_back(cell); |
1282 | } |
1283 | return cell->string(); |
1284 | } |
1285 | |
1286 | const char* DbgStringCollection::lookup(const char* dbgstr) const { |
1287 | precond(dbgstr != nullptr)do { if (!(dbgstr != nullptr)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1287, "assert(" "dbgstr != nullptr" ") failed", "precond"); ::breakpoint(); } } while (0); |
1288 | if (_strings != nullptr) { |
1289 | Cell* i = _strings; |
1290 | do { |
1291 | if (strcmp(i->string(), dbgstr) == 0) { |
1292 | return i->string(); |
1293 | } |
1294 | i = i->next; |
1295 | } while (i != _strings); |
1296 | } |
1297 | return nullptr; |
1298 | } |
1299 | |
1300 | uint DbgStringCollection::clear() { |
1301 | precond(_ref_cnt > 0)do { if (!(_ref_cnt > 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/asm/codeBuffer.cpp" , 1301, "assert(" "_ref_cnt > 0" ") failed", "precond"); :: breakpoint(); } } while (0); |
1302 | if (--_ref_cnt > 0) { |
1303 | return _ref_cnt; |
1304 | } |
1305 | if (!is_empty()) { |
1306 | uint count = 0; |
1307 | Cell* i = _strings; |
1308 | do { |
1309 | Cell* next = i->next; |
1310 | delete i; |
1311 | i = next; |
1312 | count++; |
1313 | } while (i != _strings); |
1314 | |
1315 | log_debug(codestrings)(!(LogImpl<(LogTag::_codestrings), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_codestrings), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>("Clear %u dbg-string%s.", count, count == 1 ? "" : "s"); |
1316 | _strings = nullptr; |
1317 | } |
1318 | return 0; // i.e. _ref_cnt == 0 |
1319 | } |
1320 | |
1321 | #endif // not PRODUCT |