< prev index next >

src/hotspot/share/runtime/javaCalls.cpp

Print this page

 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 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 // -----------------------------------------------------

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 #endif
152     case T_BYTE   : // fall through
153     case T_VOID   : return T_INT;
154     case T_LONG   : return T_LONG;
155     case T_FLOAT  : return T_FLOAT;
156     case T_DOUBLE : return T_DOUBLE;
157 #ifdef _LP64
158     case T_ARRAY  : // fall through
159     case T_OBJECT:  return T_OBJECT;
160 #endif
161     default:
162       ShouldNotReachHere();
163       return T_ILLEGAL;
164   }
165 }
166 
167 // ============ Virtual calls ============
168 
169 void JavaCalls::call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
170   CallInfo callinfo;
171   Handle receiver = args->receiver();
172   Klass* recvrKlass = receiver.is_null() ? (Klass*)nullptr : receiver->klass();
173   LinkInfo link_info(spec_klass, name, signature);
174   LinkResolver::resolve_virtual_call(
175           callinfo, receiver, recvrKlass, link_info, true, CHECK);
176   methodHandle method(THREAD, callinfo.selected_method());
177   assert(method.not_null(), "should have thrown exception");
178 
179   // Invoke the method

360   // Find receiver
361   Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
362 
363   // When we reenter Java, we need to re-enable the reserved/yellow zone which
364   // might already be disabled when we are in VM.
365   thread->stack_overflow_state()->reguard_stack_if_needed();
366 
367   // Check that there are shadow pages available before changing thread state
368   // to Java. Calculate current_stack_pointer here to make sure
369   // stack_shadow_pages_available() and map_stack_shadow_pages() use the same sp.
370   address sp = os::current_stack_pointer();
371   if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
372     // Throw stack overflow exception with preinitialized exception.
373     Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
374     return;
375   } else {
376     // Touch pages checked if the OS needs them to be touched to be mapped.
377     os::map_stack_shadow_pages(sp);
378   }
379 












380   // do call
381   { JavaCallWrapper link(method, receiver, result, CHECK);
382     { HandleMark hm(thread);  // HandleMark used by HandleMarkCleaner
383 
384       // NOTE: if we move the computation of the result_val_address inside
385       // the call to call_stub, the optimizer produces wrong code.
386       intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
387       intptr_t* parameter_address = args->parameters();
388 
389       address entry_point;
390       {
391         // The enter_interp_only_mode use handshake to set interp_only mode
392         // so no safepoint should be allowed between is_interp_only_mode() and call
393         NoSafepointVerifier nsv;
394         if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
395           entry_point = method->interpreter_entry();
396         } else {
397           // Since the call stub sets up like the interpreter we call the from_interpreted_entry
398           // so we can go compiled via a i2c.
399           entry_point = method->from_interpreted_entry();

424         args->size_of_parameters(),
425         CHECK
426       );
427 
428       result = link.result();  // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
429       // Preserve oop return value across possible gc points
430       if (oop_result_flag) {
431         thread->set_vm_result_oop(result->get_oop());
432       }
433     }
434   } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
435 
436   // Check if a thread stop or suspend should be executed
437   // The following assert was not realistic.  Thread.stop can set that bit at any moment.
438   //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
439 
440   // Restore possible oop return
441   if (oop_result_flag) {
442     result->set_oop(thread->vm_result_oop());
443     thread->set_vm_result_oop(nullptr);

444   }
445 }
446 
447 
448 //--------------------------------------------------------------------------------------
449 // Implementation of JavaCallArguments
450 
451 inline bool is_value_state_indirect_oop(uint state) {
452   assert(state != JavaCallArguments::value_state_oop,
453          "Checking for handles after removal");
454   assert(state < JavaCallArguments::value_state_limit,
455          "Invalid value state %u", state);
456   return state != JavaCallArguments::value_state_primitive;
457 }
458 
459 inline oop resolve_indirect_oop(intptr_t value, uint state) {
460   switch (state) {
461   case JavaCallArguments::value_state_handle:
462   {
463     oop* ptr = reinterpret_cast<oop*>(value);

572     case T_INT:
573     case T_FLOAT:  // this one also
574       check_single_word(); break;
575     case T_LONG:
576     case T_DOUBLE:
577       check_double_word(); break;
578     case T_ARRAY:
579     case T_OBJECT:
580       check_reference(); break;
581     default:
582       ShouldNotReachHere();
583     }
584   }
585 };
586 
587 
588 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
589   guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
590 
591   // Treat T_OBJECT and T_ARRAY as the same
592   if (is_reference_type(return_type)) return_type = T_OBJECT;
593 
594   // Check that oop information is correct
595   Symbol* signature = method->signature();
596 
597   SignatureChekker sc(signature,
598                       return_type,
599                       method->is_static(),
600                       _value_state,
601                       _value);
602 }

 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 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/inlineKlass.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 // -----------------------------------------------------

