src/share/vm/runtime/sharedRuntime.cpp

Print this page
rev 5190 : 8024342: PPC64 (part 111): Support for C calling conventions that require 64-bit ints.
Summary: Some platforms, as ppc and s390x/zArch require that 32-bit ints are passed as 64-bit values to C functions. This change adds support to adapt the signature and to issue proper casts to c2-compiled stubs. The functions are used in generate_native_wrapper(). Adapt signature used by the compiler as in PhaseIdealLoop::intrinsify_fill().


2697 
2698       // Generate the compiled-to-native wrapper code
2699       nm = SharedRuntime::generate_dtrace_nmethod(&_masm, method);
2700     }
2701   }
2702   return nm;
2703 }
2704 
2705 // the dtrace method needs to convert java lang string to utf8 string.
2706 void SharedRuntime::get_utf(oopDesc* src, address dst) {
2707   typeArrayOop jlsValue  = java_lang_String::value(src);
2708   int          jlsOffset = java_lang_String::offset(src);
2709   int          jlsLen    = java_lang_String::length(src);
2710   jchar*       jlsPos    = (jlsLen == 0) ? NULL :
2711                                            jlsValue->char_at_addr(jlsOffset);
2712   assert(TypeArrayKlass::cast(jlsValue->klass())->element_type() == T_CHAR, "compressed string");
2713   (void) UNICODE::as_utf8(jlsPos, jlsLen, (char *)dst, max_dtrace_string_size);
2714 }
2715 #endif // ndef HAVE_DTRACE_H
2716 

































































2717 // -------------------------------------------------------------------------
2718 // Java-Java calling convention
2719 // (what you use when Java calls Java)
2720 
2721 //------------------------------name_for_receiver----------------------------------
2722 // For a given signature, return the VMReg for parameter 0.
2723 VMReg SharedRuntime::name_for_receiver() {
2724   VMRegPair regs;
2725   BasicType sig_bt = T_OBJECT;
2726   (void) java_calling_convention(&sig_bt, &regs, 1, true);
2727   // Return argument 0 register.  In the LP64 build pointers
2728   // take 2 registers, but the VM wants only the 'main' name.
2729   return regs.first();
2730 }
2731 
2732 VMRegPair *SharedRuntime::find_callee_arguments(Symbol* sig, bool has_receiver, bool has_appendix, int* arg_size) {
2733   // This method is returning a data structure allocating as a
2734   // ResourceObject, so do not put any ResourceMarks in here.
2735   char *s = sig->as_C_string();
2736   int len = (int)strlen(s);




2697 
2698       // Generate the compiled-to-native wrapper code
2699       nm = SharedRuntime::generate_dtrace_nmethod(&_masm, method);
2700     }
2701   }
2702   return nm;
2703 }
2704 
2705 // the dtrace method needs to convert java lang string to utf8 string.
2706 void SharedRuntime::get_utf(oopDesc* src, address dst) {
2707   typeArrayOop jlsValue  = java_lang_String::value(src);
2708   int          jlsOffset = java_lang_String::offset(src);
2709   int          jlsLen    = java_lang_String::length(src);
2710   jchar*       jlsPos    = (jlsLen == 0) ? NULL :
2711                                            jlsValue->char_at_addr(jlsOffset);
2712   assert(TypeArrayKlass::cast(jlsValue->klass())->element_type() == T_CHAR, "compressed string");
2713   (void) UNICODE::as_utf8(jlsPos, jlsLen, (char *)dst, max_dtrace_string_size);
2714 }
2715 #endif // ndef HAVE_DTRACE_H
2716 
2717 int SharedRuntime::convert_ints_to_longints_argcnt(int in_args_count, BasicType* in_sig_bt) {
2718   int argcnt = in_args_count;
2719   if (CCallingConventionRequiresIntsAsLongs) {
2720     for (int in = 0; in < in_args_count; in++) {
2721       BasicType bt = in_sig_bt[in];
2722       switch (bt) {
2723         case T_BOOLEAN:
2724         case T_CHAR:
2725         case T_BYTE:
2726         case T_SHORT:
2727         case T_INT:
2728           argcnt++;
2729           break;
2730         default:
2731           break;
2732       }
2733     }
2734   } else {
2735     assert(0, "This should not be needed on this platform");
2736   }
2737 
2738   return argcnt;
2739 }
2740 
2741 void SharedRuntime::convert_ints_to_longints(int i2l_argcnt, int& in_args_count,
2742                                              BasicType*& in_sig_bt, VMRegPair*& in_regs) {
2743   if (CCallingConventionRequiresIntsAsLongs) {
2744     VMRegPair *new_in_regs   = NEW_RESOURCE_ARRAY(VMRegPair, i2l_argcnt);
2745     BasicType *new_in_sig_bt = NEW_RESOURCE_ARRAY(BasicType, i2l_argcnt);
2746 
2747     int argcnt = 0;
2748     for (int in = 0; in < in_args_count; in++, argcnt++) {
2749       BasicType bt  = in_sig_bt[in];
2750       VMRegPair reg = in_regs[in];
2751       switch (bt) {
2752         case T_BOOLEAN:
2753         case T_CHAR:
2754         case T_BYTE:
2755         case T_SHORT:
2756         case T_INT:
2757           // Convert (bt) to (T_LONG,bt).
2758           new_in_sig_bt[argcnt  ] = T_LONG;
2759           new_in_sig_bt[argcnt+1] = bt;
2760           assert(reg.first()->is_valid() && !reg.second()->is_valid(), "");
2761           new_in_regs[argcnt  ].set2(reg.first());
2762           new_in_regs[argcnt+1].set_bad();
2763           argcnt++;
2764           break;
2765         default:
2766           // No conversion needed.
2767           new_in_sig_bt[argcnt] = bt;
2768           new_in_regs[argcnt]   = reg;
2769           break;
2770       }
2771     }
2772     assert(argcnt == i2l_argcnt, "must match");
2773 
2774     in_regs = new_in_regs;
2775     in_sig_bt = new_in_sig_bt;
2776     in_args_count = i2l_argcnt;
2777   } else {
2778     assert(0, "This should not be needed on this platform");
2779   }
2780 }
2781 
2782 // -------------------------------------------------------------------------
2783 // Java-Java calling convention
2784 // (what you use when Java calls Java)
2785 
2786 //------------------------------name_for_receiver----------------------------------
2787 // For a given signature, return the VMReg for parameter 0.
2788 VMReg SharedRuntime::name_for_receiver() {
2789   VMRegPair regs;
2790   BasicType sig_bt = T_OBJECT;
2791   (void) java_calling_convention(&sig_bt, &regs, 1, true);
2792   // Return argument 0 register.  In the LP64 build pointers
2793   // take 2 registers, but the VM wants only the 'main' name.
2794   return regs.first();
2795 }
2796 
2797 VMRegPair *SharedRuntime::find_callee_arguments(Symbol* sig, bool has_receiver, bool has_appendix, int* arg_size) {
2798   // This method is returning a data structure allocating as a
2799   // ResourceObject, so do not put any ResourceMarks in here.
2800   char *s = sig->as_C_string();
2801   int len = (int)strlen(s);