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