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
365 // Find receiver
366 Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
367
368 // When we reenter Java, we need to re-enable the reserved/yellow zone which
369 // might already be disabled when we are in VM.
370 thread->stack_overflow_state()->reguard_stack_if_needed();
371
372 // Check that there are shadow pages available before changing thread state
373 // to Java. Calculate current_stack_pointer here to make sure
374 // stack_shadow_pages_available() and map_stack_shadow_pages() use the same sp.
375 address sp = os::current_stack_pointer();
376 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
377 // Throw stack overflow exception with preinitialized exception.
378 Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
379 return;
380 } else {
381 // Touch pages checked if the OS needs them to be touched to be mapped.
382 os::map_stack_shadow_pages(sp);
383 }
384
385 // do call
386 { JavaCallWrapper link(method, receiver, result, CHECK);
387 { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner
388
389 // NOTE: if we move the computation of the result_val_address inside
390 // the call to call_stub, the optimizer produces wrong code.
391 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
392 intptr_t* parameter_address = args->parameters();
393
394 address entry_point;
395 {
396 // The enter_interp_only_mode use handshake to set interp_only mode
397 // so no safepoint should be allowed between is_interp_only_mode() and call
398 NoSafepointVerifier nsv;
399 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
400 entry_point = method->interpreter_entry();
401 } else {
402 // Since the call stub sets up like the interpreter we call the from_interpreted_entry
403 // so we can go compiled via a i2c.
404 entry_point = method->from_interpreted_entry();
429 args->size_of_parameters(),
430 CHECK
431 );
432
433 result = link.result(); // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
434 // Preserve oop return value across possible gc points
435 if (oop_result_flag) {
436 thread->set_vm_result(result->get_oop());
437 }
438 }
439 } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
440
441 // Check if a thread stop or suspend should be executed
442 // The following assert was not realistic. Thread.stop can set that bit at any moment.
443 //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
444
445 // Restore possible oop return
446 if (oop_result_flag) {
447 result->set_oop(thread->vm_result());
448 thread->set_vm_result(nullptr);
449 }
450 }
451
452
453 //--------------------------------------------------------------------------------------
454 // Implementation of JavaCallArguments
455
456 inline bool is_value_state_indirect_oop(uint state) {
457 assert(state != JavaCallArguments::value_state_oop,
458 "Checking for handles after removal");
459 assert(state < JavaCallArguments::value_state_limit,
460 "Invalid value state %u", state);
461 return state != JavaCallArguments::value_state_primitive;
462 }
463
464 inline oop resolve_indirect_oop(intptr_t value, uint state) {
465 switch (state) {
466 case JavaCallArguments::value_state_handle:
467 {
468 oop* ptr = reinterpret_cast<oop*>(value);
577 case T_INT:
578 case T_FLOAT: // this one also
579 check_single_word(); break;
580 case T_LONG:
581 case T_DOUBLE:
582 check_double_word(); break;
583 case T_ARRAY:
584 case T_OBJECT:
585 check_reference(); break;
586 default:
587 ShouldNotReachHere();
588 }
589 }
590 };
591
592
593 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
594 guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
595
596 // Treat T_OBJECT and T_ARRAY as the same
597 if (is_reference_type(return_type)) return_type = T_OBJECT;
598
599 // Check that oop information is correct
600 Symbol* signature = method->signature();
601
602 SignatureChekker sc(signature,
603 return_type,
604 method->is_static(),
605 _value_state,
606 _value);
607 }
|
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
367 // Find receiver
368 Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
369
370 // When we reenter Java, we need to re-enable the reserved/yellow zone which
371 // might already be disabled when we are in VM.
372 thread->stack_overflow_state()->reguard_stack_if_needed();
373
374 // Check that there are shadow pages available before changing thread state
375 // to Java. Calculate current_stack_pointer here to make sure
376 // stack_shadow_pages_available() and map_stack_shadow_pages() use the same sp.
377 address sp = os::current_stack_pointer();
378 if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
379 // Throw stack overflow exception with preinitialized exception.
380 Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
381 return;
382 } else {
383 // Touch pages checked if the OS needs them to be touched to be mapped.
384 os::map_stack_shadow_pages(sp);
385 }
386
387 jobject value_buffer = nullptr;
388 if (InlineTypeReturnedAsFields && (result->get_type() == T_OBJECT)) {
389 // Pre allocate a buffered inline type in case the result is returned
390 // flattened by compiled code
391 InlineKlass* vk = method->returns_inline_type(thread);
392 if (vk != nullptr && vk->can_be_returned_as_fields()) {
393 oop instance = vk->allocate_instance(CHECK);
394 value_buffer = JNIHandles::make_local(thread, instance);
395 result->set_jobject(value_buffer);
396 }
397 }
398
399 // do call
400 { JavaCallWrapper link(method, receiver, result, CHECK);
401 { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner
402
403 // NOTE: if we move the computation of the result_val_address inside
404 // the call to call_stub, the optimizer produces wrong code.
405 intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
406 intptr_t* parameter_address = args->parameters();
407
408 address entry_point;
409 {
410 // The enter_interp_only_mode use handshake to set interp_only mode
411 // so no safepoint should be allowed between is_interp_only_mode() and call
412 NoSafepointVerifier nsv;
413 if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
414 entry_point = method->interpreter_entry();
415 } else {
416 // Since the call stub sets up like the interpreter we call the from_interpreted_entry
417 // so we can go compiled via a i2c.
418 entry_point = method->from_interpreted_entry();
443 args->size_of_parameters(),
444 CHECK
445 );
446
447 result = link.result(); // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
448 // Preserve oop return value across possible gc points
449 if (oop_result_flag) {
450 thread->set_vm_result(result->get_oop());
451 }
452 }
453 } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
454
455 // Check if a thread stop or suspend should be executed
456 // The following assert was not realistic. Thread.stop can set that bit at any moment.
457 //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
458
459 // Restore possible oop return
460 if (oop_result_flag) {
461 result->set_oop(thread->vm_result());
462 thread->set_vm_result(nullptr);
463 JNIHandles::destroy_local(value_buffer);
464 }
465 }
466
467
468 //--------------------------------------------------------------------------------------
469 // Implementation of JavaCallArguments
470
471 inline bool is_value_state_indirect_oop(uint state) {
472 assert(state != JavaCallArguments::value_state_oop,
473 "Checking for handles after removal");
474 assert(state < JavaCallArguments::value_state_limit,
475 "Invalid value state %u", state);
476 return state != JavaCallArguments::value_state_primitive;
477 }
478
479 inline oop resolve_indirect_oop(intptr_t value, uint state) {
480 switch (state) {
481 case JavaCallArguments::value_state_handle:
482 {
483 oop* ptr = reinterpret_cast<oop*>(value);
592 case T_INT:
593 case T_FLOAT: // this one also
594 check_single_word(); break;
595 case T_LONG:
596 case T_DOUBLE:
597 check_double_word(); break;
598 case T_ARRAY:
599 case T_OBJECT:
600 check_reference(); break;
601 default:
602 ShouldNotReachHere();
603 }
604 }
605 };
606
607
608 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
609 guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
610
611 // Treat T_OBJECT and T_ARRAY as the same
612 if (return_type == T_ARRAY) return_type = T_OBJECT;
613
614 // Check that oop information is correct
615 Symbol* signature = method->signature();
616
617 SignatureChekker sc(signature,
618 return_type,
619 method->is_static(),
620 _value_state,
621 _value);
622 }
|