src/share/vm/opto/generateOptoStub.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().


 100   // Always do this after the other "last_Java_frame" fields are set since
 101   // as soon as last_Java_sp != NULL the has_last_Java_frame is true and
 102   // users will look at the other fields.
 103   //
 104   Node *adr_sp = basic_plus_adr(top(), thread, in_bytes(JavaThread::last_Java_sp_offset()));
 105   Node *last_sp = basic_plus_adr(top(), frameptr(), (intptr_t) STACK_BIAS);
 106   store_to_memory(NULL, adr_sp, last_sp, T_ADDRESS, NoAlias);
 107 
 108   // Set _thread_in_native
 109   // The order of stores into TLS is critical!  Setting _thread_in_native MUST
 110   // be last, because a GC is allowed at any time after setting it and the GC
 111   // will require last_Java_pc and last_Java_sp.
 112   Node* adr_state = basic_plus_adr(top(), thread, in_bytes(JavaThread::thread_state_offset()));
 113 
 114   //-----------------------------
 115   // Compute signature for C call.  Varies from the Java signature!
 116   const Type **fields = TypeTuple::fields(2*parm_cnt+2);
 117   uint cnt = TypeFunc::Parms;
 118   // The C routines gets the base of thread-local storage passed in as an
 119   // extra argument.  Not all calls need it, but its cheap to add here.
 120   for( ; cnt<parm_cnt; cnt++ )
 121     fields[cnt] = jdomain->field_at(cnt);








 122   fields[cnt++] = TypeRawPtr::BOTTOM; // Thread-local storage
 123   // Also pass in the caller's PC, if asked for.
 124   if( return_pc )
 125     fields[cnt++] = TypeRawPtr::BOTTOM; // Return PC
 126 
 127   const TypeTuple* domain = TypeTuple::make(cnt,fields);
 128   // The C routine we are about to call cannot return an oop; it can block on
 129   // exit and a GC will trash the oop while it sits in C-land.  Instead, we
 130   // return the oop through TLS for runtime calls.
 131   // Also, C routines returning integer subword values leave the high
 132   // order bits dirty; these must be cleaned up by explicit sign extension.
 133   const Type* retval = (jrange->cnt() == TypeFunc::Parms) ? Type::TOP : jrange->field_at(TypeFunc::Parms);
 134   // Make a private copy of jrange->fields();
 135   const Type **rfields = TypeTuple::fields(jrange->cnt() - TypeFunc::Parms);
 136   // Fixup oop returns
 137   int retval_ptr = retval->isa_oop_ptr();
 138   if( retval_ptr ) {
 139     assert( pass_tls, "Oop must be returned thru TLS" );
 140     // Fancy-jumps return address; others return void
 141     rfields[TypeFunc::Parms] = is_fancy_jump ? TypeRawPtr::BOTTOM : Type::TOP;


 152       rfields[TypeFunc::Parms+1] = jrange->field_at(TypeFunc::Parms+1);
 153   }
 154   const TypeTuple* range = TypeTuple::make(jrange->cnt(),rfields);
 155 
 156   // Final C signature
 157   const TypeFunc *c_sig = TypeFunc::make(domain,range);
 158 
 159   //-----------------------------
 160   // Make the call node
 161   CallRuntimeNode *call = new (C)
 162     CallRuntimeNode(c_sig, C_function, name, TypePtr::BOTTOM);
 163   //-----------------------------
 164 
 165   // Fix-up the debug info for the call
 166   call->set_jvms( new (C) JVMState(0) );
 167   call->jvms()->set_bci(0);
 168   call->jvms()->set_offsets(cnt);
 169 
 170   // Set fixed predefined input arguments
 171   cnt = 0;
 172   for( i=0; i<TypeFunc::Parms; i++ )
 173     call->init_req( cnt++, map()->in(i) );
 174   // A little too aggressive on the parm copy; return address is not an input
 175   call->set_req(TypeFunc::ReturnAdr, top());
 176   for( ; i<parm_cnt; i++ )    // Regular input arguments
 177     call->init_req( cnt++, map()->in(i) );








 178 
 179   call->init_req( cnt++, thread );
 180   if( return_pc )             // Return PC, if asked for
 181     call->init_req( cnt++, returnadr() );
 182   _gvn.transform_no_reclaim(call);
 183 
 184 
 185   //-----------------------------
 186   // Now set up the return results
 187   set_control( _gvn.transform( new (C) ProjNode(call,TypeFunc::Control)) );
 188   set_i_o(     _gvn.transform( new (C) ProjNode(call,TypeFunc::I_O    )) );
 189   set_all_memory_call(call);
 190   if (range->cnt() > TypeFunc::Parms) {
 191     Node* retnode = _gvn.transform( new (C) ProjNode(call,TypeFunc::Parms) );
 192     // C-land is allowed to return sub-word values.  Convert to integer type.
 193     assert( retval != Type::TOP, "" );
 194     if (retval == TypeInt::BOOL) {
 195       retnode = _gvn.transform( new (C) AndINode(retnode, intcon(0xFF)) );
 196     } else if (retval == TypeInt::CHAR) {
 197       retnode = _gvn.transform( new (C) AndINode(retnode, intcon(0xFFFF)) );




 100   // Always do this after the other "last_Java_frame" fields are set since
 101   // as soon as last_Java_sp != NULL the has_last_Java_frame is true and
 102   // users will look at the other fields.
 103   //
 104   Node *adr_sp = basic_plus_adr(top(), thread, in_bytes(JavaThread::last_Java_sp_offset()));
 105   Node *last_sp = basic_plus_adr(top(), frameptr(), (intptr_t) STACK_BIAS);
 106   store_to_memory(NULL, adr_sp, last_sp, T_ADDRESS, NoAlias);
 107 
 108   // Set _thread_in_native
 109   // The order of stores into TLS is critical!  Setting _thread_in_native MUST
 110   // be last, because a GC is allowed at any time after setting it and the GC
 111   // will require last_Java_pc and last_Java_sp.
 112   Node* adr_state = basic_plus_adr(top(), thread, in_bytes(JavaThread::thread_state_offset()));
 113 
 114   //-----------------------------
 115   // Compute signature for C call.  Varies from the Java signature!
 116   const Type **fields = TypeTuple::fields(2*parm_cnt+2);
 117   uint cnt = TypeFunc::Parms;
 118   // The C routines gets the base of thread-local storage passed in as an
 119   // extra argument.  Not all calls need it, but its cheap to add here.
 120   for (uint pcnt = cnt; pcnt < parm_cnt; pcnt++, cnt++) {
 121     // Convert ints to longs if required.
 122     if (CCallingConventionRequiresIntsAsLongs && jdomain->field_at(pcnt)->isa_int()) {
 123       fields[cnt++] = TypeLong::LONG;
 124       fields[cnt]   = Type::HALF; // must add an additional half for a long
 125     } else {
 126       fields[cnt] = jdomain->field_at(pcnt);
 127     }
 128   }
 129 
 130   fields[cnt++] = TypeRawPtr::BOTTOM; // Thread-local storage
 131   // Also pass in the caller's PC, if asked for.
 132   if( return_pc )
 133     fields[cnt++] = TypeRawPtr::BOTTOM; // Return PC
 134 
 135   const TypeTuple* domain = TypeTuple::make(cnt,fields);
 136   // The C routine we are about to call cannot return an oop; it can block on
 137   // exit and a GC will trash the oop while it sits in C-land.  Instead, we
 138   // return the oop through TLS for runtime calls.
 139   // Also, C routines returning integer subword values leave the high
 140   // order bits dirty; these must be cleaned up by explicit sign extension.
 141   const Type* retval = (jrange->cnt() == TypeFunc::Parms) ? Type::TOP : jrange->field_at(TypeFunc::Parms);
 142   // Make a private copy of jrange->fields();
 143   const Type **rfields = TypeTuple::fields(jrange->cnt() - TypeFunc::Parms);
 144   // Fixup oop returns
 145   int retval_ptr = retval->isa_oop_ptr();
 146   if( retval_ptr ) {
 147     assert( pass_tls, "Oop must be returned thru TLS" );
 148     // Fancy-jumps return address; others return void
 149     rfields[TypeFunc::Parms] = is_fancy_jump ? TypeRawPtr::BOTTOM : Type::TOP;


 160       rfields[TypeFunc::Parms+1] = jrange->field_at(TypeFunc::Parms+1);
 161   }
 162   const TypeTuple* range = TypeTuple::make(jrange->cnt(),rfields);
 163 
 164   // Final C signature
 165   const TypeFunc *c_sig = TypeFunc::make(domain,range);
 166 
 167   //-----------------------------
 168   // Make the call node
 169   CallRuntimeNode *call = new (C)
 170     CallRuntimeNode(c_sig, C_function, name, TypePtr::BOTTOM);
 171   //-----------------------------
 172 
 173   // Fix-up the debug info for the call
 174   call->set_jvms( new (C) JVMState(0) );
 175   call->jvms()->set_bci(0);
 176   call->jvms()->set_offsets(cnt);
 177 
 178   // Set fixed predefined input arguments
 179   cnt = 0;
 180   for (i = 0; i < TypeFunc::Parms; i++)
 181     call->init_req(cnt++, map()->in(i));
 182   // A little too aggressive on the parm copy; return address is not an input
 183   call->set_req(TypeFunc::ReturnAdr, top());
 184   for (; i < parm_cnt; i++) { // Regular input arguments
 185     // Convert ints to longs if required.
 186     if (CCallingConventionRequiresIntsAsLongs && jdomain->field_at(i)->isa_int()) {
 187       Node* int_as_long = _gvn.transform(new (C) ConvI2LNode(map()->in(i)));
 188       call->init_req(cnt++, int_as_long); // long
 189       call->init_req(cnt++, top());       // half
 190     } else {
 191       call->init_req(cnt++, map()->in(i));
 192     }
 193   }
 194 
 195   call->init_req( cnt++, thread );
 196   if( return_pc )             // Return PC, if asked for
 197     call->init_req( cnt++, returnadr() );
 198   _gvn.transform_no_reclaim(call);
 199 
 200 
 201   //-----------------------------
 202   // Now set up the return results
 203   set_control( _gvn.transform( new (C) ProjNode(call,TypeFunc::Control)) );
 204   set_i_o(     _gvn.transform( new (C) ProjNode(call,TypeFunc::I_O    )) );
 205   set_all_memory_call(call);
 206   if (range->cnt() > TypeFunc::Parms) {
 207     Node* retnode = _gvn.transform( new (C) ProjNode(call,TypeFunc::Parms) );
 208     // C-land is allowed to return sub-word values.  Convert to integer type.
 209     assert( retval != Type::TOP, "" );
 210     if (retval == TypeInt::BOOL) {
 211       retnode = _gvn.transform( new (C) AndINode(retnode, intcon(0xFF)) );
 212     } else if (retval == TypeInt::CHAR) {
 213       retnode = _gvn.transform( new (C) AndINode(retnode, intcon(0xFFFF)) );