author | coleenp |
Sat, 04 Dec 2010 00:09:05 -0500 | |
changeset 7411 | afcfb75ccae1 |
parent 7397 | 5b173b4ca846 |
child 7913 | dd096a83bdbb |
child 7889 | 02144432d0e1 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5420
diff
changeset
|
2 |
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5420
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5420
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5420
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "classfile/systemDictionary.hpp" |
|
27 |
#include "classfile/vmSymbols.hpp" |
|
28 |
#include "compiler/compileBroker.hpp" |
|
29 |
#include "gc_interface/collectedHeap.hpp" |
|
30 |
#include "interpreter/interpreter.hpp" |
|
31 |
#include "interpreter/interpreterRuntime.hpp" |
|
32 |
#include "interpreter/linkResolver.hpp" |
|
33 |
#include "interpreter/templateTable.hpp" |
|
34 |
#include "memory/oopFactory.hpp" |
|
35 |
#include "memory/universe.inline.hpp" |
|
36 |
#include "oops/constantPoolOop.hpp" |
|
37 |
#include "oops/cpCacheOop.hpp" |
|
38 |
#include "oops/instanceKlass.hpp" |
|
39 |
#include "oops/methodDataOop.hpp" |
|
40 |
#include "oops/objArrayKlass.hpp" |
|
41 |
#include "oops/oop.inline.hpp" |
|
42 |
#include "oops/symbolOop.hpp" |
|
43 |
#include "prims/jvmtiExport.hpp" |
|
44 |
#include "prims/nativeLookup.hpp" |
|
45 |
#include "runtime/biasedLocking.hpp" |
|
46 |
#include "runtime/compilationPolicy.hpp" |
|
47 |
#include "runtime/deoptimization.hpp" |
|
48 |
#include "runtime/fieldDescriptor.hpp" |
|
49 |
#include "runtime/handles.inline.hpp" |
|
50 |
#include "runtime/interfaceSupport.hpp" |
|
51 |
#include "runtime/java.hpp" |
|
52 |
#include "runtime/jfieldIDWorkaround.hpp" |
|
53 |
#include "runtime/osThread.hpp" |
|
54 |
#include "runtime/sharedRuntime.hpp" |
|
55 |
#include "runtime/stubRoutines.hpp" |
|
56 |
#include "runtime/synchronizer.hpp" |
|
57 |
#include "runtime/threadCritical.hpp" |
|
58 |
#include "utilities/events.hpp" |
|
59 |
#ifdef TARGET_ARCH_x86 |
|
60 |
# include "vm_version_x86.hpp" |
|
61 |
#endif |
|
62 |
#ifdef TARGET_ARCH_sparc |
|
63 |
# include "vm_version_sparc.hpp" |
|
64 |
#endif |
|
65 |
#ifdef TARGET_ARCH_zero |
|
66 |
# include "vm_version_zero.hpp" |
|
67 |
#endif |
|
68 |
#ifdef COMPILER2 |
|
69 |
#include "opto/runtime.hpp" |
|
70 |
#endif |
|
1 | 71 |
|
72 |
class UnlockFlagSaver { |
|
73 |
private: |
|
74 |
JavaThread* _thread; |
|
75 |
bool _do_not_unlock; |
|
76 |
public: |
|
77 |
UnlockFlagSaver(JavaThread* t) { |
|
78 |
_thread = t; |
|
79 |
_do_not_unlock = t->do_not_unlock_if_synchronized(); |
|
80 |
t->set_do_not_unlock_if_synchronized(false); |
|
81 |
} |
|
82 |
~UnlockFlagSaver() { |
|
83 |
_thread->set_do_not_unlock_if_synchronized(_do_not_unlock); |
|
84 |
} |
|
85 |
}; |
|
86 |
||
87 |
//------------------------------------------------------------------------------------------------------------------------ |
|
88 |
// State accessors |
|
89 |
||
90 |
void InterpreterRuntime::set_bcp_and_mdp(address bcp, JavaThread *thread) { |
|
91 |
last_frame(thread).interpreter_frame_set_bcp(bcp); |
|
92 |
if (ProfileInterpreter) { |
|
93 |
// ProfileTraps uses MDOs independently of ProfileInterpreter. |
|
94 |
// That is why we must check both ProfileInterpreter and mdo != NULL. |
|
95 |
methodDataOop mdo = last_frame(thread).interpreter_frame_method()->method_data(); |
|
96 |
if (mdo != NULL) { |
|
97 |
NEEDS_CLEANUP; |
|
98 |
last_frame(thread).interpreter_frame_set_mdp(mdo->bci_to_dp(last_frame(thread).interpreter_frame_bci())); |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
//------------------------------------------------------------------------------------------------------------------------ |
|
104 |
// Constants |
|
105 |
||
106 |
||
107 |
IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide)) |
|
108 |
// access constant pool |
|
109 |
constantPoolOop pool = method(thread)->constants(); |
|
5688 | 110 |
int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc); |
1 | 111 |
constantTag tag = pool->tag_at(index); |
112 |
||
113 |
if (tag.is_unresolved_klass() || tag.is_klass()) { |
|
114 |
klassOop klass = pool->klass_at(index, CHECK); |
|
115 |
oop java_class = klass->klass_part()->java_mirror(); |
|
116 |
thread->set_vm_result(java_class); |
|
117 |
} else { |
|
118 |
#ifdef ASSERT |
|
119 |
// If we entered this runtime routine, we believed the tag contained |
|
120 |
// an unresolved string, an unresolved class or a resolved class. |
|
121 |
// However, another thread could have resolved the unresolved string |
|
122 |
// or class by the time we go there. |
|
123 |
assert(tag.is_unresolved_string()|| tag.is_string(), "expected string"); |
|
124 |
#endif |
|
125 |
oop s_oop = pool->string_at(index, CHECK); |
|
126 |
thread->set_vm_result(s_oop); |
|
127 |
} |
|
128 |
IRT_END |
|
129 |
||
5882 | 130 |
IRT_ENTRY(void, InterpreterRuntime::resolve_ldc(JavaThread* thread, Bytecodes::Code bytecode)) { |
131 |
assert(bytecode == Bytecodes::_fast_aldc || |
|
132 |
bytecode == Bytecodes::_fast_aldc_w, "wrong bc"); |
|
133 |
ResourceMark rm(thread); |
|
134 |
methodHandle m (thread, method(thread)); |
|
135 |
Bytecode_loadconstant* ldc = Bytecode_loadconstant_at(m, bci(thread)); |
|
136 |
oop result = ldc->resolve_constant(THREAD); |
|
137 |
DEBUG_ONLY(ConstantPoolCacheEntry* cpce = m->constants()->cache()->entry_at(ldc->cache_index())); |
|
138 |
assert(result == cpce->f1(), "expected result for assembly code"); |
|
139 |
} |
|
140 |
IRT_END |
|
141 |
||
1 | 142 |
|
143 |
//------------------------------------------------------------------------------------------------------------------------ |
|
144 |
// Allocation |
|
145 |
||
146 |
IRT_ENTRY(void, InterpreterRuntime::_new(JavaThread* thread, constantPoolOopDesc* pool, int index)) |
|
147 |
klassOop k_oop = pool->klass_at(index, CHECK); |
|
148 |
instanceKlassHandle klass (THREAD, k_oop); |
|
149 |
||
150 |
// Make sure we are not instantiating an abstract klass |
|
151 |
klass->check_valid_for_instantiation(true, CHECK); |
|
152 |
||
153 |
// Make sure klass is initialized |
|
154 |
klass->initialize(CHECK); |
|
155 |
||
156 |
// At this point the class may not be fully initialized |
|
157 |
// because of recursive initialization. If it is fully |
|
158 |
// initialized & has_finalized is not set, we rewrite |
|
159 |
// it into its fast version (Note: no locking is needed |
|
160 |
// here since this is an atomic byte write and can be |
|
161 |
// done more than once). |
|
162 |
// |
|
163 |
// Note: In case of classes with has_finalized we don't |
|
164 |
// rewrite since that saves us an extra check in |
|
165 |
// the fast version which then would call the |
|
166 |
// slow version anyway (and do a call back into |
|
167 |
// Java). |
|
168 |
// If we have a breakpoint, then we don't rewrite |
|
169 |
// because the _breakpoint bytecode would be lost. |
|
170 |
oop obj = klass->allocate_instance(CHECK); |
|
171 |
thread->set_vm_result(obj); |
|
172 |
IRT_END |
|
173 |
||
174 |
||
175 |
IRT_ENTRY(void, InterpreterRuntime::newarray(JavaThread* thread, BasicType type, jint size)) |
|
176 |
oop obj = oopFactory::new_typeArray(type, size, CHECK); |
|
177 |
thread->set_vm_result(obj); |
|
178 |
IRT_END |
|
179 |
||
180 |
||
181 |
IRT_ENTRY(void, InterpreterRuntime::anewarray(JavaThread* thread, constantPoolOopDesc* pool, int index, jint size)) |
|
182 |
// Note: no oopHandle for pool & klass needed since they are not used |
|
183 |
// anymore after new_objArray() and no GC can happen before. |
|
184 |
// (This may have to change if this code changes!) |
|
185 |
klassOop klass = pool->klass_at(index, CHECK); |
|
186 |
objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK); |
|
187 |
thread->set_vm_result(obj); |
|
188 |
IRT_END |
|
189 |
||
190 |
||
191 |
IRT_ENTRY(void, InterpreterRuntime::multianewarray(JavaThread* thread, jint* first_size_address)) |
|
192 |
// We may want to pass in more arguments - could make this slightly faster |
|
193 |
constantPoolOop constants = method(thread)->constants(); |
|
5688 | 194 |
int i = get_index_u2(thread, Bytecodes::_multianewarray); |
1 | 195 |
klassOop klass = constants->klass_at(i, CHECK); |
196 |
int nof_dims = number_of_dimensions(thread); |
|
197 |
assert(oop(klass)->is_klass(), "not a class"); |
|
198 |
assert(nof_dims >= 1, "multianewarray rank must be nonzero"); |
|
199 |
||
200 |
// We must create an array of jints to pass to multi_allocate. |
|
201 |
ResourceMark rm(thread); |
|
202 |
const int small_dims = 10; |
|
203 |
jint dim_array[small_dims]; |
|
204 |
jint *dims = &dim_array[0]; |
|
205 |
if (nof_dims > small_dims) { |
|
206 |
dims = (jint*) NEW_RESOURCE_ARRAY(jint, nof_dims); |
|
207 |
} |
|
208 |
for (int index = 0; index < nof_dims; index++) { |
|
209 |
// offset from first_size_address is addressed as local[index] |
|
210 |
int n = Interpreter::local_offset_in_bytes(index)/jintSize; |
|
211 |
dims[index] = first_size_address[n]; |
|
212 |
} |
|
213 |
oop obj = arrayKlass::cast(klass)->multi_allocate(nof_dims, dims, CHECK); |
|
214 |
thread->set_vm_result(obj); |
|
215 |
IRT_END |
|
216 |
||
217 |
||
218 |
IRT_ENTRY(void, InterpreterRuntime::register_finalizer(JavaThread* thread, oopDesc* obj)) |
|
219 |
assert(obj->is_oop(), "must be a valid oop"); |
|
220 |
assert(obj->klass()->klass_part()->has_finalizer(), "shouldn't be here otherwise"); |
|
221 |
instanceKlass::register_finalizer(instanceOop(obj), CHECK); |
|
222 |
IRT_END |
|
223 |
||
224 |
||
225 |
// Quicken instance-of and check-cast bytecodes |
|
226 |
IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread)) |
|
227 |
// Force resolving; quicken the bytecode |
|
5688 | 228 |
int which = get_index_u2(thread, Bytecodes::_checkcast); |
1 | 229 |
constantPoolOop cpool = method(thread)->constants(); |
230 |
// We'd expect to assert that we're only here to quicken bytecodes, but in a multithreaded |
|
231 |
// program we might have seen an unquick'd bytecode in the interpreter but have another |
|
232 |
// thread quicken the bytecode before we get here. |
|
233 |
// assert( cpool->tag_at(which).is_unresolved_klass(), "should only come here to quicken bytecodes" ); |
|
234 |
klassOop klass = cpool->klass_at(which, CHECK); |
|
235 |
thread->set_vm_result(klass); |
|
236 |
IRT_END |
|
237 |
||
238 |
||
239 |
//------------------------------------------------------------------------------------------------------------------------ |
|
240 |
// Exceptions |
|
241 |
||
242 |
// Assume the compiler is (or will be) interested in this event. |
|
243 |
// If necessary, create an MDO to hold the information, and record it. |
|
244 |
void InterpreterRuntime::note_trap(JavaThread* thread, int reason, TRAPS) { |
|
245 |
assert(ProfileTraps, "call me only if profiling"); |
|
246 |
methodHandle trap_method(thread, method(thread)); |
|
6463
f4362c8da849
6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
jrose
parents:
6453
diff
changeset
|
247 |
|
1 | 248 |
if (trap_method.not_null()) { |
249 |
methodDataHandle trap_mdo(thread, trap_method->method_data()); |
|
250 |
if (trap_mdo.is_null()) { |
|
251 |
methodOopDesc::build_interpreter_method_data(trap_method, THREAD); |
|
252 |
if (HAS_PENDING_EXCEPTION) { |
|
253 |
assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here"); |
|
254 |
CLEAR_PENDING_EXCEPTION; |
|
255 |
} |
|
256 |
trap_mdo = methodDataHandle(thread, trap_method->method_data()); |
|
257 |
// and fall through... |
|
258 |
} |
|
259 |
if (trap_mdo.not_null()) { |
|
260 |
// Update per-method count of trap events. The interpreter |
|
261 |
// is updating the MDO to simulate the effect of compiler traps. |
|
262 |
int trap_bci = trap_method->bci_from(bcp(thread)); |
|
263 |
Deoptimization::update_method_data_from_interpreter(trap_mdo, trap_bci, reason); |
|
264 |
} |
|
265 |
} |
|
266 |
} |
|
267 |
||
268 |
static Handle get_preinitialized_exception(klassOop k, TRAPS) { |
|
269 |
// get klass |
|
270 |
instanceKlass* klass = instanceKlass::cast(k); |
|
271 |
assert(klass->is_initialized(), |
|
272 |
"this klass should have been initialized during VM initialization"); |
|
273 |
// create instance - do not call constructor since we may have no |
|
274 |
// (java) stack space left (should assert constructor is empty) |
|
275 |
Handle exception; |
|
276 |
oop exception_oop = klass->allocate_instance(CHECK_(exception)); |
|
277 |
exception = Handle(THREAD, exception_oop); |
|
278 |
if (StackTraceInThrowable) { |
|
279 |
java_lang_Throwable::fill_in_stack_trace(exception); |
|
280 |
} |
|
281 |
return exception; |
|
282 |
} |
|
283 |
||
284 |
// Special handling for stack overflow: since we don't have any (java) stack |
|
285 |
// space left we use the pre-allocated & pre-initialized StackOverflowError |
|
286 |
// klass to create an stack overflow error instance. We do not call its |
|
287 |
// constructor for the same reason (it is empty, anyway). |
|
288 |
IRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* thread)) |
|
289 |
Handle exception = get_preinitialized_exception( |
|
290 |
SystemDictionary::StackOverflowError_klass(), |
|
291 |
CHECK); |
|
292 |
THROW_HANDLE(exception); |
|
293 |
IRT_END |
|
294 |
||
295 |
||
296 |
IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message)) |
|
297 |
// lookup exception klass |
|
298 |
symbolHandle s = oopFactory::new_symbol_handle(name, CHECK); |
|
299 |
if (ProfileTraps) { |
|
300 |
if (s == vmSymbols::java_lang_ArithmeticException()) { |
|
301 |
note_trap(thread, Deoptimization::Reason_div0_check, CHECK); |
|
302 |
} else if (s == vmSymbols::java_lang_NullPointerException()) { |
|
303 |
note_trap(thread, Deoptimization::Reason_null_check, CHECK); |
|
304 |
} |
|
305 |
} |
|
306 |
// create exception |
|
307 |
Handle exception = Exceptions::new_exception(thread, s(), message); |
|
308 |
thread->set_vm_result(exception()); |
|
309 |
IRT_END |
|
310 |
||
311 |
||
312 |
IRT_ENTRY(void, InterpreterRuntime::create_klass_exception(JavaThread* thread, char* name, oopDesc* obj)) |
|
313 |
ResourceMark rm(thread); |
|
314 |
const char* klass_name = Klass::cast(obj->klass())->external_name(); |
|
315 |
// lookup exception klass |
|
316 |
symbolHandle s = oopFactory::new_symbol_handle(name, CHECK); |
|
317 |
if (ProfileTraps) { |
|
318 |
note_trap(thread, Deoptimization::Reason_class_check, CHECK); |
|
319 |
} |
|
320 |
// create exception, with klass name as detail message |
|
321 |
Handle exception = Exceptions::new_exception(thread, s(), klass_name); |
|
322 |
thread->set_vm_result(exception()); |
|
323 |
IRT_END |
|
324 |
||
325 |
||
326 |
IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index)) |
|
327 |
char message[jintAsStringSize]; |
|
328 |
// lookup exception klass |
|
329 |
symbolHandle s = oopFactory::new_symbol_handle(name, CHECK); |
|
330 |
if (ProfileTraps) { |
|
331 |
note_trap(thread, Deoptimization::Reason_range_check, CHECK); |
|
332 |
} |
|
333 |
// create exception |
|
334 |
sprintf(message, "%d", index); |
|
335 |
THROW_MSG(s(), message); |
|
336 |
IRT_END |
|
337 |
||
338 |
IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException( |
|
339 |
JavaThread* thread, oopDesc* obj)) |
|
340 |
||
341 |
ResourceMark rm(thread); |
|
342 |
char* message = SharedRuntime::generate_class_cast_message( |
|
343 |
thread, Klass::cast(obj->klass())->external_name()); |
|
344 |
||
345 |
if (ProfileTraps) { |
|
346 |
note_trap(thread, Deoptimization::Reason_class_check, CHECK); |
|
347 |
} |
|
348 |
||
349 |
// create exception |
|
350 |
THROW_MSG(vmSymbols::java_lang_ClassCastException(), message); |
|
351 |
IRT_END |
|
352 |
||
2534 | 353 |
// required can be either a MethodType, or a Class (for a single argument) |
354 |
// actual (if not null) can be either a MethodHandle, or an arbitrary value (for a single argument) |
|
355 |
IRT_ENTRY(void, InterpreterRuntime::throw_WrongMethodTypeException(JavaThread* thread, |
|
356 |
oopDesc* required, |
|
357 |
oopDesc* actual)) { |
|
358 |
ResourceMark rm(thread); |
|
359 |
char* message = SharedRuntime::generate_wrong_method_type_message(thread, required, actual); |
|
360 |
||
361 |
if (ProfileTraps) { |
|
362 |
note_trap(thread, Deoptimization::Reason_constraint, CHECK); |
|
363 |
} |
|
364 |
||
365 |
// create exception |
|
366 |
THROW_MSG(vmSymbols::java_dyn_WrongMethodTypeException(), message); |
|
367 |
} |
|
368 |
IRT_END |
|
369 |
||
370 |
||
1 | 371 |
|
372 |
// exception_handler_for_exception(...) returns the continuation address, |
|
373 |
// the exception oop (via TLS) and sets the bci/bcp for the continuation. |
|
374 |
// The exception oop is returned to make sure it is preserved over GC (it |
|
375 |
// is only on the stack if the exception was thrown explicitly via athrow). |
|
376 |
// During this operation, the expression stack contains the values for the |
|
377 |
// bci where the exception happened. If the exception was propagated back |
|
378 |
// from a call, the expression stack contains the values for the bci at the |
|
379 |
// invoke w/o arguments (i.e., as if one were inside the call). |
|
380 |
IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception)) |
|
381 |
||
382 |
Handle h_exception(thread, exception); |
|
383 |
methodHandle h_method (thread, method(thread)); |
|
384 |
constantPoolHandle h_constants(thread, h_method->constants()); |
|
385 |
typeArrayHandle h_extable (thread, h_method->exception_table()); |
|
386 |
bool should_repeat; |
|
387 |
int handler_bci; |
|
5882 | 388 |
int current_bci = bci(thread); |
1 | 389 |
|
390 |
// Need to do this check first since when _do_not_unlock_if_synchronized |
|
391 |
// is set, we don't want to trigger any classloading which may make calls |
|
392 |
// into java, or surprisingly find a matching exception handler for bci 0 |
|
393 |
// since at this moment the method hasn't been "officially" entered yet. |
|
394 |
if (thread->do_not_unlock_if_synchronized()) { |
|
395 |
ResourceMark rm; |
|
396 |
assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized"); |
|
397 |
thread->set_vm_result(exception); |
|
398 |
#ifdef CC_INTERP |
|
399 |
return (address) -1; |
|
400 |
#else |
|
401 |
return Interpreter::remove_activation_entry(); |
|
402 |
#endif |
|
403 |
} |
|
404 |
||
405 |
do { |
|
406 |
should_repeat = false; |
|
407 |
||
408 |
// assertions |
|
409 |
#ifdef ASSERT |
|
410 |
assert(h_exception.not_null(), "NULL exceptions should be handled by athrow"); |
|
411 |
assert(h_exception->is_oop(), "just checking"); |
|
412 |
// Check that exception is a subclass of Throwable, otherwise we have a VerifyError |
|
4571 | 413 |
if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) { |
1 | 414 |
if (ExitVMOnVerifyError) vm_exit(-1); |
415 |
ShouldNotReachHere(); |
|
416 |
} |
|
417 |
#endif |
|
418 |
||
419 |
// tracing |
|
420 |
if (TraceExceptions) { |
|
421 |
ttyLocker ttyl; |
|
422 |
ResourceMark rm(thread); |
|
423 |
tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception()); |
|
424 |
tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string()); |
|
425 |
tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread); |
|
426 |
} |
|
427 |
// Don't go paging in something which won't be used. |
|
428 |
// else if (h_extable->length() == 0) { |
|
429 |
// // disabled for now - interpreter is not using shortcut yet |
|
430 |
// // (shortcut is not to call runtime if we have no exception handlers) |
|
431 |
// // warning("performance bug: should not call runtime if method has no exception handlers"); |
|
432 |
// } |
|
433 |
// for AbortVMOnException flag |
|
434 |
NOT_PRODUCT(Exceptions::debug_check_abort(h_exception)); |
|
435 |
||
436 |
// exception handler lookup |
|
437 |
KlassHandle h_klass(THREAD, h_exception->klass()); |
|
438 |
handler_bci = h_method->fast_exception_handler_bci_for(h_klass, current_bci, THREAD); |
|
439 |
if (HAS_PENDING_EXCEPTION) { |
|
440 |
// We threw an exception while trying to find the exception handler. |
|
441 |
// Transfer the new exception to the exception handle which will |
|
442 |
// be set into thread local storage, and do another lookup for an |
|
443 |
// exception handler for this exception, this time starting at the |
|
444 |
// BCI of the exception handler which caused the exception to be |
|
445 |
// thrown (bug 4307310). |
|
446 |
h_exception = Handle(THREAD, PENDING_EXCEPTION); |
|
447 |
CLEAR_PENDING_EXCEPTION; |
|
448 |
if (handler_bci >= 0) { |
|
449 |
current_bci = handler_bci; |
|
450 |
should_repeat = true; |
|
451 |
} |
|
452 |
} |
|
453 |
} while (should_repeat == true); |
|
454 |
||
455 |
// notify JVMTI of an exception throw; JVMTI will detect if this is a first |
|
456 |
// time throw or a stack unwinding throw and accordingly notify the debugger |
|
4761
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
4571
diff
changeset
|
457 |
if (JvmtiExport::can_post_on_exceptions()) { |
1 | 458 |
JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception()); |
459 |
} |
|
460 |
||
461 |
#ifdef CC_INTERP |
|
462 |
address continuation = (address)(intptr_t) handler_bci; |
|
463 |
#else |
|
464 |
address continuation = NULL; |
|
465 |
#endif |
|
466 |
address handler_pc = NULL; |
|
467 |
if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) { |
|
468 |
// Forward exception to callee (leaving bci/bcp untouched) because (a) no |
|
469 |
// handler in this method, or (b) after a stack overflow there is not yet |
|
470 |
// enough stack space available to reprotect the stack. |
|
471 |
#ifndef CC_INTERP |
|
472 |
continuation = Interpreter::remove_activation_entry(); |
|
473 |
#endif |
|
474 |
// Count this for compilation purposes |
|
475 |
h_method->interpreter_throwout_increment(); |
|
476 |
} else { |
|
477 |
// handler in this method => change bci/bcp to handler bci/bcp and continue there |
|
478 |
handler_pc = h_method->code_base() + handler_bci; |
|
479 |
#ifndef CC_INTERP |
|
480 |
set_bcp_and_mdp(handler_pc, thread); |
|
481 |
continuation = Interpreter::dispatch_table(vtos)[*handler_pc]; |
|
482 |
#endif |
|
483 |
} |
|
484 |
// notify debugger of an exception catch |
|
485 |
// (this is good for exceptions caught in native methods as well) |
|
4761
bdb7375a1fee
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
4571
diff
changeset
|
486 |
if (JvmtiExport::can_post_on_exceptions()) { |
1 | 487 |
JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL)); |
488 |
} |
|
489 |
||
490 |
thread->set_vm_result(h_exception()); |
|
491 |
return continuation; |
|
492 |
IRT_END |
|
493 |
||
494 |
||
495 |
IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread)) |
|
496 |
assert(thread->has_pending_exception(), "must only ne called if there's an exception pending"); |
|
497 |
// nothing to do - eventually we should remove this code entirely (see comments @ call sites) |
|
498 |
IRT_END |
|
499 |
||
500 |
||
501 |
IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread)) |
|
502 |
THROW(vmSymbols::java_lang_AbstractMethodError()); |
|
503 |
IRT_END |
|
504 |
||
505 |
||
506 |
IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread)) |
|
507 |
THROW(vmSymbols::java_lang_IncompatibleClassChangeError()); |
|
508 |
IRT_END |
|
509 |
||
510 |
||
511 |
//------------------------------------------------------------------------------------------------------------------------ |
|
512 |
// Fields |
|
513 |
// |
|
514 |
||
515 |
IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode)) |
|
516 |
// resolve field |
|
517 |
FieldAccessInfo info; |
|
518 |
constantPoolHandle pool(thread, method(thread)->constants()); |
|
519 |
bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic); |
|
520 |
||
521 |
{ |
|
522 |
JvmtiHideSingleStepping jhss(thread); |
|
5688 | 523 |
LinkResolver::resolve_field(info, pool, get_index_u2_cpcache(thread, bytecode), |
1 | 524 |
bytecode, false, CHECK); |
525 |
} // end JvmtiHideSingleStepping |
|
526 |
||
527 |
// check if link resolution caused cpCache to be updated |
|
528 |
if (already_resolved(thread)) return; |
|
529 |
||
530 |
// compute auxiliary field attributes |
|
531 |
TosState state = as_TosState(info.field_type()); |
|
532 |
||
533 |
// We need to delay resolving put instructions on final fields |
|
534 |
// until we actually invoke one. This is required so we throw |
|
535 |
// exceptions at the correct place. If we do not resolve completely |
|
536 |
// in the current pass, leaving the put_code set to zero will |
|
537 |
// cause the next put instruction to reresolve. |
|
538 |
bool is_put = (bytecode == Bytecodes::_putfield || |
|
539 |
bytecode == Bytecodes::_putstatic); |
|
540 |
Bytecodes::Code put_code = (Bytecodes::Code)0; |
|
541 |
||
542 |
// We also need to delay resolving getstatic instructions until the |
|
543 |
// class is intitialized. This is required so that access to the static |
|
544 |
// field will call the initialization function every time until the class |
|
545 |
// is completely initialized ala. in 2.17.5 in JVM Specification. |
|
546 |
instanceKlass *klass = instanceKlass::cast(info.klass()->as_klassOop()); |
|
547 |
bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) && |
|
548 |
!klass->is_initialized()); |
|
549 |
Bytecodes::Code get_code = (Bytecodes::Code)0; |
|
550 |
||
551 |
||
552 |
if (!uninitialized_static) { |
|
553 |
get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield); |
|
554 |
if (is_put || !info.access_flags().is_final()) { |
|
555 |
put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield); |
|
556 |
} |
|
557 |
} |
|
558 |
||
559 |
cache_entry(thread)->set_field( |
|
560 |
get_code, |
|
561 |
put_code, |
|
562 |
info.klass(), |
|
563 |
info.field_index(), |
|
564 |
info.field_offset(), |
|
565 |
state, |
|
566 |
info.access_flags().is_final(), |
|
567 |
info.access_flags().is_volatile() |
|
568 |
); |
|
569 |
IRT_END |
|
570 |
||
571 |
||
572 |
//------------------------------------------------------------------------------------------------------------------------ |
|
573 |
// Synchronization |
|
574 |
// |
|
575 |
// The interpreter's synchronization code is factored out so that it can |
|
576 |
// be shared by method invocation and synchronized blocks. |
|
577 |
//%note synchronization_3 |
|
578 |
||
579 |
static void trace_locking(Handle& h_locking_obj, bool is_locking) { |
|
580 |
ObjectSynchronizer::trace_locking(h_locking_obj, false, true, is_locking); |
|
581 |
} |
|
582 |
||
583 |
||
584 |
//%note monitor_1 |
|
585 |
IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem)) |
|
586 |
#ifdef ASSERT |
|
587 |
thread->last_frame().interpreter_frame_verify_monitor(elem); |
|
588 |
#endif |
|
589 |
if (PrintBiasedLockingStatistics) { |
|
590 |
Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); |
|
591 |
} |
|
592 |
Handle h_obj(thread, elem->obj()); |
|
593 |
assert(Universe::heap()->is_in_reserved_or_null(h_obj()), |
|
594 |
"must be NULL or an object"); |
|
595 |
if (UseBiasedLocking) { |
|
596 |
// Retry fast entry if bias is revoked to avoid unnecessary inflation |
|
597 |
ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK); |
|
598 |
} else { |
|
599 |
ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK); |
|
600 |
} |
|
601 |
assert(Universe::heap()->is_in_reserved_or_null(elem->obj()), |
|
602 |
"must be NULL or an object"); |
|
603 |
#ifdef ASSERT |
|
604 |
thread->last_frame().interpreter_frame_verify_monitor(elem); |
|
605 |
#endif |
|
606 |
IRT_END |
|
607 |
||
608 |
||
609 |
//%note monitor_1 |
|
610 |
IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem)) |
|
611 |
#ifdef ASSERT |
|
612 |
thread->last_frame().interpreter_frame_verify_monitor(elem); |
|
613 |
#endif |
|
614 |
Handle h_obj(thread, elem->obj()); |
|
615 |
assert(Universe::heap()->is_in_reserved_or_null(h_obj()), |
|
616 |
"must be NULL or an object"); |
|
617 |
if (elem == NULL || h_obj()->is_unlocked()) { |
|
618 |
THROW(vmSymbols::java_lang_IllegalMonitorStateException()); |
|
619 |
} |
|
620 |
ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread); |
|
621 |
// Free entry. This must be done here, since a pending exception might be installed on |
|
622 |
// exit. If it is not cleared, the exception handling code will try to unlock the monitor again. |
|
623 |
elem->set_obj(NULL); |
|
624 |
#ifdef ASSERT |
|
625 |
thread->last_frame().interpreter_frame_verify_monitor(elem); |
|
626 |
#endif |
|
627 |
IRT_END |
|
628 |
||
629 |
||
630 |
IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread)) |
|
631 |
THROW(vmSymbols::java_lang_IllegalMonitorStateException()); |
|
632 |
IRT_END |
|
633 |
||
634 |
||
635 |
IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread)) |
|
636 |
// Returns an illegal exception to install into the current thread. The |
|
637 |
// pending_exception flag is cleared so normal exception handling does not |
|
638 |
// trigger. Any current installed exception will be overwritten. This |
|
639 |
// method will be called during an exception unwind. |
|
640 |
||
641 |
assert(!HAS_PENDING_EXCEPTION, "no pending exception"); |
|
642 |
Handle exception(thread, thread->vm_result()); |
|
643 |
assert(exception() != NULL, "vm result should be set"); |
|
644 |
thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures) |
|
4571 | 645 |
if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) { |
1 | 646 |
exception = get_preinitialized_exception( |
647 |
SystemDictionary::IllegalMonitorStateException_klass(), |
|
648 |
CATCH); |
|
649 |
} |
|
650 |
thread->set_vm_result(exception()); |
|
651 |
IRT_END |
|
652 |
||
653 |
||
654 |
//------------------------------------------------------------------------------------------------------------------------ |
|
655 |
// Invokes |
|
656 |
||
657 |
IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp)) |
|
658 |
return method->orig_bytecode_at(method->bci_from(bcp)); |
|
659 |
IRT_END |
|
660 |
||
661 |
IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp, Bytecodes::Code new_code)) |
|
662 |
method->set_orig_bytecode_at(method->bci_from(bcp), new_code); |
|
663 |
IRT_END |
|
664 |
||
665 |
IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, methodOopDesc* method, address bcp)) |
|
666 |
JvmtiExport::post_raw_breakpoint(thread, method, bcp); |
|
667 |
IRT_END |
|
668 |
||
669 |
IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode)) |
|
670 |
// extract receiver from the outgoing argument list if necessary |
|
671 |
Handle receiver(thread, NULL); |
|
672 |
if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) { |
|
673 |
ResourceMark rm(thread); |
|
674 |
methodHandle m (thread, method(thread)); |
|
5882 | 675 |
Bytecode_invoke* call = Bytecode_invoke_at(m, bci(thread)); |
1 | 676 |
symbolHandle signature (thread, call->signature()); |
677 |
receiver = Handle(thread, |
|
678 |
thread->last_frame().interpreter_callee_receiver(signature)); |
|
679 |
assert(Universe::heap()->is_in_reserved_or_null(receiver()), |
|
680 |
"sanity check"); |
|
681 |
assert(receiver.is_null() || |
|
682 |
Universe::heap()->is_in_reserved(receiver->klass()), |
|
683 |
"sanity check"); |
|
684 |
} |
|
685 |
||
686 |
// resolve method |
|
687 |
CallInfo info; |
|
688 |
constantPoolHandle pool(thread, method(thread)->constants()); |
|
689 |
||
690 |
{ |
|
691 |
JvmtiHideSingleStepping jhss(thread); |
|
692 |
LinkResolver::resolve_invoke(info, receiver, pool, |
|
5688 | 693 |
get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); |
1 | 694 |
if (JvmtiExport::can_hotswap_or_post_breakpoint()) { |
695 |
int retry_count = 0; |
|
696 |
while (info.resolved_method()->is_old()) { |
|
697 |
// It is very unlikely that method is redefined more than 100 times |
|
698 |
// in the middle of resolve. If it is looping here more than 100 times |
|
699 |
// means then there could be a bug here. |
|
700 |
guarantee((retry_count++ < 100), |
|
701 |
"Could not resolve to latest version of redefined method"); |
|
702 |
// method is redefined in the middle of resolve so re-try. |
|
703 |
LinkResolver::resolve_invoke(info, receiver, pool, |
|
5688 | 704 |
get_index_u2_cpcache(thread, bytecode), bytecode, CHECK); |
1 | 705 |
} |
706 |
} |
|
707 |
} // end JvmtiHideSingleStepping |
|
708 |
||
709 |
// check if link resolution caused cpCache to be updated |
|
710 |
if (already_resolved(thread)) return; |
|
711 |
||
712 |
if (bytecode == Bytecodes::_invokeinterface) { |
|
713 |
||
714 |
if (TraceItables && Verbose) { |
|
715 |
ResourceMark rm(thread); |
|
716 |
tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string()); |
|
717 |
} |
|
718 |
if (info.resolved_method()->method_holder() == |
|
4571 | 719 |
SystemDictionary::Object_klass()) { |
1 | 720 |
// NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec |
721 |
// (see also cpCacheOop.cpp for details) |
|
722 |
methodHandle rm = info.resolved_method(); |
|
723 |
assert(rm->is_final() || info.has_vtable_index(), |
|
724 |
"should have been set already"); |
|
725 |
cache_entry(thread)->set_method(bytecode, rm, info.vtable_index()); |
|
726 |
} else { |
|
727 |
// Setup itable entry |
|
728 |
int index = klassItable::compute_itable_index(info.resolved_method()()); |
|
729 |
cache_entry(thread)->set_interface_call(info.resolved_method(), index); |
|
730 |
} |
|
731 |
} else { |
|
732 |
cache_entry(thread)->set_method( |
|
733 |
bytecode, |
|
734 |
info.resolved_method(), |
|
735 |
info.vtable_index()); |
|
736 |
} |
|
737 |
IRT_END |
|
738 |
||
739 |
||
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3696
diff
changeset
|
740 |
// First time execution: Resolve symbols, create a permanent CallSite object. |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
741 |
IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
742 |
ResourceMark rm(thread); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
743 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
744 |
assert(EnableInvokeDynamic, ""); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
745 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
746 |
const Bytecodes::Code bytecode = Bytecodes::_invokedynamic; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
747 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
748 |
methodHandle caller_method(thread, method(thread)); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
749 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
750 |
constantPoolHandle pool(thread, caller_method->constants()); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
751 |
pool->set_invokedynamic(); // mark header to flag active call sites |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
752 |
|
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
753 |
int caller_bci = 0; |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
754 |
int site_index = 0; |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
755 |
{ address caller_bcp = bcp(thread); |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
756 |
caller_bci = caller_method->bci_from(caller_bcp); |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
757 |
site_index = Bytes::get_native_u4(caller_bcp+1); |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
758 |
} |
5688 | 759 |
assert(site_index == InterpreterRuntime::bytecode(thread)->get_index_u4(bytecode), ""); |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
760 |
assert(constantPoolCacheOopDesc::is_secondary_index(site_index), "proper format"); |
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3696
diff
changeset
|
761 |
// there is a second CPC entries that is of interest; it caches signature info: |
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3696
diff
changeset
|
762 |
int main_index = pool->cache()->secondary_entry_at(site_index)->main_entry_index(); |
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
7104
diff
changeset
|
763 |
int pool_index = pool->cache()->entry_at(main_index)->constant_pool_index(); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
764 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
765 |
// first resolve the signature to a MH.invoke methodOop |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
766 |
if (!pool->cache()->entry_at(main_index)->is_resolved(bytecode)) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
767 |
JvmtiHideSingleStepping jhss(thread); |
7104 | 768 |
CallInfo callinfo; |
769 |
LinkResolver::resolve_invoke(callinfo, Handle(), pool, |
|
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3696
diff
changeset
|
770 |
site_index, bytecode, CHECK); |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
771 |
// The main entry corresponds to a JVM_CONSTANT_InvokeDynamic, and serves |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
772 |
// as a common reference point for all invokedynamic call sites with |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
773 |
// that exact call descriptor. We will link it in the CP cache exactly |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
774 |
// as if it were an invokevirtual of MethodHandle.invoke. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
775 |
pool->cache()->entry_at(main_index)->set_method( |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
776 |
bytecode, |
7104 | 777 |
callinfo.resolved_method(), |
778 |
callinfo.vtable_index()); |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
779 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
780 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
781 |
// The method (f2 entry) of the main entry is the MH.invoke for the |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
782 |
// invokedynamic target call signature. |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
783 |
oop f1_value = pool->cache()->entry_at(main_index)->f1(); |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
784 |
methodHandle signature_invoker(THREAD, (methodOop) f1_value); |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
785 |
assert(signature_invoker.not_null() && signature_invoker->is_method() && signature_invoker->is_method_handle_invoke(), |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
786 |
"correct result from LinkResolver::resolve_invokedynamic"); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
787 |
|
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
7104
diff
changeset
|
788 |
Handle info; // optional argument(s) in JVM_CONSTANT_InvokeDynamic |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
789 |
Handle bootm = SystemDictionary::find_bootstrap_method(caller_method, caller_bci, |
7114
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
7104
diff
changeset
|
790 |
main_index, info, CHECK); |
65d21c4c6337
6984311: JSR 292 needs optional bootstrap method parameters
jrose
parents:
7104
diff
changeset
|
791 |
if (!java_dyn_MethodHandle::is_instance(bootm())) { |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
792 |
THROW_MSG(vmSymbols::java_lang_IllegalStateException(), |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
793 |
"no bootstrap method found for invokedynamic"); |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
794 |
} |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
795 |
|
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
796 |
// Short circuit if CallSite has been bound already: |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
797 |
if (!pool->cache()->secondary_entry_at(site_index)->is_f1_null()) |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
798 |
return; |
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5883
diff
changeset
|
799 |
|
4429
d7eb4e2099aa
6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents:
3696
diff
changeset
|
800 |
symbolHandle call_site_name(THREAD, pool->name_ref_at(site_index)); |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
801 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
802 |
Handle call_site |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
803 |
= SystemDictionary::make_dynamic_call_site(bootm, |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
804 |
// Callee information: |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
805 |
call_site_name, |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
806 |
signature_invoker, |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
807 |
info, |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
808 |
// Caller information: |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
809 |
caller_method, |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
810 |
caller_bci, |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
811 |
CHECK); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
812 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
813 |
// In the secondary entry, the f1 field is the call site, and the f2 (index) |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
814 |
// field is some data about the invoke site. Currently, it is just the BCI. |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
815 |
// Later, it might be changed to help manage inlining dependencies. |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5419
diff
changeset
|
816 |
pool->cache()->secondary_entry_at(site_index)->set_dynamic_call(call_site, signature_invoker); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
817 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
818 |
IRT_END |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
819 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2534
diff
changeset
|
820 |
|
1 | 821 |
//------------------------------------------------------------------------------------------------------------------------ |
822 |
// Miscellaneous |
|
823 |
||
824 |
||
3696 | 825 |
nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) { |
826 |
nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp); |
|
827 |
assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests"); |
|
828 |
if (branch_bcp != NULL && nm != NULL) { |
|
829 |
// This was a successful request for an OSR nmethod. Because |
|
830 |
// frequency_counter_overflow_inner ends with a safepoint check, |
|
831 |
// nm could have been unloaded so look it up again. It's unsafe |
|
832 |
// to examine nm directly since it might have been freed and used |
|
833 |
// for something else. |
|
834 |
frame fr = thread->last_frame(); |
|
835 |
methodOop method = fr.interpreter_frame_method(); |
|
836 |
int bci = method->bci_from(fr.interpreter_frame_bcp()); |
|
6453 | 837 |
nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false); |
3696 | 838 |
} |
839 |
return nm; |
|
840 |
} |
|
841 |
||
1 | 842 |
IRT_ENTRY(nmethod*, |
3696 | 843 |
InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp)) |
1 | 844 |
// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized |
845 |
// flag, in case this method triggers classloading which will call into Java. |
|
846 |
UnlockFlagSaver fs(thread); |
|
847 |
||
848 |
frame fr = thread->last_frame(); |
|
849 |
assert(fr.is_interpreted_frame(), "must come from interpreter"); |
|
850 |
methodHandle method(thread, fr.interpreter_frame_method()); |
|
6453 | 851 |
const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci; |
852 |
const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci; |
|
853 |
||
854 |
nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, thread); |
|
1 | 855 |
|
6453 | 856 |
if (osr_nm != NULL) { |
857 |
// We may need to do on-stack replacement which requires that no |
|
858 |
// monitors in the activation are biased because their |
|
859 |
// BasicObjectLocks will need to migrate during OSR. Force |
|
860 |
// unbiasing of all monitors in the activation now (even though |
|
861 |
// the OSR nmethod might be invalidated) because we don't have a |
|
862 |
// safepoint opportunity later once the migration begins. |
|
863 |
if (UseBiasedLocking) { |
|
864 |
ResourceMark rm; |
|
865 |
GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>(); |
|
866 |
for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end(); |
|
867 |
kptr < fr.interpreter_frame_monitor_begin(); |
|
868 |
kptr = fr.next_monitor_in_interpreter_frame(kptr) ) { |
|
869 |
if( kptr->obj() != NULL ) { |
|
870 |
objects_to_revoke->append(Handle(THREAD, kptr->obj())); |
|
871 |
} |
|
1 | 872 |
} |
6453 | 873 |
BiasedLocking::revoke(objects_to_revoke); |
1 | 874 |
} |
875 |
} |
|
6453 | 876 |
return osr_nm; |
1 | 877 |
IRT_END |
878 |
||
879 |
IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(methodOopDesc* method, address cur_bcp)) |
|
880 |
assert(ProfileInterpreter, "must be profiling interpreter"); |
|
881 |
int bci = method->bci_from(cur_bcp); |
|
882 |
methodDataOop mdo = method->method_data(); |
|
883 |
if (mdo == NULL) return 0; |
|
884 |
return mdo->bci_to_di(bci); |
|
885 |
IRT_END |
|
886 |
||
887 |
IRT_ENTRY(jint, InterpreterRuntime::profile_method(JavaThread* thread, address cur_bcp)) |
|
888 |
// use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized |
|
889 |
// flag, in case this method triggers classloading which will call into Java. |
|
890 |
UnlockFlagSaver fs(thread); |
|
891 |
||
892 |
assert(ProfileInterpreter, "must be profiling interpreter"); |
|
893 |
frame fr = thread->last_frame(); |
|
894 |
assert(fr.is_interpreted_frame(), "must come from interpreter"); |
|
895 |
methodHandle method(thread, fr.interpreter_frame_method()); |
|
896 |
int bci = method->bci_from(cur_bcp); |
|
897 |
methodOopDesc::build_interpreter_method_data(method, THREAD); |
|
898 |
if (HAS_PENDING_EXCEPTION) { |
|
899 |
assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here"); |
|
900 |
CLEAR_PENDING_EXCEPTION; |
|
901 |
// and fall through... |
|
902 |
} |
|
903 |
methodDataOop mdo = method->method_data(); |
|
904 |
if (mdo == NULL) return 0; |
|
905 |
return mdo->bci_to_di(bci); |
|
906 |
IRT_END |
|
907 |
||
908 |
||
909 |
#ifdef ASSERT |
|
910 |
IRT_LEAF(void, InterpreterRuntime::verify_mdp(methodOopDesc* method, address bcp, address mdp)) |
|
911 |
assert(ProfileInterpreter, "must be profiling interpreter"); |
|
912 |
||
913 |
methodDataOop mdo = method->method_data(); |
|
914 |
assert(mdo != NULL, "must not be null"); |
|
915 |
||
916 |
int bci = method->bci_from(bcp); |
|
917 |
||
918 |
address mdp2 = mdo->bci_to_dp(bci); |
|
919 |
if (mdp != mdp2) { |
|
920 |
ResourceMark rm; |
|
921 |
ResetNoHandleMark rnm; // In a LEAF entry. |
|
922 |
HandleMark hm; |
|
923 |
tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci); |
|
924 |
int current_di = mdo->dp_to_di(mdp); |
|
925 |
int expected_di = mdo->dp_to_di(mdp2); |
|
926 |
tty->print_cr(" actual di %d expected di %d", current_di, expected_di); |
|
927 |
int expected_approx_bci = mdo->data_at(expected_di)->bci(); |
|
928 |
int approx_bci = -1; |
|
929 |
if (current_di >= 0) { |
|
930 |
approx_bci = mdo->data_at(current_di)->bci(); |
|
931 |
} |
|
932 |
tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci); |
|
933 |
mdo->print_on(tty); |
|
934 |
method->print_codes(); |
|
935 |
} |
|
936 |
assert(mdp == mdp2, "wrong mdp"); |
|
937 |
IRT_END |
|
938 |
#endif // ASSERT |
|
939 |
||
940 |
IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci)) |
|
941 |
assert(ProfileInterpreter, "must be profiling interpreter"); |
|
942 |
ResourceMark rm(thread); |
|
943 |
HandleMark hm(thread); |
|
944 |
frame fr = thread->last_frame(); |
|
945 |
assert(fr.is_interpreted_frame(), "must come from interpreter"); |
|
946 |
methodDataHandle h_mdo(thread, fr.interpreter_frame_method()->method_data()); |
|
947 |
||
948 |
// Grab a lock to ensure atomic access to setting the return bci and |
|
949 |
// the displacement. This can block and GC, invalidating all naked oops. |
|
950 |
MutexLocker ml(RetData_lock); |
|
951 |
||
952 |
// ProfileData is essentially a wrapper around a derived oop, so we |
|
953 |
// need to take the lock before making any ProfileData structures. |
|
954 |
ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp())); |
|
955 |
RetData* rdata = data->as_RetData(); |
|
956 |
address new_mdp = rdata->fixup_ret(return_bci, h_mdo); |
|
957 |
fr.interpreter_frame_set_mdp(new_mdp); |
|
958 |
IRT_END |
|
959 |
||
960 |
||
961 |
IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread)) |
|
962 |
// We used to need an explict preserve_arguments here for invoke bytecodes. However, |
|
963 |
// stack traversal automatically takes care of preserving arguments for invoke, so |
|
964 |
// this is no longer needed. |
|
965 |
||
966 |
// IRT_END does an implicit safepoint check, hence we are guaranteed to block |
|
967 |
// if this is called during a safepoint |
|
968 |
||
969 |
if (JvmtiExport::should_post_single_step()) { |
|
970 |
// We are called during regular safepoints and when the VM is |
|
971 |
// single stepping. If any thread is marked for single stepping, |
|
972 |
// then we may have JVMTI work to do. |
|
973 |
JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread)); |
|
974 |
} |
|
975 |
IRT_END |
|
976 |
||
977 |
IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj, |
|
978 |
ConstantPoolCacheEntry *cp_entry)) |
|
979 |
||
980 |
// check the access_flags for the field in the klass |
|
981 |
instanceKlass* ik = instanceKlass::cast((klassOop)cp_entry->f1()); |
|
982 |
typeArrayOop fields = ik->fields(); |
|
983 |
int index = cp_entry->field_index(); |
|
984 |
assert(index < fields->length(), "holders field index is out of range"); |
|
985 |
// bail out if field accesses are not watched |
|
986 |
if ((fields->ushort_at(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return; |
|
987 |
||
988 |
switch(cp_entry->flag_state()) { |
|
989 |
case btos: // fall through |
|
990 |
case ctos: // fall through |
|
991 |
case stos: // fall through |
|
992 |
case itos: // fall through |
|
993 |
case ftos: // fall through |
|
994 |
case ltos: // fall through |
|
995 |
case dtos: // fall through |
|
996 |
case atos: break; |
|
997 |
default: ShouldNotReachHere(); return; |
|
998 |
} |
|
999 |
bool is_static = (obj == NULL); |
|
1000 |
HandleMark hm(thread); |
|
1001 |
||
1002 |
Handle h_obj; |
|
1003 |
if (!is_static) { |
|
1004 |
// non-static field accessors have an object, but we need a handle |
|
1005 |
h_obj = Handle(thread, obj); |
|
1006 |
} |
|
1007 |
instanceKlassHandle h_cp_entry_f1(thread, (klassOop)cp_entry->f1()); |
|
1008 |
jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2(), is_static); |
|
1009 |
JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid); |
|
1010 |
IRT_END |
|
1011 |
||
1012 |
IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread, |
|
1013 |
oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value)) |
|
1014 |
||
1015 |
klassOop k = (klassOop)cp_entry->f1(); |
|
1016 |
||
1017 |
// check the access_flags for the field in the klass |
|
1018 |
instanceKlass* ik = instanceKlass::cast(k); |
|
1019 |
typeArrayOop fields = ik->fields(); |
|
1020 |
int index = cp_entry->field_index(); |
|
1021 |
assert(index < fields->length(), "holders field index is out of range"); |
|
1022 |
// bail out if field modifications are not watched |
|
1023 |
if ((fields->ushort_at(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return; |
|
1024 |
||
1025 |
char sig_type = '\0'; |
|
1026 |
||
1027 |
switch(cp_entry->flag_state()) { |
|
1028 |
case btos: sig_type = 'Z'; break; |
|
1029 |
case ctos: sig_type = 'C'; break; |
|
1030 |
case stos: sig_type = 'S'; break; |
|
1031 |
case itos: sig_type = 'I'; break; |
|
1032 |
case ftos: sig_type = 'F'; break; |
|
1033 |
case atos: sig_type = 'L'; break; |
|
1034 |
case ltos: sig_type = 'J'; break; |
|
1035 |
case dtos: sig_type = 'D'; break; |
|
1036 |
default: ShouldNotReachHere(); return; |
|
1037 |
} |
|
1038 |
bool is_static = (obj == NULL); |
|
1039 |
||
1040 |
HandleMark hm(thread); |
|
1041 |
instanceKlassHandle h_klass(thread, k); |
|
1042 |
jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2(), is_static); |
|
1043 |
jvalue fvalue; |
|
1044 |
#ifdef _LP64 |
|
1045 |
fvalue = *value; |
|
1046 |
#else |
|
1047 |
// Long/double values are stored unaligned and also noncontiguously with |
|
1048 |
// tagged stacks. We can't just do a simple assignment even in the non- |
|
1049 |
// J/D cases because a C++ compiler is allowed to assume that a jvalue is |
|
1050 |
// 8-byte aligned, and interpreter stack slots are only 4-byte aligned. |
|
1051 |
// We assume that the two halves of longs/doubles are stored in interpreter |
|
1052 |
// stack slots in platform-endian order. |
|
1053 |
jlong_accessor u; |
|
1054 |
jint* newval = (jint*)value; |
|
1055 |
u.words[0] = newval[0]; |
|
5419 | 1056 |
u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag |
1 | 1057 |
fvalue.j = u.long_value; |
1058 |
#endif // _LP64 |
|
1059 |
||
1060 |
Handle h_obj; |
|
1061 |
if (!is_static) { |
|
1062 |
// non-static field accessors have an object, but we need a handle |
|
1063 |
h_obj = Handle(thread, obj); |
|
1064 |
} |
|
1065 |
||
1066 |
JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj, |
|
1067 |
fid, sig_type, &fvalue); |
|
1068 |
IRT_END |
|
1069 |
||
1070 |
IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread)) |
|
1071 |
JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread)); |
|
1072 |
IRT_END |
|
1073 |
||
1074 |
||
1075 |
IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread)) |
|
1076 |
JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread)); |
|
1077 |
IRT_END |
|
1078 |
||
1079 |
IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc)) |
|
1080 |
{ |
|
1081 |
return (Interpreter::contains(pc) ? 1 : 0); |
|
1082 |
} |
|
1083 |
IRT_END |
|
1084 |
||
1085 |
||
1086 |
// Implementation of SignatureHandlerLibrary |
|
1087 |
||
1088 |
address SignatureHandlerLibrary::set_handler_blob() { |
|
1089 |
BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size); |
|
1090 |
if (handler_blob == NULL) { |
|
1091 |
return NULL; |
|
1092 |
} |
|
6418 | 1093 |
address handler = handler_blob->code_begin(); |
1 | 1094 |
_handler_blob = handler_blob; |
1095 |
_handler = handler; |
|
1096 |
return handler; |
|
1097 |
} |
|
1098 |
||
1099 |
void SignatureHandlerLibrary::initialize() { |
|
1100 |
if (_fingerprints != NULL) { |
|
1101 |
return; |
|
1102 |
} |
|
1103 |
if (set_handler_blob() == NULL) { |
|
1104 |
vm_exit_out_of_memory(blob_size, "native signature handlers"); |
|
1105 |
} |
|
1106 |
||
1107 |
BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer", |
|
1108 |
SignatureHandlerLibrary::buffer_size); |
|
6418 | 1109 |
_buffer = bb->code_begin(); |
1 | 1110 |
|
1111 |
_fingerprints = new(ResourceObj::C_HEAP)GrowableArray<uint64_t>(32, true); |
|
1112 |
_handlers = new(ResourceObj::C_HEAP)GrowableArray<address>(32, true); |
|
1113 |
} |
|
1114 |
||
1115 |
address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) { |
|
1116 |
address handler = _handler; |
|
6418 | 1117 |
int insts_size = buffer->pure_insts_size(); |
1118 |
if (handler + insts_size > _handler_blob->code_end()) { |
|
1 | 1119 |
// get a new handler blob |
1120 |
handler = set_handler_blob(); |
|
1121 |
} |
|
1122 |
if (handler != NULL) { |
|
6418 | 1123 |
memcpy(handler, buffer->insts_begin(), insts_size); |
1 | 1124 |
pd_set_handler(handler); |
6418 | 1125 |
ICache::invalidate_range(handler, insts_size); |
1126 |
_handler = handler + insts_size; |
|
1 | 1127 |
} |
1128 |
return handler; |
|
1129 |
} |
|
1130 |
||
1131 |
void SignatureHandlerLibrary::add(methodHandle method) { |
|
1132 |
if (method->signature_handler() == NULL) { |
|
1133 |
// use slow signature handler if we can't do better |
|
1134 |
int handler_index = -1; |
|
1135 |
// check if we can use customized (fast) signature handler |
|
1136 |
if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) { |
|
1137 |
// use customized signature handler |
|
1138 |
MutexLocker mu(SignatureHandlerLibrary_lock); |
|
1139 |
// make sure data structure is initialized |
|
1140 |
initialize(); |
|
1141 |
// lookup method signature's fingerprint |
|
1142 |
uint64_t fingerprint = Fingerprinter(method).fingerprint(); |
|
1143 |
handler_index = _fingerprints->find(fingerprint); |
|
1144 |
// create handler if necessary |
|
1145 |
if (handler_index < 0) { |
|
1146 |
ResourceMark rm; |
|
1147 |
ptrdiff_t align_offset = (address) |
|
1148 |
round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer; |
|
1149 |
CodeBuffer buffer((address)(_buffer + align_offset), |
|
1150 |
SignatureHandlerLibrary::buffer_size - align_offset); |
|
1151 |
InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint); |
|
1152 |
// copy into code heap |
|
1153 |
address handler = set_handler(&buffer); |
|
1154 |
if (handler == NULL) { |
|
1155 |
// use slow signature handler |
|
1156 |
} else { |
|
1157 |
// debugging suppport |
|
1158 |
if (PrintSignatureHandlers) { |
|
1159 |
tty->cr(); |
|
1160 |
tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)", |
|
1161 |
_handlers->length(), |
|
1162 |
(method->is_static() ? "static" : "receiver"), |
|
1163 |
method->name_and_sig_as_C_string(), |
|
1164 |
fingerprint, |
|
6418 | 1165 |
buffer.insts_size()); |
1166 |
Disassembler::decode(handler, handler + buffer.insts_size()); |
|
1 | 1167 |
#ifndef PRODUCT |
1168 |
tty->print_cr(" --- associated result handler ---"); |
|
1169 |
address rh_begin = Interpreter::result_handler(method()->result_type()); |
|
1170 |
address rh_end = rh_begin; |
|
1171 |
while (*(int*)rh_end != 0) { |
|
1172 |
rh_end += sizeof(int); |
|
1173 |
} |
|
1174 |
Disassembler::decode(rh_begin, rh_end); |
|
1175 |
#endif |
|
1176 |
} |
|
1177 |
// add handler to library |
|
1178 |
_fingerprints->append(fingerprint); |
|
1179 |
_handlers->append(handler); |
|
1180 |
// set handler index |
|
1181 |
assert(_fingerprints->length() == _handlers->length(), "sanity check"); |
|
1182 |
handler_index = _fingerprints->length() - 1; |
|
1183 |
} |
|
1184 |
} |
|
1185 |
} else { |
|
1186 |
CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops()); |
|
1187 |
} |
|
1188 |
if (handler_index < 0) { |
|
1189 |
// use generic signature handler |
|
1190 |
method->set_signature_handler(Interpreter::slow_signature_handler()); |
|
1191 |
} else { |
|
1192 |
// set handler |
|
1193 |
method->set_signature_handler(_handlers->at(handler_index)); |
|
1194 |
} |
|
1195 |
} |
|
7411
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1196 |
#ifdef ASSERT |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1197 |
int handler_index, fingerprint_index; |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1198 |
{ |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1199 |
// '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1200 |
// in any way if accessed from multiple threads. To avoid races with another |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1201 |
// thread which may change the arrays in the above, mutex protected block, we |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1202 |
// have to protect this read access here with the same mutex as well! |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1203 |
MutexLocker mu(SignatureHandlerLibrary_lock); |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1204 |
handler_index = _handlers->find(method->signature_handler()); |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1205 |
fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint()); |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1206 |
} |
1 | 1207 |
assert(method->signature_handler() == Interpreter::slow_signature_handler() || |
7411
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1208 |
handler_index == fingerprint_index, "sanity check"); |
afcfb75ccae1
6704010: Internal Error (src/share/vm/interpreter/interpreterRuntime.cpp:1106)
coleenp
parents:
7397
diff
changeset
|
1209 |
#endif |
1 | 1210 |
} |
1211 |
||
1212 |
||
1213 |
BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL; |
|
1214 |
address SignatureHandlerLibrary::_handler = NULL; |
|
1215 |
GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL; |
|
1216 |
GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL; |
|
1217 |
address SignatureHandlerLibrary::_buffer = NULL; |
|
1218 |
||
1219 |
||
1220 |
IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, methodOopDesc* method)) |
|
1221 |
methodHandle m(thread, method); |
|
1222 |
assert(m->is_native(), "sanity check"); |
|
1223 |
// lookup native function entry point if it doesn't exist |
|
1224 |
bool in_base_library; |
|
1225 |
if (!m->has_native_function()) { |
|
1226 |
NativeLookup::lookup(m, in_base_library, CHECK); |
|
1227 |
} |
|
1228 |
// make sure signature handler is installed |
|
1229 |
SignatureHandlerLibrary::add(m); |
|
1230 |
// The interpreter entry point checks the signature handler first, |
|
1231 |
// before trying to fetch the native entry point and klass mirror. |
|
1232 |
// We must set the signature handler last, so that multiple processors |
|
1233 |
// preparing the same method will be sure to see non-null entry & mirror. |
|
1234 |
IRT_END |
|
1235 |
||
1236 |
#if defined(IA32) || defined(AMD64) |
|
1237 |
IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address)) |
|
1238 |
if (src_address == dest_address) { |
|
1239 |
return; |
|
1240 |
} |
|
1241 |
ResetNoHandleMark rnm; // In a LEAF entry. |
|
1242 |
HandleMark hm; |
|
1243 |
ResourceMark rm; |
|
1244 |
frame fr = thread->last_frame(); |
|
1245 |
assert(fr.is_interpreted_frame(), ""); |
|
1246 |
jint bci = fr.interpreter_frame_bci(); |
|
1247 |
methodHandle mh(thread, fr.interpreter_frame_method()); |
|
1248 |
Bytecode_invoke* invoke = Bytecode_invoke_at(mh, bci); |
|
1249 |
ArgumentSizeComputer asc(invoke->signature()); |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4429
diff
changeset
|
1250 |
int size_of_arguments = (asc.size() + (invoke->has_receiver() ? 1 : 0)); // receiver |
5883
8dc4bdc132d5
6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents:
5882
diff
changeset
|
1251 |
Copy::conjoint_jbytes(src_address, dest_address, |
5419 | 1252 |
size_of_arguments * Interpreter::stackElementSize); |
1 | 1253 |
IRT_END |
1254 |
#endif |