15 *
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 "classfile/vmSymbols.hpp"
27 #include "code/nmethod.hpp"
28 #include "compiler/compilationPolicy.hpp"
29 #include "compiler/compileBroker.hpp"
30 #include "interpreter/interpreter.hpp"
31 #include "interpreter/linkResolver.hpp"
32 #include "memory/universe.hpp"
33 #include "oops/method.inline.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "prims/jniCheck.hpp"
36 #include "prims/jvmtiExport.hpp"
37 #include "runtime/handles.inline.hpp"
38 #include "runtime/interfaceSupport.inline.hpp"
39 #include "runtime/javaCalls.hpp"
40 #include "runtime/javaThread.hpp"
41 #include "runtime/jniHandles.inline.hpp"
42 #include "runtime/mutexLocker.hpp"
43 #include "runtime/os.inline.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "runtime/signature.hpp"
46 #include "runtime/stubRoutines.hpp"
47 #include "runtime/thread.inline.hpp"
48 #if INCLUDE_JVMCI
49 #include "jvmci/jvmciJavaClasses.hpp"
50 #endif
51
52 // -----------------------------------------------------
53 // Implementation of JavaCallWrapper
54
123
124 if (_thread->has_pending_exception() && _thread->has_last_Java_frame()) {
125 // If we get here, the Java code threw an exception that unwound a frame.
126 // It could be that the new frame anchor has not passed through the required
127 // StackWatermark barriers. Therefore, we process any such deferred unwind
128 // requests here.
129 StackWatermarkSet::after_unwind(_thread);
130 }
131 }
132
133
134 void JavaCallWrapper::oops_do(OopClosure* f) {
135 f->do_oop((oop*)&_receiver);
136 handles()->oops_do(f);
137 }
138
139
140 // Helper methods
141 static BasicType runtime_type_from(JavaValue* result) {
142 switch (result->get_type()) {
143 case T_BOOLEAN: // fall through
144 case T_CHAR : // fall through
145 case T_SHORT : // fall through
146 case T_INT : // fall through
147 #ifndef _LP64
148 case T_OBJECT : // fall through
149 case T_ARRAY : // fall through
150 #endif
151 case T_BYTE : // fall through
152 case T_VOID : return T_INT;
153 case T_LONG : return T_LONG;
154 case T_FLOAT : return T_FLOAT;
155 case T_DOUBLE : return T_DOUBLE;
156 #ifdef _LP64
157 case T_ARRAY : // fall through
158 case T_OBJECT: return T_OBJECT;
159 #endif
160 default:
161 ShouldNotReachHere();
162 return T_ILLEGAL;
163 }
164 }
165
166 // ============ Virtual calls ============
167
168 void JavaCalls::call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
169 CallInfo callinfo;
170 Handle receiver = args->receiver();
171 Klass* recvrKlass = receiver.is_null() ? (Klass*)nullptr : receiver->klass();
172 LinkInfo link_info(spec_klass, name, signature);
173 LinkResolver::resolve_virtual_call(
174 callinfo, receiver, recvrKlass, link_info, true, CHECK);
175 methodHandle method(THREAD, callinfo.selected_method());
176 assert(method.not_null(), "should have thrown exception");
177
178 // Invoke the method
359 // Find receiver
360 Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
361
362 // When we reenter Java, we need to re-enable the reserved/yellow zone which
363 // might already be disabled when we are in VM.
364 thread->stack_overflow_state()->reguard_stack_if_needed();
365
366 // Check that there are shadow pages available before changing thread state
367 // to Java. Calculate current_stack_pointer here to make sure
368 // stack_shadow_pages_available() and map_stack_shadow_pages() use the same sp.
369 address sp = os::current_stack_pointer();
370 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
371 // Throw stack overflow exception with preinitialized exception.
372 Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
373 return;
374 } else {
375 // Touch pages checked if the OS needs them to be touched to be mapped.
376 os::map_stack_shadow_pages(sp);
377 }
378
379 // do call
380 { JavaCallWrapper link(method, receiver, result, CHECK);
381 { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner
382
383 // NOTE: if we move the computation of the result_val_address inside
384 // the call to call_stub, the optimizer produces wrong code.
385 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
386 intptr_t* parameter_address = args->parameters();
387
388 address entry_point;
389 {
390 // The enter_interp_only_mode use handshake to set interp_only mode
391 // so no safepoint should be allowed between is_interp_only_mode() and call
392 NoSafepointVerifier nsv;
393 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
394 entry_point = method->interpreter_entry();
395 } else {
396 // Since the call stub sets up like the interpreter we call the from_interpreted_entry
397 // so we can go compiled via a i2c.
398 entry_point = method->from_interpreted_entry();
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 }
|
15 *
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 "classfile/vmSymbols.hpp"
27 #include "code/nmethod.hpp"
28 #include "compiler/compilationPolicy.hpp"
29 #include "compiler/compileBroker.hpp"
30 #include "interpreter/interpreter.hpp"
31 #include "interpreter/linkResolver.hpp"
32 #include "memory/universe.hpp"
33 #include "oops/method.inline.hpp"
34 #include "oops/oop.inline.hpp"
35 #include "oops/inlineKlass.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
124
125 if (_thread->has_pending_exception() && _thread->has_last_Java_frame()) {
126 // If we get here, the Java code threw an exception that unwound a frame.
127 // It could be that the new frame anchor has not passed through the required
128 // StackWatermark barriers. Therefore, we process any such deferred unwind
129 // requests here.
130 StackWatermarkSet::after_unwind(_thread);
131 }
132 }
133
134
135 void JavaCallWrapper::oops_do(OopClosure* f) {
136 f->do_oop((oop*)&_receiver);
137 handles()->oops_do(f);
138 }
139
140
141 // Helper methods
142 static BasicType runtime_type_from(JavaValue* result) {
143 switch (result->get_type()) {
144 case T_BOOLEAN : // fall through
145 case T_CHAR : // fall through
146 case T_SHORT : // fall through
147 case T_INT : // fall through
148 #ifndef _LP64
149 case T_OBJECT : // fall through
150 case T_ARRAY : // fall through
151 case T_FLAT_ELEMENT: // fall through
152 #endif
153 case T_BYTE : // fall through
154 case T_VOID : return T_INT;
155 case T_LONG : return T_LONG;
156 case T_FLOAT : return T_FLOAT;
157 case T_DOUBLE : return T_DOUBLE;
158 #ifdef _LP64
159 case T_ARRAY : // fall through
160 case T_OBJECT : return T_OBJECT;
161 #endif
162 default:
163 ShouldNotReachHere();
164 return T_ILLEGAL;
165 }
166 }
167
168 // ============ Virtual calls ============
169
170 void JavaCalls::call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
171 CallInfo callinfo;
172 Handle receiver = args->receiver();
173 Klass* recvrKlass = receiver.is_null() ? (Klass*)nullptr : receiver->klass();
174 LinkInfo link_info(spec_klass, name, signature);
175 LinkResolver::resolve_virtual_call(
176 callinfo, receiver, recvrKlass, link_info, true, CHECK);
177 methodHandle method(THREAD, callinfo.selected_method());
178 assert(method.not_null(), "should have thrown exception");
179
180 // Invoke the method
361 // Find receiver
362 Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
363
364 // When we reenter Java, we need to re-enable the reserved/yellow zone which
365 // might already be disabled when we are in VM.
366 thread->stack_overflow_state()->reguard_stack_if_needed();
367
368 // Check that there are shadow pages available before changing thread state
369 // to Java. Calculate current_stack_pointer here to make sure
370 // stack_shadow_pages_available() and map_stack_shadow_pages() use the same sp.
371 address sp = os::current_stack_pointer();
372 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
373 // Throw stack overflow exception with preinitialized exception.
374 Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
375 return;
376 } else {
377 // Touch pages checked if the OS needs them to be touched to be mapped.
378 os::map_stack_shadow_pages(sp);
379 }
380
381 jobject value_buffer = nullptr;
382 if (InlineTypeReturnedAsFields && (result->get_type() == T_OBJECT)) {
383 // Pre allocate a buffered inline type in case the result is returned
384 // flattened by compiled code
385 InlineKlass* vk = method->returns_inline_type(thread);
386 if (vk != nullptr && vk->can_be_returned_as_fields()) {
387 oop instance = vk->allocate_instance(CHECK);
388 value_buffer = JNIHandles::make_local(thread, instance);
389 result->set_jobject(value_buffer);
390 }
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
402 address entry_point;
403 {
404 // The enter_interp_only_mode use handshake to set interp_only mode
405 // so no safepoint should be allowed between is_interp_only_mode() and call
406 NoSafepointVerifier nsv;
407 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
408 entry_point = method->interpreter_entry();
409 } else {
410 // Since the call stub sets up like the interpreter we call the from_interpreted_entry
411 // so we can go compiled via a i2c.
412 entry_point = method->from_interpreted_entry();
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 }
|