125 
126   if (_thread->has_pending_exception() && _thread->has_last_Java_frame()) {
127     // If we get here, the Java code threw an exception that unwound a frame.
128     // It could be that the new frame anchor has not passed through the required
129     // StackWatermark barriers. Therefore, we process any such deferred unwind
130     // requests here.
131     StackWatermarkSet::after_unwind(_thread);
132   }
133 }
134 
135 
136 void JavaCallWrapper::oops_do(OopClosure* f) {
137   f->do_oop((oop*)&_receiver);
138   handles()->oops_do(f);
139 }
140 
141 
142 // Helper methods
143 static BasicType runtime_type_from(JavaValue* result) {
144   switch (result->get_type()) {
145     case T_BOOLEAN  : // fall through
146     case T_CHAR     : // fall through
147     case T_SHORT    : // fall through
148     case T_INT      : // fall through
149 #ifndef _LP64
150     case T_OBJECT   : // fall through
151     case T_ARRAY    : // fall through
152     case T_FLAT_ELEMENT: // fall through
153 #endif
154     case T_BYTE     : // fall through
155     case T_VOID     : return T_INT;
156     case T_LONG     : return T_LONG;
157     case T_FLOAT    : return T_FLOAT;
158     case T_DOUBLE   : return T_DOUBLE;
159 #ifdef _LP64
160     case T_ARRAY    : // fall through
161     case T_OBJECT   : return T_OBJECT;
162 #endif
163     default:
164       ShouldNotReachHere();
165       return T_ILLEGAL;
166   }
167 }
168 
169 // ============ Virtual calls ============
170 
171 void JavaCalls::call_virtual(JavaValue* result, Klass* spec_klass, Symbol* name, Symbol* signature, JavaCallArguments* args, TRAPS) {
172   CallInfo callinfo;
173   Handle receiver = args->receiver();
174   Klass* recvrKlass = receiver.is_null() ? (Klass*)nullptr : receiver->klass();
175   LinkInfo link_info(spec_klass, name, signature);
176   LinkResolver::resolve_virtual_call(
177           callinfo, receiver, recvrKlass, link_info, true, CHECK);
178   methodHandle method(THREAD, callinfo.selected_method());
179   assert(method.not_null(), "should have thrown exception");
180 
181   // Invoke the method

362   // Find receiver
363   Handle receiver = (!method->is_static()) ? args->receiver() : Handle();
364 
365   // When we reenter Java, we need to re-enable the reserved/yellow zone which
366   // might already be disabled when we are in VM.
367   thread->stack_overflow_state()->reguard_stack_if_needed();
368 
369   // Check that there are shadow pages available before changing thread state
370   // to Java. Calculate current_stack_pointer here to make sure
371   // stack_shadow_pages_available() and map_stack_shadow_pages() use the same sp.
372   address sp = os::current_stack_pointer();
373   if (!os::stack_shadow_pages_available(THREAD, method, sp)) {
374     // Throw stack overflow exception with preinitialized exception.
375     Exceptions::throw_stack_overflow_exception(THREAD, __FILE__, __LINE__, method);
376     return;
377   } else {
378     // Touch pages checked if the OS needs them to be touched to be mapped.
379     os::map_stack_shadow_pages(sp);
380   }
381 
382   jobject value_buffer = nullptr;
383   if (InlineTypeReturnedAsFields && (result->get_type() == T_OBJECT)) {
384     // Pre allocate a buffered inline type in case the result is returned
385     // flattened by compiled code
386     InlineKlass* vk = method->returns_inline_type();
387     if (vk != nullptr && vk->can_be_returned_as_fields()) {
388       oop instance = vk->allocate_instance(CHECK);
389       value_buffer = JNIHandles::make_local(thread, instance);
390       result->set_jobject(value_buffer);
391     }
392   }
393 
394   // do call
395   { JavaCallWrapper link(method, receiver, result, CHECK);
396     { HandleMark hm(thread);  // HandleMark used by HandleMarkCleaner
397 
398       // NOTE: if we move the computation of the result_val_address inside
399       // the call to call_stub, the optimizer produces wrong code.
400       intptr_t* result_val_address = (intptr_t*)(result->get_value_addr());
401       intptr_t* parameter_address = args->parameters();
402 
403       address entry_point;
404       {
405         // The enter_interp_only_mode use handshake to set interp_only mode
406         // so no safepoint should be allowed between is_interp_only_mode() and call
407         NoSafepointVerifier nsv;
408         if (JvmtiExport::can_post_interpreter_events() && thread->is_interp_only_mode()) {
409           entry_point = method->interpreter_entry();
410         } else {
411           // Since the call stub sets up like the interpreter we call the from_interpreted_entry
412           // so we can go compiled via a i2c.
413           entry_point = method->from_interpreted_entry();

438         args->size_of_parameters(),
439         CHECK
440       );
441 
442       result = link.result();  // circumvent MS C++ 5.0 compiler bug (result is clobbered across call)
443       // Preserve oop return value across possible gc points
444       if (oop_result_flag) {
445         thread->set_vm_result_oop(result->get_oop());
446       }
447     }
448   } // Exit JavaCallWrapper (can block - potential return oop must be preserved)
449 
450   // Check if a thread stop or suspend should be executed
451   // The following assert was not realistic.  Thread.stop can set that bit at any moment.
452   //assert(!thread->has_special_runtime_exit_condition(), "no async. exceptions should be installed");
453 
454   // Restore possible oop return
455   if (oop_result_flag) {
456     result->set_oop(thread->vm_result_oop());
457     thread->set_vm_result_oop(nullptr);
458     JNIHandles::destroy_local(value_buffer);
459   }
460 }
461 
462 
463 //--------------------------------------------------------------------------------------
464 // Implementation of JavaCallArguments
465 
466 inline bool is_value_state_indirect_oop(uint state) {
467   assert(state != JavaCallArguments::value_state_oop,
468          "Checking for handles after removal");
469   assert(state < JavaCallArguments::value_state_limit,
470          "Invalid value state %u", state);
471   return state != JavaCallArguments::value_state_primitive;
472 }
473 
474 inline oop resolve_indirect_oop(intptr_t value, uint state) {
475   switch (state) {
476   case JavaCallArguments::value_state_handle:
477   {
478     oop* ptr = reinterpret_cast<oop*>(value);

587     case T_INT:
588     case T_FLOAT:  // this one also
589       check_single_word(); break;
590     case T_LONG:
591     case T_DOUBLE:
592       check_double_word(); break;
593     case T_ARRAY:
594     case T_OBJECT:
595       check_reference(); break;
596     default:
597       ShouldNotReachHere();
598     }
599   }
600 };
601 
602 
603 void JavaCallArguments::verify(const methodHandle& method, BasicType return_type) {
604   guarantee(method->size_of_parameters() == size_of_parameters(), "wrong no. of arguments pushed");
605 
606   // Treat T_OBJECT and T_ARRAY as the same
607   if (return_type == T_ARRAY) return_type = T_OBJECT;
608 
609   // Check that oop information is correct
610   Symbol* signature = method->signature();
611 
612   SignatureChekker sc(signature,
613                       return_type,
614                       method->is_static(),
615                       _value_state,
616                       _value);
617 }
< prev index next >