annotate src/share/vm/asm/codeBuffer.cpp @ 20804:7848fc12602b

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