annotate src/share/vm/asm/assembler.cpp @ 4710:41406797186b

7113012: G1: rename not-fully-young GCs as "mixed" Summary: Renamed partially-young GCs as mixed and fully-young GCs as young. Change all external output that includes those terms (GC log and GC ergo log) as well as any comments, fields, methods, etc. The changeset also includes very minor code tidying up (added some curly brackets). Reviewed-by: johnc, brutisso
author tonyp
date Fri, 16 Dec 2011 02:14:27 -0500
parents 1d1603768966
children 40c2484c09e1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2426
1d1603768966 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 2192
diff changeset
2 * Copyright (c) 1997, 2011, 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: 1490
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1490
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: 1490
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: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "asm/assembler.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "asm/assembler.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "asm/codeBuffer.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "runtime/icache.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "runtime/os.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #ifdef TARGET_ARCH_x86
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
32 # include "assembler_x86.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
33 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
34 #ifdef TARGET_ARCH_sparc
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
35 # include "assembler_sparc.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
36 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
37 #ifdef TARGET_ARCH_zero
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
38 # include "assembler_zero.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
39 #endif
2192
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
40 #ifdef TARGET_ARCH_arm
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
41 # include "assembler_arm.inline.hpp"
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
42 #endif
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
43 #ifdef TARGET_ARCH_ppc
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
44 # include "assembler_ppc.inline.hpp"
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 1972
diff changeset
45 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // Implementation of AbstractAssembler
a61af66fc99e Initial load
duke
parents:
diff changeset
49 //
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // The AbstractAssembler is generating code into a CodeBuffer. To make code generation faster,
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // the assembler keeps a copy of the code buffers boundaries & modifies them when
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // emitting bytes rather than using the code buffers accessor functions all the time.
605
98cb887364d3 6810672: Comment typos
twisti
parents: 380
diff changeset
53 // The code buffer is updated via set_code_end(...) after emitting a whole instruction.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
54
a61af66fc99e Initial load
duke
parents:
diff changeset
55 AbstractAssembler::AbstractAssembler(CodeBuffer* code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 if (code == NULL) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
57 CodeSection* cs = code->insts();
a61af66fc99e Initial load
duke
parents:
diff changeset
58 cs->clear_mark(); // new assembler kills old mark
a61af66fc99e Initial load
duke
parents:
diff changeset
59 _code_section = cs;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 _code_begin = cs->start();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _code_limit = cs->limit();
a61af66fc99e Initial load
duke
parents:
diff changeset
62 _code_pos = cs->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
63 _oop_recorder= code->oop_recorder();
a61af66fc99e Initial load
duke
parents:
diff changeset
64 if (_code_begin == NULL) {
1490
f03d0a26bf83 6888954: argument formatting for assert() and friends
jcoomes
parents: 844
diff changeset
65 vm_exit_out_of_memory(0, err_msg("CodeCache: no room for %s",
f03d0a26bf83 6888954: argument formatting for assert() and friends
jcoomes
parents: 844
diff changeset
66 code->name()));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
67 }
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 void AbstractAssembler::set_code_section(CodeSection* cs) {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 assert(cs->outer() == code_section()->outer(), "sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
72 assert(cs->is_allocated(), "need to pre-allocate this section");
a61af66fc99e Initial load
duke
parents:
diff changeset
73 cs->clear_mark(); // new assembly into this section kills old mark
a61af66fc99e Initial load
duke
parents:
diff changeset
74 _code_section = cs;
a61af66fc99e Initial load
duke
parents:
diff changeset
75 _code_begin = cs->start();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 _code_limit = cs->limit();
a61af66fc99e Initial load
duke
parents:
diff changeset
77 _code_pos = cs->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Inform CodeBuffer that incoming code and relocation will be for stubs
a61af66fc99e Initial load
duke
parents:
diff changeset
81 address AbstractAssembler::start_a_stub(int required_space) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 CodeBuffer* cb = code();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 CodeSection* cs = cb->stubs();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 assert(_code_section == cb->insts(), "not in insts?");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 sync();
a61af66fc99e Initial load
duke
parents:
diff changeset
86 if (cs->maybe_expand_to_ensure_remaining(required_space)
a61af66fc99e Initial load
duke
parents:
diff changeset
87 && cb->blob() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 set_code_section(cs);
a61af66fc99e Initial load
duke
parents:
diff changeset
91 return pc();
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // Inform CodeBuffer that incoming code and relocation will be code
a61af66fc99e Initial load
duke
parents:
diff changeset
95 // Should not be called if start_a_stub() returned NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
96 void AbstractAssembler::end_a_stub() {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 assert(_code_section == code()->stubs(), "not in stubs?");
a61af66fc99e Initial load
duke
parents:
diff changeset
98 sync();
a61af66fc99e Initial load
duke
parents:
diff changeset
99 set_code_section(code()->insts());
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102 // Inform CodeBuffer that incoming code and relocation will be for stubs
a61af66fc99e Initial load
duke
parents:
diff changeset
103 address AbstractAssembler::start_a_const(int required_space, int required_align) {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 CodeBuffer* cb = code();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 CodeSection* cs = cb->consts();
a61af66fc99e Initial load
duke
parents:
diff changeset
106 assert(_code_section == cb->insts(), "not in insts?");
a61af66fc99e Initial load
duke
parents:
diff changeset
107 sync();
a61af66fc99e Initial load
duke
parents:
diff changeset
108 address end = cs->end();
a61af66fc99e Initial load
duke
parents:
diff changeset
109 int pad = -(intptr_t)end & (required_align-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (cs->maybe_expand_to_ensure_remaining(pad + required_space)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (cb->blob() == NULL) return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 end = cs->end(); // refresh pointer
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 if (pad > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 while (--pad >= 0) { *end++ = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 cs->set_end(end);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 set_code_section(cs);
a61af66fc99e Initial load
duke
parents:
diff changeset
119 return end;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 // Inform CodeBuffer that incoming code and relocation will be code
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Should not be called if start_a_const() returned NULL
a61af66fc99e Initial load
duke
parents:
diff changeset
124 void AbstractAssembler::end_a_const() {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 assert(_code_section == code()->consts(), "not in consts?");
a61af66fc99e Initial load
duke
parents:
diff changeset
126 sync();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 set_code_section(code()->insts());
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 void AbstractAssembler::flush() {
a61af66fc99e Initial load
duke
parents:
diff changeset
132 sync();
a61af66fc99e Initial load
duke
parents:
diff changeset
133 ICache::invalidate_range(addr_at(0), offset());
a61af66fc99e Initial load
duke
parents:
diff changeset
134 }
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 void AbstractAssembler::a_byte(int x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 emit_byte(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 void AbstractAssembler::a_long(jint x) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 emit_long(x);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 // Labels refer to positions in the (to be) generated code. There are bound
a61af66fc99e Initial load
duke
parents:
diff changeset
147 // and unbound
a61af66fc99e Initial load
duke
parents:
diff changeset
148 //
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // Bound labels refer to known positions in the already generated code.
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // offset() is the position the label refers to.
a61af66fc99e Initial load
duke
parents:
diff changeset
151 //
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Unbound labels refer to unknown positions in the code to be generated; it
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // may contain a list of unresolved displacements that refer to it
a61af66fc99e Initial load
duke
parents:
diff changeset
154 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
155 void AbstractAssembler::print(Label& L) {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (L.is_bound()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 tty->print_cr("bound label to %d|%d", L.loc_pos(), L.loc_sect());
a61af66fc99e Initial load
duke
parents:
diff changeset
158 } else if (L.is_unbound()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
159 L.print_instructions((MacroAssembler*)this);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 tty->print_cr("label in inconsistent state (loc = %d)", L.loc());
a61af66fc99e Initial load
duke
parents:
diff changeset
162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 #endif // PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 void AbstractAssembler::bind(Label& L) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (L.is_bound()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Assembler can bind a label more than once to the same place.
a61af66fc99e Initial load
duke
parents:
diff changeset
170 guarantee(L.loc() == locator(), "attempt to redefine label");
a61af66fc99e Initial load
duke
parents:
diff changeset
171 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 L.bind_loc(locator());
a61af66fc99e Initial load
duke
parents:
diff changeset
174 L.patch_instructions((MacroAssembler*)this);
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 void AbstractAssembler::generate_stack_overflow_check( int frame_size_in_bytes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (UseStackBanging) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // Each code entry causes one stack bang n pages down the stack where n
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // is configurable by StackBangPages. The setting depends on the maximum
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // depth of VM call stack or native before going back into java code,
a61af66fc99e Initial load
duke
parents:
diff changeset
182 // since only java code can raise a stack overflow exception using the
a61af66fc99e Initial load
duke
parents:
diff changeset
183 // stack banging mechanism. The VM and native code does not detect stack
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // overflow.
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // The code in JavaCalls::call() checks that there is at least n pages
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // available, so all entry code needs to do is bang once for the end of
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // this shadow zone.
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // The entry code may need to bang additional pages if the framesize
a61af66fc99e Initial load
duke
parents:
diff changeset
189 // is greater than a page.
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 const int page_size = os::vm_page_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 int bang_end = StackShadowPages*page_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // This is how far the previous frame's stack banging extended.
a61af66fc99e Initial load
duke
parents:
diff changeset
195 const int bang_end_safe = bang_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
196
a61af66fc99e Initial load
duke
parents:
diff changeset
197 if (frame_size_in_bytes > page_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 bang_end += frame_size_in_bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 }
a61af66fc99e Initial load
duke
parents:
diff changeset
200
a61af66fc99e Initial load
duke
parents:
diff changeset
201 int bang_offset = bang_end_safe;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 while (bang_offset <= bang_end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // Need at least one stack bang at end of shadow zone.
a61af66fc99e Initial load
duke
parents:
diff changeset
204 bang_stack_with_offset(bang_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
205 bang_offset += page_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207 } // end (UseStackBanging)
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209
a61af66fc99e Initial load
duke
parents:
diff changeset
210 void Label::add_patch_at(CodeBuffer* cb, int branch_loc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 assert(_loc == -1, "Label is unbound");
a61af66fc99e Initial load
duke
parents:
diff changeset
212 if (_patch_index < PatchCacheSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
213 _patches[_patch_index] = branch_loc;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
215 if (_patch_overflow == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
216 _patch_overflow = cb->create_patch_overflow();
a61af66fc99e Initial load
duke
parents:
diff changeset
217 }
a61af66fc99e Initial load
duke
parents:
diff changeset
218 _patch_overflow->push(branch_loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
220 ++_patch_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
a61af66fc99e Initial load
duke
parents:
diff changeset
223 void Label::patch_instructions(MacroAssembler* masm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
224 assert(is_bound(), "Label is bound");
a61af66fc99e Initial load
duke
parents:
diff changeset
225 CodeBuffer* cb = masm->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
226 int target_sect = CodeBuffer::locator_sect(loc());
a61af66fc99e Initial load
duke
parents:
diff changeset
227 address target = cb->locator_address(loc());
a61af66fc99e Initial load
duke
parents:
diff changeset
228 while (_patch_index > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 --_patch_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 int branch_loc;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 if (_patch_index >= PatchCacheSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 branch_loc = _patch_overflow->pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
234 branch_loc = _patches[_patch_index];
a61af66fc99e Initial load
duke
parents:
diff changeset
235 }
a61af66fc99e Initial load
duke
parents:
diff changeset
236 int branch_sect = CodeBuffer::locator_sect(branch_loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
237 address branch = cb->locator_address(branch_loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 if (branch_sect == CodeBuffer::SECT_CONSTS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // The thing to patch is a constant word.
a61af66fc99e Initial load
duke
parents:
diff changeset
240 *(address*)branch = target;
a61af66fc99e Initial load
duke
parents:
diff changeset
241 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
242 }
a61af66fc99e Initial load
duke
parents:
diff changeset
243
a61af66fc99e Initial load
duke
parents:
diff changeset
244 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // Cross-section branches only work if the
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // intermediate section boundaries are frozen.
a61af66fc99e Initial load
duke
parents:
diff changeset
247 if (target_sect != branch_sect) {
a61af66fc99e Initial load
duke
parents:
diff changeset
248 for (int n = MIN2(target_sect, branch_sect),
a61af66fc99e Initial load
duke
parents:
diff changeset
249 nlimit = (target_sect + branch_sect) - n;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 n < nlimit; n++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 CodeSection* cs = cb->code_section(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 assert(cs->is_frozen(), "cross-section branch needs stable offsets");
a61af66fc99e Initial load
duke
parents:
diff changeset
253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255 #endif //ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // Push the target offset into the branch instruction.
a61af66fc99e Initial load
duke
parents:
diff changeset
258 masm->pd_patch_instruction(branch, target);
a61af66fc99e Initial load
duke
parents:
diff changeset
259 }
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
a61af66fc99e Initial load
duke
parents:
diff changeset
261
622
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
262 struct DelayedConstant {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
263 typedef void (*value_fn_t)();
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
264 BasicType type;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
265 intptr_t value;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
266 value_fn_t value_fn;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
267 // This limit of 20 is generous for initial uses.
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
268 // The limit needs to be large enough to store the field offsets
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
269 // into classes which do not have statically fixed layouts.
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
270 // (Initial use is for method handle object offsets.)
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
271 // Look for uses of "delayed_value" in the source code
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
272 // and make sure this number is generous enough to handle all of them.
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
273 enum { DC_LIMIT = 20 };
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
274 static DelayedConstant delayed_constants[DC_LIMIT];
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
275 static DelayedConstant* add(BasicType type, value_fn_t value_fn);
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
276 bool match(BasicType t, value_fn_t cfn) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
277 return type == t && value_fn == cfn;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
278 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
279 static void update_all();
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
280 };
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
281
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
282 DelayedConstant DelayedConstant::delayed_constants[DC_LIMIT];
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
283 // Default C structure initialization rules have the following effect here:
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
284 // = { { (BasicType)0, (intptr_t)NULL }, ... };
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
285
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
286 DelayedConstant* DelayedConstant::add(BasicType type,
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
287 DelayedConstant::value_fn_t cfn) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
288 for (int i = 0; i < DC_LIMIT; i++) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
289 DelayedConstant* dcon = &delayed_constants[i];
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
290 if (dcon->match(type, cfn))
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
291 return dcon;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
292 if (dcon->value_fn == NULL) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
293 // (cmpxchg not because this is multi-threaded but because I'm paranoid)
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
294 if (Atomic::cmpxchg_ptr(CAST_FROM_FN_PTR(void*, cfn), &dcon->value_fn, NULL) == NULL) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
295 dcon->type = type;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
296 return dcon;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
297 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
298 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
299 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
300 // If this assert is hit (in pre-integration testing!) then re-evaluate
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
301 // the comment on the definition of DC_LIMIT.
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
302 guarantee(false, "too many delayed constants");
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
303 return NULL;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
304 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
305
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
306 void DelayedConstant::update_all() {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
307 for (int i = 0; i < DC_LIMIT; i++) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
308 DelayedConstant* dcon = &delayed_constants[i];
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
309 if (dcon->value_fn != NULL && dcon->value == 0) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
310 typedef int (*int_fn_t)();
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
311 typedef address (*address_fn_t)();
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
312 switch (dcon->type) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
313 case T_INT: dcon->value = (intptr_t) ((int_fn_t) dcon->value_fn)(); break;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
314 case T_ADDRESS: dcon->value = (intptr_t) ((address_fn_t)dcon->value_fn)(); break;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
315 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
316 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
317 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
318 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
319
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
320 intptr_t* AbstractAssembler::delayed_value_addr(int(*value_fn)()) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
321 DelayedConstant* dcon = DelayedConstant::add(T_INT, (DelayedConstant::value_fn_t) value_fn);
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
322 return &dcon->value;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
323 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
324 intptr_t* AbstractAssembler::delayed_value_addr(address(*value_fn)()) {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
325 DelayedConstant* dcon = DelayedConstant::add(T_ADDRESS, (DelayedConstant::value_fn_t) value_fn);
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
326 return &dcon->value;
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
327 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
328 void AbstractAssembler::update_delayed_values() {
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
329 DelayedConstant::update_all();
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
330 }
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
331
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
332
56aae7be60d4 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 605
diff changeset
333
0
a61af66fc99e Initial load
duke
parents:
diff changeset
334
a61af66fc99e Initial load
duke
parents:
diff changeset
335 void AbstractAssembler::block_comment(const char* comment) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 if (sect() == CodeBuffer::SECT_INSTS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
337 code_section()->outer()->block_comment(offset(), comment);
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339 }
a61af66fc99e Initial load
duke
parents:
diff changeset
340
237
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
341 bool MacroAssembler::needs_explicit_null_check(intptr_t offset) {
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
342 // Exception handler checks the nmethod's implicit null checks table
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
343 // only when this method returns false.
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 622
diff changeset
344 #ifdef _LP64
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 622
diff changeset
345 if (UseCompressedOops && Universe::narrow_oop_base() != NULL) {
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 622
diff changeset
346 assert (Universe::heap() != NULL, "java heap should be initialized");
237
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
347 // The first page after heap_base is unmapped and
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
348 // the 'offset' is equal to [heap_base + offset] for
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
349 // narrow oop implicit null checks.
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 622
diff changeset
350 uintptr_t base = (uintptr_t)Universe::narrow_oop_base();
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 622
diff changeset
351 if ((uintptr_t)offset >= base) {
237
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
352 // Normalize offset for the next check.
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 622
diff changeset
353 offset = (intptr_t)(pointer_delta((void*)offset, (void*)base, 1));
237
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
354 }
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
355 }
642
660978a2a31a 6791178: Specialize for zero as the compressed oop vm heap base
kvn
parents: 622
diff changeset
356 #endif
237
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
357 return offset < 0 || os::vm_page_size() <= offset;
1fdb98a17101 6716785: implicit null checks not triggering with CompressedOops
coleenp
parents: 0
diff changeset
358 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
359
a61af66fc99e Initial load
duke
parents:
diff changeset
360 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
361 void Label::print_instructions(MacroAssembler* masm) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
362 CodeBuffer* cb = masm->code();
a61af66fc99e Initial load
duke
parents:
diff changeset
363 for (int i = 0; i < _patch_index; ++i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
364 int branch_loc;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 if (i >= PatchCacheSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 branch_loc = _patch_overflow->at(i - PatchCacheSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
367 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
368 branch_loc = _patches[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 int branch_pos = CodeBuffer::locator_pos(branch_loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
371 int branch_sect = CodeBuffer::locator_sect(branch_loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
372 address branch = cb->locator_address(branch_loc);
a61af66fc99e Initial load
duke
parents:
diff changeset
373 tty->print_cr("unbound label");
a61af66fc99e Initial load
duke
parents:
diff changeset
374 tty->print("@ %d|%d ", branch_pos, branch_sect);
a61af66fc99e Initial load
duke
parents:
diff changeset
375 if (branch_sect == CodeBuffer::SECT_CONSTS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
376 tty->print_cr(PTR_FORMAT, *(address*)branch);
a61af66fc99e Initial load
duke
parents:
diff changeset
377 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
378 }
a61af66fc99e Initial load
duke
parents:
diff changeset
379 masm->pd_print_patched_instruction(branch);
a61af66fc99e Initial load
duke
parents:
diff changeset
380 tty->cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
382 }
a61af66fc99e Initial load
duke
parents:
diff changeset
383 #endif // ndef PRODUCT