src/share/vm/opto/generateOptoStub.cpp

Wed, 24 Apr 2013 20:55:28 -0400

author
dlong
date
Wed, 24 Apr 2013 20:55:28 -0400
changeset 5000
a6e09d6dd8e5
parent 4535
9fae07c31641
child 5626
766fac3395d6
child 6453
75ef1a499665
permissions
-rw-r--r--

8003853: specify offset of IC load in java_to_interp stub
Summary: refactored code to allow platform-specific differences
Reviewed-by: dlong, twisti
Contributed-by: Goetz Lindenmaier <goetz.lindenmaier@sap.com>

duke@435 1 /*
mikael@4153 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "opto/addnode.hpp"
stefank@2314 27 #include "opto/callnode.hpp"
stefank@2314 28 #include "opto/cfgnode.hpp"
stefank@2314 29 #include "opto/compile.hpp"
stefank@2314 30 #include "opto/connode.hpp"
stefank@2314 31 #include "opto/locknode.hpp"
stefank@2314 32 #include "opto/memnode.hpp"
stefank@2314 33 #include "opto/mulnode.hpp"
stefank@2314 34 #include "opto/node.hpp"
stefank@2314 35 #include "opto/parse.hpp"
stefank@2314 36 #include "opto/phaseX.hpp"
stefank@2314 37 #include "opto/rootnode.hpp"
stefank@2314 38 #include "opto/runtime.hpp"
stefank@2314 39 #include "opto/type.hpp"
duke@435 40
duke@435 41 //--------------------gen_stub-------------------------------
duke@435 42 void GraphKit::gen_stub(address C_function,
duke@435 43 const char *name,
duke@435 44 int is_fancy_jump,
duke@435 45 bool pass_tls,
duke@435 46 bool return_pc) {
duke@435 47 ResourceMark rm;
duke@435 48
duke@435 49 const TypeTuple *jdomain = C->tf()->domain();
duke@435 50 const TypeTuple *jrange = C->tf()->range();
duke@435 51
duke@435 52 // The procedure start
kvn@4115 53 StartNode* start = new (C) StartNode(root(), jdomain);
duke@435 54 _gvn.set_type_bottom(start);
duke@435 55
duke@435 56 // Make a map, with JVM state
duke@435 57 uint parm_cnt = jdomain->cnt();
duke@435 58 uint max_map = MAX2(2*parm_cnt+1, jrange->cnt());
duke@435 59 // %%% SynchronizationEntryBCI is redundant; use InvocationEntryBci in interfaces
duke@435 60 assert(SynchronizationEntryBCI == InvocationEntryBci, "");
duke@435 61 JVMState* jvms = new (C) JVMState(0);
duke@435 62 jvms->set_bci(InvocationEntryBci);
duke@435 63 jvms->set_monoff(max_map);
duke@435 64 jvms->set_endoff(max_map);
duke@435 65 {
kvn@4115 66 SafePointNode *map = new (C) SafePointNode( max_map, jvms );
duke@435 67 jvms->set_map(map);
duke@435 68 set_jvms(jvms);
duke@435 69 assert(map == this->map(), "kit.map is set");
duke@435 70 }
duke@435 71
duke@435 72 // Make up the parameters
duke@435 73 uint i;
duke@435 74 for( i = 0; i < parm_cnt; i++ )
kvn@4115 75 map()->init_req(i, _gvn.transform(new (C) ParmNode(start, i)));
duke@435 76 for( ; i<map()->req(); i++ )
duke@435 77 map()->init_req(i, top()); // For nicer debugging
duke@435 78
duke@435 79 // GraphKit requires memory to be a MergeMemNode:
duke@435 80 set_all_memory(map()->memory());
duke@435 81
duke@435 82 // Get base of thread-local storage area
kvn@4115 83 Node* thread = _gvn.transform( new (C) ThreadLocalNode() );
duke@435 84
duke@435 85 const int NoAlias = Compile::AliasIdxBot;
duke@435 86
duke@435 87 Node* adr_last_Java_pc = basic_plus_adr(top(),
duke@435 88 thread,
duke@435 89 in_bytes(JavaThread::frame_anchor_offset()) +
duke@435 90 in_bytes(JavaFrameAnchor::last_Java_pc_offset()));
morris@4535 91 #if defined(SPARC)
duke@435 92 Node* adr_flags = basic_plus_adr(top(),
duke@435 93 thread,
duke@435 94 in_bytes(JavaThread::frame_anchor_offset()) +
duke@435 95 in_bytes(JavaFrameAnchor::flags_offset()));
morris@4535 96 #endif /* defined(SPARC) */
duke@435 97
duke@435 98
duke@435 99 // Drop in the last_Java_sp. last_Java_fp is not touched.
duke@435 100 // Always do this after the other "last_Java_frame" fields are set since
duke@435 101 // as soon as last_Java_sp != NULL the has_last_Java_frame is true and
duke@435 102 // users will look at the other fields.
duke@435 103 //
duke@435 104 Node *adr_sp = basic_plus_adr(top(), thread, in_bytes(JavaThread::last_Java_sp_offset()));
duke@435 105 Node *last_sp = basic_plus_adr(top(), frameptr(), (intptr_t) STACK_BIAS);
duke@435 106 store_to_memory(NULL, adr_sp, last_sp, T_ADDRESS, NoAlias);
duke@435 107
duke@435 108 // Set _thread_in_native
duke@435 109 // The order of stores into TLS is critical! Setting _thread_in_native MUST
duke@435 110 // be last, because a GC is allowed at any time after setting it and the GC
duke@435 111 // will require last_Java_pc and last_Java_sp.
duke@435 112 Node* adr_state = basic_plus_adr(top(), thread, in_bytes(JavaThread::thread_state_offset()));
duke@435 113
duke@435 114 //-----------------------------
duke@435 115 // Compute signature for C call. Varies from the Java signature!
duke@435 116 const Type **fields = TypeTuple::fields(2*parm_cnt+2);
duke@435 117 uint cnt = TypeFunc::Parms;
duke@435 118 // The C routines gets the base of thread-local storage passed in as an
duke@435 119 // extra argument. Not all calls need it, but its cheap to add here.
duke@435 120 for( ; cnt<parm_cnt; cnt++ )
duke@435 121 fields[cnt] = jdomain->field_at(cnt);
duke@435 122 fields[cnt++] = TypeRawPtr::BOTTOM; // Thread-local storage
duke@435 123 // Also pass in the caller's PC, if asked for.
duke@435 124 if( return_pc )
duke@435 125 fields[cnt++] = TypeRawPtr::BOTTOM; // Return PC
duke@435 126
duke@435 127 const TypeTuple* domain = TypeTuple::make(cnt,fields);
duke@435 128 // The C routine we are about to call cannot return an oop; it can block on
duke@435 129 // exit and a GC will trash the oop while it sits in C-land. Instead, we
duke@435 130 // return the oop through TLS for runtime calls.
duke@435 131 // Also, C routines returning integer subword values leave the high
duke@435 132 // order bits dirty; these must be cleaned up by explicit sign extension.
duke@435 133 const Type* retval = (jrange->cnt() == TypeFunc::Parms) ? Type::TOP : jrange->field_at(TypeFunc::Parms);
duke@435 134 // Make a private copy of jrange->fields();
duke@435 135 const Type **rfields = TypeTuple::fields(jrange->cnt() - TypeFunc::Parms);
duke@435 136 // Fixup oop returns
duke@435 137 int retval_ptr = retval->isa_oop_ptr();
duke@435 138 if( retval_ptr ) {
duke@435 139 assert( pass_tls, "Oop must be returned thru TLS" );
duke@435 140 // Fancy-jumps return address; others return void
duke@435 141 rfields[TypeFunc::Parms] = is_fancy_jump ? TypeRawPtr::BOTTOM : Type::TOP;
duke@435 142
duke@435 143 } else if( retval->isa_int() ) { // Returning any integer subtype?
duke@435 144 // "Fatten" byte, char & short return types to 'int' to show that
duke@435 145 // the native C code can return values with junk high order bits.
duke@435 146 // We'll sign-extend it below later.
duke@435 147 rfields[TypeFunc::Parms] = TypeInt::INT; // It's "dirty" and needs sign-ext
duke@435 148
duke@435 149 } else if( jrange->cnt() >= TypeFunc::Parms+1 ) { // Else copy other types
duke@435 150 rfields[TypeFunc::Parms] = jrange->field_at(TypeFunc::Parms);
duke@435 151 if( jrange->cnt() == TypeFunc::Parms+2 )
duke@435 152 rfields[TypeFunc::Parms+1] = jrange->field_at(TypeFunc::Parms+1);
duke@435 153 }
duke@435 154 const TypeTuple* range = TypeTuple::make(jrange->cnt(),rfields);
duke@435 155
duke@435 156 // Final C signature
duke@435 157 const TypeFunc *c_sig = TypeFunc::make(domain,range);
duke@435 158
duke@435 159 //-----------------------------
duke@435 160 // Make the call node
kvn@4115 161 CallRuntimeNode *call = new (C)
duke@435 162 CallRuntimeNode(c_sig, C_function, name, TypePtr::BOTTOM);
duke@435 163 //-----------------------------
duke@435 164
duke@435 165 // Fix-up the debug info for the call
duke@435 166 call->set_jvms( new (C) JVMState(0) );
duke@435 167 call->jvms()->set_bci(0);
duke@435 168 call->jvms()->set_offsets(cnt);
duke@435 169
duke@435 170 // Set fixed predefined input arguments
duke@435 171 cnt = 0;
duke@435 172 for( i=0; i<TypeFunc::Parms; i++ )
duke@435 173 call->init_req( cnt++, map()->in(i) );
duke@435 174 // A little too aggressive on the parm copy; return address is not an input
duke@435 175 call->set_req(TypeFunc::ReturnAdr, top());
duke@435 176 for( ; i<parm_cnt; i++ ) // Regular input arguments
duke@435 177 call->init_req( cnt++, map()->in(i) );
duke@435 178
duke@435 179 call->init_req( cnt++, thread );
duke@435 180 if( return_pc ) // Return PC, if asked for
duke@435 181 call->init_req( cnt++, returnadr() );
duke@435 182 _gvn.transform_no_reclaim(call);
duke@435 183
duke@435 184
duke@435 185 //-----------------------------
duke@435 186 // Now set up the return results
kvn@4115 187 set_control( _gvn.transform( new (C) ProjNode(call,TypeFunc::Control)) );
kvn@4115 188 set_i_o( _gvn.transform( new (C) ProjNode(call,TypeFunc::I_O )) );
duke@435 189 set_all_memory_call(call);
duke@435 190 if (range->cnt() > TypeFunc::Parms) {
kvn@4115 191 Node* retnode = _gvn.transform( new (C) ProjNode(call,TypeFunc::Parms) );
duke@435 192 // C-land is allowed to return sub-word values. Convert to integer type.
duke@435 193 assert( retval != Type::TOP, "" );
duke@435 194 if (retval == TypeInt::BOOL) {
kvn@4115 195 retnode = _gvn.transform( new (C) AndINode(retnode, intcon(0xFF)) );
duke@435 196 } else if (retval == TypeInt::CHAR) {
kvn@4115 197 retnode = _gvn.transform( new (C) AndINode(retnode, intcon(0xFFFF)) );
duke@435 198 } else if (retval == TypeInt::BYTE) {
kvn@4115 199 retnode = _gvn.transform( new (C) LShiftINode(retnode, intcon(24)) );
kvn@4115 200 retnode = _gvn.transform( new (C) RShiftINode(retnode, intcon(24)) );
duke@435 201 } else if (retval == TypeInt::SHORT) {
kvn@4115 202 retnode = _gvn.transform( new (C) LShiftINode(retnode, intcon(16)) );
kvn@4115 203 retnode = _gvn.transform( new (C) RShiftINode(retnode, intcon(16)) );
duke@435 204 }
duke@435 205 map()->set_req( TypeFunc::Parms, retnode );
duke@435 206 }
duke@435 207
duke@435 208 //-----------------------------
duke@435 209
duke@435 210 // Clear last_Java_sp
duke@435 211 store_to_memory(NULL, adr_sp, null(), T_ADDRESS, NoAlias);
duke@435 212 // Clear last_Java_pc and (optionally)_flags
duke@435 213 store_to_memory(NULL, adr_last_Java_pc, null(), T_ADDRESS, NoAlias);
morris@4535 214 #if defined(SPARC)
duke@435 215 store_to_memory(NULL, adr_flags, intcon(0), T_INT, NoAlias);
morris@4535 216 #endif /* defined(SPARC) */
duke@435 217 #ifdef IA64
duke@435 218 Node* adr_last_Java_fp = basic_plus_adr(top(), thread, in_bytes(JavaThread::last_Java_fp_offset()));
duke@435 219 if( os::is_MP() ) insert_mem_bar(Op_MemBarRelease);
duke@435 220 store_to_memory(NULL, adr_last_Java_fp, null(), T_ADDRESS, NoAlias);
duke@435 221 #endif
duke@435 222
duke@435 223 // For is-fancy-jump, the C-return value is also the branch target
duke@435 224 Node* target = map()->in(TypeFunc::Parms);
duke@435 225 // Runtime call returning oop in TLS? Fetch it out
duke@435 226 if( pass_tls ) {
duke@435 227 Node* adr = basic_plus_adr(top(), thread, in_bytes(JavaThread::vm_result_offset()));
duke@435 228 Node* vm_result = make_load(NULL, adr, TypeOopPtr::BOTTOM, T_OBJECT, NoAlias, false);
duke@435 229 map()->set_req(TypeFunc::Parms, vm_result); // vm_result passed as result
duke@435 230 // clear thread-local-storage(tls)
duke@435 231 store_to_memory(NULL, adr, null(), T_ADDRESS, NoAlias);
duke@435 232 }
duke@435 233
duke@435 234 //-----------------------------
duke@435 235 // check exception
duke@435 236 Node* adr = basic_plus_adr(top(), thread, in_bytes(Thread::pending_exception_offset()));
duke@435 237 Node* pending = make_load(NULL, adr, TypeOopPtr::BOTTOM, T_OBJECT, NoAlias, false);
duke@435 238
duke@435 239 Node* exit_memory = reset_memory();
duke@435 240
kvn@4115 241 Node* cmp = _gvn.transform( new (C) CmpPNode(pending, null()) );
kvn@4115 242 Node* bo = _gvn.transform( new (C) BoolNode(cmp, BoolTest::ne) );
duke@435 243 IfNode *iff = create_and_map_if(control(), bo, PROB_MIN, COUNT_UNKNOWN);
duke@435 244
kvn@4115 245 Node* if_null = _gvn.transform( new (C) IfFalseNode(iff) );
kvn@4115 246 Node* if_not_null = _gvn.transform( new (C) IfTrueNode(iff) );
duke@435 247
duke@435 248 assert (StubRoutines::forward_exception_entry() != NULL, "must be generated before");
duke@435 249 Node *exc_target = makecon(TypeRawPtr::make( StubRoutines::forward_exception_entry() ));
kvn@4115 250 Node *to_exc = new (C) TailCallNode(if_not_null,
kvn@4115 251 i_o(),
kvn@4115 252 exit_memory,
kvn@4115 253 frameptr(),
kvn@4115 254 returnadr(),
kvn@4115 255 exc_target, null());
duke@435 256 root()->add_req(_gvn.transform(to_exc)); // bind to root to keep live
duke@435 257 C->init_start(start);
duke@435 258
duke@435 259 //-----------------------------
duke@435 260 // If this is a normal subroutine return, issue the return and be done.
duke@435 261 Node *ret;
duke@435 262 switch( is_fancy_jump ) {
duke@435 263 case 0: // Make a return instruction
duke@435 264 // Return to caller, free any space for return address
kvn@4115 265 ret = new (C) ReturnNode(TypeFunc::Parms, if_null,
kvn@4115 266 i_o(),
kvn@4115 267 exit_memory,
kvn@4115 268 frameptr(),
kvn@4115 269 returnadr());
duke@435 270 if (C->tf()->range()->cnt() > TypeFunc::Parms)
duke@435 271 ret->add_req( map()->in(TypeFunc::Parms) );
duke@435 272 break;
duke@435 273 case 1: // This is a fancy tail-call jump. Jump to computed address.
duke@435 274 // Jump to new callee; leave old return address alone.
kvn@4115 275 ret = new (C) TailCallNode(if_null,
kvn@4115 276 i_o(),
kvn@4115 277 exit_memory,
kvn@4115 278 frameptr(),
kvn@4115 279 returnadr(),
kvn@4115 280 target, map()->in(TypeFunc::Parms));
duke@435 281 break;
duke@435 282 case 2: // Pop return address & jump
duke@435 283 // Throw away old return address; jump to new computed address
duke@435 284 //assert(C_function == CAST_FROM_FN_PTR(address, OptoRuntime::rethrow_C), "fancy_jump==2 only for rethrow");
kvn@4115 285 ret = new (C) TailJumpNode(if_null,
kvn@4115 286 i_o(),
kvn@4115 287 exit_memory,
kvn@4115 288 frameptr(),
kvn@4115 289 target, map()->in(TypeFunc::Parms));
duke@435 290 break;
duke@435 291 default:
duke@435 292 ShouldNotReachHere();
duke@435 293 }
duke@435 294 root()->add_req(_gvn.transform(ret));
duke@435 295 }

mercurial