src/cpu/mips/vm/c1_CodeStubs_mips.cpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
child 6880
52ea28d233d2
permissions
-rw-r--r--

Added MIPS 64-bit port.

aoqi@1 1 /*
aoqi@1 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@1 3 * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
aoqi@1 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@1 5 *
aoqi@1 6 * This code is free software; you can redistribute it and/or modify it
aoqi@1 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@1 8 * published by the Free Software Foundation.
aoqi@1 9 *
aoqi@1 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@1 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@1 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@1 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@1 14 * accompanied this code).
aoqi@1 15 *
aoqi@1 16 * You should have received a copy of the GNU General Public License version
aoqi@1 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@1 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@1 19 *
aoqi@1 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@1 21 * or visit www.oracle.com if you need additional information or have any
aoqi@1 22 * questions.
aoqi@1 23 *
aoqi@1 24 */
aoqi@1 25
aoqi@1 26 #include "precompiled.hpp"
aoqi@1 27 #include "c1/c1_CodeStubs.hpp"
aoqi@1 28 #include "c1/c1_FrameMap.hpp"
aoqi@1 29 #include "c1/c1_LIRAssembler.hpp"
aoqi@1 30 #include "c1/c1_MacroAssembler.hpp"
aoqi@1 31 #include "c1/c1_Runtime1.hpp"
aoqi@1 32 #include "nativeInst_mips.hpp"
aoqi@1 33 #include "runtime/sharedRuntime.hpp"
aoqi@1 34 #include "vmreg_mips.inline.hpp"
aoqi@1 35 #ifndef SERIALGC
aoqi@1 36 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
aoqi@1 37 #endif
aoqi@1 38
aoqi@1 39
aoqi@1 40 #define __ ce->masm()->
aoqi@1 41
aoqi@1 42 float ConversionStub::float_zero = 0.0;
aoqi@1 43 double ConversionStub::double_zero = 0.0;
aoqi@1 44
aoqi@1 45 void ConversionStub::emit_code(LIR_Assembler* ce) {
aoqi@1 46 __ bind(_entry);
aoqi@1 47 assert(bytecode() == Bytecodes::_f2i || bytecode() == Bytecodes::_d2i, "other conversions do not require stub");
aoqi@1 48 }
aoqi@1 49
aoqi@1 50 #ifdef TIERED
aoqi@1 51 void CounterOverflowStub::emit_code(LIR_Assembler* ce) {
aoqi@1 52 __ bind(_entry);
aoqi@1 53 ce->store_parameter(_bci, 0);
aoqi@1 54 //__ call(RuntimeAddress(Runtime1::entry_for(Runtime1::counter_overflow_id)));
aoqi@1 55 __ call(Runtime1::entry_for(Runtime1::counter_overflow_id), relocInfo::runtime_call_type);
aoqi@1 56 __ delayed()->nop();
aoqi@1 57 ce->add_call_info_here(_info);
aoqi@1 58 ce->verify_oop_map(_info);
aoqi@1 59
aoqi@1 60 //__ jmp(_continuation);
aoqi@1 61 __ b_far(_continuation);
aoqi@1 62 __ delayed()->nop();
aoqi@1 63 }
aoqi@1 64 #endif // TIERED
aoqi@1 65
aoqi@1 66
aoqi@1 67
aoqi@1 68 RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index,
aoqi@1 69 bool throw_index_out_of_bounds_exception)
aoqi@1 70 : _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception)
aoqi@1 71 , _index(index)
aoqi@1 72 {
aoqi@1 73 _info = info == NULL ? NULL : new CodeEmitInfo(info);
aoqi@1 74 }
aoqi@1 75
aoqi@1 76
aoqi@1 77 void RangeCheckStub::emit_code(LIR_Assembler* ce) {
aoqi@1 78 #ifdef OPT_RANGECHECK
aoqi@1 79 if (_throw_pc != -1) {
aoqi@1 80 ce->compilation()->null_check_table()->append(_throw_pc, __ offset());
aoqi@1 81 }
aoqi@1 82 #endif
aoqi@1 83 __ bind(_entry);
aoqi@1 84 //// Pass the array index in eax since the runtime stub will add register state to the stack
aoqi@1 85 // pass the array index on stack because all registers must be preserved
aoqi@1 86
aoqi@1 87 if (_index->is_cpu_register()) {
aoqi@1 88 ce->store_parameter(_index->as_register(), 0);
aoqi@1 89 } else {
aoqi@1 90 ce->store_parameter(_index->as_jint(), 0);
aoqi@1 91 }
aoqi@1 92
aoqi@1 93 if (_throw_index_out_of_bounds_exception) {
aoqi@1 94 __ call(Runtime1::entry_for(Runtime1::throw_index_exception_id), relocInfo::runtime_call_type);
aoqi@1 95 } else {
aoqi@1 96 __ call(Runtime1::entry_for(Runtime1::throw_range_check_failed_id), relocInfo::runtime_call_type);
aoqi@1 97 }
aoqi@1 98 __ delayed()->nop();
aoqi@1 99 ce->add_call_info_here(_info);
aoqi@1 100 debug_only(__ should_not_reach_here());
aoqi@1 101 }
aoqi@1 102
aoqi@1 103 PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) { // Fu:20130814
aoqi@1 104 _info = new CodeEmitInfo(info);
aoqi@1 105 }
aoqi@1 106
aoqi@1 107 void PredicateFailedStub::emit_code(LIR_Assembler* ce) { // Fu:20130814
aoqi@1 108 tty->print_cr("PredicateFailedStub::emit_code unimplemented yet!");
aoqi@1 109 Unimplemented();
aoqi@1 110 }
aoqi@1 111
aoqi@1 112 void DivByZeroStub::emit_code(LIR_Assembler* ce) {
aoqi@1 113 if (_offset != -1) {
aoqi@1 114 // ce->compilation()->null_check_table()->append(_offset, __ offset());
aoqi@1 115 ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
aoqi@1 116 }
aoqi@1 117 __ bind(_entry);
aoqi@1 118 __ call(Runtime1::entry_for(Runtime1::throw_div0_exception_id), relocInfo::runtime_call_type);
aoqi@1 119 __ delayed()->nop();
aoqi@1 120 ce->add_call_info_here(_info);
aoqi@1 121 debug_only(__ should_not_reach_here());
aoqi@1 122
aoqi@1 123 }
aoqi@1 124
aoqi@1 125
aoqi@1 126 // Implementation of NewInstanceStub
aoqi@1 127
aoqi@1 128 NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {
aoqi@1 129 _result = result;
aoqi@1 130 _klass = klass;
aoqi@1 131 _klass_reg = klass_reg;
aoqi@1 132 _info = new CodeEmitInfo(info);
aoqi@1 133 assert(stub_id == Runtime1::new_instance_id ||
aoqi@1 134 stub_id == Runtime1::fast_new_instance_id ||
aoqi@1 135 stub_id == Runtime1::fast_new_instance_init_check_id,
aoqi@1 136 "need new_instance id");
aoqi@1 137 _stub_id = stub_id;
aoqi@1 138 }
aoqi@1 139
aoqi@1 140 // i use T4 as klass register, V0 as result register. MUST accord with Runtime1::generate_code_for.
aoqi@1 141 void NewInstanceStub::emit_code(LIR_Assembler* ce) {
aoqi@1 142 assert(__ sp_offset() == 0, "frame size should be fixed");
aoqi@1 143 __ bind(_entry);
aoqi@1 144 //__ movptr(rdx, _klass_reg->as_register());
aoqi@1 145 //__ call(RuntimeAddress(Runtime1::entry_for(_stub_id)));
aoqi@1 146 #ifndef _LP64
aoqi@1 147 assert(_klass_reg->as_register() == T4, "klass_reg must in T4");
aoqi@1 148 #else
aoqi@1 149 //FIXME. in A4? aoqi
aoqi@1 150 assert(_klass_reg->as_register() == A4, "klass_reg must in A4");
aoqi@1 151 #endif
aoqi@1 152
aoqi@1 153
aoqi@1 154 __ call(Runtime1::entry_for(_stub_id), relocInfo::runtime_call_type);
aoqi@1 155 __ delayed()->nop();
aoqi@1 156 ce->add_call_info_here(_info);
aoqi@1 157 ce->verify_oop_map(_info);
aoqi@1 158 assert(_result->as_register() == V0, "result must in V0,");
aoqi@1 159 __ b_far(_continuation);
aoqi@1 160 __ delayed()->nop();
aoqi@1 161 }
aoqi@1 162
aoqi@1 163
aoqi@1 164 // Implementation of NewTypeArrayStub
aoqi@1 165
aoqi@1 166 NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
aoqi@1 167 _klass_reg = klass_reg;
aoqi@1 168 _length = length;
aoqi@1 169 _result = result;
aoqi@1 170 _info = new CodeEmitInfo(info);
aoqi@1 171 }
aoqi@1 172
aoqi@1 173 // i use T2 as length register, T4 as klass register, V0 as result register.
aoqi@1 174 // MUST accord with Runtime1::generate_code_for
aoqi@1 175 void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {
aoqi@1 176 assert(__ sp_offset() == 0, "frame size should be fixed");
aoqi@1 177 __ bind(_entry);
aoqi@1 178 assert(_length->as_register() == T2, "length must in T2,");
aoqi@1 179 #ifndef _LP64
aoqi@1 180 assert(_klass_reg->as_register() == T4, "klass_reg must in T4");
aoqi@1 181 #else
aoqi@1 182 //FIXME. in A4? aoqi
aoqi@1 183 assert(_klass_reg->as_register() == A4, "klass_reg must in A4");
aoqi@1 184 #endif
aoqi@1 185
aoqi@1 186 //__ call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_type_array_id)));
aoqi@1 187 __ call(Runtime1::entry_for(Runtime1::new_type_array_id), relocInfo::runtime_call_type);
aoqi@1 188 __ delayed()->nop();
aoqi@1 189 ce->add_call_info_here(_info);
aoqi@1 190 ce->verify_oop_map(_info);
aoqi@1 191
aoqi@1 192 assert(_result->as_register() == V0, "result must in V0,");
aoqi@1 193 __ b_far(_continuation);
aoqi@1 194 __ delayed()->nop();
aoqi@1 195 }
aoqi@1 196
aoqi@1 197
aoqi@1 198 // Implementation of NewObjectArrayStub
aoqi@1 199
aoqi@1 200 NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
aoqi@1 201 _klass_reg = klass_reg;
aoqi@1 202 _result = result;
aoqi@1 203 _length = length;
aoqi@1 204 _info = new CodeEmitInfo(info);
aoqi@1 205 }
aoqi@1 206
aoqi@1 207
aoqi@1 208 void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
aoqi@1 209 assert(__ sp_offset() == 0, "frame size should be fixed");
aoqi@1 210 __ bind(_entry);
aoqi@1 211 //assert(_length->as_register() == rbx, "length must in rbx,");
aoqi@1 212 //assert(_klass_reg->as_register() == rdx, "klass_reg must in rdx");
aoqi@1 213 //__ call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_object_array_id)));
aoqi@1 214 assert(_length->as_register() == T2, "length must in ebx");
aoqi@1 215 #ifndef _LP64
aoqi@1 216 assert(_klass_reg->as_register() == T4, "klass_reg must in T4");
aoqi@1 217 #else
aoqi@1 218 //FIXME. in A4? aoqi
aoqi@1 219 assert(_klass_reg->as_register() == A4, "klass_reg must in A4");
aoqi@1 220 #endif
aoqi@1 221 __ call(Runtime1::entry_for(Runtime1::new_object_array_id), relocInfo::runtime_call_type);
aoqi@1 222 __ delayed()->nop();
aoqi@1 223 ce->add_call_info_here(_info);
aoqi@1 224 ce->verify_oop_map(_info);
aoqi@1 225 //assert(_result->as_register() == rax, "result must in rax,");
aoqi@1 226 //__ jmp(_continuation);
aoqi@1 227 assert(_result->as_register() == V0, "result must in eax");
aoqi@1 228 __ b_far(_continuation);
aoqi@1 229 __ delayed()->nop();
aoqi@1 230 }
aoqi@1 231
aoqi@1 232
aoqi@1 233 // Implementation of MonitorAccessStubs
aoqi@1 234
aoqi@1 235 MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
aoqi@1 236 : MonitorAccessStub(obj_reg, lock_reg)
aoqi@1 237 {
aoqi@1 238 _info = new CodeEmitInfo(info);
aoqi@1 239 }
aoqi@1 240
aoqi@1 241
aoqi@1 242 void MonitorEnterStub::emit_code(LIR_Assembler* ce) {
aoqi@1 243 assert(__ sp_offset() == 0, "frame size should be fixed");
aoqi@1 244 __ bind(_entry);
aoqi@1 245 ce->store_parameter(_obj_reg->as_register(), 1);
aoqi@1 246 ce->store_parameter(_lock_reg->is_single_cpu()? _lock_reg->as_register() : _lock_reg->as_register_lo(), 0);
aoqi@1 247 /*
aoqi@1 248 Runtime1::StubID enter_id;
aoqi@1 249 if (ce->compilation()->has_fpu_code()) {
aoqi@1 250 enter_id = Runtime1::monitorenter_id;
aoqi@1 251 } else {
aoqi@1 252 enter_id = Runtime1::monitorenter_nofpu_id;
aoqi@1 253 }
aoqi@1 254 __ call(RuntimeAddress(Runtime1::entry_for(enter_id)));
aoqi@1 255 */
aoqi@1 256 if (ce->compilation()->has_fpu_code()) {
aoqi@1 257 __ call(Runtime1::entry_for(Runtime1::monitorenter_id), relocInfo::runtime_call_type);
aoqi@1 258 } else {
aoqi@1 259 __ call(Runtime1::entry_for(Runtime1::monitorenter_nofpu_id), relocInfo::runtime_call_type);
aoqi@1 260 }
aoqi@1 261 __ delayed()->nop();
aoqi@1 262 ce->add_call_info_here(_info);
aoqi@1 263 ce->verify_oop_map(_info);
aoqi@1 264 //__ jmp(_continuation);
aoqi@1 265 __ b_far(_continuation);
aoqi@1 266 __ delayed()->nop();
aoqi@1 267 }
aoqi@1 268
aoqi@1 269
aoqi@1 270 void MonitorExitStub::emit_code(LIR_Assembler* ce) {
aoqi@1 271 __ bind(_entry);
aoqi@1 272 if (_compute_lock) {
aoqi@1 273 // lock_reg was destroyed by fast unlocking attempt => recompute it
aoqi@1 274 ce->monitor_address(_monitor_ix, _lock_reg);
aoqi@1 275 }
aoqi@1 276 ce->store_parameter(_lock_reg->as_register(), 0);
aoqi@1 277 // note: non-blocking leaf routine => no call info needed
aoqi@1 278 /*
aoqi@1 279 Runtime1::StubID exit_id;
aoqi@1 280 if (ce->compilation()->has_fpu_code()) {
aoqi@1 281 exit_id = Runtime1::monitorexit_id;
aoqi@1 282 } else {
aoqi@1 283 exit_id = Runtime1::monitorexit_nofpu_id;
aoqi@1 284 }
aoqi@1 285 __ call(RuntimeAddress(Runtime1::entry_for(exit_id)));
aoqi@1 286 __ jmp(_continuation);
aoqi@1 287 */
aoqi@1 288 if (ce->compilation()->has_fpu_code()) {
aoqi@1 289 __ call(Runtime1::entry_for(Runtime1::monitorexit_id), relocInfo::runtime_call_type);
aoqi@1 290 } else {
aoqi@1 291 __ call(Runtime1::entry_for(Runtime1::monitorexit_nofpu_id), relocInfo::runtime_call_type);
aoqi@1 292 }
aoqi@1 293 __ delayed()->nop();
aoqi@1 294
aoqi@1 295 //__ jmp(_continuation);
aoqi@1 296 __ b_far(_continuation);
aoqi@1 297 __ delayed()->nop();
aoqi@1 298 }
aoqi@1 299
aoqi@1 300
aoqi@1 301 // Implementation of patching:
aoqi@1 302 // - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes)
aoqi@1 303 // - Replace original code with a call to the stub
aoqi@1 304 // At Runtime:
aoqi@1 305 // - call to stub, jump to runtime
aoqi@1 306 // - in runtime: preserve all registers (especially objects, i.e., source and destination object)
aoqi@1 307 // - in runtime: after initializing class, restore original code, reexecute instruction
aoqi@1 308
aoqi@1 309 //int PatchingStub::_patch_info_offset = -NativeGeneralJump::instruction_size;
aoqi@1 310 int PatchingStub::_patch_info_offset = -NativeCall::instruction_size;
aoqi@1 311
aoqi@1 312 void PatchingStub::align_patch_site(MacroAssembler* masm) {
aoqi@1 313 // We're patching a 5-7 byte instruction on intel and we need to
aoqi@1 314 // make sure that we don't see a piece of the instruction. It
aoqi@1 315 // appears mostly impossible on Intel to simply invalidate other
aoqi@1 316 // processors caches and since they may do aggressive prefetch it's
aoqi@1 317 // very hard to make a guess about what code might be in the icache.
aoqi@1 318 // Force the instruction to be double word aligned so that it
aoqi@1 319 // doesn't span a cache line.
aoqi@1 320
aoqi@1 321 // the NativeJump is not finished, i am not sure what to do here. FIXME
aoqi@1 322 //masm->align(round_to(NativeGeneralJump::instruction_size, wordSize));
aoqi@1 323 }
aoqi@1 324
aoqi@1 325 void PatchingStub::emit_code(LIR_Assembler* ce) {
aoqi@1 326 assert(NativeCall::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF, "not enough room for call");
aoqi@1 327 assert(_bytes_to_copy <= 0xFF, "not enough room for call");
aoqi@1 328
aoqi@1 329 Label call_patch;
aoqi@1 330
aoqi@1 331 // static field accesses have special semantics while the class
aoqi@1 332 // initializer is being run so we emit a test which can be used to
aoqi@1 333 // check that this code is being executed by the initializing
aoqi@1 334 // thread.
aoqi@1 335 address being_initialized_entry = __ pc();
aoqi@1 336 if (CommentedAssembly) {
aoqi@1 337 __ block_comment(" patch template");
aoqi@1 338 }
aoqi@1 339 if (_id == load_klass_id) {
aoqi@1 340 // produce a copy of the load klass instruction for use by the being initialized case
aoqi@1 341 address start = __ pc();
aoqi@1 342 jobject o = NULL;
aoqi@1 343 int oop_index = __ oop_recorder()->allocate_oop_index(o);
aoqi@1 344 RelocationHolder rspec = oop_Relocation::spec(oop_index);
aoqi@1 345 __ relocate(rspec);
aoqi@1 346 #ifndef _LP64
aoqi@1 347 //by_css
aoqi@1 348 __ lui(_obj, Assembler::split_high((int)o));
aoqi@1 349 __ addiu(_obj, _obj, Assembler::split_low((int)o));
aoqi@1 350 #else
aoqi@1 351 //This should be same as jobject2reg_with_patching.
aoqi@1 352 __ li48(_obj, (long)o);
aoqi@1 353 #endif
aoqi@1 354 while ((intx)__ pc() - (intx)start < NativeCall::instruction_size) {
aoqi@1 355 __ nop();
aoqi@1 356 }
aoqi@1 357 #ifdef ASSERT
aoqi@1 358 for (int i = 0; i < _bytes_to_copy; i++) {
aoqi@1 359 address ptr = (address)(_pc_start + i);
aoqi@1 360 int a_byte = (*ptr) & 0xFF;
aoqi@1 361 assert(a_byte == *start++, "should be the same code");
aoqi@1 362 }
aoqi@1 363 #endif
aoqi@1 364 } else {
aoqi@1 365
aoqi@1 366 // make a copy the code which is going to be patched.
aoqi@1 367 assert((_bytes_to_copy&3)==0, "change this code");
aoqi@1 368 address start = __ pc();
aoqi@1 369 for ( int i = 0; i < _bytes_to_copy; i+=4) {
aoqi@1 370 __ emit_int32(*(int*)(_pc_start + i));
aoqi@1 371 //make the site look like a nop, @jerome
aoqi@1 372 *(int*)(_pc_start + i)=0;
aoqi@1 373 }
aoqi@1 374 while ((intx)__ pc() - (intx)start < NativeCall::instruction_size) {
aoqi@1 375 __ nop();
aoqi@1 376 }
aoqi@1 377 }
aoqi@1 378
aoqi@1 379 address end_of_patch = __ pc();
aoqi@1 380 int bytes_to_skip = 0;
aoqi@1 381 if (_id == load_klass_id) {
aoqi@1 382 int offset = __ offset();
aoqi@1 383 if (CommentedAssembly) {
aoqi@1 384 __ block_comment(" being_initialized check");
aoqi@1 385 }
aoqi@1 386 assert(_obj != NOREG, "must be a valid register");
aoqi@1 387 #ifndef OPT_THREAD
aoqi@1 388 //FIXME, T8 need be saved ?
aoqi@1 389 Register thread = T8;
aoqi@1 390 __ get_thread(thread);
aoqi@1 391 #else
aoqi@1 392 Register thread = TREG;
aoqi@1 393 #endif
aoqi@1 394 __ ld(AT, _obj, in_bytes(InstanceKlass::init_thread_offset()));
aoqi@1 395 __ bne(thread, AT, call_patch);
aoqi@1 396 __ delayed()->nop();
aoqi@1 397
aoqi@1 398 // access_field patches may execute the patched code before it's
aoqi@1 399 // copied back into place so we need to jump back into the main
aoqi@1 400 // code of the nmethod to continue execution.
aoqi@1 401 /* address temppc = __ pc();
aoqi@1 402 __ b(_patch_site_continuation);
aoqi@1 403 __ delayed()->nop();
aoqi@1 404 bytes_to_skip += (__ pc() - temppc);
aoqi@1 405 */
aoqi@1 406 __ b_far(_patch_site_continuation);
aoqi@1 407 __ delayed()->nop();
aoqi@1 408 bytes_to_skip += __ offset() - offset;
aoqi@1 409
aoqi@1 410 }
aoqi@1 411
aoqi@1 412 if (CommentedAssembly) {
aoqi@1 413 __ block_comment("patch data");
aoqi@1 414 }
aoqi@1 415 // Now emit the patch record telling the runtime how to find the
aoqi@1 416 // pieces of the patch. We only need 3 bytes but for alignment, we
aoqi@1 417 // need 4 bytes
aoqi@1 418 int sizeof_patch_record = 4;
aoqi@1 419 bytes_to_skip += sizeof_patch_record;
aoqi@1 420
aoqi@1 421 // emit the offsets needed to find the code to patch
aoqi@1 422 int being_initialized_entry_offset = __ pc() - being_initialized_entry + patch_info_size;
aoqi@1 423
aoqi@1 424 #ifdef _LP64
aoqi@1 425 /* Jin: In MIPS64, byte_skip is much larger than that in X86. It can not be contained in a byte:
aoqi@1 426 * - bytes_to_skip = 0x190;
aoqi@1 427 * - _bytes_to_copy = 0x20;
aoqi@1 428 * - being_initialized_entry_offset = 0x1b0;
aoqi@1 429 *
aoqi@1 430 * To minimize the modification of share codes, the values are decreased 4 times when generated,
aoqi@1 431 * thus can be packed into a long type.
aoqi@1 432 *
aoqi@1 433 * See [share/vm/c1/c1_Runtime1.cpp 918] Runtime1::patch_code()
aoqi@1 434 */
aoqi@1 435 being_initialized_entry_offset /= 4;
aoqi@1 436 _bytes_to_copy /= 4;
aoqi@1 437 bytes_to_skip /= 4;
aoqi@1 438 #endif
aoqi@1 439 // patch_info_pc offset | size of b instruction(8)| patched code size
aoqi@1 440 assert((char)being_initialized_entry_offset==being_initialized_entry_offset, "just check");
aoqi@1 441 assert((char)bytes_to_skip==bytes_to_skip, "just check");
aoqi@1 442 assert((char)_bytes_to_copy==_bytes_to_copy, "just check");
aoqi@1 443 __ emit_int32(being_initialized_entry_offset<<8 | (bytes_to_skip<<16) | (_bytes_to_copy<<24) );
aoqi@1 444
aoqi@1 445 address patch_info_pc = __ pc();
aoqi@1 446 #ifdef _LP64
aoqi@1 447 assert(patch_info_pc - end_of_patch == bytes_to_skip * 4, "incorrect patch info");
aoqi@1 448 #else
aoqi@1 449 assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info");
aoqi@1 450 #endif
aoqi@1 451
aoqi@1 452 address entry = __ pc();
aoqi@1 453 NativeGeneralJump::insert_unconditional((address)_pc_start, entry);
aoqi@1 454 address target = NULL;
aoqi@1 455 switch (_id) {
aoqi@1 456 case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); break;
aoqi@1 457 case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id); break;
aoqi@1 458 default: ShouldNotReachHere();
aoqi@1 459 }
aoqi@1 460 __ bind(call_patch);
aoqi@1 461
aoqi@1 462
aoqi@1 463 if (CommentedAssembly) {
aoqi@1 464 __ block_comment("patch entry point");
aoqi@1 465 }
aoqi@1 466 //__ call(RuntimeAddress(target));
aoqi@1 467 #ifndef _LP64
aoqi@1 468 //by_css
aoqi@1 469 __ lui(T9, Assembler::split_high((int)target));
aoqi@1 470 __ addiu(T9, T9, Assembler::split_low((int)target));
aoqi@1 471 #else
aoqi@1 472 __ li48(T9, (long)target);
aoqi@1 473 #endif
aoqi@1 474 __ jalr(T9);
aoqi@1 475 __ delayed()->nop();
aoqi@1 476 assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change");
aoqi@1 477 ce->add_call_info_here(_info);
aoqi@1 478 int jmp_off = __ offset();
aoqi@1 479 __ b_far(_patch_site_entry);
aoqi@1 480 __ delayed()->nop();
aoqi@1 481 // Add enough nops so deoptimization can overwrite the jmp above with a call
aoqi@1 482 // and not destroy the world.
aoqi@1 483 for (int j = __ offset(); j < jmp_off + NativeCall::instruction_size; j += 4 ) {
aoqi@1 484 __ nop();
aoqi@1 485 }
aoqi@1 486 if (_id == load_klass_id) {
aoqi@1 487 CodeSection* cs = __ code_section();
aoqi@1 488 address pc = (address)_pc_start;
aoqi@1 489 RelocIterator iter(cs, pc, pc + 1);
aoqi@1 490 relocInfo::change_reloc_info_for_address(&iter, pc, relocInfo::oop_type, relocInfo::none);
aoqi@1 491 }
aoqi@1 492 }
aoqi@1 493
aoqi@1 494
aoqi@1 495 void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {
aoqi@1 496 ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
aoqi@1 497 __ bind(_entry);
aoqi@1 498 __ call(Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id), relocInfo::runtime_call_type);
aoqi@1 499 __ delayed()->nop();
aoqi@1 500 ce->add_call_info_here(_info);
aoqi@1 501 debug_only(__ should_not_reach_here());
aoqi@1 502 }
aoqi@1 503
aoqi@1 504
aoqi@1 505 // i dont know which register to use here, i just assume A1 here. FIXME
aoqi@1 506 void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {
aoqi@1 507 assert(__ sp_offset() == 0, "frame size should be fixed");
aoqi@1 508
aoqi@1 509 __ bind(_entry);
aoqi@1 510 // pass the object on stack because all registers must be preserved
aoqi@1 511 if (_obj->is_cpu_register()) {
aoqi@1 512 ce->store_parameter(_obj->as_register(), 0);
aoqi@1 513 }
aoqi@1 514 __ call(Runtime1::entry_for(_stub), relocInfo::runtime_call_type);
aoqi@1 515 __ delayed()->nop();
aoqi@1 516 ce->add_call_info_here(_info);
aoqi@1 517 debug_only(__ should_not_reach_here());
aoqi@1 518 }
aoqi@1 519
aoqi@1 520 /*
aoqi@1 521 ArrayStoreExceptionStub::ArrayStoreExceptionStub(CodeEmitInfo* info):
aoqi@1 522 _info(info) {
aoqi@1 523 }
aoqi@1 524
aoqi@1 525
aoqi@1 526 void ArrayStoreExceptionStub::emit_code(LIR_Assembler* ce) {
aoqi@1 527 assert(__ sp_offset() == 0, "frame size should be fixed");
aoqi@1 528 __ bind(_entry);
aoqi@1 529 //__ call(RuntimeAddress(Runtime1::entry_for(Runtime1::throw_array_store_exception_id)));
aoqi@1 530 __ call(Runtime1::entry_for(Runtime1::throw_array_store_exception_id), relocInfo::runtime_call_type);
aoqi@1 531 __ delayed()->nop();
aoqi@1 532 ce->add_call_info_here(_info);
aoqi@1 533 debug_only(__ should_not_reach_here());
aoqi@1 534 }
aoqi@1 535
aoqi@1 536 */
aoqi@1 537 void ArrayCopyStub::emit_code(LIR_Assembler* ce) {
aoqi@1 538 //---------------slow case: call to native-----------------
aoqi@1 539 __ bind(_entry);
aoqi@1 540 // Figure out where the args should go
aoqi@1 541 // This should really convert the IntrinsicID to the methodOop and signature
aoqi@1 542 // but I don't know how to do that.
aoqi@1 543 //
aoqi@1 544 VMRegPair args[5];
aoqi@1 545 BasicType signature[5] = { T_OBJECT, T_INT, T_OBJECT, T_INT, T_INT};
aoqi@1 546 SharedRuntime::java_calling_convention(signature, args, 5, true);
aoqi@1 547
aoqi@1 548 // push parameters
aoqi@1 549 // (src, src_pos, dest, destPos, length)
aoqi@1 550 Register r[5];
aoqi@1 551 r[0] = src()->as_register();
aoqi@1 552 r[1] = src_pos()->as_register();
aoqi@1 553 r[2] = dst()->as_register();
aoqi@1 554 r[3] = dst_pos()->as_register();
aoqi@1 555 r[4] = length()->as_register();
aoqi@1 556
aoqi@1 557 // next registers will get stored on the stack
aoqi@1 558 for (int i = 0; i < 5 ; i++ ) {
aoqi@1 559 VMReg r_1 = args[i].first();
aoqi@1 560 if (r_1->is_stack()) {
aoqi@1 561 int st_off = r_1->reg2stack() * wordSize;
aoqi@1 562 //__ movptr (Address(rsp, st_off), r[i]);
aoqi@1 563 __ sw( r[i], SP, st_off);
aoqi@1 564 } else {
aoqi@1 565 assert(r[i] == args[i].first()->as_Register(), "Wrong register for arg ");
aoqi@1 566 }
aoqi@1 567 }
aoqi@1 568
aoqi@1 569 ce->align_call(lir_static_call);
aoqi@1 570
aoqi@1 571 ce->emit_static_call_stub();
aoqi@1 572 //AddressLiteral resolve(SharedRuntime::get_resolve_static_call_stub(),
aoqi@1 573 // relocInfo::static_call_type);
aoqi@1 574 //__ call(resolve);
aoqi@1 575 __ call(SharedRuntime::get_resolve_static_call_stub(), relocInfo::static_call_type);
aoqi@1 576 __ delayed()->nop();
aoqi@1 577 ce->add_call_info_here(info());
aoqi@1 578
aoqi@1 579 #ifndef PRODUCT
aoqi@1 580 //__ incrementl(ExternalAddress((address)&Runtime1::_arraycopy_slowcase_cnt));
aoqi@1 581 #ifndef _LP64
aoqi@1 582 __ lui(T8, Assembler::split_high((int)&Runtime1::_arraycopy_slowcase_cnt));
aoqi@1 583 __ lw(AT, T8, Assembler::split_low((int)&Runtime1::_arraycopy_slowcase_cnt));
aoqi@1 584 __ addiu(AT, AT, 1);
aoqi@1 585 __ sw(AT, T8, Assembler::split_low((int)&Runtime1::_arraycopy_slowcase_cnt));
aoqi@1 586 #else
aoqi@1 587 __ li(T8, (long)&Runtime1::_arraycopy_slowcase_cnt);
aoqi@1 588 __ lw(AT, T8, 0);
aoqi@1 589 __ daddiu(AT, AT, 1);
aoqi@1 590 __ sw(AT, T8, 0);
aoqi@1 591 #endif
aoqi@1 592 #endif
aoqi@1 593
aoqi@1 594 __ b_far(_continuation);
aoqi@1 595 __ delayed()->nop();
aoqi@1 596 }
aoqi@1 597
aoqi@1 598 /////////////////////////////////////////////////////////////////////////////
aoqi@1 599 #ifndef SERIALGC
aoqi@1 600
aoqi@1 601 void G1PreBarrierStub::emit_code(LIR_Assembler* ce) {
aoqi@1 602 Unimplemented();
aoqi@1 603 }
aoqi@1 604 /*
aoqi@1 605 jbyte* G1PostBarrierStub::_byte_map_base = NULL;
aoqi@1 606
aoqi@1 607 jbyte* G1PostBarrierStub::byte_map_base_slow() {
aoqi@1 608 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@1 609 assert(bs->is_a(BarrierSet::G1SATBCTLogging),
aoqi@1 610 "Must be if we're using this.");
aoqi@1 611 return ((G1SATBCardTableModRefBS*)bs)->byte_map_base;
aoqi@1 612 }
aoqi@1 613 */
aoqi@1 614 void G1PostBarrierStub::emit_code(LIR_Assembler* ce) {
aoqi@1 615 Unimplemented();
aoqi@1 616 }
aoqi@1 617
aoqi@1 618 #endif // SERIALGC
aoqi@1 619 /////////////////////////////////////////////////////////////////////////////
aoqi@1 620
aoqi@1 621 #undef __

mercurial