Thu, 24 Mar 2011 02:11:50 -0700
7030207: Zero tweak to remove accidentally incorporated code
Summary: IcedTea contains a now-unmaintained ARM-specific interpreter and part of that interpreter was accidentally incorporated in one of the webrevs when Zero was initially imported.
Reviewed-by: twisti
Contributed-by: Gary Benson <gbenson@redhat.com>
1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
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/symbol.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 TARGET_ARCH_arm
69 # include "vm_version_arm.hpp"
70 #endif
71 #ifdef TARGET_ARCH_ppc
72 # include "vm_version_ppc.hpp"
73 #endif
74 #ifdef COMPILER2
75 #include "opto/runtime.hpp"
76 #endif
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 };
93 //------------------------------------------------------------------------------------------------------------------------
94 // State accessors
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 }
109 //------------------------------------------------------------------------------------------------------------------------
110 // Constants
113 IRT_ENTRY(void, InterpreterRuntime::ldc(JavaThread* thread, bool wide))
114 // access constant pool
115 constantPoolOop pool = method(thread)->constants();
116 int index = wide ? get_index_u2(thread, Bytecodes::_ldc_w) : get_index_u1(thread, Bytecodes::_ldc);
117 constantTag tag = pool->tag_at(index);
119 if (tag.is_unresolved_klass() || tag.is_klass()) {
120 klassOop klass = pool->klass_at(index, CHECK);
121 oop java_class = klass->klass_part()->java_mirror();
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
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));
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()));
144 assert(result == cpce->f1(), "expected result for assembly code");
145 }
146 IRT_END
149 //------------------------------------------------------------------------------------------------------------------------
150 // Allocation
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);
156 // Make sure we are not instantiating an abstract klass
157 klass->check_valid_for_instantiation(true, CHECK);
159 // Make sure klass is initialized
160 klass->initialize(CHECK);
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
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
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
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();
200 int i = get_index_u2(thread, Bytecodes::_multianewarray);
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");
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
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
231 // Quicken instance-of and check-cast bytecodes
232 IRT_ENTRY(void, InterpreterRuntime::quicken_io_cc(JavaThread* thread))
233 // Force resolving; quicken the bytecode
234 int which = get_index_u2(thread, Bytecodes::_checkcast);
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
245 //------------------------------------------------------------------------------------------------------------------------
246 // Exceptions
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));
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 }
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 }
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
302 IRT_ENTRY(void, InterpreterRuntime::create_exception(JavaThread* thread, char* name, char* message))
303 // lookup exception klass
304 TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
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
313 Handle exception = Exceptions::new_exception(thread, s, message);
314 thread->set_vm_result(exception());
315 IRT_END
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
322 TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
323 if (ProfileTraps) {
324 note_trap(thread, Deoptimization::Reason_class_check, CHECK);
325 }
326 // create exception, with klass name as detail message
327 Handle exception = Exceptions::new_exception(thread, s, klass_name);
328 thread->set_vm_result(exception());
329 IRT_END
332 IRT_ENTRY(void, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index))
333 char message[jintAsStringSize];
334 // lookup exception klass
335 TempNewSymbol s = SymbolTable::new_symbol(name, CHECK);
336 if (ProfileTraps) {
337 note_trap(thread, Deoptimization::Reason_range_check, CHECK);
338 }
339 // create exception
340 sprintf(message, "%d", index);
341 THROW_MSG(s, message);
342 IRT_END
344 IRT_ENTRY(void, InterpreterRuntime::throw_ClassCastException(
345 JavaThread* thread, oopDesc* obj))
347 ResourceMark rm(thread);
348 char* message = SharedRuntime::generate_class_cast_message(
349 thread, Klass::cast(obj->klass())->external_name());
351 if (ProfileTraps) {
352 note_trap(thread, Deoptimization::Reason_class_check, CHECK);
353 }
355 // create exception
356 THROW_MSG(vmSymbols::java_lang_ClassCastException(), message);
357 IRT_END
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);
367 if (ProfileTraps) {
368 note_trap(thread, Deoptimization::Reason_constraint, CHECK);
369 }
371 // create exception
372 Symbol* java_lang_invoke_WrongMethodTypeException = vmSymbols::java_lang_invoke_WrongMethodTypeException();
373 if (AllowTransitionalJSR292)
374 java_lang_invoke_WrongMethodTypeException = SystemDictionaryHandles::WrongMethodTypeException_klass()->name();
375 THROW_MSG(java_lang_invoke_WrongMethodTypeException, message);
376 }
377 IRT_END
381 // exception_handler_for_exception(...) returns the continuation address,
382 // the exception oop (via TLS) and sets the bci/bcp for the continuation.
383 // The exception oop is returned to make sure it is preserved over GC (it
384 // is only on the stack if the exception was thrown explicitly via athrow).
385 // During this operation, the expression stack contains the values for the
386 // bci where the exception happened. If the exception was propagated back
387 // from a call, the expression stack contains the values for the bci at the
388 // invoke w/o arguments (i.e., as if one were inside the call).
389 IRT_ENTRY(address, InterpreterRuntime::exception_handler_for_exception(JavaThread* thread, oopDesc* exception))
391 Handle h_exception(thread, exception);
392 methodHandle h_method (thread, method(thread));
393 constantPoolHandle h_constants(thread, h_method->constants());
394 typeArrayHandle h_extable (thread, h_method->exception_table());
395 bool should_repeat;
396 int handler_bci;
397 int current_bci = bci(thread);
399 // Need to do this check first since when _do_not_unlock_if_synchronized
400 // is set, we don't want to trigger any classloading which may make calls
401 // into java, or surprisingly find a matching exception handler for bci 0
402 // since at this moment the method hasn't been "officially" entered yet.
403 if (thread->do_not_unlock_if_synchronized()) {
404 ResourceMark rm;
405 assert(current_bci == 0, "bci isn't zero for do_not_unlock_if_synchronized");
406 thread->set_vm_result(exception);
407 #ifdef CC_INTERP
408 return (address) -1;
409 #else
410 return Interpreter::remove_activation_entry();
411 #endif
412 }
414 do {
415 should_repeat = false;
417 // assertions
418 #ifdef ASSERT
419 assert(h_exception.not_null(), "NULL exceptions should be handled by athrow");
420 assert(h_exception->is_oop(), "just checking");
421 // Check that exception is a subclass of Throwable, otherwise we have a VerifyError
422 if (!(h_exception->is_a(SystemDictionary::Throwable_klass()))) {
423 if (ExitVMOnVerifyError) vm_exit(-1);
424 ShouldNotReachHere();
425 }
426 #endif
428 // tracing
429 if (TraceExceptions) {
430 ttyLocker ttyl;
431 ResourceMark rm(thread);
432 tty->print_cr("Exception <%s> (" INTPTR_FORMAT ")", h_exception->print_value_string(), (address)h_exception());
433 tty->print_cr(" thrown in interpreter method <%s>", h_method->print_value_string());
434 tty->print_cr(" at bci %d for thread " INTPTR_FORMAT, current_bci, thread);
435 }
436 // Don't go paging in something which won't be used.
437 // else if (h_extable->length() == 0) {
438 // // disabled for now - interpreter is not using shortcut yet
439 // // (shortcut is not to call runtime if we have no exception handlers)
440 // // warning("performance bug: should not call runtime if method has no exception handlers");
441 // }
442 // for AbortVMOnException flag
443 NOT_PRODUCT(Exceptions::debug_check_abort(h_exception));
445 // exception handler lookup
446 KlassHandle h_klass(THREAD, h_exception->klass());
447 handler_bci = h_method->fast_exception_handler_bci_for(h_klass, current_bci, THREAD);
448 if (HAS_PENDING_EXCEPTION) {
449 // We threw an exception while trying to find the exception handler.
450 // Transfer the new exception to the exception handle which will
451 // be set into thread local storage, and do another lookup for an
452 // exception handler for this exception, this time starting at the
453 // BCI of the exception handler which caused the exception to be
454 // thrown (bug 4307310).
455 h_exception = Handle(THREAD, PENDING_EXCEPTION);
456 CLEAR_PENDING_EXCEPTION;
457 if (handler_bci >= 0) {
458 current_bci = handler_bci;
459 should_repeat = true;
460 }
461 }
462 } while (should_repeat == true);
464 // notify JVMTI of an exception throw; JVMTI will detect if this is a first
465 // time throw or a stack unwinding throw and accordingly notify the debugger
466 if (JvmtiExport::can_post_on_exceptions()) {
467 JvmtiExport::post_exception_throw(thread, h_method(), bcp(thread), h_exception());
468 }
470 #ifdef CC_INTERP
471 address continuation = (address)(intptr_t) handler_bci;
472 #else
473 address continuation = NULL;
474 #endif
475 address handler_pc = NULL;
476 if (handler_bci < 0 || !thread->reguard_stack((address) &continuation)) {
477 // Forward exception to callee (leaving bci/bcp untouched) because (a) no
478 // handler in this method, or (b) after a stack overflow there is not yet
479 // enough stack space available to reprotect the stack.
480 #ifndef CC_INTERP
481 continuation = Interpreter::remove_activation_entry();
482 #endif
483 // Count this for compilation purposes
484 h_method->interpreter_throwout_increment();
485 } else {
486 // handler in this method => change bci/bcp to handler bci/bcp and continue there
487 handler_pc = h_method->code_base() + handler_bci;
488 #ifndef CC_INTERP
489 set_bcp_and_mdp(handler_pc, thread);
490 continuation = Interpreter::dispatch_table(vtos)[*handler_pc];
491 #endif
492 }
493 // notify debugger of an exception catch
494 // (this is good for exceptions caught in native methods as well)
495 if (JvmtiExport::can_post_on_exceptions()) {
496 JvmtiExport::notice_unwind_due_to_exception(thread, h_method(), handler_pc, h_exception(), (handler_pc != NULL));
497 }
499 thread->set_vm_result(h_exception());
500 return continuation;
501 IRT_END
504 IRT_ENTRY(void, InterpreterRuntime::throw_pending_exception(JavaThread* thread))
505 assert(thread->has_pending_exception(), "must only ne called if there's an exception pending");
506 // nothing to do - eventually we should remove this code entirely (see comments @ call sites)
507 IRT_END
510 IRT_ENTRY(void, InterpreterRuntime::throw_AbstractMethodError(JavaThread* thread))
511 THROW(vmSymbols::java_lang_AbstractMethodError());
512 IRT_END
515 IRT_ENTRY(void, InterpreterRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))
516 THROW(vmSymbols::java_lang_IncompatibleClassChangeError());
517 IRT_END
520 //------------------------------------------------------------------------------------------------------------------------
521 // Fields
522 //
524 IRT_ENTRY(void, InterpreterRuntime::resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode))
525 // resolve field
526 FieldAccessInfo info;
527 constantPoolHandle pool(thread, method(thread)->constants());
528 bool is_static = (bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic);
530 {
531 JvmtiHideSingleStepping jhss(thread);
532 LinkResolver::resolve_field(info, pool, get_index_u2_cpcache(thread, bytecode),
533 bytecode, false, CHECK);
534 } // end JvmtiHideSingleStepping
536 // check if link resolution caused cpCache to be updated
537 if (already_resolved(thread)) return;
539 // compute auxiliary field attributes
540 TosState state = as_TosState(info.field_type());
542 // We need to delay resolving put instructions on final fields
543 // until we actually invoke one. This is required so we throw
544 // exceptions at the correct place. If we do not resolve completely
545 // in the current pass, leaving the put_code set to zero will
546 // cause the next put instruction to reresolve.
547 bool is_put = (bytecode == Bytecodes::_putfield ||
548 bytecode == Bytecodes::_putstatic);
549 Bytecodes::Code put_code = (Bytecodes::Code)0;
551 // We also need to delay resolving getstatic instructions until the
552 // class is intitialized. This is required so that access to the static
553 // field will call the initialization function every time until the class
554 // is completely initialized ala. in 2.17.5 in JVM Specification.
555 instanceKlass *klass = instanceKlass::cast(info.klass()->as_klassOop());
556 bool uninitialized_static = ((bytecode == Bytecodes::_getstatic || bytecode == Bytecodes::_putstatic) &&
557 !klass->is_initialized());
558 Bytecodes::Code get_code = (Bytecodes::Code)0;
561 if (!uninitialized_static) {
562 get_code = ((is_static) ? Bytecodes::_getstatic : Bytecodes::_getfield);
563 if (is_put || !info.access_flags().is_final()) {
564 put_code = ((is_static) ? Bytecodes::_putstatic : Bytecodes::_putfield);
565 }
566 }
568 cache_entry(thread)->set_field(
569 get_code,
570 put_code,
571 info.klass(),
572 info.field_index(),
573 info.field_offset(),
574 state,
575 info.access_flags().is_final(),
576 info.access_flags().is_volatile()
577 );
578 IRT_END
581 //------------------------------------------------------------------------------------------------------------------------
582 // Synchronization
583 //
584 // The interpreter's synchronization code is factored out so that it can
585 // be shared by method invocation and synchronized blocks.
586 //%note synchronization_3
588 static void trace_locking(Handle& h_locking_obj, bool is_locking) {
589 ObjectSynchronizer::trace_locking(h_locking_obj, false, true, is_locking);
590 }
593 //%note monitor_1
594 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorenter(JavaThread* thread, BasicObjectLock* elem))
595 #ifdef ASSERT
596 thread->last_frame().interpreter_frame_verify_monitor(elem);
597 #endif
598 if (PrintBiasedLockingStatistics) {
599 Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
600 }
601 Handle h_obj(thread, elem->obj());
602 assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
603 "must be NULL or an object");
604 if (UseBiasedLocking) {
605 // Retry fast entry if bias is revoked to avoid unnecessary inflation
606 ObjectSynchronizer::fast_enter(h_obj, elem->lock(), true, CHECK);
607 } else {
608 ObjectSynchronizer::slow_enter(h_obj, elem->lock(), CHECK);
609 }
610 assert(Universe::heap()->is_in_reserved_or_null(elem->obj()),
611 "must be NULL or an object");
612 #ifdef ASSERT
613 thread->last_frame().interpreter_frame_verify_monitor(elem);
614 #endif
615 IRT_END
618 //%note monitor_1
619 IRT_ENTRY_NO_ASYNC(void, InterpreterRuntime::monitorexit(JavaThread* thread, BasicObjectLock* elem))
620 #ifdef ASSERT
621 thread->last_frame().interpreter_frame_verify_monitor(elem);
622 #endif
623 Handle h_obj(thread, elem->obj());
624 assert(Universe::heap()->is_in_reserved_or_null(h_obj()),
625 "must be NULL or an object");
626 if (elem == NULL || h_obj()->is_unlocked()) {
627 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
628 }
629 ObjectSynchronizer::slow_exit(h_obj(), elem->lock(), thread);
630 // Free entry. This must be done here, since a pending exception might be installed on
631 // exit. If it is not cleared, the exception handling code will try to unlock the monitor again.
632 elem->set_obj(NULL);
633 #ifdef ASSERT
634 thread->last_frame().interpreter_frame_verify_monitor(elem);
635 #endif
636 IRT_END
639 IRT_ENTRY(void, InterpreterRuntime::throw_illegal_monitor_state_exception(JavaThread* thread))
640 THROW(vmSymbols::java_lang_IllegalMonitorStateException());
641 IRT_END
644 IRT_ENTRY(void, InterpreterRuntime::new_illegal_monitor_state_exception(JavaThread* thread))
645 // Returns an illegal exception to install into the current thread. The
646 // pending_exception flag is cleared so normal exception handling does not
647 // trigger. Any current installed exception will be overwritten. This
648 // method will be called during an exception unwind.
650 assert(!HAS_PENDING_EXCEPTION, "no pending exception");
651 Handle exception(thread, thread->vm_result());
652 assert(exception() != NULL, "vm result should be set");
653 thread->set_vm_result(NULL); // clear vm result before continuing (may cause memory leaks and assert failures)
654 if (!exception->is_a(SystemDictionary::ThreadDeath_klass())) {
655 exception = get_preinitialized_exception(
656 SystemDictionary::IllegalMonitorStateException_klass(),
657 CATCH);
658 }
659 thread->set_vm_result(exception());
660 IRT_END
663 //------------------------------------------------------------------------------------------------------------------------
664 // Invokes
666 IRT_ENTRY(Bytecodes::Code, InterpreterRuntime::get_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp))
667 return method->orig_bytecode_at(method->bci_from(bcp));
668 IRT_END
670 IRT_ENTRY(void, InterpreterRuntime::set_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp, Bytecodes::Code new_code))
671 method->set_orig_bytecode_at(method->bci_from(bcp), new_code);
672 IRT_END
674 IRT_ENTRY(void, InterpreterRuntime::_breakpoint(JavaThread* thread, methodOopDesc* method, address bcp))
675 JvmtiExport::post_raw_breakpoint(thread, method, bcp);
676 IRT_END
678 IRT_ENTRY(void, InterpreterRuntime::resolve_invoke(JavaThread* thread, Bytecodes::Code bytecode))
679 // extract receiver from the outgoing argument list if necessary
680 Handle receiver(thread, NULL);
681 if (bytecode == Bytecodes::_invokevirtual || bytecode == Bytecodes::_invokeinterface) {
682 ResourceMark rm(thread);
683 methodHandle m (thread, method(thread));
684 Bytecode_invoke call(m, bci(thread));
685 Symbol* signature = call.signature();
686 receiver = Handle(thread,
687 thread->last_frame().interpreter_callee_receiver(signature));
688 assert(Universe::heap()->is_in_reserved_or_null(receiver()),
689 "sanity check");
690 assert(receiver.is_null() ||
691 Universe::heap()->is_in_reserved(receiver->klass()),
692 "sanity check");
693 }
695 // resolve method
696 CallInfo info;
697 constantPoolHandle pool(thread, method(thread)->constants());
699 {
700 JvmtiHideSingleStepping jhss(thread);
701 LinkResolver::resolve_invoke(info, receiver, pool,
702 get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
703 if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
704 int retry_count = 0;
705 while (info.resolved_method()->is_old()) {
706 // It is very unlikely that method is redefined more than 100 times
707 // in the middle of resolve. If it is looping here more than 100 times
708 // means then there could be a bug here.
709 guarantee((retry_count++ < 100),
710 "Could not resolve to latest version of redefined method");
711 // method is redefined in the middle of resolve so re-try.
712 LinkResolver::resolve_invoke(info, receiver, pool,
713 get_index_u2_cpcache(thread, bytecode), bytecode, CHECK);
714 }
715 }
716 } // end JvmtiHideSingleStepping
718 // check if link resolution caused cpCache to be updated
719 if (already_resolved(thread)) return;
721 if (bytecode == Bytecodes::_invokeinterface) {
723 if (TraceItables && Verbose) {
724 ResourceMark rm(thread);
725 tty->print_cr("Resolving: klass: %s to method: %s", info.resolved_klass()->name()->as_C_string(), info.resolved_method()->name()->as_C_string());
726 }
727 if (info.resolved_method()->method_holder() ==
728 SystemDictionary::Object_klass()) {
729 // NOTE: THIS IS A FIX FOR A CORNER CASE in the JVM spec
730 // (see also cpCacheOop.cpp for details)
731 methodHandle rm = info.resolved_method();
732 assert(rm->is_final() || info.has_vtable_index(),
733 "should have been set already");
734 cache_entry(thread)->set_method(bytecode, rm, info.vtable_index());
735 } else {
736 // Setup itable entry
737 int index = klassItable::compute_itable_index(info.resolved_method()());
738 cache_entry(thread)->set_interface_call(info.resolved_method(), index);
739 }
740 } else {
741 cache_entry(thread)->set_method(
742 bytecode,
743 info.resolved_method(),
744 info.vtable_index());
745 }
746 IRT_END
749 // First time execution: Resolve symbols, create a permanent CallSite object.
750 IRT_ENTRY(void, InterpreterRuntime::resolve_invokedynamic(JavaThread* thread)) {
751 ResourceMark rm(thread);
753 assert(EnableInvokeDynamic, "");
755 const Bytecodes::Code bytecode = Bytecodes::_invokedynamic;
757 methodHandle caller_method(thread, method(thread));
759 constantPoolHandle pool(thread, caller_method->constants());
760 pool->set_invokedynamic(); // mark header to flag active call sites
762 int caller_bci = 0;
763 int site_index = 0;
764 { address caller_bcp = bcp(thread);
765 caller_bci = caller_method->bci_from(caller_bcp);
766 site_index = Bytes::get_native_u4(caller_bcp+1);
767 }
768 assert(site_index == InterpreterRuntime::bytecode(thread).get_index_u4(bytecode), "");
769 assert(constantPoolCacheOopDesc::is_secondary_index(site_index), "proper format");
770 // there is a second CPC entries that is of interest; it caches signature info:
771 int main_index = pool->cache()->secondary_entry_at(site_index)->main_entry_index();
772 int pool_index = pool->cache()->entry_at(main_index)->constant_pool_index();
774 // first resolve the signature to a MH.invoke methodOop
775 if (!pool->cache()->entry_at(main_index)->is_resolved(bytecode)) {
776 JvmtiHideSingleStepping jhss(thread);
777 CallInfo callinfo;
778 LinkResolver::resolve_invoke(callinfo, Handle(), pool,
779 site_index, bytecode, CHECK);
780 // The main entry corresponds to a JVM_CONSTANT_InvokeDynamic, and serves
781 // as a common reference point for all invokedynamic call sites with
782 // that exact call descriptor. We will link it in the CP cache exactly
783 // as if it were an invokevirtual of MethodHandle.invoke.
784 pool->cache()->entry_at(main_index)->set_method(
785 bytecode,
786 callinfo.resolved_method(),
787 callinfo.vtable_index());
788 }
790 // The method (f2 entry) of the main entry is the MH.invoke for the
791 // invokedynamic target call signature.
792 oop f1_value = pool->cache()->entry_at(main_index)->f1();
793 methodHandle signature_invoker(THREAD, (methodOop) f1_value);
794 assert(signature_invoker.not_null() && signature_invoker->is_method() && signature_invoker->is_method_handle_invoke(),
795 "correct result from LinkResolver::resolve_invokedynamic");
797 Handle info; // optional argument(s) in JVM_CONSTANT_InvokeDynamic
798 Handle bootm = SystemDictionary::find_bootstrap_method(caller_method, caller_bci,
799 main_index, info, CHECK);
800 if (!java_lang_invoke_MethodHandle::is_instance(bootm())) {
801 THROW_MSG(vmSymbols::java_lang_IllegalStateException(),
802 "no bootstrap method found for invokedynamic");
803 }
805 // Short circuit if CallSite has been bound already:
806 if (!pool->cache()->secondary_entry_at(site_index)->is_f1_null())
807 return;
809 Symbol* call_site_name = pool->name_ref_at(site_index);
811 Handle call_site
812 = SystemDictionary::make_dynamic_call_site(bootm,
813 // Callee information:
814 call_site_name,
815 signature_invoker,
816 info,
817 // Caller information:
818 caller_method,
819 caller_bci,
820 CHECK);
822 // In the secondary entry, the f1 field is the call site, and the f2 (index)
823 // field is some data about the invoke site. Currently, it is just the BCI.
824 // Later, it might be changed to help manage inlining dependencies.
825 pool->cache()->secondary_entry_at(site_index)->set_dynamic_call(call_site, signature_invoker);
826 }
827 IRT_END
830 //------------------------------------------------------------------------------------------------------------------------
831 // Miscellaneous
834 nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* thread, address branch_bcp) {
835 nmethod* nm = frequency_counter_overflow_inner(thread, branch_bcp);
836 assert(branch_bcp != NULL || nm == NULL, "always returns null for non OSR requests");
837 if (branch_bcp != NULL && nm != NULL) {
838 // This was a successful request for an OSR nmethod. Because
839 // frequency_counter_overflow_inner ends with a safepoint check,
840 // nm could have been unloaded so look it up again. It's unsafe
841 // to examine nm directly since it might have been freed and used
842 // for something else.
843 frame fr = thread->last_frame();
844 methodOop method = fr.interpreter_frame_method();
845 int bci = method->bci_from(fr.interpreter_frame_bcp());
846 nm = method->lookup_osr_nmethod_for(bci, CompLevel_none, false);
847 }
848 return nm;
849 }
851 IRT_ENTRY(nmethod*,
852 InterpreterRuntime::frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp))
853 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
854 // flag, in case this method triggers classloading which will call into Java.
855 UnlockFlagSaver fs(thread);
857 frame fr = thread->last_frame();
858 assert(fr.is_interpreted_frame(), "must come from interpreter");
859 methodHandle method(thread, fr.interpreter_frame_method());
860 const int branch_bci = branch_bcp != NULL ? method->bci_from(branch_bcp) : InvocationEntryBci;
861 const int bci = branch_bcp != NULL ? method->bci_from(fr.interpreter_frame_bcp()) : InvocationEntryBci;
863 nmethod* osr_nm = CompilationPolicy::policy()->event(method, method, branch_bci, bci, CompLevel_none, thread);
865 if (osr_nm != NULL) {
866 // We may need to do on-stack replacement which requires that no
867 // monitors in the activation are biased because their
868 // BasicObjectLocks will need to migrate during OSR. Force
869 // unbiasing of all monitors in the activation now (even though
870 // the OSR nmethod might be invalidated) because we don't have a
871 // safepoint opportunity later once the migration begins.
872 if (UseBiasedLocking) {
873 ResourceMark rm;
874 GrowableArray<Handle>* objects_to_revoke = new GrowableArray<Handle>();
875 for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end();
876 kptr < fr.interpreter_frame_monitor_begin();
877 kptr = fr.next_monitor_in_interpreter_frame(kptr) ) {
878 if( kptr->obj() != NULL ) {
879 objects_to_revoke->append(Handle(THREAD, kptr->obj()));
880 }
881 }
882 BiasedLocking::revoke(objects_to_revoke);
883 }
884 }
885 return osr_nm;
886 IRT_END
888 IRT_LEAF(jint, InterpreterRuntime::bcp_to_di(methodOopDesc* method, address cur_bcp))
889 assert(ProfileInterpreter, "must be profiling interpreter");
890 int bci = method->bci_from(cur_bcp);
891 methodDataOop mdo = method->method_data();
892 if (mdo == NULL) return 0;
893 return mdo->bci_to_di(bci);
894 IRT_END
896 IRT_ENTRY(void, InterpreterRuntime::profile_method(JavaThread* thread))
897 // use UnlockFlagSaver to clear and restore the _do_not_unlock_if_synchronized
898 // flag, in case this method triggers classloading which will call into Java.
899 UnlockFlagSaver fs(thread);
901 assert(ProfileInterpreter, "must be profiling interpreter");
902 frame fr = thread->last_frame();
903 assert(fr.is_interpreted_frame(), "must come from interpreter");
904 methodHandle method(thread, fr.interpreter_frame_method());
905 methodOopDesc::build_interpreter_method_data(method, THREAD);
906 if (HAS_PENDING_EXCEPTION) {
907 assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");
908 CLEAR_PENDING_EXCEPTION;
909 // and fall through...
910 }
911 IRT_END
914 #ifdef ASSERT
915 IRT_LEAF(void, InterpreterRuntime::verify_mdp(methodOopDesc* method, address bcp, address mdp))
916 assert(ProfileInterpreter, "must be profiling interpreter");
918 methodDataOop mdo = method->method_data();
919 assert(mdo != NULL, "must not be null");
921 int bci = method->bci_from(bcp);
923 address mdp2 = mdo->bci_to_dp(bci);
924 if (mdp != mdp2) {
925 ResourceMark rm;
926 ResetNoHandleMark rnm; // In a LEAF entry.
927 HandleMark hm;
928 tty->print_cr("FAILED verify : actual mdp %p expected mdp %p @ bci %d", mdp, mdp2, bci);
929 int current_di = mdo->dp_to_di(mdp);
930 int expected_di = mdo->dp_to_di(mdp2);
931 tty->print_cr(" actual di %d expected di %d", current_di, expected_di);
932 int expected_approx_bci = mdo->data_at(expected_di)->bci();
933 int approx_bci = -1;
934 if (current_di >= 0) {
935 approx_bci = mdo->data_at(current_di)->bci();
936 }
937 tty->print_cr(" actual bci is %d expected bci %d", approx_bci, expected_approx_bci);
938 mdo->print_on(tty);
939 method->print_codes();
940 }
941 assert(mdp == mdp2, "wrong mdp");
942 IRT_END
943 #endif // ASSERT
945 IRT_ENTRY(void, InterpreterRuntime::update_mdp_for_ret(JavaThread* thread, int return_bci))
946 assert(ProfileInterpreter, "must be profiling interpreter");
947 ResourceMark rm(thread);
948 HandleMark hm(thread);
949 frame fr = thread->last_frame();
950 assert(fr.is_interpreted_frame(), "must come from interpreter");
951 methodDataHandle h_mdo(thread, fr.interpreter_frame_method()->method_data());
953 // Grab a lock to ensure atomic access to setting the return bci and
954 // the displacement. This can block and GC, invalidating all naked oops.
955 MutexLocker ml(RetData_lock);
957 // ProfileData is essentially a wrapper around a derived oop, so we
958 // need to take the lock before making any ProfileData structures.
959 ProfileData* data = h_mdo->data_at(h_mdo->dp_to_di(fr.interpreter_frame_mdp()));
960 RetData* rdata = data->as_RetData();
961 address new_mdp = rdata->fixup_ret(return_bci, h_mdo);
962 fr.interpreter_frame_set_mdp(new_mdp);
963 IRT_END
966 IRT_ENTRY(void, InterpreterRuntime::at_safepoint(JavaThread* thread))
967 // We used to need an explict preserve_arguments here for invoke bytecodes. However,
968 // stack traversal automatically takes care of preserving arguments for invoke, so
969 // this is no longer needed.
971 // IRT_END does an implicit safepoint check, hence we are guaranteed to block
972 // if this is called during a safepoint
974 if (JvmtiExport::should_post_single_step()) {
975 // We are called during regular safepoints and when the VM is
976 // single stepping. If any thread is marked for single stepping,
977 // then we may have JVMTI work to do.
978 JvmtiExport::at_single_stepping_point(thread, method(thread), bcp(thread));
979 }
980 IRT_END
982 IRT_ENTRY(void, InterpreterRuntime::post_field_access(JavaThread *thread, oopDesc* obj,
983 ConstantPoolCacheEntry *cp_entry))
985 // check the access_flags for the field in the klass
986 instanceKlass* ik = instanceKlass::cast((klassOop)cp_entry->f1());
987 typeArrayOop fields = ik->fields();
988 int index = cp_entry->field_index();
989 assert(index < fields->length(), "holders field index is out of range");
990 // bail out if field accesses are not watched
991 if ((fields->ushort_at(index) & JVM_ACC_FIELD_ACCESS_WATCHED) == 0) return;
993 switch(cp_entry->flag_state()) {
994 case btos: // fall through
995 case ctos: // fall through
996 case stos: // fall through
997 case itos: // fall through
998 case ftos: // fall through
999 case ltos: // fall through
1000 case dtos: // fall through
1001 case atos: break;
1002 default: ShouldNotReachHere(); return;
1003 }
1004 bool is_static = (obj == NULL);
1005 HandleMark hm(thread);
1007 Handle h_obj;
1008 if (!is_static) {
1009 // non-static field accessors have an object, but we need a handle
1010 h_obj = Handle(thread, obj);
1011 }
1012 instanceKlassHandle h_cp_entry_f1(thread, (klassOop)cp_entry->f1());
1013 jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_cp_entry_f1, cp_entry->f2(), is_static);
1014 JvmtiExport::post_field_access(thread, method(thread), bcp(thread), h_cp_entry_f1, h_obj, fid);
1015 IRT_END
1017 IRT_ENTRY(void, InterpreterRuntime::post_field_modification(JavaThread *thread,
1018 oopDesc* obj, ConstantPoolCacheEntry *cp_entry, jvalue *value))
1020 klassOop k = (klassOop)cp_entry->f1();
1022 // check the access_flags for the field in the klass
1023 instanceKlass* ik = instanceKlass::cast(k);
1024 typeArrayOop fields = ik->fields();
1025 int index = cp_entry->field_index();
1026 assert(index < fields->length(), "holders field index is out of range");
1027 // bail out if field modifications are not watched
1028 if ((fields->ushort_at(index) & JVM_ACC_FIELD_MODIFICATION_WATCHED) == 0) return;
1030 char sig_type = '\0';
1032 switch(cp_entry->flag_state()) {
1033 case btos: sig_type = 'Z'; break;
1034 case ctos: sig_type = 'C'; break;
1035 case stos: sig_type = 'S'; break;
1036 case itos: sig_type = 'I'; break;
1037 case ftos: sig_type = 'F'; break;
1038 case atos: sig_type = 'L'; break;
1039 case ltos: sig_type = 'J'; break;
1040 case dtos: sig_type = 'D'; break;
1041 default: ShouldNotReachHere(); return;
1042 }
1043 bool is_static = (obj == NULL);
1045 HandleMark hm(thread);
1046 instanceKlassHandle h_klass(thread, k);
1047 jfieldID fid = jfieldIDWorkaround::to_jfieldID(h_klass, cp_entry->f2(), is_static);
1048 jvalue fvalue;
1049 #ifdef _LP64
1050 fvalue = *value;
1051 #else
1052 // Long/double values are stored unaligned and also noncontiguously with
1053 // tagged stacks. We can't just do a simple assignment even in the non-
1054 // J/D cases because a C++ compiler is allowed to assume that a jvalue is
1055 // 8-byte aligned, and interpreter stack slots are only 4-byte aligned.
1056 // We assume that the two halves of longs/doubles are stored in interpreter
1057 // stack slots in platform-endian order.
1058 jlong_accessor u;
1059 jint* newval = (jint*)value;
1060 u.words[0] = newval[0];
1061 u.words[1] = newval[Interpreter::stackElementWords]; // skip if tag
1062 fvalue.j = u.long_value;
1063 #endif // _LP64
1065 Handle h_obj;
1066 if (!is_static) {
1067 // non-static field accessors have an object, but we need a handle
1068 h_obj = Handle(thread, obj);
1069 }
1071 JvmtiExport::post_raw_field_modification(thread, method(thread), bcp(thread), h_klass, h_obj,
1072 fid, sig_type, &fvalue);
1073 IRT_END
1075 IRT_ENTRY(void, InterpreterRuntime::post_method_entry(JavaThread *thread))
1076 JvmtiExport::post_method_entry(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
1077 IRT_END
1080 IRT_ENTRY(void, InterpreterRuntime::post_method_exit(JavaThread *thread))
1081 JvmtiExport::post_method_exit(thread, InterpreterRuntime::method(thread), InterpreterRuntime::last_frame(thread));
1082 IRT_END
1084 IRT_LEAF(int, InterpreterRuntime::interpreter_contains(address pc))
1085 {
1086 return (Interpreter::contains(pc) ? 1 : 0);
1087 }
1088 IRT_END
1091 // Implementation of SignatureHandlerLibrary
1093 address SignatureHandlerLibrary::set_handler_blob() {
1094 BufferBlob* handler_blob = BufferBlob::create("native signature handlers", blob_size);
1095 if (handler_blob == NULL) {
1096 return NULL;
1097 }
1098 address handler = handler_blob->code_begin();
1099 _handler_blob = handler_blob;
1100 _handler = handler;
1101 return handler;
1102 }
1104 void SignatureHandlerLibrary::initialize() {
1105 if (_fingerprints != NULL) {
1106 return;
1107 }
1108 if (set_handler_blob() == NULL) {
1109 vm_exit_out_of_memory(blob_size, "native signature handlers");
1110 }
1112 BufferBlob* bb = BufferBlob::create("Signature Handler Temp Buffer",
1113 SignatureHandlerLibrary::buffer_size);
1114 _buffer = bb->code_begin();
1116 _fingerprints = new(ResourceObj::C_HEAP)GrowableArray<uint64_t>(32, true);
1117 _handlers = new(ResourceObj::C_HEAP)GrowableArray<address>(32, true);
1118 }
1120 address SignatureHandlerLibrary::set_handler(CodeBuffer* buffer) {
1121 address handler = _handler;
1122 int insts_size = buffer->pure_insts_size();
1123 if (handler + insts_size > _handler_blob->code_end()) {
1124 // get a new handler blob
1125 handler = set_handler_blob();
1126 }
1127 if (handler != NULL) {
1128 memcpy(handler, buffer->insts_begin(), insts_size);
1129 pd_set_handler(handler);
1130 ICache::invalidate_range(handler, insts_size);
1131 _handler = handler + insts_size;
1132 }
1133 return handler;
1134 }
1136 void SignatureHandlerLibrary::add(methodHandle method) {
1137 if (method->signature_handler() == NULL) {
1138 // use slow signature handler if we can't do better
1139 int handler_index = -1;
1140 // check if we can use customized (fast) signature handler
1141 if (UseFastSignatureHandlers && method->size_of_parameters() <= Fingerprinter::max_size_of_parameters) {
1142 // use customized signature handler
1143 MutexLocker mu(SignatureHandlerLibrary_lock);
1144 // make sure data structure is initialized
1145 initialize();
1146 // lookup method signature's fingerprint
1147 uint64_t fingerprint = Fingerprinter(method).fingerprint();
1148 handler_index = _fingerprints->find(fingerprint);
1149 // create handler if necessary
1150 if (handler_index < 0) {
1151 ResourceMark rm;
1152 ptrdiff_t align_offset = (address)
1153 round_to((intptr_t)_buffer, CodeEntryAlignment) - (address)_buffer;
1154 CodeBuffer buffer((address)(_buffer + align_offset),
1155 SignatureHandlerLibrary::buffer_size - align_offset);
1156 InterpreterRuntime::SignatureHandlerGenerator(method, &buffer).generate(fingerprint);
1157 // copy into code heap
1158 address handler = set_handler(&buffer);
1159 if (handler == NULL) {
1160 // use slow signature handler
1161 } else {
1162 // debugging suppport
1163 if (PrintSignatureHandlers) {
1164 tty->cr();
1165 tty->print_cr("argument handler #%d for: %s %s (fingerprint = " UINT64_FORMAT ", %d bytes generated)",
1166 _handlers->length(),
1167 (method->is_static() ? "static" : "receiver"),
1168 method->name_and_sig_as_C_string(),
1169 fingerprint,
1170 buffer.insts_size());
1171 Disassembler::decode(handler, handler + buffer.insts_size());
1172 #ifndef PRODUCT
1173 tty->print_cr(" --- associated result handler ---");
1174 address rh_begin = Interpreter::result_handler(method()->result_type());
1175 address rh_end = rh_begin;
1176 while (*(int*)rh_end != 0) {
1177 rh_end += sizeof(int);
1178 }
1179 Disassembler::decode(rh_begin, rh_end);
1180 #endif
1181 }
1182 // add handler to library
1183 _fingerprints->append(fingerprint);
1184 _handlers->append(handler);
1185 // set handler index
1186 assert(_fingerprints->length() == _handlers->length(), "sanity check");
1187 handler_index = _fingerprints->length() - 1;
1188 }
1189 }
1190 // Set handler under SignatureHandlerLibrary_lock
1191 if (handler_index < 0) {
1192 // use generic signature handler
1193 method->set_signature_handler(Interpreter::slow_signature_handler());
1194 } else {
1195 // set handler
1196 method->set_signature_handler(_handlers->at(handler_index));
1197 }
1198 } else {
1199 CHECK_UNHANDLED_OOPS_ONLY(Thread::current()->clear_unhandled_oops());
1200 // use generic signature handler
1201 method->set_signature_handler(Interpreter::slow_signature_handler());
1202 }
1203 }
1204 #ifdef ASSERT
1205 int handler_index = -1;
1206 int fingerprint_index = -2;
1207 {
1208 // '_handlers' and '_fingerprints' are 'GrowableArray's and are NOT synchronized
1209 // in any way if accessed from multiple threads. To avoid races with another
1210 // thread which may change the arrays in the above, mutex protected block, we
1211 // have to protect this read access here with the same mutex as well!
1212 MutexLocker mu(SignatureHandlerLibrary_lock);
1213 if (_handlers != NULL) {
1214 handler_index = _handlers->find(method->signature_handler());
1215 fingerprint_index = _fingerprints->find(Fingerprinter(method).fingerprint());
1216 }
1217 }
1218 assert(method->signature_handler() == Interpreter::slow_signature_handler() ||
1219 handler_index == fingerprint_index, "sanity check");
1220 #endif // ASSERT
1221 }
1224 BufferBlob* SignatureHandlerLibrary::_handler_blob = NULL;
1225 address SignatureHandlerLibrary::_handler = NULL;
1226 GrowableArray<uint64_t>* SignatureHandlerLibrary::_fingerprints = NULL;
1227 GrowableArray<address>* SignatureHandlerLibrary::_handlers = NULL;
1228 address SignatureHandlerLibrary::_buffer = NULL;
1231 IRT_ENTRY(void, InterpreterRuntime::prepare_native_call(JavaThread* thread, methodOopDesc* method))
1232 methodHandle m(thread, method);
1233 assert(m->is_native(), "sanity check");
1234 // lookup native function entry point if it doesn't exist
1235 bool in_base_library;
1236 if (!m->has_native_function()) {
1237 NativeLookup::lookup(m, in_base_library, CHECK);
1238 }
1239 // make sure signature handler is installed
1240 SignatureHandlerLibrary::add(m);
1241 // The interpreter entry point checks the signature handler first,
1242 // before trying to fetch the native entry point and klass mirror.
1243 // We must set the signature handler last, so that multiple processors
1244 // preparing the same method will be sure to see non-null entry & mirror.
1245 IRT_END
1247 #if defined(IA32) || defined(AMD64)
1248 IRT_LEAF(void, InterpreterRuntime::popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address))
1249 if (src_address == dest_address) {
1250 return;
1251 }
1252 ResetNoHandleMark rnm; // In a LEAF entry.
1253 HandleMark hm;
1254 ResourceMark rm;
1255 frame fr = thread->last_frame();
1256 assert(fr.is_interpreted_frame(), "");
1257 jint bci = fr.interpreter_frame_bci();
1258 methodHandle mh(thread, fr.interpreter_frame_method());
1259 Bytecode_invoke invoke(mh, bci);
1260 ArgumentSizeComputer asc(invoke.signature());
1261 int size_of_arguments = (asc.size() + (invoke.has_receiver() ? 1 : 0)); // receiver
1262 Copy::conjoint_jbytes(src_address, dest_address,
1263 size_of_arguments * Interpreter::stackElementSize);
1264 IRT_END
1265 #endif