Mercurial > hg > graal-compiler
annotate src/share/vm/code/icBuffer.cpp @ 7183:b2dbd323c668
8003848: Make ConstMethod::generic_signature_index optional and move Method::_max_stack to ConstMethod.
Summary: Make ConstMethod::generic_signature_index optional and move Method::_max_stack to ConstMethod.
Reviewed-by: bdelsart, sspitsyn, coleenp
author | jiangli |
---|---|
date | Tue, 27 Nov 2012 17:03:56 -0500 |
parents | da91efe96a93 |
children | 7d815d842ee0 cd3d6a6b95d9 |
rev | line source |
---|---|
0 | 1 /* |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
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:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "code/compiledIC.hpp" | |
27 #include "code/icBuffer.hpp" | |
28 #include "code/nmethod.hpp" | |
29 #include "code/scopeDesc.hpp" | |
30 #include "gc_interface/collectedHeap.inline.hpp" | |
31 #include "interpreter/interpreter.hpp" | |
32 #include "interpreter/linkResolver.hpp" | |
33 #include "memory/resourceArea.hpp" | |
34 #include "memory/universe.inline.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
35 #include "oops/method.hpp" |
1972 | 36 #include "oops/oop.inline.hpp" |
37 #include "oops/oop.inline2.hpp" | |
38 #include "runtime/mutexLocker.hpp" | |
39 #include "runtime/stubRoutines.hpp" | |
40 #ifdef TARGET_ARCH_x86 | |
41 # include "assembler_x86.inline.hpp" | |
42 #endif | |
43 #ifdef TARGET_ARCH_sparc | |
44 # include "assembler_sparc.inline.hpp" | |
45 #endif | |
46 #ifdef TARGET_ARCH_zero | |
47 # include "assembler_zero.inline.hpp" | |
48 #endif | |
2192
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
1972
diff
changeset
|
49 #ifdef TARGET_ARCH_arm |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
1972
diff
changeset
|
50 # include "assembler_arm.inline.hpp" |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
1972
diff
changeset
|
51 #endif |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
1972
diff
changeset
|
52 #ifdef TARGET_ARCH_ppc |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
1972
diff
changeset
|
53 # include "assembler_ppc.inline.hpp" |
b92c45f2bc75
7016023: Enable building ARM and PPC from src/closed repository
bobv
parents:
1972
diff
changeset
|
54 #endif |
0 | 55 |
56 | |
57 DEF_STUB_INTERFACE(ICStub); | |
58 | |
59 StubQueue* InlineCacheBuffer::_buffer = NULL; | |
60 ICStub* InlineCacheBuffer::_next_stub = NULL; | |
61 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
62 CompiledICHolder* InlineCacheBuffer::_pending_released = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
63 int InlineCacheBuffer::_pending_count = 0; |
0 | 64 |
65 void ICStub::finalize() { | |
66 if (!is_empty()) { | |
67 ResourceMark rm; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
68 CompiledIC *ic = CompiledIC_at(CodeCache::find_nmethod(ic_site()), ic_site()); |
0 | 69 assert(CodeCache::find_nmethod(ic->instruction_address()) != NULL, "inline cache in non-nmethod?"); |
70 | |
71 assert(this == ICStub_from_destination_address(ic->stub_address()), "wrong owner of ic buffer"); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
72 ic->set_ic_destination_and_value(destination(), cached_value()); |
0 | 73 } |
74 } | |
75 | |
76 | |
77 address ICStub::destination() const { | |
78 return InlineCacheBuffer::ic_buffer_entry_point(code_begin()); | |
79 } | |
80 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
81 void* ICStub::cached_value() const { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
82 return InlineCacheBuffer::ic_buffer_cached_value(code_begin()); |
0 | 83 } |
84 | |
85 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
86 void ICStub::set_stub(CompiledIC *ic, void* cached_val, address dest_addr) { |
0 | 87 // We cannot store a pointer to the 'ic' object, since it is resource allocated. Instead we |
88 // store the location of the inline cache. Then we have enough information recreate the CompiledIC | |
89 // object when we need to remove the stub. | |
90 _ic_site = ic->instruction_address(); | |
91 | |
92 // Assemble new stub | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
93 InlineCacheBuffer::assemble_ic_buffer_code(code_begin(), cached_val, dest_addr); |
0 | 94 assert(destination() == dest_addr, "can recover destination"); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
95 assert(cached_value() == cached_val, "can recover destination"); |
0 | 96 } |
97 | |
98 | |
99 void ICStub::clear() { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
100 if (CompiledIC::is_icholder_entry(destination())) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
101 InlineCacheBuffer::queue_for_release((CompiledICHolder*)cached_value()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
102 } |
0 | 103 _ic_site = NULL; |
104 } | |
105 | |
106 | |
107 #ifndef PRODUCT | |
108 // anybody calling to this stub will trap | |
109 | |
110 void ICStub::verify() { | |
111 } | |
112 | |
113 void ICStub::print() { | |
114 tty->print_cr("ICStub: site: " INTPTR_FORMAT, _ic_site); | |
115 } | |
116 #endif | |
117 | |
118 //----------------------------------------------------------------------------------------------- | |
119 // Implementation of InlineCacheBuffer | |
120 | |
121 void InlineCacheBuffer::init_next_stub() { | |
122 ICStub* ic_stub = (ICStub*)buffer()->request_committed (ic_stub_code_size()); | |
123 assert (ic_stub != NULL, "no room for a single stub"); | |
124 set_next_stub(ic_stub); | |
125 } | |
126 | |
127 void InlineCacheBuffer::initialize() { | |
128 if (_buffer != NULL) return; // already initialized | |
129 _buffer = new StubQueue(new ICStubInterface, 10*K, InlineCacheBuffer_lock, "InlineCacheBuffer"); | |
130 assert (_buffer != NULL, "cannot allocate InlineCacheBuffer"); | |
131 init_next_stub(); | |
132 } | |
133 | |
134 | |
135 ICStub* InlineCacheBuffer::new_ic_stub() { | |
136 while (true) { | |
137 ICStub* ic_stub = (ICStub*)buffer()->request_committed(ic_stub_code_size()); | |
138 if (ic_stub != NULL) { | |
139 return ic_stub; | |
140 } | |
141 // we ran out of inline cache buffer space; must enter safepoint. | |
142 // We do this by forcing a safepoint | |
143 EXCEPTION_MARK; | |
144 | |
145 VM_ForceSafepoint vfs; | |
146 VMThread::execute(&vfs); | |
147 // We could potential get an async. exception at this point. | |
148 // In that case we will rethrow it to ourselvs. | |
149 if (HAS_PENDING_EXCEPTION) { | |
150 oop exception = PENDING_EXCEPTION; | |
151 CLEAR_PENDING_EXCEPTION; | |
152 Thread::send_async_exception(JavaThread::current()->threadObj(), exception); | |
153 } | |
154 } | |
155 ShouldNotReachHere(); | |
156 return NULL; | |
157 } | |
158 | |
159 | |
160 void InlineCacheBuffer::update_inline_caches() { | |
161 if (buffer()->number_of_stubs() > 1) { | |
162 if (TraceICBuffer) { | |
163 tty->print_cr("[updating inline caches with %d stubs]", buffer()->number_of_stubs()); | |
164 } | |
165 buffer()->remove_all(); | |
166 init_next_stub(); | |
167 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
168 release_pending_icholders(); |
0 | 169 } |
170 | |
171 | |
172 bool InlineCacheBuffer::contains(address instruction_address) { | |
173 return buffer()->contains(instruction_address); | |
174 } | |
175 | |
176 | |
177 bool InlineCacheBuffer::is_empty() { | |
178 return buffer()->number_of_stubs() == 1; // always has sentinel | |
179 } | |
180 | |
181 | |
182 void InlineCacheBuffer_init() { | |
183 InlineCacheBuffer::initialize(); | |
184 } | |
185 | |
186 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
187 void InlineCacheBuffer::create_transition_stub(CompiledIC *ic, void* cached_value, address entry) { |
0 | 188 assert(!SafepointSynchronize::is_at_safepoint(), "should not be called during a safepoint"); |
189 assert (CompiledIC_lock->is_locked(), ""); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
190 if (TraceICBuffer) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
191 tty->print_cr(" create transition stub for " INTPTR_FORMAT " destination " INTPTR_FORMAT " cached value " INTPTR_FORMAT, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
192 ic->instruction_address(), entry, cached_value); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
193 } |
0 | 194 |
195 // If an transition stub is already associate with the inline cache, then we remove the association. | |
196 if (ic->is_in_transition_state()) { | |
197 ICStub* old_stub = ICStub_from_destination_address(ic->stub_address()); | |
198 old_stub->clear(); | |
199 } | |
200 | |
201 // allocate and initialize new "out-of-line" inline-cache | |
202 ICStub* ic_stub = get_next_stub(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
203 ic_stub->set_stub(ic, cached_value, entry); |
0 | 204 |
205 // Update inline cache in nmethod to point to new "out-of-line" allocated inline cache | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
206 ic->set_ic_destination(ic_stub); |
0 | 207 |
208 set_next_stub(new_ic_stub()); // can cause safepoint synchronization | |
209 } | |
210 | |
211 | |
212 address InlineCacheBuffer::ic_destination_for(CompiledIC *ic) { | |
213 ICStub* stub = ICStub_from_destination_address(ic->stub_address()); | |
214 return stub->destination(); | |
215 } | |
216 | |
217 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
218 void* InlineCacheBuffer::cached_value_for(CompiledIC *ic) { |
0 | 219 ICStub* stub = ICStub_from_destination_address(ic->stub_address()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
220 return stub->cached_value(); |
0 | 221 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
222 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
223 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
224 // Free CompiledICHolder*s that are no longer in use |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
225 void InlineCacheBuffer::release_pending_icholders() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
226 assert(SafepointSynchronize::is_at_safepoint(), "should only be called during a safepoint"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
227 CompiledICHolder* holder = _pending_released; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
228 _pending_released = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
229 while (holder != NULL) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
230 CompiledICHolder* next = holder->next(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
231 delete holder; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
232 holder = next; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
233 _pending_count--; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
234 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
235 assert(_pending_count == 0, "wrong count"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
236 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
237 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
238 // Enqueue this icholder for release during the next safepoint. It's |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
239 // not safe to free them until them since they might be visible to |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
240 // another thread. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
241 void InlineCacheBuffer::queue_for_release(CompiledICHolder* icholder) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
242 MutexLockerEx mex(InlineCacheBuffer_lock); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
243 icholder->set_next(_pending_released); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
244 _pending_released = icholder; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
245 _pending_count++; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
246 if (TraceICBuffer) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
247 tty->print_cr("enqueueing icholder " INTPTR_FORMAT " to be freed", icholder); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
248 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
249 } |