1 /*
  2  * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "c1/c1_CodeStubs.hpp"
 27 #include "c1/c1_FrameMap.hpp"
 28 #include "c1/c1_LIRAssembler.hpp"
 29 #include "c1/c1_MacroAssembler.hpp"
 30 #include "c1/c1_Runtime1.hpp"
 31 #include "classfile/javaClasses.hpp"
 32 #include "nativeInst_x86.hpp"
 33 #include "oops/objArrayKlass.hpp"
 34 #include "runtime/sharedRuntime.hpp"
 35 #include "utilities/align.hpp"
 36 #include "utilities/macros.hpp"
 37 #include "vmreg_x86.inline.hpp"
 38 
 39 
 40 #define __ ce->masm()->
 41 
 42 #ifndef _LP64
 43 float ConversionStub::float_zero = 0.0;
 44 double ConversionStub::double_zero = 0.0;
 45 
 46 void ConversionStub::emit_code(LIR_Assembler* ce) {
 47   __ bind(_entry);
 48   assert(bytecode() == Bytecodes::_f2i || bytecode() == Bytecodes::_d2i, "other conversions do not require stub");
 49 
 50 
 51   if (input()->is_single_xmm()) {
 52     __ comiss(input()->as_xmm_float_reg(),
 53               ExternalAddress((address)&float_zero));
 54   } else if (input()->is_double_xmm()) {
 55     __ comisd(input()->as_xmm_double_reg(),
 56               ExternalAddress((address)&double_zero));
 57   } else {
 58     __ push(rax);
 59     __ ftst();
 60     __ fnstsw_ax();
 61     __ sahf();
 62     __ pop(rax);
 63   }
 64 
 65   Label NaN, do_return;
 66   __ jccb(Assembler::parity, NaN);
 67   __ jccb(Assembler::below, do_return);
 68 
 69   // input is > 0 -> return maxInt
 70   // result register already contains 0x80000000, so subtracting 1 gives 0x7fffffff
 71   __ decrement(result()->as_register());
 72   __ jmpb(do_return);
 73 
 74   // input is NaN -> return 0
 75   __ bind(NaN);
 76   __ xorptr(result()->as_register(), result()->as_register());
 77 
 78   __ bind(do_return);
 79   __ jmp(_continuation);
 80 }
 81 #endif // !_LP64
 82 
 83 void C1SafepointPollStub::emit_code(LIR_Assembler* ce) {
 84   __ bind(_entry);
 85   InternalAddress safepoint_pc(ce->masm()->pc() - ce->masm()->offset() + safepoint_offset());
 86 #ifdef _LP64
 87   __ lea(rscratch1, safepoint_pc);
 88   __ movptr(Address(r15_thread, JavaThread::saved_exception_pc_offset()), rscratch1);
 89 #else
 90   const Register tmp1 = rcx;
 91   const Register tmp2 = rdx;
 92   __ push(tmp1);
 93   __ push(tmp2);
 94 
 95   __ lea(tmp1, safepoint_pc);
 96   __ get_thread(tmp2);
 97   __ movptr(Address(tmp2, JavaThread::saved_exception_pc_offset()), tmp1);
 98 
 99   __ pop(tmp2);
100   __ pop(tmp1);
101 #endif /* _LP64 */
102   assert(SharedRuntime::polling_page_return_handler_blob() != NULL,
103          "polling page return stub not created yet");
104 
105   address stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();
106   __ jump(RuntimeAddress(stub));
107 }
108 
109 void CounterOverflowStub::emit_code(LIR_Assembler* ce) {
110   __ bind(_entry);
111   Metadata *m = _method->as_constant_ptr()->as_metadata();
112   ce->store_parameter(m, 1);
113   ce->store_parameter(_bci, 0);
114   __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::counter_overflow_id)));
115   ce->add_call_info_here(_info);
116   ce->verify_oop_map(_info);
117   __ jmp(_continuation);
118 }
119 
120 RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index, LIR_Opr array)
121   : _index(index), _array(array), _throw_index_out_of_bounds_exception(false) {
122   assert(info != NULL, "must have info");
123   _info = new CodeEmitInfo(info);
124 }
125 
126 RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index)
127   : _index(index), _array(NULL), _throw_index_out_of_bounds_exception(true) {
128   assert(info != NULL, "must have info");
129   _info = new CodeEmitInfo(info);
130 }
131 
132 void RangeCheckStub::emit_code(LIR_Assembler* ce) {
133   __ bind(_entry);
134   if (_info->deoptimize_on_exception()) {
135     address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);
136     __ call(RuntimeAddress(a));
137     ce->add_call_info_here(_info);
138     ce->verify_oop_map(_info);
139     debug_only(__ should_not_reach_here());
140     return;
141   }
142 
143   // pass the array index on stack because all registers must be preserved
144   if (_index->is_cpu_register()) {
145     ce->store_parameter(_index->as_register(), 0);
146   } else {
147     ce->store_parameter(_index->as_jint(), 0);
148   }
149   Runtime1::StubID stub_id;
150   if (_throw_index_out_of_bounds_exception) {
151     stub_id = Runtime1::throw_index_exception_id;
152   } else {
153     stub_id = Runtime1::throw_range_check_failed_id;
154     ce->store_parameter(_array->as_pointer_register(), 1);
155   }
156   __ call(RuntimeAddress(Runtime1::entry_for(stub_id)));
157   ce->add_call_info_here(_info);
158   ce->verify_oop_map(_info);
159   debug_only(__ should_not_reach_here());
160 }
161 
162 PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) {
163   _info = new CodeEmitInfo(info);
164 }
165 
166 void PredicateFailedStub::emit_code(LIR_Assembler* ce) {
167   __ bind(_entry);
168   address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);
169   __ call(RuntimeAddress(a));
170   ce->add_call_info_here(_info);
171   ce->verify_oop_map(_info);
172   debug_only(__ should_not_reach_here());
173 }
174 
175 void DivByZeroStub::emit_code(LIR_Assembler* ce) {
176   if (_offset != -1) {
177     ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
178   }
179   __ bind(_entry);
180   __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::throw_div0_exception_id)));
181   ce->add_call_info_here(_info);
182   debug_only(__ should_not_reach_here());
183 }
184 
185 
186 // Implementation of LoadFlattenedArrayStub
187 
188 LoadFlattenedArrayStub::LoadFlattenedArrayStub(LIR_Opr array, LIR_Opr index, LIR_Opr result, CodeEmitInfo* info) {
189   _array = array;
190   _index = index;
191   _result = result;
192   // Tell the register allocator that the runtime call will scratch rax.
193   _scratch_reg = FrameMap::rax_oop_opr;
194   _info = new CodeEmitInfo(info);
195 }
196 
197 void LoadFlattenedArrayStub::emit_code(LIR_Assembler* ce) {
198   assert(__ rsp_offset() == 0, "frame size should be fixed");
199   __ bind(_entry);
200   ce->store_parameter(_array->as_register(), 1);
201   ce->store_parameter(_index->as_register(), 0);
202   __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::load_flattened_array_id)));
203   ce->add_call_info_here(_info);
204   ce->verify_oop_map(_info);
205   if (_result->as_register() != rax) {
206     __ movptr(_result->as_register(), rax);
207   }
208   __ jmp(_continuation);
209 }
210 
211 
212 // Implementation of StoreFlattenedArrayStub
213 
214 StoreFlattenedArrayStub::StoreFlattenedArrayStub(LIR_Opr array, LIR_Opr index, LIR_Opr value, CodeEmitInfo* info) {
215   _array = array;
216   _index = index;
217   _value = value;
218   // Tell the register allocator that the runtime call will scratch rax.
219   _scratch_reg = FrameMap::rax_oop_opr;
220   _info = new CodeEmitInfo(info);
221 }
222 
223 
224 void StoreFlattenedArrayStub::emit_code(LIR_Assembler* ce) {
225   assert(__ rsp_offset() == 0, "frame size should be fixed");
226   __ bind(_entry);
227   ce->store_parameter(_array->as_register(), 2);
228   ce->store_parameter(_index->as_register(), 1);
229   ce->store_parameter(_value->as_register(), 0);
230   __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::store_flattened_array_id)));
231   ce->add_call_info_here(_info);
232   ce->verify_oop_map(_info);
233   __ jmp(_continuation);
234 }
235 
236 
237 // Implementation of SubstitutabilityCheckStub
238 
239 SubstitutabilityCheckStub::SubstitutabilityCheckStub(LIR_Opr left, LIR_Opr right, CodeEmitInfo* info) {
240   _left = left;
241   _right = right;
242   // Tell the register allocator that the runtime call will scratch rax.
243   _scratch_reg = FrameMap::rax_oop_opr;
244   _info = new CodeEmitInfo(info);
245 }
246 
247 void SubstitutabilityCheckStub::emit_code(LIR_Assembler* ce) {
248   assert(__ rsp_offset() == 0, "frame size should be fixed");
249   __ bind(_entry);
250   ce->store_parameter(_left->as_register(), 1);
251   ce->store_parameter(_right->as_register(), 0);
252   __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::substitutability_check_id)));
253   ce->add_call_info_here(_info);
254   ce->verify_oop_map(_info);
255   __ jmp(_continuation);
256 }
257 
258 
259 // Implementation of NewInstanceStub
260 
261 NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {
262   _result = result;
263   _klass = klass;
264   _klass_reg = klass_reg;
265   _info = new CodeEmitInfo(info);
266   assert(stub_id == Runtime1::new_instance_id                 ||
267          stub_id == Runtime1::new_instance_no_inline_id       ||
268          stub_id == Runtime1::fast_new_instance_id            ||
269          stub_id == Runtime1::fast_new_instance_init_check_id,
270          "need new_instance id");
271   _stub_id   = stub_id;
272 }
273 
274 
275 void NewInstanceStub::emit_code(LIR_Assembler* ce) {
276   assert(__ rsp_offset() == 0, "frame size should be fixed");
277   __ bind(_entry);
278   __ movptr(rdx, _klass_reg->as_register());
279   __ call(RuntimeAddress(Runtime1::entry_for(_stub_id)));
280   ce->add_call_info_here(_info);
281   ce->verify_oop_map(_info);
282   assert(_result->as_register() == rax, "result must in rax,");
283   __ jmp(_continuation);
284 }
285 
286 
287 // Implementation of NewTypeArrayStub
288 
289 NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
290   _klass_reg = klass_reg;
291   _length = length;
292   _result = result;
293   _info = new CodeEmitInfo(info);
294 }
295 
296 
297 void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {
298   assert(__ rsp_offset() == 0, "frame size should be fixed");
299   __ bind(_entry);
300   assert(_length->as_register() == rbx, "length must in rbx,");
301   assert(_klass_reg->as_register() == rdx, "klass_reg must in rdx");
302   __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_type_array_id)));
303   ce->add_call_info_here(_info);
304   ce->verify_oop_map(_info);
305   assert(_result->as_register() == rax, "result must in rax,");
306   __ jmp(_continuation);
307 }
308 
309 
310 // Implementation of NewObjectArrayStub
311 
312 NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result,
313                                        CodeEmitInfo* info, bool is_null_free) {
314   _klass_reg = klass_reg;
315   _result = result;
316   _length = length;
317   _info = new CodeEmitInfo(info);
318   _is_null_free = is_null_free;
319 }
320 
321 
322 void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
323   assert(__ rsp_offset() == 0, "frame size should be fixed");
324   __ bind(_entry);
325   assert(_length->as_register() == rbx, "length must in rbx,");
326   assert(_klass_reg->as_register() == rdx, "klass_reg must in rdx");
327   if (_is_null_free) {
328     __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_flat_array_id)));
329   } else {
330     __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_object_array_id)));
331   }
332   ce->add_call_info_here(_info);
333   ce->verify_oop_map(_info);
334   assert(_result->as_register() == rax, "result must in rax,");
335   __ jmp(_continuation);
336 }
337 
338 
339 // Implementation of MonitorAccessStubs
340 
341 MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info, CodeStub* throw_imse_stub, LIR_Opr scratch_reg)
342 : MonitorAccessStub(obj_reg, lock_reg)
343 {
344   _info = new CodeEmitInfo(info);
345   _throw_imse_stub = throw_imse_stub;
346   _scratch_reg = scratch_reg;
347   if (_throw_imse_stub != NULL) {
348     assert(_scratch_reg != LIR_OprFact::illegalOpr, "must be");
349   }
350 }
351 
352 
353 void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
354   assert(__ rsp_offset() == 0, "frame size should be fixed");
355   __ bind(_entry);
356   if (_throw_imse_stub != NULL) {
357     // When we come here, _obj_reg has already been checked to be non-null.
358     const int is_value_mask = markWord::inline_type_pattern;
359     Register mark = _scratch_reg->as_register();
360     __ movptr(mark, Address(_obj_reg->as_register(), oopDesc::mark_offset_in_bytes()));
361     __ andptr(mark, is_value_mask);
362     __ cmpl(mark, is_value_mask);
363     __ jcc(Assembler::equal, *_throw_imse_stub->entry());
364   }
365   ce->store_parameter(_obj_reg->as_register(),  1);
366   ce->store_parameter(_lock_reg->as_register(), 0);
367   Runtime1::StubID enter_id;
368   if (ce->compilation()->has_fpu_code()) {
369     enter_id = Runtime1::monitorenter_id;
370   } else {
371     enter_id = Runtime1::monitorenter_nofpu_id;
372   }
373   __ call(RuntimeAddress(Runtime1::entry_for(enter_id)));
374   ce->add_call_info_here(_info);
375   ce->verify_oop_map(_info);
376   __ jmp(_continuation);
377 }
378 
379 
380 void MonitorExitStub::emit_code(LIR_Assembler* ce) {
381   __ bind(_entry);
382   if (_compute_lock) {
383     // lock_reg was destroyed by fast unlocking attempt => recompute it
384     ce->monitor_address(_monitor_ix, _lock_reg);
385   }
386   ce->store_parameter(_lock_reg->as_register(), 0);
387   // note: non-blocking leaf routine => no call info needed
388   Runtime1::StubID exit_id;
389   if (ce->compilation()->has_fpu_code()) {
390     exit_id = Runtime1::monitorexit_id;
391   } else {
392     exit_id = Runtime1::monitorexit_nofpu_id;
393   }
394   __ call(RuntimeAddress(Runtime1::entry_for(exit_id)));
395   __ jmp(_continuation);
396 }
397 
398 
399 // Implementation of patching:
400 // - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes)
401 // - Replace original code with a call to the stub
402 // At Runtime:
403 // - call to stub, jump to runtime
404 // - in runtime: preserve all registers (rspecially objects, i.e., source and destination object)
405 // - in runtime: after initializing class, restore original code, reexecute instruction
406 
407 int PatchingStub::_patch_info_offset = -NativeGeneralJump::instruction_size;
408 
409 void PatchingStub::align_patch_site(MacroAssembler* masm) {
410   // We're patching a 5-7 byte instruction on intel and we need to
411   // make sure that we don't see a piece of the instruction.  It
412   // appears mostly impossible on Intel to simply invalidate other
413   // processors caches and since they may do aggressive prefetch it's
414   // very hard to make a guess about what code might be in the icache.
415   // Force the instruction to be double word aligned so that it
416   // doesn't span a cache line.
417   masm->align(align_up((int)NativeGeneralJump::instruction_size, wordSize));
418 }
419 
420 void PatchingStub::emit_code(LIR_Assembler* ce) {
421   assert(NativeCall::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF, "not enough room for call");
422 
423   Label call_patch;
424 
425   // static field accesses have special semantics while the class
426   // initializer is being run so we emit a test which can be used to
427   // check that this code is being executed by the initializing
428   // thread.
429   address being_initialized_entry = __ pc();
430   if (CommentedAssembly) {
431     __ block_comment(" patch template");
432   }
433   if (_id == load_klass_id) {
434     // produce a copy of the load klass instruction for use by the being initialized case
435 #ifdef ASSERT
436     address start = __ pc();
437 #endif
438     Metadata* o = NULL;
439     __ mov_metadata(_obj, o);
440 #ifdef ASSERT
441     for (int i = 0; i < _bytes_to_copy; i++) {
442       address ptr = (address)(_pc_start + i);
443       int a_byte = (*ptr) & 0xFF;
444       assert(a_byte == *start++, "should be the same code");
445     }
446 #endif
447   } else if (_id == load_mirror_id) {
448     // produce a copy of the load mirror instruction for use by the being
449     // initialized case
450 #ifdef ASSERT
451     address start = __ pc();
452 #endif
453     jobject o = NULL;
454     __ movoop(_obj, o);
455 #ifdef ASSERT
456     for (int i = 0; i < _bytes_to_copy; i++) {
457       address ptr = (address)(_pc_start + i);
458       int a_byte = (*ptr) & 0xFF;
459       assert(a_byte == *start++, "should be the same code");
460     }
461 #endif
462   } else {
463     // make a copy the code which is going to be patched.
464     for (int i = 0; i < _bytes_to_copy; i++) {
465       address ptr = (address)(_pc_start + i);
466       int a_byte = (*ptr) & 0xFF;
467       __ emit_int8(a_byte);
468       *ptr = 0x90; // make the site look like a nop
469     }
470   }
471 
472   address end_of_patch = __ pc();
473   int bytes_to_skip = 0;
474   if (_id == load_mirror_id) {
475     int offset = __ offset();
476     if (CommentedAssembly) {
477       __ block_comment(" being_initialized check");
478     }
479     assert(_obj != noreg, "must be a valid register");
480     Register tmp = rax;
481     Register tmp2 = rbx;
482     __ push(tmp);
483     __ push(tmp2);
484     // Load without verification to keep code size small. We need it because
485     // begin_initialized_entry_offset has to fit in a byte. Also, we know it's not null.
486     __ movptr(tmp2, Address(_obj, java_lang_Class::klass_offset()));
487     __ get_thread(tmp);
488     __ cmpptr(tmp, Address(tmp2, InstanceKlass::init_thread_offset()));
489     __ pop(tmp2);
490     __ pop(tmp);
491     __ jcc(Assembler::notEqual, call_patch);
492 
493     // access_field patches may execute the patched code before it's
494     // copied back into place so we need to jump back into the main
495     // code of the nmethod to continue execution.
496     __ jmp(_patch_site_continuation);
497 
498     // make sure this extra code gets skipped
499     bytes_to_skip += __ offset() - offset;
500   }
501   if (CommentedAssembly) {
502     __ block_comment("patch data encoded as movl");
503   }
504   // Now emit the patch record telling the runtime how to find the
505   // pieces of the patch.  We only need 3 bytes but for readability of
506   // the disassembly we make the data look like a movl reg, imm32,
507   // which requires 5 bytes
508   int sizeof_patch_record = 5;
509   bytes_to_skip += sizeof_patch_record;
510 
511   // emit the offsets needed to find the code to patch
512   int being_initialized_entry_offset = __ pc() - being_initialized_entry + sizeof_patch_record;
513 
514   __ emit_int8((unsigned char)0xB8);
515   __ emit_int8(0);
516   __ emit_int8(being_initialized_entry_offset);
517   __ emit_int8(bytes_to_skip);
518   __ emit_int8(_bytes_to_copy);
519   address patch_info_pc = __ pc();
520   assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info");
521 
522   address entry = __ pc();
523   NativeGeneralJump::insert_unconditional((address)_pc_start, entry);
524   address target = NULL;
525   relocInfo::relocType reloc_type = relocInfo::none;
526   switch (_id) {
527     case access_field_id:  target = Runtime1::entry_for(Runtime1::access_field_patching_id); break;
528     case load_klass_id:    target = Runtime1::entry_for(Runtime1::load_klass_patching_id); reloc_type = relocInfo::metadata_type; break;
529     case load_mirror_id:   target = Runtime1::entry_for(Runtime1::load_mirror_patching_id); reloc_type = relocInfo::oop_type; break;
530     case load_appendix_id:      target = Runtime1::entry_for(Runtime1::load_appendix_patching_id); reloc_type = relocInfo::oop_type; break;
531     default: ShouldNotReachHere();
532   }
533   __ bind(call_patch);
534 
535   if (CommentedAssembly) {
536     __ block_comment("patch entry point");
537   }
538   __ call(RuntimeAddress(target));
539   assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change");
540   ce->add_call_info_here(_info);
541   int jmp_off = __ offset();
542   __ jmp(_patch_site_entry);
543   // Add enough nops so deoptimization can overwrite the jmp above with a call
544   // and not destroy the world. We cannot use fat nops here, since the concurrent
545   // code rewrite may transiently create the illegal instruction sequence.
546   for (int j = __ offset() ; j < jmp_off + 5 ; j++ ) {
547     __ nop();
548   }
549   if (_id == load_klass_id || _id == load_mirror_id || _id == load_appendix_id) {
550     CodeSection* cs = __ code_section();
551     RelocIterator iter(cs, (address)_pc_start, (address)(_pc_start + 1));
552     relocInfo::change_reloc_info_for_address(&iter, (address) _pc_start, reloc_type, relocInfo::none);
553   }
554 }
555 
556 
557 void DeoptimizeStub::emit_code(LIR_Assembler* ce) {
558   __ bind(_entry);
559   ce->store_parameter(_trap_request, 0);
560   __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::deoptimize_id)));
561   ce->add_call_info_here(_info);
562   DEBUG_ONLY(__ should_not_reach_here());
563 }
564 
565 
566 void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {
567   address a;
568   if (_info->deoptimize_on_exception()) {
569     // Deoptimize, do not throw the exception, because it is probably wrong to do it here.
570     a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);
571   } else {
572     a = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);
573   }
574 
575   ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
576   __ bind(_entry);
577   __ call(RuntimeAddress(a));
578   ce->add_call_info_here(_info);
579   ce->verify_oop_map(_info);
580   debug_only(__ should_not_reach_here());
581 }
582 
583 
584 void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {
585   assert(__ rsp_offset() == 0, "frame size should be fixed");
586 
587   __ bind(_entry);
588   // pass the object on stack because all registers must be preserved
589   if (_obj->is_cpu_register()) {
590     ce->store_parameter(_obj->as_register(), 0);
591   }
592   __ call(RuntimeAddress(Runtime1::entry_for(_stub)));
593   ce->add_call_info_here(_info);
594   debug_only(__ should_not_reach_here());
595 }
596 
597 
598 void ArrayCopyStub::emit_code(LIR_Assembler* ce) {
599   //---------------slow case: call to native-----------------
600   __ bind(_entry);
601   // Figure out where the args should go
602   // This should really convert the IntrinsicID to the Method* and signature
603   // but I don't know how to do that.
604   //
605   VMRegPair args[5];
606   BasicType signature[5] = { T_OBJECT, T_INT, T_OBJECT, T_INT, T_INT};
607   SharedRuntime::java_calling_convention(signature, args, 5);
608 
609   // push parameters
610   // (src, src_pos, dest, destPos, length)
611   Register r[5];
612   r[0] = src()->as_register();
613   r[1] = src_pos()->as_register();
614   r[2] = dst()->as_register();
615   r[3] = dst_pos()->as_register();
616   r[4] = length()->as_register();
617 
618   // next registers will get stored on the stack
619   for (int i = 0; i < 5 ; i++ ) {
620     VMReg r_1 = args[i].first();
621     if (r_1->is_stack()) {
622       int st_off = r_1->reg2stack() * wordSize;
623       __ movptr (Address(rsp, st_off), r[i]);
624     } else {
625       assert(r[i] == args[i].first()->as_Register(), "Wrong register for arg ");
626     }
627   }
628 
629   ce->align_call(lir_static_call);
630 
631   ce->emit_static_call_stub();
632   if (ce->compilation()->bailed_out()) {
633     return; // CodeCache is full
634   }
635   AddressLiteral resolve(SharedRuntime::get_resolve_static_call_stub(),
636                          relocInfo::static_call_type);
637   __ call(resolve);
638   ce->add_call_info_here(info());
639 
640 #ifndef PRODUCT
641   if (PrintC1Statistics) {
642     __ incrementl(ExternalAddress((address)&Runtime1::_arraycopy_slowcase_cnt));
643   }
644 #endif
645 
646   __ jmp(_continuation);
647 }
648 
649 #undef __