Mercurial > hg > graal-compiler
annotate src/share/vm/code/icBuffer.cpp @ 20096:3844fb65016c
SL: repeating node should implement SLStatementNode for a proper toString implementation.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 30 Mar 2015 22:52:03 +0200 |
parents | 52b4284cb496 |
children |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
7199
diff
changeset
|
2 * Copyright (c) 1997, 2014, 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" |
7199
cd3d6a6b95d9
8003240: x86: move MacroAssembler into separate file
twisti
parents:
6725
diff
changeset
|
26 #include "code/codeCache.hpp" |
1972 | 27 #include "code/compiledIC.hpp" |
28 #include "code/icBuffer.hpp" | |
29 #include "code/nmethod.hpp" | |
30 #include "code/scopeDesc.hpp" | |
31 #include "gc_interface/collectedHeap.inline.hpp" | |
32 #include "interpreter/interpreter.hpp" | |
33 #include "interpreter/linkResolver.hpp" | |
34 #include "memory/resourceArea.hpp" | |
35 #include "memory/universe.inline.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
36 #include "oops/method.hpp" |
1972 | 37 #include "oops/oop.inline.hpp" |
38 #include "oops/oop.inline2.hpp" | |
39 #include "runtime/mutexLocker.hpp" | |
40 #include "runtime/stubRoutines.hpp" | |
0 | 41 |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
7199
diff
changeset
|
42 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
0 | 43 |
44 DEF_STUB_INTERFACE(ICStub); | |
45 | |
46 StubQueue* InlineCacheBuffer::_buffer = NULL; | |
47 ICStub* InlineCacheBuffer::_next_stub = NULL; | |
48 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
49 CompiledICHolder* InlineCacheBuffer::_pending_released = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
50 int InlineCacheBuffer::_pending_count = 0; |
0 | 51 |
52 void ICStub::finalize() { | |
53 if (!is_empty()) { | |
54 ResourceMark rm; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
55 CompiledIC *ic = CompiledIC_at(CodeCache::find_nmethod(ic_site()), ic_site()); |
0 | 56 assert(CodeCache::find_nmethod(ic->instruction_address()) != NULL, "inline cache in non-nmethod?"); |
57 | |
58 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
|
59 ic->set_ic_destination_and_value(destination(), cached_value()); |
0 | 60 } |
61 } | |
62 | |
63 | |
64 address ICStub::destination() const { | |
65 return InlineCacheBuffer::ic_buffer_entry_point(code_begin()); | |
66 } | |
67 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
68 void* ICStub::cached_value() const { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
69 return InlineCacheBuffer::ic_buffer_cached_value(code_begin()); |
0 | 70 } |
71 | |
72 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
73 void ICStub::set_stub(CompiledIC *ic, void* cached_val, address dest_addr) { |
0 | 74 // We cannot store a pointer to the 'ic' object, since it is resource allocated. Instead we |
75 // store the location of the inline cache. Then we have enough information recreate the CompiledIC | |
76 // object when we need to remove the stub. | |
77 _ic_site = ic->instruction_address(); | |
78 | |
79 // Assemble new stub | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
80 InlineCacheBuffer::assemble_ic_buffer_code(code_begin(), cached_val, dest_addr); |
0 | 81 assert(destination() == dest_addr, "can recover destination"); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
82 assert(cached_value() == cached_val, "can recover destination"); |
0 | 83 } |
84 | |
85 | |
86 void ICStub::clear() { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
87 if (CompiledIC::is_icholder_entry(destination())) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
88 InlineCacheBuffer::queue_for_release((CompiledICHolder*)cached_value()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
89 } |
0 | 90 _ic_site = NULL; |
91 } | |
92 | |
93 | |
94 #ifndef PRODUCT | |
95 // anybody calling to this stub will trap | |
96 | |
97 void ICStub::verify() { | |
98 } | |
99 | |
100 void ICStub::print() { | |
101 tty->print_cr("ICStub: site: " INTPTR_FORMAT, _ic_site); | |
102 } | |
103 #endif | |
104 | |
105 //----------------------------------------------------------------------------------------------- | |
106 // Implementation of InlineCacheBuffer | |
107 | |
108 void InlineCacheBuffer::init_next_stub() { | |
109 ICStub* ic_stub = (ICStub*)buffer()->request_committed (ic_stub_code_size()); | |
110 assert (ic_stub != NULL, "no room for a single stub"); | |
111 set_next_stub(ic_stub); | |
112 } | |
113 | |
114 void InlineCacheBuffer::initialize() { | |
115 if (_buffer != NULL) return; // already initialized | |
116 _buffer = new StubQueue(new ICStubInterface, 10*K, InlineCacheBuffer_lock, "InlineCacheBuffer"); | |
117 assert (_buffer != NULL, "cannot allocate InlineCacheBuffer"); | |
118 init_next_stub(); | |
119 } | |
120 | |
121 | |
122 ICStub* InlineCacheBuffer::new_ic_stub() { | |
123 while (true) { | |
124 ICStub* ic_stub = (ICStub*)buffer()->request_committed(ic_stub_code_size()); | |
125 if (ic_stub != NULL) { | |
126 return ic_stub; | |
127 } | |
128 // we ran out of inline cache buffer space; must enter safepoint. | |
129 // We do this by forcing a safepoint | |
130 EXCEPTION_MARK; | |
131 | |
132 VM_ForceSafepoint vfs; | |
133 VMThread::execute(&vfs); | |
134 // We could potential get an async. exception at this point. | |
135 // In that case we will rethrow it to ourselvs. | |
136 if (HAS_PENDING_EXCEPTION) { | |
137 oop exception = PENDING_EXCEPTION; | |
138 CLEAR_PENDING_EXCEPTION; | |
139 Thread::send_async_exception(JavaThread::current()->threadObj(), exception); | |
140 } | |
141 } | |
142 ShouldNotReachHere(); | |
143 return NULL; | |
144 } | |
145 | |
146 | |
147 void InlineCacheBuffer::update_inline_caches() { | |
148 if (buffer()->number_of_stubs() > 1) { | |
149 if (TraceICBuffer) { | |
150 tty->print_cr("[updating inline caches with %d stubs]", buffer()->number_of_stubs()); | |
151 } | |
152 buffer()->remove_all(); | |
153 init_next_stub(); | |
154 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
155 release_pending_icholders(); |
0 | 156 } |
157 | |
158 | |
159 bool InlineCacheBuffer::contains(address instruction_address) { | |
160 return buffer()->contains(instruction_address); | |
161 } | |
162 | |
163 | |
164 bool InlineCacheBuffer::is_empty() { | |
165 return buffer()->number_of_stubs() == 1; // always has sentinel | |
166 } | |
167 | |
168 | |
169 void InlineCacheBuffer_init() { | |
170 InlineCacheBuffer::initialize(); | |
171 } | |
172 | |
173 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
174 void InlineCacheBuffer::create_transition_stub(CompiledIC *ic, void* cached_value, address entry) { |
0 | 175 assert(!SafepointSynchronize::is_at_safepoint(), "should not be called during a safepoint"); |
176 assert (CompiledIC_lock->is_locked(), ""); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
177 if (TraceICBuffer) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
178 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
|
179 ic->instruction_address(), entry, cached_value); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
180 } |
0 | 181 |
182 // If an transition stub is already associate with the inline cache, then we remove the association. | |
183 if (ic->is_in_transition_state()) { | |
184 ICStub* old_stub = ICStub_from_destination_address(ic->stub_address()); | |
185 old_stub->clear(); | |
186 } | |
187 | |
188 // allocate and initialize new "out-of-line" inline-cache | |
189 ICStub* ic_stub = get_next_stub(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
190 ic_stub->set_stub(ic, cached_value, entry); |
0 | 191 |
192 // 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
|
193 ic->set_ic_destination(ic_stub); |
0 | 194 |
195 set_next_stub(new_ic_stub()); // can cause safepoint synchronization | |
196 } | |
197 | |
198 | |
199 address InlineCacheBuffer::ic_destination_for(CompiledIC *ic) { | |
200 ICStub* stub = ICStub_from_destination_address(ic->stub_address()); | |
201 return stub->destination(); | |
202 } | |
203 | |
204 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
205 void* InlineCacheBuffer::cached_value_for(CompiledIC *ic) { |
0 | 206 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
|
207 return stub->cached_value(); |
0 | 208 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
209 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
210 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
211 // 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
|
212 void InlineCacheBuffer::release_pending_icholders() { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
213 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
|
214 CompiledICHolder* holder = _pending_released; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
215 _pending_released = NULL; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
216 while (holder != NULL) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
217 CompiledICHolder* next = holder->next(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
218 delete holder; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
219 holder = next; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
220 _pending_count--; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
221 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
222 assert(_pending_count == 0, "wrong count"); |
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 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
225 // 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
|
226 // 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
|
227 // another thread. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
228 void InlineCacheBuffer::queue_for_release(CompiledICHolder* icholder) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
229 MutexLockerEx mex(InlineCacheBuffer_lock); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
230 icholder->set_next(_pending_released); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
231 _pending_released = icholder; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
232 _pending_count++; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
233 if (TraceICBuffer) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
234 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
|
235 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
2426
diff
changeset
|
236 } |