16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "code/nmethod.hpp"
29 #include "compiler/compilationPolicy.hpp"
30 #include "compiler/compileBroker.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "interpreter/linkResolver.hpp"
33 #include "memory/universe.hpp"
34 #include "oops/method.inline.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "prims/jniCheck.hpp"
37 #include "prims/jvmtiExport.hpp"
38 #include "runtime/handles.inline.hpp"
39 #include "runtime/interfaceSupport.inline.hpp"
40 #include "runtime/javaCalls.hpp"
41 #include "runtime/javaThread.hpp"
42 #include "runtime/jniHandles.inline.hpp"
43 #include "runtime/mutexLocker.hpp"
44 #include "runtime/os.inline.hpp"
45 #include "runtime/sharedRuntime.hpp"
46 #include "runtime/signature.hpp"
47 #include "runtime/stubRoutines.hpp"
48 #include "runtime/thread.inline.hpp"
49 #if INCLUDE_JVMCI
50 #include "jvmci/jvmciJavaClasses.hpp"
51 #endif
52
53 // -----------------------------------------------------
54 // Implementation of JavaCallWrapper
55
129
130 if (_thread->has_pending_exception() && _thread->has_last_Java_frame()) {
131 // If we get here, the Java code threw an exception that unwound a frame.
132 // It could be that the new frame anchor has not passed through the required
133 // StackWatermark barriers. Therefore, we process any such deferred unwind
134 // requests here.
135 StackWatermarkSet::after_unwind(_thread);
136 }
137 }
138
139
140 void JavaCallWrapper::oops_do(OopClosure* f) {
141 f->do_oop((oop*)&_receiver);
142 handles()->oops_do(f);
143 }
144
145
146 // Helper methods
147 static BasicType runtime_type_from(JavaValue* result) {
148 switch (result->get_type()) {
149 case T_BOOLEAN: // fall through
150 case T_CHAR : // fall through
151 case T_SHORT : // fall through
152 case T_INT : // fall through
153 #ifndef _LP64
154 case T_OBJECT : // fall through
155 case T_ARRAY : // fall through
156 #endif
157 case T_BYTE : // fall through
158 case T_VOID : return T_INT;
159 case T_LONG : return T_LONG;
160 case T_FLOAT : return T_FLOAT;
161 case T_DOUBLE : return T_DOUBLE;
162 #ifdef _LP64
163 case T_ARRAY : // fall through
164 case T_OBJECT: return T_OBJECT;
165 #endif
166 default:
167 ShouldNotReachHere();
168 return T_ILLEGAL;
169 }
170 }
171
172 // ============ Virtual calls ============
173
174 void JavaCalls::call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
175 CallInfo callinfo;
176 Handle receiver = args->receiver();
177 Klass* recvrKlass = receiver.is_null() ? (Klass*)nullptr : receiver->klass();
178 LinkInfo link_info(spec_klass, name, signature);
179 LinkResolver::resolve_virtual_call(
180 callinfo, receiver, recvrKlass, link_info, true, CHECK);
181 methodHandle method(THREAD, callinfo.selected_method());
182 assert(method.not_null(), "should have thrown exception");
183
184 // Invoke the method
373 // Find receiver
374 Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
375
376 // When we reenter Java, we need to re-enable the reserved/yellow zone which
377 // might already be disabled when we are in VM.
378 thread->stack_overflow_state()->reguard_stack_if_needed();
379
380 // Check that there are shadow pages available before changing thread state
381 // to Java. Calculate current_stack_pointer here to make sure
382 // stack_shadow_pages_available() and map_stack_shadow_pages() use the same sp.
383 address sp = os::current_stack_pointer();
384 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
385 // Throw stack overflow exception with preinitialized exception.
386 Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
387 return;
388 } else {
389 // Touch pages checked if the OS needs them to be touched to be mapped.
390 os::map_stack_shadow_pages(sp);
391 }
392
393 // do call
394 { JavaCallWrapper link(method, receiver, result, CHECK);
395 { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner
396
397 // NOTE: if we move the computation of the result_val_address inside
398 // the call to call_stub, the optimizer produces wrong code.
399 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
400 intptr_t* parameter_address = args->parameters();
401 #if INCLUDE_JVMCI
402 // Gets the alternative target (if any) that should be called
403 Handle alternative_target = args->alternative_target();
404 if (!alternative_target.is_null()) {
405 // Must extract verified entry point from HotSpotNmethod after VM to Java
406 // transition in JavaCallWrapper constructor so that it is safe with
407 // respect to nmethod sweeping.
408 address verified_entry_point = (address) HotSpotJVMCI::InstalledCode::entryPoint(nullptr, alternative_target());
409 if (verified_entry_point != nullptr) {
410 thread->set_jvmci_alternate_call_target(verified_entry_point);
411 entry_point = method->adapter()->get_i2c_entry();
412 }
423 args->size_of_parameters(),
424 CHECK
425 );
426
427 result = link.result(); // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
428 // Preserve oop return value across possible gc points
429 if (oop_result_flag) {
430 thread->set_vm_result(result->get_oop());
431 }
432 }
433 } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
434
435 // Check if a thread stop or suspend should be executed
436 // The following assert was not realistic. Thread.stop can set that bit at any moment.
437 //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
438
439 // Restore possible oop return
440 if (oop_result_flag) {
441 result->set_oop(thread->vm_result());
442 thread->set_vm_result(nullptr);
443 }
444 }
445
446
447 //--------------------------------------------------------------------------------------
448 // Implementation of JavaCallArguments
449
450 inline bool is_value_state_indirect_oop(uint state) {
451 assert(state != JavaCallArguments::value_state_oop,
452 "Checking for handles after removal");
453 assert(state < JavaCallArguments::value_state_limit,
454 "Invalid value state %u", state);
455 return state != JavaCallArguments::value_state_primitive;
456 }
457
458 inline oop resolve_indirect_oop(intptr_t value, uint state) {
459 switch (state) {
460 case JavaCallArguments::value_state_handle:
461 {
462 oop* ptr = reinterpret_cast<oop*>(value);
571 case T_INT:
572 case T_FLOAT: // this one also
573 check_single_word(); break;
574 case T_LONG:
575 case T_DOUBLE:
576 check_double_word(); break;
577 case T_ARRAY:
578 case T_OBJECT:
579 check_reference(); break;
580 default:
581 ShouldNotReachHere();
582 }
583 }
584 };
585
586
587 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
588 guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
589
590 // Treat T_OBJECT and T_ARRAY as the same
591 if (is_reference_type(return_type)) return_type = T_OBJECT;
592
593 // Check that oop information is correct
594 Symbol* signature = method->signature();
595
596 SignatureChekker sc(signature,
597 return_type,
598 method->is_static(),
599 _value_state,
600 _value);
601 }
|
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #include "classfile/vmSymbols.hpp"
28 #include "code/nmethod.hpp"
29 #include "compiler/compilationPolicy.hpp"
30 #include "compiler/compileBroker.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "interpreter/linkResolver.hpp"
33 #include "memory/universe.hpp"
34 #include "oops/method.inline.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "oops/inlineKlass.hpp"
37 #include "prims/jniCheck.hpp"
38 #include "prims/jvmtiExport.hpp"
39 #include "runtime/handles.inline.hpp"
40 #include "runtime/interfaceSupport.inline.hpp"
41 #include "runtime/javaCalls.hpp"
42 #include "runtime/javaThread.hpp"
43 #include "runtime/jniHandles.inline.hpp"
44 #include "runtime/mutexLocker.hpp"
45 #include "runtime/os.inline.hpp"
46 #include "runtime/sharedRuntime.hpp"
47 #include "runtime/signature.hpp"
48 #include "runtime/stubRoutines.hpp"
49 #include "runtime/thread.inline.hpp"
50 #if INCLUDE_JVMCI
51 #include "jvmci/jvmciJavaClasses.hpp"
52 #endif
53
54 // -----------------------------------------------------
55 // Implementation of JavaCallWrapper
56
130
131 if (_thread->has_pending_exception() && _thread->has_last_Java_frame()) {
132 // If we get here, the Java code threw an exception that unwound a frame.
133 // It could be that the new frame anchor has not passed through the required
134 // StackWatermark barriers. Therefore, we process any such deferred unwind
135 // requests here.
136 StackWatermarkSet::after_unwind(_thread);
137 }
138 }
139
140
141 void JavaCallWrapper::oops_do(OopClosure* f) {
142 f->do_oop((oop*)&_receiver);
143 handles()->oops_do(f);
144 }
145
146
147 // Helper methods
148 static BasicType runtime_type_from(JavaValue* result) {
149 switch (result->get_type()) {
150 case T_BOOLEAN : // fall through
151 case T_CHAR : // fall through
152 case T_SHORT : // fall through
153 case T_INT : // fall through
154 #ifndef _LP64
155 case T_OBJECT : // fall through
156 case T_ARRAY : // fall through
157 case T_PRIMITIVE_OBJECT: // fall through
158 #endif
159 case T_BYTE : // fall through
160 case T_VOID : return T_INT;
161 case T_LONG : return T_LONG;
162 case T_FLOAT : return T_FLOAT;
163 case T_DOUBLE : return T_DOUBLE;
164 #ifdef _LP64
165 case T_ARRAY : // fall through
166 case T_OBJECT : return T_OBJECT;
167 #endif
168 default:
169 ShouldNotReachHere();
170 return T_ILLEGAL;
171 }
172 }
173
174 // ============ Virtual calls ============
175
176 void JavaCalls::call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
177 CallInfo callinfo;
178 Handle receiver = args->receiver();
179 Klass* recvrKlass = receiver.is_null() ? (Klass*)nullptr : receiver->klass();
180 LinkInfo link_info(spec_klass, name, signature);
181 LinkResolver::resolve_virtual_call(
182 callinfo, receiver, recvrKlass, link_info, true, CHECK);
183 methodHandle method(THREAD, callinfo.selected_method());
184 assert(method.not_null(), "should have thrown exception");
185
186 // Invoke the method
375 // Find receiver
376 Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
377
378 // When we reenter Java, we need to re-enable the reserved/yellow zone which
379 // might already be disabled when we are in VM.
380 thread->stack_overflow_state()->reguard_stack_if_needed();
381
382 // Check that there are shadow pages available before changing thread state
383 // to Java. Calculate current_stack_pointer here to make sure
384 // stack_shadow_pages_available() and map_stack_shadow_pages() use the same sp.
385 address sp = os::current_stack_pointer();
386 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
387 // Throw stack overflow exception with preinitialized exception.
388 Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
389 return;
390 } else {
391 // Touch pages checked if the OS needs them to be touched to be mapped.
392 os::map_stack_shadow_pages(sp);
393 }
394
395 jobject value_buffer = nullptr;
396 if (InlineTypeReturnedAsFields && (result->get_type() == T_OBJECT)) {
397 // Pre allocate a buffered inline type in case the result is returned
398 // flattened by compiled code
399 InlineKlass* vk = method->returns_inline_type(thread);
400 if (vk != nullptr && vk->can_be_returned_as_fields()) {
401 oop instance = vk->allocate_instance(CHECK);
402 value_buffer = JNIHandles::make_local(thread, instance);
403 result->set_jobject(value_buffer);
404 }
405 }
406
407 // do call
408 { JavaCallWrapper link(method, receiver, result, CHECK);
409 { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner
410
411 // NOTE: if we move the computation of the result_val_address inside
412 // the call to call_stub, the optimizer produces wrong code.
413 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
414 intptr_t* parameter_address = args->parameters();
415 #if INCLUDE_JVMCI
416 // Gets the alternative target (if any) that should be called
417 Handle alternative_target = args->alternative_target();
418 if (!alternative_target.is_null()) {
419 // Must extract verified entry point from HotSpotNmethod after VM to Java
420 // transition in JavaCallWrapper constructor so that it is safe with
421 // respect to nmethod sweeping.
422 address verified_entry_point = (address) HotSpotJVMCI::InstalledCode::entryPoint(nullptr, alternative_target());
423 if (verified_entry_point != nullptr) {
424 thread->set_jvmci_alternate_call_target(verified_entry_point);
425 entry_point = method->adapter()->get_i2c_entry();
426 }
437 args->size_of_parameters(),
438 CHECK
439 );
440
441 result = link.result(); // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
442 // Preserve oop return value across possible gc points
443 if (oop_result_flag) {
444 thread->set_vm_result(result->get_oop());
445 }
446 }
447 } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
448
449 // Check if a thread stop or suspend should be executed
450 // The following assert was not realistic. Thread.stop can set that bit at any moment.
451 //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
452
453 // Restore possible oop return
454 if (oop_result_flag) {
455 result->set_oop(thread->vm_result());
456 thread->set_vm_result(nullptr);
457 JNIHandles::destroy_local(value_buffer);
458 }
459 }
460
461
462 //--------------------------------------------------------------------------------------
463 // Implementation of JavaCallArguments
464
465 inline bool is_value_state_indirect_oop(uint state) {
466 assert(state != JavaCallArguments::value_state_oop,
467 "Checking for handles after removal");
468 assert(state < JavaCallArguments::value_state_limit,
469 "Invalid value state %u", state);
470 return state != JavaCallArguments::value_state_primitive;
471 }
472
473 inline oop resolve_indirect_oop(intptr_t value, uint state) {
474 switch (state) {
475 case JavaCallArguments::value_state_handle:
476 {
477 oop* ptr = reinterpret_cast<oop*>(value);
586 case T_INT:
587 case T_FLOAT: // this one also
588 check_single_word(); break;
589 case T_LONG:
590 case T_DOUBLE:
591 check_double_word(); break;
592 case T_ARRAY:
593 case T_OBJECT:
594 check_reference(); break;
595 default:
596 ShouldNotReachHere();
597 }
598 }
599 };
600
601
602 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
603 guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
604
605 // Treat T_OBJECT and T_ARRAY as the same
606 if (return_type == T_ARRAY) return_type = T_OBJECT;
607
608 // Check that oop information is correct
609 Symbol* signature = method->signature();
610
611 SignatureChekker sc(signature,
612 return_type,
613 method->is_static(),
614 _value_state,
615 _value);
616 }
|