annotate src/share/vm/code/icBuffer.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_icBuffer.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 DEF_STUB_INTERFACE(ICStub);
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 StubQueue* InlineCacheBuffer::_buffer = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 ICStub* InlineCacheBuffer::_next_stub = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 void ICStub::finalize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 if (!is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 CompiledIC *ic = CompiledIC_at(ic_site());
a61af66fc99e Initial load
duke
parents:
diff changeset
39 assert(CodeCache::find_nmethod(ic->instruction_address()) != NULL, "inline cache in non-nmethod?");
a61af66fc99e Initial load
duke
parents:
diff changeset
40
a61af66fc99e Initial load
duke
parents:
diff changeset
41 assert(this == ICStub_from_destination_address(ic->stub_address()), "wrong owner of ic buffer");
a61af66fc99e Initial load
duke
parents:
diff changeset
42 ic->set_cached_oop(cached_oop());
a61af66fc99e Initial load
duke
parents:
diff changeset
43 ic->set_ic_destination(destination());
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 address ICStub::destination() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 return InlineCacheBuffer::ic_buffer_entry_point(code_begin());
a61af66fc99e Initial load
duke
parents:
diff changeset
50 }
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 oop ICStub::cached_oop() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 return InlineCacheBuffer::ic_buffer_cached_oop(code_begin());
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 void ICStub::set_stub(CompiledIC *ic, oop cached_value, address dest_addr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // We cannot store a pointer to the 'ic' object, since it is resource allocated. Instead we
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // store the location of the inline cache. Then we have enough information recreate the CompiledIC
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // object when we need to remove the stub.
a61af66fc99e Initial load
duke
parents:
diff changeset
61 _ic_site = ic->instruction_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Assemble new stub
a61af66fc99e Initial load
duke
parents:
diff changeset
64 InlineCacheBuffer::assemble_ic_buffer_code(code_begin(), cached_value, dest_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 assert(destination() == dest_addr, "can recover destination");
a61af66fc99e Initial load
duke
parents:
diff changeset
66 assert(cached_oop() == cached_value, "can recover destination");
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 ICStub::clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 _ic_site = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // anybody calling to this stub will trap
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 void ICStub::verify() {
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 void ICStub::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 tty->print_cr("ICStub: site: " INTPTR_FORMAT, _ic_site);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 //-----------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
87 // Implementation of InlineCacheBuffer
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 void InlineCacheBuffer::init_next_stub() {
a61af66fc99e Initial load
duke
parents:
diff changeset
90 ICStub* ic_stub = (ICStub*)buffer()->request_committed (ic_stub_code_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
91 assert (ic_stub != NULL, "no room for a single stub");
a61af66fc99e Initial load
duke
parents:
diff changeset
92 set_next_stub(ic_stub);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94
a61af66fc99e Initial load
duke
parents:
diff changeset
95 void InlineCacheBuffer::initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (_buffer != NULL) return; // already initialized
a61af66fc99e Initial load
duke
parents:
diff changeset
97 _buffer = new StubQueue(new ICStubInterface, 10*K, InlineCacheBuffer_lock, "InlineCacheBuffer");
a61af66fc99e Initial load
duke
parents:
diff changeset
98 assert (_buffer != NULL, "cannot allocate InlineCacheBuffer");
a61af66fc99e Initial load
duke
parents:
diff changeset
99 init_next_stub();
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 ICStub* InlineCacheBuffer::new_ic_stub() {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 while (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 ICStub* ic_stub = (ICStub*)buffer()->request_committed(ic_stub_code_size());
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if (ic_stub != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return ic_stub;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 // we ran out of inline cache buffer space; must enter safepoint.
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // We do this by forcing a safepoint
a61af66fc99e Initial load
duke
parents:
diff changeset
111 EXCEPTION_MARK;
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113 VM_ForceSafepoint vfs;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 VMThread::execute(&vfs);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // We could potential get an async. exception at this point.
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // In that case we will rethrow it to ourselvs.
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (HAS_PENDING_EXCEPTION) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 oop exception = PENDING_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
119 CLEAR_PENDING_EXCEPTION;
a61af66fc99e Initial load
duke
parents:
diff changeset
120 Thread::send_async_exception(JavaThread::current()->threadObj(), exception);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 void InlineCacheBuffer::update_inline_caches() {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (buffer()->number_of_stubs() > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (TraceICBuffer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 tty->print_cr("[updating inline caches with %d stubs]", buffer()->number_of_stubs());
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133 buffer()->remove_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 init_next_stub();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 bool InlineCacheBuffer::contains(address instruction_address) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 return buffer()->contains(instruction_address);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 }
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 bool InlineCacheBuffer::is_empty() {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 return buffer()->number_of_stubs() == 1; // always has sentinel
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 void InlineCacheBuffer_init() {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 InlineCacheBuffer::initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 void InlineCacheBuffer::create_transition_stub(CompiledIC *ic, oop cached_oop, address entry) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 assert(!SafepointSynchronize::is_at_safepoint(), "should not be called during a safepoint");
a61af66fc99e Initial load
duke
parents:
diff changeset
156 assert (CompiledIC_lock->is_locked(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
157 assert(cached_oop == NULL || cached_oop->is_perm(), "must belong to perm. space");
a61af66fc99e Initial load
duke
parents:
diff changeset
158 if (TraceICBuffer) { tty->print_cr(" create transition stub for " INTPTR_FORMAT, ic->instruction_address()); }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // If an transition stub is already associate with the inline cache, then we remove the association.
a61af66fc99e Initial load
duke
parents:
diff changeset
161 if (ic->is_in_transition_state()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 ICStub* old_stub = ICStub_from_destination_address(ic->stub_address());
a61af66fc99e Initial load
duke
parents:
diff changeset
163 old_stub->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 // allocate and initialize new "out-of-line" inline-cache
a61af66fc99e Initial load
duke
parents:
diff changeset
167 ICStub* ic_stub = get_next_stub();
a61af66fc99e Initial load
duke
parents:
diff changeset
168 ic_stub->set_stub(ic, cached_oop, entry);
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Update inline cache in nmethod to point to new "out-of-line" allocated inline cache
a61af66fc99e Initial load
duke
parents:
diff changeset
171 ic->set_ic_destination(ic_stub->code_begin());
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 set_next_stub(new_ic_stub()); // can cause safepoint synchronization
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 address InlineCacheBuffer::ic_destination_for(CompiledIC *ic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 ICStub* stub = ICStub_from_destination_address(ic->stub_address());
a61af66fc99e Initial load
duke
parents:
diff changeset
179 return stub->destination();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 oop InlineCacheBuffer::cached_oop_for(CompiledIC *ic) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 ICStub* stub = ICStub_from_destination_address(ic->stub_address());
a61af66fc99e Initial load
duke
parents:
diff changeset
185 return stub->cached_oop();
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }