# HG changeset patch # User goetz # Date 1378475512 -7200 # Node ID 0cd8111baec7cc4457b69f67c726c66300712eef # Parent 7687c56b66939cc43053ce12efbc5aeb3e02fdbf 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 in PhaseIdealLoop::intrinsify_fill(). diff --git a/src/cpu/ppc/vm/sharedRuntime_ppc.cpp b/src/cpu/ppc/vm/sharedRuntime_ppc.cpp --- a/src/cpu/ppc/vm/sharedRuntime_ppc.cpp +++ b/src/cpu/ppc/vm/sharedRuntime_ppc.cpp @@ -734,11 +734,8 @@ // We must cast ints to longs and use full 64 bit stack slots // here. We do the cast in GraphKit::gen_stub() and just guard // here against loosing that change. - Unimplemented(); // TODO: PPC port - /* assert(SharedRuntime::c_calling_convention_requires_ints_as_longs(), "argument of type int should be promoted to type long"); - */ guarantee(i > 0 && sig_bt[i-1] == T_LONG, "argument of type (bt) should have been promoted to type (T_LONG,bt) for bt in " "{T_BOOLEAN, T_CHAR, T_BYTE, T_SHORT, T_INT}"); @@ -830,6 +827,74 @@ } #endif // COMPILER2 +// Do we need to convert ints to longs for c calls? +bool SharedRuntime::c_calling_convention_requires_ints_as_longs() { + return true; +} + +// This is platform independent, but only needed on PPC64 so far. +static int convert_ints_to_longints_argcnt(int in_args_count, BasicType* in_sig_bt) { + assert(SharedRuntime::c_calling_convention_requires_ints_as_longs(), ""); + + int argcnt = in_args_count; + for (int in = 0; in < in_args_count; in++) { + BasicType bt = in_sig_bt[in]; + switch (bt) { + case T_BOOLEAN: + case T_CHAR: + case T_BYTE: + case T_SHORT: + case T_INT: + argcnt++; + break; + default: + break; + } + } + + return argcnt; +} + +// This is platform independent, but only needed on PPC64 so far. +static void SharedRuntime::convert_ints_to_longints(int i2l_argcnt, int& in_args_count, + BasicType*& in_sig_bt, VMRegPair*& in_regs) { + assert(SharedRuntime::c_calling_convention_requires_ints_as_longs(), ""); + + VMRegPair *new_in_regs = NEW_RESOURCE_ARRAY(VMRegPair, i2l_argcnt); + BasicType *new_in_sig_bt = NEW_RESOURCE_ARRAY(BasicType, i2l_argcnt); + + int argcnt = 0; + for (int in = 0; in < in_args_count; in++, argcnt++) { + BasicType bt = in_sig_bt[in]; + VMRegPair reg = in_regs[in]; + switch (bt) { + case T_BOOLEAN: + case T_CHAR: + case T_BYTE: + case T_SHORT: + case T_INT: + // convert (bt) to (T_LONG,bt) + new_in_sig_bt[argcnt ] = T_LONG; + new_in_sig_bt[argcnt+1] = bt; + assert(reg.first()->is_valid() && !reg.second()->is_valid(), ""); + new_in_regs[argcnt ].set2(reg.first()); + new_in_regs[argcnt+1].set_bad(); + argcnt++; + break; + default: + // no conversion needed + new_in_sig_bt[argcnt] = bt; + new_in_regs[argcnt] = reg; + break; + } + } + assert(argcnt == i2l_argcnt, "must match"); + + in_regs = new_in_regs; + in_sig_bt = new_in_sig_bt; + in_args_count = i2l_argcnt; +} + static address gen_c2i_adapter(MacroAssembler *masm, int total_args_passed, int comp_args_on_stack, diff --git a/src/cpu/sparc/vm/sharedRuntime_sparc.cpp b/src/cpu/sparc/vm/sharedRuntime_sparc.cpp --- a/src/cpu/sparc/vm/sharedRuntime_sparc.cpp +++ b/src/cpu/sparc/vm/sharedRuntime_sparc.cpp @@ -1228,6 +1228,10 @@ } +// Do we need to convert ints to longs for c calls? +bool SharedRuntime::c_calling_convention_requires_ints_as_longs() { + return false; +} // --------------------------------------------------------------------------- void SharedRuntime::save_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) { diff --git a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp --- a/src/cpu/x86/vm/sharedRuntime_x86_32.cpp +++ b/src/cpu/x86/vm/sharedRuntime_x86_32.cpp @@ -1015,6 +1015,11 @@ return stack; } +// Do we need to convert ints to longs for c calls? +bool SharedRuntime::c_calling_convention_requires_ints_as_longs() { + return false; +} + // A simple move of integer like type static void simple_move32(MacroAssembler* masm, VMRegPair src, VMRegPair dst) { if (src.first()->is_stack()) { diff --git a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp --- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp +++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp @@ -1000,6 +1000,11 @@ return stk_args; } +// Do we need to convert ints to longs for c calls? +bool SharedRuntime::c_calling_convention_requires_ints_as_longs() { + return false; +} + // On 64 bit we will store integer like items to the stack as // 64 bits items (sparc abi) even though java would only store // 32bits for a parameter. On 32bit it will simply be 32 bits diff --git a/src/cpu/zero/vm/sharedRuntime_zero.cpp b/src/cpu/zero/vm/sharedRuntime_zero.cpp --- a/src/cpu/zero/vm/sharedRuntime_zero.cpp +++ b/src/cpu/zero/vm/sharedRuntime_zero.cpp @@ -139,3 +139,8 @@ ShouldNotCallThis(); return 0; } + +// Do we need to convert ints to longs for c calls? +bool SharedRuntime::c_calling_convention_requires_ints_as_longs() { + ShouldNotCallThis(); +} diff --git a/src/share/vm/opto/generateOptoStub.cpp b/src/share/vm/opto/generateOptoStub.cpp --- a/src/share/vm/opto/generateOptoStub.cpp +++ b/src/share/vm/opto/generateOptoStub.cpp @@ -46,6 +46,10 @@ bool return_pc) { ResourceMark rm; + // Do we need to convert ints to longs for c calls? + const bool convert_ints_to_longs = + SharedRuntime::c_calling_convention_requires_ints_as_longs(); + const TypeTuple *jdomain = C->tf()->domain(); const TypeTuple *jrange = C->tf()->range(); @@ -117,8 +121,16 @@ uint cnt = TypeFunc::Parms; // The C routines gets the base of thread-local storage passed in as an // extra argument. Not all calls need it, but its cheap to add here. - for( ; cntfield_at(cnt); + for (uint pcnt = cnt; pcnt < parm_cnt; pcnt++, cnt++) { + // Convert ints to longs if required. + if (convert_ints_to_longs && jdomain->field_at(pcnt)->isa_int()) { + fields[cnt++] = TypeLong::LONG; + fields[cnt] = Type::HALF; // must add an additional half for a long + } else { + fields[cnt] = jdomain->field_at(pcnt); + } + } + fields[cnt++] = TypeRawPtr::BOTTOM; // Thread-local storage // Also pass in the caller's PC, if asked for. if( return_pc ) @@ -169,12 +181,20 @@ // Set fixed predefined input arguments cnt = 0; - for( i=0; iinit_req( cnt++, map()->in(i) ); + for (i = 0; i < TypeFunc::Parms; i++) + call->init_req(cnt++, map()->in(i)); // A little too aggressive on the parm copy; return address is not an input call->set_req(TypeFunc::ReturnAdr, top()); - for( ; iinit_req( cnt++, map()->in(i) ); + for (; i < parm_cnt; i++) { // Regular input arguments + // Convert ints to longs if required. + if (convert_ints_to_longs && jdomain->field_at(i)->isa_int()) { + Node* int_as_long = _gvn.transform(new (C) ConvI2LNode(map()->in(i))); + call->init_req(cnt++, int_as_long); // long + call->init_req(cnt++, top()); // half + } else { + call->init_req(cnt++, map()->in(i)); + } + } call->init_req( cnt++, thread ); if( return_pc ) // Return PC, if asked for diff --git a/src/share/vm/opto/loopTransform.cpp b/src/share/vm/opto/loopTransform.cpp --- a/src/share/vm/opto/loopTransform.cpp +++ b/src/share/vm/opto/loopTransform.cpp @@ -2692,21 +2692,32 @@ _igvn.register_new_node_with_optimizer(store_value); } + if (SharedRuntime::c_calling_convention_requires_ints_as_longs() && + // see StubRoutines::select_fill_function for types. FLOAT has been converted to INT + (t == T_FLOAT || t == T_INT || is_subword_type(t))) { + store_value = new (C) ConvI2LNode(store_value); + _igvn.register_new_node_with_optimizer(store_value); + } + Node* mem_phi = store->in(MemNode::Memory); Node* result_ctrl; Node* result_mem; const TypeFunc* call_type = OptoRuntime::array_fill_Type(); CallLeafNode *call = new (C) CallLeafNoFPNode(call_type, fill, fill_name, TypeAryPtr::get_array_body_type(t)); - call->init_req(TypeFunc::Parms+0, from); - call->init_req(TypeFunc::Parms+1, store_value); + uint cnt = 0; + call->init_req(TypeFunc::Parms + cnt++, from); + call->init_req(TypeFunc::Parms + cnt++, store_value); + if (SharedRuntime::c_calling_convention_requires_ints_as_longs()) { + call->init_req(TypeFunc::Parms + cnt++, C->top()); + } #ifdef _LP64 len = new (C) ConvI2LNode(len); _igvn.register_new_node_with_optimizer(len); #endif - call->init_req(TypeFunc::Parms+2, len); + call->init_req(TypeFunc::Parms + cnt++, len); #ifdef _LP64 - call->init_req(TypeFunc::Parms+3, C->top()); + call->init_req(TypeFunc::Parms + cnt++, C->top()); #endif call->init_req( TypeFunc::Control, head->init_control()); call->init_req( TypeFunc::I_O , C->top() ) ; // does no i/o diff --git a/src/share/vm/opto/runtime.cpp b/src/share/vm/opto/runtime.cpp --- a/src/share/vm/opto/runtime.cpp +++ b/src/share/vm/opto/runtime.cpp @@ -795,11 +795,19 @@ const TypeFunc* OptoRuntime::array_fill_Type() { + const Type** fields; + int argp = TypeFunc::Parms; // create input type (domain): pointer, int, size_t - const Type** fields = TypeTuple::fields(3 LP64_ONLY( + 1)); - int argp = TypeFunc::Parms; - fields[argp++] = TypePtr::NOTNULL; - fields[argp++] = TypeInt::INT; + if (SharedRuntime::c_calling_convention_requires_ints_as_longs()) { + fields = TypeTuple::fields(3 LP64_ONLY( + 2)); + fields[argp++] = TypePtr::NOTNULL; + fields[argp++] = TypeLong::LONG; + fields[argp++] = Type::HALF; + } else { + fields = TypeTuple::fields(3 LP64_ONLY( + 1)); + fields[argp++] = TypePtr::NOTNULL; + fields[argp++] = TypeInt::INT; + } fields[argp++] = TypeX_X; // size in whatevers (size_t) LP64_ONLY(fields[argp++] = Type::HALF); // other half of long length const TypeTuple *domain = TypeTuple::make(argp, fields); diff --git a/src/share/vm/runtime/sharedRuntime.hpp b/src/share/vm/runtime/sharedRuntime.hpp --- a/src/share/vm/runtime/sharedRuntime.hpp +++ b/src/share/vm/runtime/sharedRuntime.hpp @@ -358,6 +358,11 @@ // Ditto except for calling C static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed); + // Querry whether this platforms requires that 32 bit integers are + // passed as 64 bit wide entities in C calls. (This is the case on PPC + // and z/Arch.) + static bool c_calling_convention_requires_ints_as_longs(); + // Generate I2C and C2I adapters. These adapters are simple argument marshalling // blobs. Unlike adapters in the tiger and earlier releases the code in these // blobs does not create a new frame and are therefore virtually invisible @@ -370,7 +375,7 @@ // location for the interpreter to record. This is used by the frame code // to correct the sender code to match up with the stack pointer when the // thread left the compiled code. In addition it allows the interpreter - // to remove the space the c2i adapter allocated to do it argument conversion. + // to remove the space the c2i adapter allocated to do its argument conversion. // Although a c2i blob will always run interpreted even if compiled code is // present if we see that compiled code is present the compiled call site